2009-08-09 21:16:39 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* Copyright 2009-2011 Jörg Hermann Müller
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
|
|
|
* This file is part of AudaSpace.
|
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* Audaspace is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
2009-08-09 21:16:39 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* AudaSpace is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-02-18 23:47:37 +00:00
|
|
|
* GNU General Public License for more details.
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Audaspace; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2009-08-09 21:16:39 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 10:21:56 +00:00
|
|
|
/** \file audaspace/intern/AUD_C-API.cpp
|
|
|
|
* \ingroup audaspaceintern
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-08-16 18:50:59 +00:00
|
|
|
// needed for INT64_C
|
|
|
|
#ifndef __STDC_CONSTANT_MACROS
|
|
|
|
#define __STDC_CONSTANT_MACROS
|
|
|
|
#endif
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-08-16 20:05:59 +00:00
|
|
|
#include "AUD_PyInit.h"
|
2010-07-09 12:35:40 +00:00
|
|
|
#include "AUD_PyAPI.h"
|
|
|
|
|
|
|
|
Device* g_device;
|
|
|
|
bool g_pyinitialized = false;
|
|
|
|
#endif
|
|
|
|
|
2010-08-16 15:38:55 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cmath>
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "AUD_NULLDevice.h"
|
|
|
|
#include "AUD_I3DDevice.h"
|
2009-08-21 19:39:28 +00:00
|
|
|
#include "AUD_FileFactory.h"
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "AUD_StreamBufferFactory.h"
|
|
|
|
#include "AUD_DelayFactory.h"
|
|
|
|
#include "AUD_LimiterFactory.h"
|
|
|
|
#include "AUD_PingPongFactory.h"
|
|
|
|
#include "AUD_LoopFactory.h"
|
2009-12-24 14:58:11 +00:00
|
|
|
#include "AUD_RectifyFactory.h"
|
2010-01-01 05:09:30 +00:00
|
|
|
#include "AUD_EnvelopeFactory.h"
|
|
|
|
#include "AUD_LinearResampleFactory.h"
|
|
|
|
#include "AUD_LowpassFactory.h"
|
|
|
|
#include "AUD_HighpassFactory.h"
|
2010-01-01 18:45:21 +00:00
|
|
|
#include "AUD_AccumulatorFactory.h"
|
|
|
|
#include "AUD_SumFactory.h"
|
|
|
|
#include "AUD_SquareFactory.h"
|
2010-01-01 05:09:30 +00:00
|
|
|
#include "AUD_ChannelMapperFactory.h"
|
|
|
|
#include "AUD_Buffer.h"
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "AUD_ReadDevice.h"
|
|
|
|
#include "AUD_IReader.h"
|
2010-02-07 23:41:17 +00:00
|
|
|
#include "AUD_SequencerFactory.h"
|
2010-08-02 18:22:34 +00:00
|
|
|
#include "AUD_SilenceFactory.h"
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
#ifdef WITH_SDL
|
|
|
|
#include "AUD_SDLDevice.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WITH_OPENAL
|
|
|
|
#include "AUD_OpenALDevice.h"
|
|
|
|
#endif
|
|
|
|
|
2009-08-16 14:53:11 +00:00
|
|
|
#ifdef WITH_JACK
|
|
|
|
#include "AUD_JackDevice.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-16 19:41:49 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
#ifdef WITH_FFMPEG
|
|
|
|
extern "C" {
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
#include <cassert>
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
typedef AUD_IFactory AUD_Sound;
|
|
|
|
typedef AUD_ReadDevice AUD_Device;
|
2010-07-09 12:35:40 +00:00
|
|
|
typedef AUD_Handle AUD_Channel;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
#define AUD_CAPI_IMPLEMENTATION
|
|
|
|
#include "AUD_C-API.h"
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static AUD_IDevice* AUD_device = NULL;
|
|
|
|
static AUD_I3DDevice* AUD_3ddevice = NULL;
|
|
|
|
|
2010-04-24 16:35:16 +00:00
|
|
|
void AUD_initOnce()
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_FFMPEG
|
|
|
|
av_register_all();
|
|
|
|
#endif
|
2010-04-24 16:35:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
|
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
AUD_IDevice* dev = NULL;
|
|
|
|
|
2009-08-26 10:02:17 +00:00
|
|
|
if(AUD_device)
|
|
|
|
AUD_exit();
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
switch(device)
|
|
|
|
{
|
|
|
|
case AUD_NULL_DEVICE:
|
|
|
|
dev = new AUD_NULLDevice();
|
|
|
|
break;
|
|
|
|
#ifdef WITH_SDL
|
|
|
|
case AUD_SDL_DEVICE:
|
2010-01-01 05:09:30 +00:00
|
|
|
dev = new AUD_SDLDevice(specs, buffersize);
|
|
|
|
break;
|
2009-08-09 21:16:39 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_OPENAL
|
|
|
|
case AUD_OPENAL_DEVICE:
|
|
|
|
dev = new AUD_OpenALDevice(specs, buffersize);
|
|
|
|
break;
|
2009-08-16 14:53:11 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
case AUD_JACK_DEVICE:
|
2010-08-03 08:07:21 +00:00
|
|
|
dev = new AUD_JackDevice("Blender", specs, buffersize);
|
2009-08-16 14:53:11 +00:00
|
|
|
break;
|
2009-08-09 21:16:39 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_device = dev;
|
2010-07-28 12:43:59 +00:00
|
|
|
AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-07-09 12:35:40 +00:00
|
|
|
if(g_pyinitialized)
|
|
|
|
{
|
|
|
|
g_device = (Device*)Device_empty();
|
|
|
|
if(g_device != NULL)
|
|
|
|
{
|
|
|
|
g_device->device = dev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_exit()
|
|
|
|
{
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-07-09 12:35:40 +00:00
|
|
|
if(g_device)
|
2009-08-11 13:07:24 +00:00
|
|
|
{
|
2010-07-09 12:35:40 +00:00
|
|
|
Py_XDECREF(g_device);
|
|
|
|
g_device = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if(AUD_device)
|
2009-08-11 13:07:24 +00:00
|
|
|
delete AUD_device;
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_device = NULL;
|
|
|
|
AUD_3ddevice = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2010-07-09 12:35:40 +00:00
|
|
|
static PyObject* AUD_getCDevice(PyObject* self)
|
|
|
|
{
|
|
|
|
if(g_device)
|
|
|
|
{
|
|
|
|
Py_INCREF(g_device);
|
|
|
|
return (PyObject*)g_device;
|
|
|
|
}
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2010-07-26 11:17:43 +00:00
|
|
|
static PyMethodDef meth_getcdevice[] = {{ "device", (PyCFunction)AUD_getCDevice, METH_NOARGS,
|
|
|
|
"device()\n\n"
|
2010-08-05 15:50:36 +00:00
|
|
|
"Returns the application's :class:`Device`.\n\n"
|
|
|
|
":return: The application's :class:`Device`.\n"
|
|
|
|
":rtype: :class:`Device`"}};
|
2010-07-09 12:35:40 +00:00
|
|
|
|
|
|
|
PyObject* AUD_initPython()
|
|
|
|
{
|
|
|
|
PyObject* module = PyInit_aud();
|
2010-07-26 11:17:43 +00:00
|
|
|
PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
|
2010-10-29 22:59:39 +00:00
|
|
|
PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
|
2010-07-09 12:35:40 +00:00
|
|
|
if(AUD_device)
|
|
|
|
{
|
|
|
|
g_device = (Device*)Device_empty();
|
|
|
|
if(g_device != NULL)
|
|
|
|
{
|
|
|
|
g_device->device = AUD_device;
|
|
|
|
}
|
2009-08-11 13:07:24 +00:00
|
|
|
}
|
2010-07-09 12:35:40 +00:00
|
|
|
g_pyinitialized = true;
|
|
|
|
|
|
|
|
return module;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-09 12:35:40 +00:00
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
void AUD_lock()
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
AUD_device->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_unlock()
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
AUD_device->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
AUD_SoundInfo info;
|
2010-08-16 13:13:05 +00:00
|
|
|
info.specs.channels = AUD_CHANNELS_INVALID;
|
|
|
|
info.specs.rate = AUD_RATE_INVALID;
|
|
|
|
info.length = 0.0f;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-08-16 13:13:05 +00:00
|
|
|
try
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-08-16 13:13:05 +00:00
|
|
|
AUD_IReader* reader = sound->createReader();
|
|
|
|
|
|
|
|
if(reader)
|
|
|
|
{
|
|
|
|
info.specs = reader->getSpecs();
|
|
|
|
info.length = reader->getLength() / (float) info.specs.rate;
|
2010-10-31 14:21:06 +00:00
|
|
|
delete reader;
|
2010-08-16 13:13:05 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-08-16 13:13:05 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_load(const char* filename)
|
|
|
|
{
|
|
|
|
assert(filename);
|
2009-08-21 19:39:28 +00:00
|
|
|
return new AUD_FileFactory(filename);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
|
|
|
|
{
|
|
|
|
assert(buffer);
|
2009-08-21 19:39:28 +00:00
|
|
|
return new AUD_FileFactory(buffer, size);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_StreamBufferFactory(sound);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_DelayFactory(sound, delay);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_LimiterFactory(sound, start, end);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_pingpongSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_PingPongFactory(sound);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_loopSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_LoopFactory(sound);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 10:03:08 +00:00
|
|
|
int AUD_setLoop(AUD_Channel* handle, int loops)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
if(handle)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2010-07-31 10:03:08 +00:00
|
|
|
return AUD_device->setLoopCount(handle, loops);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-31 10:03:08 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:58:11 +00:00
|
|
|
AUD_Sound* AUD_rectifySound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_RectifyFactory(sound);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-12-24 14:58:11 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
void AUD_unload(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
delete sound;
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_Channel* AUD_play(AUD_Sound* sound, int keep)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
assert(sound);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return AUD_device->play(sound, keep);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_pause(AUD_Channel* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->pause(handle);
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_resume(AUD_Channel* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->resume(handle);
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_stop(AUD_Channel* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
if(AUD_device)
|
|
|
|
return AUD_device->stop(handle);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_setKeep(AUD_Channel* handle, int keep)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->setKeep(handle, keep);
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_seek(AUD_Channel* handle, float seekTo)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->seek(handle, seekTo);
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
float AUD_getPosition(AUD_Channel* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->getPosition(handle);
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_Status AUD_getStatus(AUD_Channel* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
return AUD_device->getStatus(handle);
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setListenerLocation(const float* location)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_Vector3 v(location[0], location[1], location[2]);
|
|
|
|
AUD_3ddevice->setListenerLocation(v);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setListenerVelocity(const float* velocity)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
|
|
|
|
AUD_3ddevice->setListenerVelocity(v);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setListenerOrientation(const float* orientation)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-08-16 14:55:45 +00:00
|
|
|
AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]);
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_3ddevice->setListenerOrientation(q);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setSpeedOfSound(float speed)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_3ddevice->setSpeedOfSound(speed);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setDopplerFactor(float factor)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_3ddevice->setDopplerFactor(factor);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setDistanceModel(AUD_DistanceModel model)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_3ddevice->setDistanceModel(model);
|
|
|
|
return true;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setSourceLocation(AUD_Channel* handle, const float* location)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_Vector3 v(location[0], location[1], location[2]);
|
|
|
|
return AUD_3ddevice->setSourceLocation(handle, v);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setSourceVelocity(AUD_Channel* handle, const float* velocity)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
AUD_Vector3 v(velocity[0], velocity[1], velocity[2]);
|
|
|
|
return AUD_3ddevice->setSourceVelocity(handle, v);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setSourceOrientation(AUD_Channel* handle, const float* orientation)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-08-16 14:55:45 +00:00
|
|
|
AUD_Quaternion q(orientation[3], orientation[0], orientation[1], orientation[2]);
|
2010-07-30 22:20:08 +00:00
|
|
|
return AUD_3ddevice->setSourceOrientation(handle, q);
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setRelative(AUD_Channel* handle, int relative)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setRelative(handle, relative);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setVolumeMaximum(AUD_Channel* handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
return AUD_3ddevice->setVolumeMaximum(handle, volume);
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setVolumeMinimum(AUD_Channel* handle, float volume)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setVolumeMinimum(handle, volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setDistanceMaximum(AUD_Channel* handle, float distance)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-30 22:20:08 +00:00
|
|
|
return AUD_3ddevice->setDistanceMaximum(handle, distance);
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setDistanceReference(AUD_Channel* handle, float distance)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setDistanceReference(handle, distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setAttenuation(AUD_Channel* handle, float factor)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setAttenuation(handle, factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setConeAngleOuter(AUD_Channel* handle, float angle)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setConeAngleOuter(handle, angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setConeAngleInner(AUD_Channel* handle, float angle)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setConeAngleInner(handle, angle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_setConeVolumeOuter(AUD_Channel* handle, float volume)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
if(AUD_3ddevice)
|
|
|
|
{
|
|
|
|
return AUD_3ddevice->setConeVolumeOuter(handle, volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_setSoundVolume(AUD_Channel* handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
if(handle)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-07-28 12:43:59 +00:00
|
|
|
return AUD_device->setVolume(handle, volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&) {}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_setSoundPitch(AUD_Channel* handle, float pitch)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
if(handle)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-07-28 12:43:59 +00:00
|
|
|
return AUD_device->setPitch(handle, pitch);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&) {}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return new AUD_ReadDevice(specs);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_Channel* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_Channel* handle = device->play(sound);
|
2010-02-07 23:41:17 +00:00
|
|
|
device->seek(handle, seek);
|
|
|
|
return handle;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2009-09-20 14:00:00 +00:00
|
|
|
return NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 20:03:01 +00:00
|
|
|
int AUD_setDeviceVolume(AUD_Device* device, float volume)
|
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-07-28 12:43:59 +00:00
|
|
|
device->setVolume(volume);
|
|
|
|
return true;
|
2009-09-26 20:03:01 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&) {}
|
2010-10-31 14:21:06 +00:00
|
|
|
|
2009-09-28 05:02:09 +00:00
|
|
|
return false;
|
2009-09-26 20:03:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Channel* handle,
|
2009-09-20 14:00:00 +00:00
|
|
|
float volume)
|
|
|
|
{
|
|
|
|
if(handle)
|
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2010-07-28 12:43:59 +00:00
|
|
|
return device->setVolume(handle, volume);
|
2009-09-20 14:00:00 +00:00
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&) {}
|
2009-09-20 14:00:00 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
int AUD_readDevice(AUD_Device* device, data_t* buffer, int length)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(buffer);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return device->read(buffer, length);
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_closeReadDevice(AUD_Device* device)
|
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
delete device;
|
|
|
|
}
|
2010-07-28 09:36:03 +00:00
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
float* AUD_readSoundBuffer(const char* filename, float low, float high,
|
|
|
|
float attack, float release, float threshold,
|
2010-01-01 18:45:21 +00:00
|
|
|
int accumulate, int additive, int square,
|
|
|
|
float sthreshold, int samplerate, int* length)
|
2010-01-01 05:09:30 +00:00
|
|
|
{
|
|
|
|
AUD_Buffer buffer;
|
|
|
|
AUD_DeviceSpecs specs;
|
|
|
|
specs.channels = AUD_CHANNELS_MONO;
|
|
|
|
specs.rate = (AUD_SampleRate)samplerate;
|
2010-01-01 18:45:21 +00:00
|
|
|
AUD_Sound* sound;
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
AUD_FileFactory file(filename);
|
2010-10-31 14:44:45 +00:00
|
|
|
|
|
|
|
AUD_IReader* reader = file.createReader();
|
|
|
|
AUD_SampleRate rate = reader->getSpecs().rate;
|
|
|
|
delete reader;
|
|
|
|
|
2010-01-01 05:09:30 +00:00
|
|
|
AUD_ChannelMapperFactory mapper(&file, specs);
|
2010-10-31 14:44:45 +00:00
|
|
|
sound = &mapper;
|
|
|
|
AUD_LowpassFactory lowpass(sound, high);
|
|
|
|
if(high < rate)
|
|
|
|
sound = &lowpass;
|
|
|
|
AUD_HighpassFactory highpass(sound, low);
|
|
|
|
if(low > 0)
|
|
|
|
sound = &highpass;
|
|
|
|
AUD_EnvelopeFactory envelope(sound, attack, release, threshold, 0.1f);
|
2010-01-01 05:09:30 +00:00
|
|
|
AUD_LinearResampleFactory resampler(&envelope, specs);
|
2010-01-01 18:45:21 +00:00
|
|
|
sound = &resampler;
|
|
|
|
AUD_SquareFactory squaref(sound, sthreshold);
|
|
|
|
if(square)
|
|
|
|
sound = &squaref;
|
|
|
|
AUD_AccumulatorFactory accumulator(sound, additive);
|
|
|
|
AUD_SumFactory sum(sound);
|
|
|
|
if(accumulate)
|
|
|
|
sound = &accumulator;
|
|
|
|
else if(additive)
|
|
|
|
sound = ∑
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2010-10-31 14:44:45 +00:00
|
|
|
reader = sound->createReader();
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
if(reader == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int len;
|
|
|
|
int position = 0;
|
|
|
|
sample_t* readbuffer;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
len = samplerate;
|
|
|
|
buffer.resize((position + len) * sizeof(float), true);
|
|
|
|
reader->read(len, readbuffer);
|
|
|
|
memcpy(buffer.getBuffer() + position, readbuffer, len * sizeof(float));
|
|
|
|
position += len;
|
|
|
|
} while(len != 0);
|
|
|
|
delete reader;
|
|
|
|
|
|
|
|
float* result = (float*)malloc(position * sizeof(float));
|
|
|
|
memcpy(result, buffer.getBuffer(), position * sizeof(float));
|
|
|
|
*length = position;
|
|
|
|
return result;
|
|
|
|
}
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2010-08-02 18:22:34 +00:00
|
|
|
static void pauseSound(AUD_Channel* handle)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
AUD_device->pause(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Channel* AUD_pauseAfter(AUD_Channel* handle, float seconds)
|
|
|
|
{
|
|
|
|
assert(AUD_device);
|
|
|
|
|
|
|
|
AUD_SilenceFactory silence;
|
|
|
|
AUD_LimiterFactory limiter(&silence, 0, seconds);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
AUD_Channel* channel = AUD_device->play(&limiter);
|
|
|
|
AUD_device->setStopCallback(channel, (stopCallback)pauseSound, handle);
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-10 22:40:37 +00:00
|
|
|
AUD_Sound* AUD_createSequencer(int muted, void* data, AUD_volumeFunction volume)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2010-02-08 15:37:38 +00:00
|
|
|
/* AUD_XXX should be this: but AUD_createSequencer is called before the device
|
|
|
|
* is initialized.
|
|
|
|
|
|
|
|
return new AUD_SequencerFactory(AUD_device->getSpecs().specs, data, volume);
|
|
|
|
*/
|
|
|
|
AUD_Specs specs;
|
|
|
|
specs.channels = AUD_CHANNELS_STEREO;
|
|
|
|
specs.rate = AUD_RATE_44100;
|
2011-04-10 22:40:37 +00:00
|
|
|
return new AUD_SequencerFactory(specs, muted, data, volume);
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_destroySequencer(AUD_Sound* sequencer)
|
|
|
|
{
|
|
|
|
delete ((AUD_SequencerFactory*)sequencer);
|
|
|
|
}
|
|
|
|
|
2011-04-10 22:40:37 +00:00
|
|
|
void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted)
|
|
|
|
{
|
|
|
|
((AUD_SequencerFactory*)sequencer)->mute(muted);
|
|
|
|
}
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
|
|
|
|
float begin, float end, float skip, void* data)
|
|
|
|
{
|
|
|
|
return ((AUD_SequencerFactory*)sequencer)->add((AUD_IFactory**) sound, begin, end, skip, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry)
|
|
|
|
{
|
|
|
|
((AUD_SequencerFactory*)sequencer)->remove(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
|
|
|
|
float begin, float end, float skip)
|
|
|
|
{
|
|
|
|
((AUD_SequencerFactory*)sequencer)->move(entry, begin, end, skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry, char mute)
|
|
|
|
{
|
|
|
|
((AUD_SequencerFactory*)sequencer)->mute(entry, mute);
|
|
|
|
}
|
|
|
|
|
|
|
|
int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
|
|
|
|
{
|
|
|
|
AUD_DeviceSpecs specs;
|
|
|
|
sample_t* buf;
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
specs.rate = AUD_RATE_INVALID;
|
2010-02-07 23:41:17 +00:00
|
|
|
specs.channels = AUD_CHANNELS_MONO;
|
2010-07-28 09:36:03 +00:00
|
|
|
specs.format = AUD_FORMAT_INVALID;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
AUD_ChannelMapperFactory mapper(sound, specs);
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
AUD_IReader* reader = mapper.createReader();
|
2010-02-07 23:41:17 +00:00
|
|
|
|
|
|
|
int len = reader->getLength();
|
|
|
|
float samplejump = (float)len / (float)length;
|
|
|
|
float min, max;
|
|
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
len = floor(samplejump * (i+1)) - floor(samplejump * i);
|
|
|
|
reader->read(len, buf);
|
|
|
|
|
|
|
|
if(len < 1)
|
|
|
|
{
|
|
|
|
length = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
max = min = *buf;
|
|
|
|
for(int j = 1; j < len; j++)
|
|
|
|
{
|
|
|
|
if(buf[j] < min)
|
|
|
|
min = buf[j];
|
|
|
|
if(buf[j] > max)
|
|
|
|
max = buf[j];
|
|
|
|
buffer[i * 2] = min;
|
|
|
|
buffer[i * 2 + 1] = max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
delete reader;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2010-02-08 14:43:44 +00:00
|
|
|
|
2010-02-21 18:01:41 +00:00
|
|
|
void AUD_startPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
device->startPlayback();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_stopPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
device->stopPlayback();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
void AUD_seekSequencer(AUD_Channel* handle, float time)
|
2010-02-21 18:01:41 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
device->seekPlayback(time);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
AUD_device->seek(handle, time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
float AUD_getSequencerPosition(AUD_Channel* handle)
|
2010-02-21 18:01:41 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
return device->getPlaybackPosition();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
return AUD_device->getPosition(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-21 19:54:18 +00:00
|
|
|
#ifdef WITH_JACK
|
2010-02-21 18:01:41 +00:00
|
|
|
void AUD_setSyncCallback(AUD_syncFunction function, void* data)
|
|
|
|
{
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
device->setSyncCallback(function, data);
|
|
|
|
}
|
2010-02-21 19:54:18 +00:00
|
|
|
#endif
|
2010-02-21 18:01:41 +00:00
|
|
|
|
|
|
|
int AUD_doesPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
|
|
|
|
if(device)
|
|
|
|
return device->doesPlayback();
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|