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"
|
|
|
|
#endif
|
|
|
|
|
2011-08-03 09:25:40 +00:00
|
|
|
#include <set>
|
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"
|
2011-06-21 20:21:43 +00:00
|
|
|
#include "AUD_I3DHandle.h"
|
2009-08-21 19:39:28 +00:00
|
|
|
#include "AUD_FileFactory.h"
|
2011-08-06 17:57:20 +00:00
|
|
|
#include "AUD_FileWriter.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"
|
2011-07-26 13:56:31 +00:00
|
|
|
#include "AUD_SequencerEntry.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
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
typedef AUD_Reference<AUD_IFactory> AUD_Sound;
|
|
|
|
typedef AUD_Reference<AUD_ReadDevice> AUD_Device;
|
2011-06-21 20:24:40 +00:00
|
|
|
typedef AUD_Reference<AUD_IHandle> AUD_Handle;
|
2011-06-03 23:28:57 +00:00
|
|
|
typedef AUD_Reference<AUD_SequencerEntry> AUD_SEntry;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
#define AUD_CAPI_IMPLEMENTATION
|
|
|
|
#include "AUD_C-API.h"
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define NULL 0
|
|
|
|
#endif
|
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
static AUD_Reference<AUD_IDevice> AUD_device;
|
|
|
|
static AUD_I3DDevice* AUD_3ddevice;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2011-07-26 13:56:31 +00:00
|
|
|
AUD_Reference<AUD_IDevice> dev;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
if(!AUD_device.isNull())
|
2009-08-26 10:02:17 +00:00
|
|
|
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;
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get());
|
2010-07-09 12:35:40 +00:00
|
|
|
|
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()
|
|
|
|
{
|
2011-07-26 13:56:31 +00:00
|
|
|
AUD_device = AUD_Reference<AUD_IDevice>();
|
2010-07-09 12:35:40 +00:00
|
|
|
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)
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
if(!AUD_device.isNull())
|
2010-07-09 12:35:40 +00:00
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
Device* device = (Device*)Device_empty();
|
|
|
|
if(device != NULL)
|
|
|
|
{
|
|
|
|
device->device = new AUD_Reference<AUD_IDevice>(AUD_device);
|
|
|
|
return (PyObject*)device;
|
|
|
|
}
|
2010-07-09 12:35:40 +00:00
|
|
|
}
|
2011-06-03 23:28:57 +00:00
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
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
|
|
|
|
2011-06-05 22:06:29 +00:00
|
|
|
extern "C" {
|
|
|
|
extern void* sound_get_factory(void* sound);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject* AUD_getSoundFromPointer(PyObject* self, PyObject* args)
|
|
|
|
{
|
|
|
|
long int lptr;
|
|
|
|
|
|
|
|
if(PyArg_Parse(args, "l:_sound_from_pointer", &lptr))
|
|
|
|
{
|
|
|
|
if(lptr)
|
|
|
|
{
|
|
|
|
AUD_Reference<AUD_IFactory>* factory = (AUD_Reference<AUD_IFactory>*) sound_get_factory((void*) lptr);
|
|
|
|
|
|
|
|
if(factory)
|
|
|
|
{
|
|
|
|
Factory* obj = (Factory*) Factory_empty();
|
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
obj->factory = new AUD_Reference<AUD_IFactory>(*factory);
|
|
|
|
return (PyObject*) obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef meth_sound_from_pointer[] = {{ "_sound_from_pointer", (PyCFunction)AUD_getSoundFromPointer, METH_O,
|
|
|
|
"_sound_from_pointer(pointer)\n\n"
|
|
|
|
"Returns the corresponding :class:`Factory` object.\n\n"
|
|
|
|
":arg pointer: The pointer to the bSound object as long.\n"
|
|
|
|
":type pointer: long\n"
|
|
|
|
":return: The corresponding :class:`Factory` object.\n"
|
|
|
|
":rtype: :class:`Factory`"}};
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
PyObject* AUD_initPython()
|
|
|
|
{
|
|
|
|
PyObject* module = PyInit_aud();
|
2011-06-05 22:06:29 +00:00
|
|
|
PyModule_AddObject(module, "device", (PyObject*)PyCFunction_New(meth_getcdevice, NULL));
|
|
|
|
PyModule_AddObject(module, "_sound_from_pointer", (PyObject*)PyCFunction_New(meth_sound_from_pointer, NULL));
|
2010-10-29 22:59:39 +00:00
|
|
|
PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
|
2010-07-09 12:35:40 +00:00
|
|
|
|
|
|
|
return module;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2011-06-16 09:13:29 +00:00
|
|
|
|
|
|
|
PyObject* AUD_getPythonFactory(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
if(sound)
|
|
|
|
{
|
|
|
|
Factory* obj = (Factory*) Factory_empty();
|
|
|
|
if(obj)
|
|
|
|
{
|
|
|
|
obj->factory = new AUD_Reference<AUD_IFactory>(*sound);
|
|
|
|
return (PyObject*) obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_getPythonSound(PyObject* sound)
|
|
|
|
{
|
|
|
|
Factory* factory = checkFactory(sound);
|
|
|
|
|
|
|
|
if(!factory)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return new AUD_Reference<AUD_IFactory>(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(factory->factory));
|
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
void AUD_lock()
|
|
|
|
{
|
|
|
|
AUD_device->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_unlock()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IReader> reader = (*sound)->createReader();
|
2010-08-16 13:13:05 +00:00
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
if(!reader.isNull())
|
2010-08-16 13:13:05 +00:00
|
|
|
{
|
|
|
|
info.specs = reader->getSpecs();
|
|
|
|
info.length = reader->getLength() / (float) info.specs.rate;
|
|
|
|
}
|
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);
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_FileFactory(filename));
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
|
|
|
|
{
|
|
|
|
assert(buffer);
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_FileFactory(buffer, size));
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_StreamBufferFactory(*sound));
|
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 NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_DelayFactory(*sound, delay));
|
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 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
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_LimiterFactory(*sound, start, end));
|
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 NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_pingpongSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_PingPongFactory(*sound));
|
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 NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_Sound* AUD_loopSound(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_LoopFactory(*sound));
|
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 NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setLoop(AUD_Handle* handle, int loops)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return (*handle)->setLoopCount(loops);
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
}
|
2011-06-21 20:21:43 +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
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Sound(new AUD_RectifyFactory(*sound));
|
2009-12-24 14:58:11 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle* AUD_play(AUD_Sound* sound, int keep)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
try
|
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle = AUD_device->play(*sound, keep);
|
|
|
|
if(!handle.isNull())
|
|
|
|
return new AUD_Handle(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
|
|
|
{
|
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
return NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_pause(AUD_Handle* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->pause();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_resume(AUD_Handle* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->resume();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_stop(AUD_Handle* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
int result = (*handle)->stop();
|
|
|
|
delete handle;
|
|
|
|
return result;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setKeep(AUD_Handle* handle, int keep)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->setKeep(keep);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_seek(AUD_Handle* handle, float seekTo)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->seek(seekTo);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
float AUD_getPosition(AUD_Handle* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->getPosition();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Status AUD_getStatus(AUD_Handle* handle)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
return (*handle)->getStatus();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
int AUD_setListenerLocation(const float* location)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setSourceLocation(AUD_Handle* handle, const float* location)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
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]);
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setSourceLocation(v);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2010-07-30 22:20:08 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setSourceVelocity(AUD_Handle* handle, const float* velocity)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
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]);
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setSourceVelocity(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
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setSourceOrientation(AUD_Handle* handle, const float* orientation)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
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]);
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setSourceOrientation(q);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setRelative(AUD_Handle* handle, int relative)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setRelative(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;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setVolumeMaximum(AUD_Handle* handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setVolumeMaximum(volume);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setVolumeMinimum(AUD_Handle* handle, float volume)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setVolumeMinimum(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;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setDistanceMaximum(AUD_Handle* handle, float distance)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setDistanceMaximum(distance);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setDistanceReference(AUD_Handle* handle, float distance)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setDistanceReference(distance);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setAttenuation(AUD_Handle* handle, float factor)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setAttenuation(factor);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setConeAngleOuter(AUD_Handle* handle, float angle)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setConeAngleOuter(angle);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setConeAngleInner(AUD_Handle* handle, float angle)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setConeAngleInner(angle);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setConeVolumeOuter(AUD_Handle* handle, float volume)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
AUD_Reference<AUD_I3DHandle> h(*handle);
|
|
|
|
|
|
|
|
if(!h.isNull())
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setConeVolumeOuter(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
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setSoundVolume(AUD_Handle* handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
try
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return (*handle)->setVolume(volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
catch(AUD_Exception&) {}
|
2009-08-09 21:16:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
int AUD_setSoundPitch(AUD_Handle* handle, float pitch)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
try
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
return (*handle)->setPitch(pitch);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2011-06-21 20:21:43 +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
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return new AUD_Device(new AUD_ReadDevice(specs));
|
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 NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(sound);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle = (*device)->play(*sound);
|
|
|
|
if(!handle.isNull())
|
2011-06-21 20:21:43 +00:00
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
handle->seek(seek);
|
|
|
|
return new AUD_Handle(handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
}
|
2011-06-21 20:21:43 +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
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
(*device)->setVolume(volume);
|
2010-07-28 12:43:59 +00:00
|
|
|
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-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
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
return (*device)->read(buffer, length);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2011-06-21 20:29:02 +00:00
|
|
|
float sthreshold, double 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;
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IFactory> sound;
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IFactory> file = new AUD_FileFactory(filename);
|
2010-10-31 14:44:45 +00:00
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IReader> reader = file->createReader();
|
2010-10-31 14:44:45 +00:00
|
|
|
AUD_SampleRate rate = reader->getSpecs().rate;
|
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_ChannelMapperFactory(file, specs);
|
|
|
|
|
2010-10-31 14:44:45 +00:00
|
|
|
if(high < rate)
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_LowpassFactory(sound, high);
|
2010-10-31 14:44:45 +00:00
|
|
|
if(low > 0)
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_HighpassFactory(sound, low);;
|
|
|
|
|
|
|
|
sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f);
|
|
|
|
sound = new AUD_LinearResampleFactory(sound, specs);
|
|
|
|
|
2010-01-01 18:45:21 +00:00
|
|
|
if(square)
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_SquareFactory(sound, sthreshold);
|
|
|
|
|
2010-01-01 18:45:21 +00:00
|
|
|
if(accumulate)
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_AccumulatorFactory(sound, additive);
|
2010-01-01 18:45:21 +00:00
|
|
|
else if(additive)
|
2011-06-03 23:28:57 +00:00
|
|
|
sound = new AUD_SumFactory(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
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
if(reader.isNull())
|
2010-01-01 05:09:30 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int len;
|
|
|
|
int position = 0;
|
2011-06-21 20:14:53 +00:00
|
|
|
bool eos;
|
2010-01-01 05:09:30 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
len = samplerate;
|
|
|
|
buffer.resize((position + len) * sizeof(float), true);
|
2011-06-21 20:14:53 +00:00
|
|
|
reader->read(len, eos, buffer.getBuffer() + position);
|
2010-01-01 05:09:30 +00:00
|
|
|
position += len;
|
2011-06-21 20:14:53 +00:00
|
|
|
} while(!eos);
|
2010-01-01 05:09:30 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
static void pauseSound(AUD_Handle* handle)
|
2010-08-02 18:22:34 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
(*handle)->pause();
|
2010-08-02 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds)
|
2010-08-02 18:22:34 +00:00
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IFactory> silence = new AUD_SilenceFactory;
|
|
|
|
AUD_Reference<AUD_IFactory> limiter = new AUD_LimiterFactory(silence, 0, seconds);
|
2010-08-02 18:22:34 +00:00
|
|
|
|
2011-06-21 20:21:43 +00:00
|
|
|
AUD_device->lock();
|
|
|
|
|
2010-08-02 18:22:34 +00:00
|
|
|
try
|
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle2 = AUD_device->play(limiter);
|
|
|
|
if(!handle2.isNull())
|
2011-06-21 20:21:43 +00:00
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
handle2->setStopCallback((stopCallback)pauseSound, handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
AUD_device->unlock();
|
2011-06-21 20:24:40 +00:00
|
|
|
return new AUD_Handle(handle2);
|
2011-06-21 20:21:43 +00:00
|
|
|
}
|
2010-08-02 18:22:34 +00:00
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
|
|
|
|
AUD_device->unlock();
|
|
|
|
|
|
|
|
return NULL;
|
2010-08-02 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
AUD_Sound* AUD_createSequencer(float fps, int muted)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-06-21 20:39:41 +00:00
|
|
|
// specs are changed at a later point!
|
2010-02-08 15:37:38 +00:00
|
|
|
AUD_Specs specs;
|
|
|
|
specs.channels = AUD_CHANNELS_STEREO;
|
|
|
|
specs.rate = AUD_RATE_44100;
|
2011-07-26 13:56:31 +00:00
|
|
|
AUD_Sound* sequencer = new AUD_Sound(AUD_Reference<AUD_SequencerFactory>(new AUD_SequencerFactory(specs, fps, muted)));
|
|
|
|
return sequencer;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_destroySequencer(AUD_Sound* sequencer)
|
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
delete sequencer;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2011-04-10 22:40:37 +00:00
|
|
|
void AUD_setSequencerMuted(AUD_Sound* sequencer, int muted)
|
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->mute(muted);
|
2011-04-10 22:40:37 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
void AUD_setSequencerFPS(AUD_Sound* sequencer, float fps)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setFPS(fps);
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
AUD_SEntry* AUD_addSequence(AUD_Sound* sequencer, AUD_Sound* sound,
|
|
|
|
float begin, float end, float skip)
|
|
|
|
{
|
|
|
|
if(!sound)
|
|
|
|
return new AUD_SEntry(((AUD_SequencerFactory*)sequencer->get())->add(AUD_Sound(), begin, end, skip));
|
|
|
|
return new AUD_SEntry(((AUD_SequencerFactory*)sequencer->get())->add(*sound, begin, end, skip));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_removeSequence(AUD_Sound* sequencer, AUD_SEntry* entry)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->remove(*entry);
|
2011-06-03 23:28:57 +00:00
|
|
|
delete entry;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
void AUD_moveSequence(AUD_SEntry* entry, float begin, float end, float skip)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-07-26 13:56:31 +00:00
|
|
|
(*entry)->move(begin, end, skip);
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
void AUD_muteSequence(AUD_SEntry* entry, char mute)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-07-26 13:56:31 +00:00
|
|
|
(*entry)->mute(mute);
|
|
|
|
}
|
|
|
|
|
2011-08-03 09:25:40 +00:00
|
|
|
void AUD_setRelativeSequence(AUD_SEntry* entry, char relative)
|
|
|
|
{
|
|
|
|
(*entry)->setRelative(relative);
|
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
void AUD_updateSequenceSound(AUD_SEntry* entry, AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
if(sound)
|
|
|
|
(*entry)->setSound(*sound);
|
|
|
|
else
|
|
|
|
(*entry)->setSound(AUD_Sound());
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
|
|
|
void AUD_setSequenceAnimData(AUD_SEntry* entry, AUD_AnimateablePropertyType type, int frame, float* data, char animated)
|
|
|
|
{
|
|
|
|
AUD_AnimateableProperty* prop = (*entry)->getAnimProperty(type);
|
|
|
|
if(animated)
|
|
|
|
prop->write(data, frame, 1);
|
|
|
|
else
|
|
|
|
prop->write(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_setSequencerAnimData(AUD_Sound* sequencer, AUD_AnimateablePropertyType type, int frame, float* data, char animated)
|
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
AUD_AnimateableProperty* prop = dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->getAnimProperty(type);
|
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
|
|
|
if(animated)
|
|
|
|
prop->write(data, frame, 1);
|
|
|
|
else
|
|
|
|
prop->write(data);
|
|
|
|
}
|
|
|
|
|
2011-08-03 09:25:40 +00:00
|
|
|
void AUD_updateSequenceData(AUD_SEntry* entry, float volume_max, float volume_min,
|
|
|
|
float distance_max, float distance_reference, float attenuation,
|
|
|
|
float cone_angle_outer, float cone_angle_inner, float cone_volume_outer)
|
|
|
|
{
|
|
|
|
(*entry)->updateAll(volume_max, volume_min, distance_max, distance_reference, attenuation,
|
|
|
|
cone_angle_outer, cone_angle_inner, cone_volume_outer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_updateSequencerData(AUD_Sound* sequencer, float speed_of_sound,
|
|
|
|
float factor, AUD_DistanceModel model)
|
|
|
|
{
|
|
|
|
AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sequencer->get());
|
|
|
|
f->setSpeedOfSound(speed_of_sound);
|
|
|
|
f->setDopplerFactor(factor);
|
|
|
|
f->setDistanceModel(model);
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:39:41 +00:00
|
|
|
void AUD_setSequencerDeviceSpecs(AUD_Sound* sequencer)
|
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(AUD_device->getSpecs().specs);
|
2011-06-21 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_setSequencerSpecs(AUD_Sound* sequencer, AUD_Specs specs)
|
|
|
|
{
|
2011-08-03 09:25:40 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory*>(sequencer->get())->setSpecs(specs);
|
2011-06-21 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 13:56:31 +00:00
|
|
|
void AUD_seekSequencer(AUD_Handle* handle, float time)
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
device->seekPlayback(time);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
(*handle)->seek(time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float AUD_getSequencerPosition(AUD_Handle* handle)
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
return device->getPlaybackPosition();
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
return (*handle)->getPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_startPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
device->startPlayback();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_stopPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
device->stopPlayback();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
void AUD_setSyncCallback(AUD_syncFunction function, void* data)
|
|
|
|
{
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
device->setSyncCallback(function, data);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int AUD_doesPlayback()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device.get());
|
|
|
|
if(device)
|
|
|
|
return device->doesPlayback();
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length)
|
|
|
|
{
|
|
|
|
AUD_DeviceSpecs specs;
|
|
|
|
sample_t* buf;
|
2011-06-14 12:13:19 +00:00
|
|
|
AUD_Buffer aBuffer;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
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
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_Reference<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, specs).createReader();
|
2010-02-07 23:41:17 +00:00
|
|
|
|
|
|
|
int len = reader->getLength();
|
|
|
|
float samplejump = (float)len / (float)length;
|
|
|
|
float min, max;
|
2011-06-21 20:14:53 +00:00
|
|
|
bool eos;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
len = floor(samplejump * (i+1)) - floor(samplejump * i);
|
2011-06-14 12:13:19 +00:00
|
|
|
|
|
|
|
if(aBuffer.getSize() < len * AUD_SAMPLE_SIZE(reader->getSpecs()))
|
|
|
|
{
|
|
|
|
aBuffer.resize(len * AUD_SAMPLE_SIZE(reader->getSpecs()));
|
|
|
|
buf = aBuffer.getBuffer();
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:14:53 +00:00
|
|
|
reader->read(len, eos, buf);
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2011-06-21 20:14:53 +00:00
|
|
|
if(eos)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
2010-02-08 14:43:44 +00:00
|
|
|
|
2011-06-16 09:13:29 +00:00
|
|
|
AUD_Sound* AUD_copy(AUD_Sound* sound)
|
|
|
|
{
|
|
|
|
return new AUD_Reference<AUD_IFactory>(*sound);
|
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2011-06-21 20:24:40 +00:00
|
|
|
void AUD_freeHandle(AUD_Handle* handle)
|
2011-06-21 20:21:43 +00:00
|
|
|
{
|
2011-06-21 20:24:40 +00:00
|
|
|
delete handle;
|
2011-06-21 20:21:43 +00:00
|
|
|
}
|
2011-08-03 09:25:40 +00:00
|
|
|
|
|
|
|
void* AUD_createSet()
|
|
|
|
{
|
|
|
|
return new std::set<void*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_destroySet(void* set)
|
|
|
|
{
|
|
|
|
delete reinterpret_cast<std::set<void*>*>(set);
|
|
|
|
}
|
|
|
|
|
|
|
|
char AUD_removeSet(void* set, void* entry)
|
|
|
|
{
|
|
|
|
if(set)
|
|
|
|
return reinterpret_cast<std::set<void*>*>(set)->erase(entry);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_addSet(void* set, void* entry)
|
|
|
|
{
|
|
|
|
if(entry)
|
|
|
|
reinterpret_cast<std::set<void*>*>(set)->insert(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* AUD_getSet(void* set)
|
|
|
|
{
|
|
|
|
if(set)
|
|
|
|
{
|
|
|
|
std::set<void*>* rset = reinterpret_cast<std::set<void*>*>(set);
|
|
|
|
if(!rset->empty())
|
|
|
|
{
|
|
|
|
std::set<void*>::iterator it = rset->begin();
|
|
|
|
void* result = *it;
|
|
|
|
rset->erase(it);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-08-06 17:57:20 +00:00
|
|
|
|
|
|
|
const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sound->get());
|
|
|
|
|
|
|
|
f->setSpecs(specs.specs);
|
|
|
|
AUD_Reference<AUD_IReader> reader = f->createReader();
|
|
|
|
reader->seek(start);
|
|
|
|
AUD_Reference<AUD_IWriter> writer = AUD_FileWriter::createWriter(filename, specs, format, codec, bitrate);
|
|
|
|
AUD_FileWriter::writeReader(reader, writer, length, buffersize);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
catch(AUD_Exception& e)
|
|
|
|
{
|
|
|
|
return e.str;
|
|
|
|
}
|
|
|
|
}
|