2009-08-09 21:16:39 +00:00
|
|
|
/*
|
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
|
|
|
|
|
2013-12-30 12:19:27 +11:00
|
|
|
// quiet unudef define warning
|
|
|
|
#ifdef __STDC_CONSTANT_MACROS
|
|
|
|
// pass
|
|
|
|
#endif
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2013-03-22 14:31:03 +00:00
|
|
|
# include "AUD_PyInit.h"
|
|
|
|
# include "AUD_PyAPI.h"
|
2010-07-09 12:35:40 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-16 15:38:55 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cmath>
|
2012-04-28 13:16:29 +00:00
|
|
|
#include <sstream>
|
2014-11-24 18:18:35 +01:00
|
|
|
#include <iostream>
|
2010-08-16 15:38:55 +00:00
|
|
|
|
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"
|
2012-10-24 21:33:44 +00:00
|
|
|
#include "AUD_MutexLock.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"
|
2013-03-27 07:19:54 +00:00
|
|
|
#include "AUD_JackLibrary.h"
|
2009-08-16 14:53:11 +00:00
|
|
|
#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
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
typedef boost::shared_ptr<AUD_IFactory> AUD_Sound;
|
2014-11-15 22:15:06 +13:00
|
|
|
typedef boost::shared_ptr<AUD_IDevice> AUD_Device;
|
2012-11-05 14:24:35 +00:00
|
|
|
typedef boost::shared_ptr<AUD_IHandle> AUD_Handle;
|
|
|
|
typedef boost::shared_ptr<AUD_SequencerEntry> AUD_SEntry;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
#define AUD_CAPI_IMPLEMENTATION
|
|
|
|
#include "AUD_C-API.h"
|
|
|
|
|
|
|
|
#ifndef NULL
|
2012-09-14 23:11:47 +00:00
|
|
|
# define NULL (void *)0
|
2009-08-09 21:16:39 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
static boost::shared_ptr<AUD_IDevice> AUD_device;
|
2012-09-14 23:11:47 +00:00
|
|
|
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
|
2013-03-27 07:19:54 +00:00
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_jack_init();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_exitOnce()
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
AUD_jack_exit();
|
|
|
|
#endif
|
2010-04-24 16:35:16 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Device* AUD_init(const char* device, AUD_DeviceSpecs specs, int buffersize, const char* name)
|
2010-04-24 16:35:16 +00:00
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IDevice> dev;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (AUD_device.get()) {
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_exit(NULL);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2009-08-26 10:02:17 +00:00
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
std::string dname = device;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2014-03-03 23:57:59 +01:00
|
|
|
if(dname == "Null") {
|
2012-11-05 14:24:35 +00:00
|
|
|
dev = boost::shared_ptr<AUD_IDevice>(new AUD_NULLDevice());
|
2014-03-03 23:57:59 +01:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
#ifdef WITH_SDL
|
2014-03-03 23:57:59 +01:00
|
|
|
else if(dname == "SDL")
|
|
|
|
{
|
|
|
|
dev = boost::shared_ptr<AUD_IDevice>(new AUD_SDLDevice(specs, buffersize));
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_OPENAL
|
2014-03-03 23:57:59 +01:00
|
|
|
else if(dname == "OpenAL")
|
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
dev = boost::shared_ptr<AUD_IDevice>(new AUD_OpenALDevice(specs, buffersize));
|
2014-03-03 23:57:59 +01:00
|
|
|
}
|
2009-08-16 14:53:11 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_JACK
|
2014-03-03 23:57:59 +01:00
|
|
|
else if(dname == "Jack")
|
|
|
|
{
|
2011-12-14 06:15:52 +00:00
|
|
|
#ifdef __APPLE__
|
2011-12-14 08:01:24 +00:00
|
|
|
struct stat st;
|
2012-09-14 23:11:47 +00:00
|
|
|
if (stat("/Library/Frameworks/Jackmp.framework", &st) != 0) {
|
2011-12-14 08:38:21 +00:00
|
|
|
printf("Warning: Jack Framework not installed\n");
|
2014-11-15 22:15:06 +13:00
|
|
|
return NULL;
|
2011-12-14 08:38:21 +00:00
|
|
|
}
|
|
|
|
else
|
2011-12-14 06:15:52 +00:00
|
|
|
#endif
|
2013-03-27 07:19:54 +00:00
|
|
|
if (!AUD_jack_supported()) {
|
2014-03-03 23:57:59 +01:00
|
|
|
printf("Warning: Jack cllient not installed\n");
|
2014-11-15 22:15:06 +13:00
|
|
|
return NULL;
|
2013-03-27 07:19:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-03-03 23:57:59 +01:00
|
|
|
dev = boost::shared_ptr<AUD_IDevice>(new AUD_JackDevice(name, specs, buffersize));
|
2011-12-14 06:15:52 +00:00
|
|
|
}
|
2014-03-03 23:57:59 +01:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
#endif
|
2014-03-03 23:57:59 +01:00
|
|
|
else
|
|
|
|
{
|
2014-11-15 22:15:06 +13:00
|
|
|
return NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_device = dev;
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_3ddevice = dynamic_cast<AUD_I3DDevice *>(AUD_device.get());
|
2010-07-09 12:35:40 +00:00
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
return (AUD_Device*)1;
|
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
|
|
|
{
|
2014-11-15 22:15:06 +13:00
|
|
|
return NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_exit(AUD_Device* device)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
AUD_device = boost::shared_ptr<AUD_IDevice>();
|
2010-07-09 12:35:40 +00:00
|
|
|
AUD_3ddevice = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2012-09-14 23:11:47 +00:00
|
|
|
static PyObject *AUD_getCDevice(PyObject *self)
|
2010-07-09 12:35:40 +00:00
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
if (AUD_device.get()) {
|
2012-09-14 23:11:47 +00:00
|
|
|
Device *device = (Device *)Device_empty();
|
|
|
|
if (device != NULL) {
|
2012-11-05 14:24:35 +00:00
|
|
|
device->device = new boost::shared_ptr<AUD_IDevice>(AUD_device);
|
2012-09-14 23:11:47 +00:00
|
|
|
return (PyObject *)device;
|
2011-06-03 23:28:57 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
static PyMethodDef meth_getcdevice[] = {
|
|
|
|
{"device", (PyCFunction)AUD_getCDevice, METH_NOARGS,
|
|
|
|
"device()\n\n"
|
|
|
|
"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" {
|
2015-03-26 11:35:41 +01:00
|
|
|
extern void *BKE_sound_get_factory(void *sound);
|
2011-06-05 22:06:29 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
static PyObject *AUD_getSoundFromPointer(PyObject *self, PyObject *args)
|
2011-06-05 22:06:29 +00:00
|
|
|
{
|
|
|
|
long int lptr;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (PyArg_Parse(args, "l:_sound_from_pointer", &lptr)) {
|
|
|
|
if (lptr) {
|
2015-03-26 11:35:41 +01:00
|
|
|
boost::shared_ptr<AUD_IFactory>* factory = (boost::shared_ptr<AUD_IFactory>*) BKE_sound_get_factory((void *) lptr);
|
2011-06-05 22:06:29 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (factory) {
|
|
|
|
Factory *obj = (Factory *)Factory_empty();
|
|
|
|
if (obj) {
|
2012-11-05 14:24:35 +00:00
|
|
|
obj->factory = new boost::shared_ptr<AUD_IFactory>(*factory);
|
2012-09-14 23:11:47 +00:00
|
|
|
return (PyObject *) obj;
|
2011-06-05 22:06:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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`"}
|
|
|
|
};
|
2011-06-05 22:06:29 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
PyObject *AUD_initPython()
|
2010-07-09 12:35:40 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
PyObject *module = PyInit_aud();
|
|
|
|
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
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
void *AUD_getPythonSound(AUD_Sound *sound)
|
2011-06-16 09:13:29 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (sound) {
|
|
|
|
Factory *obj = (Factory *) Factory_empty();
|
|
|
|
if (obj) {
|
2012-11-05 14:24:35 +00:00
|
|
|
obj->factory = new boost::shared_ptr<AUD_IFactory>(*sound);
|
2012-09-14 23:11:47 +00:00
|
|
|
return (PyObject *) obj;
|
2011-06-16 09:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
AUD_Sound *AUD_getSoundFromPython(void *sound)
|
2011-06-16 09:13:29 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
Factory *factory = checkFactory((PyObject *)sound);
|
2011-06-16 09:13:29 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (!factory)
|
2011-06-16 09:13:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
return new boost::shared_ptr<AUD_IFactory>(*reinterpret_cast<boost::shared_ptr<AUD_IFactory>*>(factory->factory));
|
2011-06-16 09:13:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-09 12:35:40 +00:00
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Device_lock(AUD_Device* device)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
AUD_device->lock();
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Device_unlock(AUD_Device* device)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
AUD_device->unlock();
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Channels AUD_Device_getChannels(AUD_Device* device)
|
|
|
|
{
|
|
|
|
return AUD_device->getSpecs().channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_SampleRate AUD_Device_getRate(AUD_Device* device)
|
|
|
|
{
|
|
|
|
return AUD_device->getSpecs().rate;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_SoundInfo AUD_getInfo(AUD_Sound *sound)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IReader> reader = (*sound)->createReader();
|
2010-08-16 13:13:05 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (reader.get()) {
|
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
|
|
|
}
|
2014-11-24 18:18:35 +01:00
|
|
|
catch(AUD_Exception &ae)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2014-11-24 18:18:35 +01:00
|
|
|
std::cout << ae.str << std::endl;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_file(const char *filename)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_bufferFile(unsigned char *buffer, int size)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_cache(AUD_Sound *sound)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
2011-08-11 11:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_rechannel(AUD_Sound *sound, AUD_Channels channels)
|
2011-08-11 11:41:24 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2011-08-11 11:41:24 +00:00
|
|
|
AUD_DeviceSpecs specs;
|
2014-11-15 22:15:06 +13:00
|
|
|
specs.channels = channels;
|
2011-08-11 11:41:24 +00:00
|
|
|
specs.rate = AUD_RATE_INVALID;
|
|
|
|
specs.format = AUD_FORMAT_INVALID;
|
|
|
|
return new AUD_Sound(new AUD_ChannelMapperFactory(*sound, specs));
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
return NULL;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_delay(AUD_Sound *sound, float delay)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_limit(AUD_Sound *sound, float start, float end)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_pingpong(AUD_Sound *sound)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_loop(AUD_Sound *sound)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setLoopCount(AUD_Handle *handle, int loops)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2011-06-21 20:21:43 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_Sound *AUD_rectifySound(AUD_Sound *sound)
|
2009-12-24 14:58:11 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sound_free(AUD_Sound *sound)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
|
|
|
delete sound;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Handle *AUD_Device_play(AUD_Device* device, AUD_Sound *sound, int keep)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(sound);
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle = AUD_device->play(*sound, keep);
|
2012-11-05 14:24:35 +00:00
|
|
|
if (handle.get()) {
|
2011-06-21 20:24:40 +00:00
|
|
|
return new AUD_Handle(handle);
|
2012-09-14 23:11:47 +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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Device_stopAll(void* device)
|
2014-03-03 23:57:59 +01:00
|
|
|
{
|
|
|
|
AUD_device->stopAll();
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setPosition(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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
float AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Status AUD_Handle_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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setListenerLocation(const float location[3])
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setListenerVelocity(const float velocity[3])
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setListenerOrientation(const float orientation[4])
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setSpeedOfSound(void* device, float speed)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setDopplerFactor(void* device, float factor)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_setDistanceModel(void* device, AUD_DistanceModel model)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (AUD_3ddevice) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setLocation(AUD_Handle *handle, const float location[3])
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setVelocity(AUD_Handle *handle, const float velocity[3])
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setOrientation(AUD_Handle *handle, const float orientation[4])
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setRelative(AUD_Handle *handle, int relative)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setVolumeMaximum(AUD_Handle *handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setVolumeMinimum(AUD_Handle *handle, float volume)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setDistanceMaximum(AUD_Handle *handle, float distance)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setDistanceReference(AUD_Handle *handle, float distance)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setDistanceReference(distance);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setAttenuation(AUD_Handle *handle, float factor)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setAttenuation(factor);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setConeAngleOuter(AUD_Handle *handle, float angle)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setConeAngleOuter(angle);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setConeAngleInner(AUD_Handle *handle, float angle)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
2011-06-21 20:21:43 +00:00
|
|
|
return h->setConeAngleInner(angle);
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setConeVolumeOuter(AUD_Handle *handle, float volume)
|
2010-07-30 22:20:08 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_I3DHandle> h = boost::dynamic_pointer_cast<AUD_I3DHandle>(*handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (h.get()) {
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setVolume(AUD_Handle *handle, float volume)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Handle_setPitch(AUD_Handle *handle, float pitch)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
assert(handle);
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
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;
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_Device *AUD_openReadDevice(AUD_DeviceSpecs specs)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +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);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle = (*device)->play(*sound);
|
2012-11-05 14:24:35 +00:00
|
|
|
if (handle.get()) {
|
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
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
int AUD_setDeviceVolume(AUD_Device *device, float volume)
|
2009-09-26 20:03:01 +00:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
int AUD_Device_read(AUD_Device *device, data_t *buffer, int length)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
assert(device);
|
|
|
|
assert(buffer);
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2014-11-15 22:15:06 +13:00
|
|
|
return boost::dynamic_pointer_cast<AUD_ReadDevice>(*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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Device_free(AUD_Device *device)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2015-08-02 11:26:20 +02:00
|
|
|
if(device != &AUD_device)
|
|
|
|
delete device;
|
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-01-01 05:09:30 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
float *AUD_readSoundBuffer(const char *filename, float low, float high,
|
|
|
|
float attack, float release, float threshold,
|
|
|
|
int accumulate, int additive, int square,
|
|
|
|
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;
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IFactory> sound;
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IFactory> file = boost::shared_ptr<AUD_IFactory>(new AUD_FileFactory(filename));
|
2010-10-31 14:44:45 +00:00
|
|
|
|
2011-10-14 16:58:21 +00:00
|
|
|
int position = 0;
|
2010-10-31 14:44:45 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IReader> reader = file->createReader();
|
2011-06-03 23:28:57 +00:00
|
|
|
|
2011-10-14 16:58:21 +00:00
|
|
|
AUD_SampleRate rate = reader->getSpecs().rate;
|
2011-06-03 23:28:57 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_ChannelMapperFactory(file, specs));
|
2011-06-03 23:28:57 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (high < rate)
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_LowpassFactory(sound, high));
|
2012-09-14 23:11:47 +00:00
|
|
|
if (low > 0)
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_HighpassFactory(sound, low));
|
2011-06-03 23:28:57 +00:00
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f));
|
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_LinearResampleFactory(sound, specs));
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (square)
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_SquareFactory(sound, sthreshold));
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (accumulate)
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_AccumulatorFactory(sound, additive));
|
2012-09-14 23:11:47 +00:00
|
|
|
else if (additive)
|
2012-11-05 14:24:35 +00:00
|
|
|
sound = boost::shared_ptr<AUD_IFactory>(new AUD_SumFactory(sound));
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2011-10-14 16:58:21 +00:00
|
|
|
reader = sound->createReader();
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
if (!reader.get())
|
2011-10-14 16:58:21 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
int len;
|
|
|
|
bool eos;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
len = samplerate;
|
|
|
|
buffer.resize((position + len) * sizeof(float), true);
|
|
|
|
reader->read(len, eos, buffer.getBuffer() + position);
|
|
|
|
position += len;
|
|
|
|
} while(!eos);
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-01 05:09:30 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
float * result = (float *)malloc(position * sizeof(float));
|
2010-01-01 05:09:30 +00:00
|
|
|
memcpy(result, buffer.getBuffer(), position * sizeof(float));
|
|
|
|
*length = position;
|
|
|
|
return result;
|
|
|
|
}
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2012-09-14 23:11:47 +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
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_Handle *AUD_pauseAfter(AUD_Handle *handle, float seconds)
|
2010-08-02 18:22:34 +00:00
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IFactory> silence = boost::shared_ptr<AUD_IFactory>(new AUD_SilenceFactory);
|
|
|
|
boost::shared_ptr<AUD_IFactory> limiter = boost::shared_ptr<AUD_IFactory>(new AUD_LimiterFactory(silence, 0, seconds));
|
2010-08-02 18:22:34 +00:00
|
|
|
|
2012-10-24 21:33:44 +00:00
|
|
|
AUD_MutexLock lock(*AUD_device);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
2011-06-21 20:24:40 +00:00
|
|
|
AUD_Handle handle2 = AUD_device->play(limiter);
|
2012-11-05 14:24:35 +00:00
|
|
|
if (handle2.get()) {
|
2011-06-21 20:24:40 +00:00
|
|
|
handle2->setStopCallback((stopCallback)pauseSound, handle);
|
|
|
|
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
|
|
|
|
|
|
|
return NULL;
|
2010-08-02 18:22:34 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sequence_create(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;
|
2015-12-27 16:33:54 +01:00
|
|
|
specs.rate = AUD_RATE_48000;
|
2012-11-05 14:24:35 +00:00
|
|
|
AUD_Sound *sequencer = new AUD_Sound(boost::shared_ptr<AUD_SequencerFactory>(new AUD_SequencerFactory(specs, fps, muted)));
|
2011-07-26 13:56:31 +00:00
|
|
|
return sequencer;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_free(AUD_Sound *sequencer)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-06-03 23:28:57 +00:00
|
|
|
delete sequencer;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_setMuted(AUD_Sound *sequencer, int muted)
|
2011-04-10 22:40:37 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->mute(muted);
|
2011-04-10 22:40:37 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_setFPS(AUD_Sound *sequencer, float fps)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setFPS(fps);
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_SEntry *AUD_Sequence_add(AUD_Sound *sequencer, AUD_Sound *sound,
|
2012-09-14 23:11:47 +00:00
|
|
|
float begin, float end, float skip)
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
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));
|
2011-07-26 13:56:31 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_remove(AUD_Sound *sequencer, AUD_SEntry *entry)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_SequenceEntry_move(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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_SequenceEntry_setMuted(AUD_SEntry *entry, char mute)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
2011-07-26 13:56:31 +00:00
|
|
|
(*entry)->mute(mute);
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_SequenceEntry_setSound(AUD_SEntry *entry, AUD_Sound *sound)
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
if (sound)
|
2011-07-26 13:56:31 +00:00
|
|
|
(*entry)->setSound(*sound);
|
|
|
|
else
|
|
|
|
(*entry)->setSound(AUD_Sound());
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_SequenceEntry_setAnimationData(AUD_SEntry *entry, AUD_AnimateablePropertyType type, int frame, float *data, char animated)
|
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
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_AnimateableProperty *prop = (*entry)->getAnimProperty(type);
|
|
|
|
if (animated) {
|
|
|
|
if (frame >= 0)
|
2011-08-22 18:59:56 +00:00
|
|
|
prop->write(data, frame, 1);
|
|
|
|
}
|
2012-09-14 23:11:47 +00:00
|
|
|
else {
|
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
|
|
|
prop->write(data);
|
2012-09-14 23:11:47 +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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_setAnimationData(AUD_Sound *sequencer, AUD_AnimateablePropertyType type, int frame, float *data, char animated)
|
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
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_AnimateableProperty *prop = dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->getAnimProperty(type);
|
|
|
|
if (animated) {
|
|
|
|
if (frame >= 0) {
|
2011-08-22 18:59:56 +00:00
|
|
|
prop->write(data, frame, 1);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-08-22 18:59:56 +00:00
|
|
|
}
|
2012-09-14 23:11:47 +00:00
|
|
|
else {
|
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
|
|
|
prop->write(data);
|
2012-09-14 23:11:47 +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
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_setDistanceModel(AUD_Sound* sequence, AUD_DistanceModel value)
|
|
|
|
{
|
|
|
|
assert(sequence);
|
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequence->get())->setDistanceModel(static_cast<AUD_DistanceModel>(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_Sequence_setDopplerFactor(AUD_Sound* sequence, float value)
|
|
|
|
{
|
|
|
|
assert(sequence);
|
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequence->get())->setDopplerFactor(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_Sequence_setSpeedOfSound(AUD_Sound* sequence, float value)
|
|
|
|
{
|
|
|
|
assert(sequence);
|
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequence->get())->setSpeedOfSound(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setAttenuation(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setAttenuation(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setConeAngleInner(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setConeAngleInner(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setConeAngleOuter(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setConeAngleOuter(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setConeVolumeOuter(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setConeVolumeOuter(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setDistanceMaximum(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setDistanceMaximum(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setDistanceReference(AUD_SEntry* sequence_entry, float value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setDistanceReference(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setRelative(AUD_SEntry* sequence_entry, int value)
|
|
|
|
{
|
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setRelative(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SequenceEntry_setVolumeMaximum(AUD_SEntry* sequence_entry, float value)
|
2011-08-03 09:25:40 +00:00
|
|
|
{
|
2014-11-15 22:15:06 +13:00
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setVolumeMaximum(value);
|
2011-08-03 09:25:40 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_SequenceEntry_setVolumeMinimum(AUD_SEntry* sequence_entry, float value)
|
2011-08-03 09:25:40 +00:00
|
|
|
{
|
2014-11-15 22:15:06 +13:00
|
|
|
assert(sequence_entry);
|
|
|
|
(*sequence_entry)->setVolumeMinimum(value);
|
2011-08-03 09:25:40 +00:00
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
void AUD_setSequencerDeviceSpecs(AUD_Sound *sequencer)
|
2011-06-21 20:39:41 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(AUD_device->getSpecs().specs);
|
2011-06-21 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Sequence_setSpecs(AUD_Sound *sequencer, AUD_Specs specs)
|
2011-06-21 20:39:41 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(specs);
|
2011-06-21 20:39:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
void AUD_seekSynchronizer(AUD_Handle *handle, float time)
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
device->seekPlayback(time);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
(*handle)->seek(time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
float AUD_getSynchronizerPosition(AUD_Handle *handle)
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
return device->getPlaybackPosition();
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
assert(handle);
|
|
|
|
return (*handle)->getPosition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
void AUD_playSynchronizer()
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
device->startPlayback();
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
void AUD_stopSynchronizer()
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
device->stopPlayback();
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef WITH_JACK
|
2014-03-03 23:57:59 +01:00
|
|
|
void AUD_setSynchronizerCallback(AUD_syncFunction function, void *data)
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
device->setSyncCallback(function, data);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-03-03 23:57:59 +01:00
|
|
|
int AUD_isSynchronizerPlaying()
|
2011-07-26 13:56:31 +00:00
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
|
|
|
|
if (device) {
|
2011-07-26 13:56:31 +00:00
|
|
|
return device->doesPlayback();
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-07-26 13:56:31 +00:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-11-24 18:18:35 +01:00
|
|
|
int AUD_readSound(AUD_Sound *sound, sample_t *buffer, int length, int samples_per_second, short *interrupt)
|
2010-02-07 23:41:17 +00:00
|
|
|
{
|
|
|
|
AUD_DeviceSpecs specs;
|
2012-09-14 23:11:47 +00:00
|
|
|
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
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, specs).createReader();
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2011-08-09 14:10:32 +00:00
|
|
|
specs.specs = reader->getSpecs();
|
|
|
|
int len;
|
|
|
|
float samplejump = specs.rate / samples_per_second;
|
2011-10-10 14:59:13 +00:00
|
|
|
float min, max, power, overallmax;
|
2011-06-21 20:14:53 +00:00
|
|
|
bool eos;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2011-10-10 14:59:13 +00:00
|
|
|
overallmax = 0;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2010-02-07 23:41:17 +00:00
|
|
|
len = floor(samplejump * (i+1)) - floor(samplejump * i);
|
2011-06-14 12:13:19 +00:00
|
|
|
|
2014-11-24 18:18:35 +01:00
|
|
|
if (*interrupt) {
|
|
|
|
return 0;
|
|
|
|
}
|
2011-08-09 14:10:32 +00:00
|
|
|
aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs));
|
|
|
|
buf = aBuffer.getBuffer();
|
2011-06-14 12:13:19 +00:00
|
|
|
|
2011-06-21 20:14:53 +00:00
|
|
|
reader->read(len, eos, buf);
|
2010-02-07 23:41:17 +00:00
|
|
|
|
|
|
|
max = min = *buf;
|
2011-08-09 14:10:32 +00:00
|
|
|
power = *buf * *buf;
|
2012-09-14 23:11:47 +00:00
|
|
|
for (int j = 1; j < len; j++) {
|
|
|
|
if (buf[j] < min)
|
2010-02-07 23:41:17 +00:00
|
|
|
min = buf[j];
|
2012-09-14 23:11:47 +00:00
|
|
|
if (buf[j] > max)
|
2010-02-07 23:41:17 +00:00
|
|
|
max = buf[j];
|
2011-08-09 14:10:32 +00:00
|
|
|
power += buf[j] * buf[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[i * 3] = min;
|
|
|
|
buffer[i * 3 + 1] = max;
|
|
|
|
buffer[i * 3 + 2] = sqrt(power) / len;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (overallmax < max)
|
2011-10-10 14:59:13 +00:00
|
|
|
overallmax = max;
|
2012-09-14 23:11:47 +00:00
|
|
|
if (overallmax < -min)
|
2011-10-10 14:59:13 +00:00
|
|
|
overallmax = -min;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (eos) {
|
2011-08-09 14:10:32 +00:00
|
|
|
length = i;
|
|
|
|
break;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
if (overallmax > 1.0f) {
|
|
|
|
for (int i = 0; i < length * 3; i++) {
|
2011-10-10 14:59:13 +00:00
|
|
|
buffer[i] /= overallmax;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-07 23:41:17 +00:00
|
|
|
return length;
|
|
|
|
}
|
2010-02-08 14:43:44 +00:00
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
AUD_Sound *AUD_Sound_copy(AUD_Sound *sound)
|
2011-06-16 09:13:29 +00:00
|
|
|
{
|
2012-11-05 14:24:35 +00:00
|
|
|
return new boost::shared_ptr<AUD_IFactory>(*sound);
|
2011-06-16 09:13:29 +00:00
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2014-11-15 22:15:06 +13:00
|
|
|
void AUD_Handle_free(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
|
|
|
|
2012-09-14 23:11:47 +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)
|
2011-08-06 17:57:20 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
|
|
|
AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sound->get());
|
2011-08-06 17:57:20 +00:00
|
|
|
|
|
|
|
f->setSpecs(specs.specs);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IReader> reader = f->createQualityReader();
|
2011-08-06 17:57:20 +00:00
|
|
|
reader->seek(start);
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IWriter> writer = AUD_FileWriter::createWriter(filename, specs, format, codec, bitrate);
|
2011-08-06 17:57:20 +00:00
|
|
|
AUD_FileWriter::writeReader(reader, writer, length, buffersize);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
catch(AUD_Exception& e)
|
|
|
|
{
|
|
|
|
return e.str;
|
|
|
|
}
|
|
|
|
}
|
2011-08-07 11:54:58 +00:00
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
const char *AUD_mixdown_per_channel(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)
|
2012-04-28 13:16:29 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
|
|
|
AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sound->get());
|
2012-04-28 13:16:29 +00:00
|
|
|
|
|
|
|
f->setSpecs(specs.specs);
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
std::vector<boost::shared_ptr<AUD_IWriter> > writers;
|
2012-04-28 13:16:29 +00:00
|
|
|
|
|
|
|
int channels = specs.channels;
|
|
|
|
specs.channels = AUD_CHANNELS_MONO;
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
for (int i = 0; i < channels; i++) {
|
2012-04-28 13:16:29 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
std::string fn = filename;
|
|
|
|
size_t index = fn.find_last_of('.');
|
|
|
|
size_t index_slash = fn.find_last_of('/');
|
|
|
|
size_t index_backslash = fn.find_last_of('\\');
|
2012-09-14 23:11:47 +00:00
|
|
|
|
|
|
|
if ((index == std::string::npos) ||
|
|
|
|
((index < index_slash) && (index_slash != std::string::npos)) ||
|
|
|
|
((index < index_backslash) && (index_backslash != std::string::npos)))
|
|
|
|
{
|
2012-04-28 13:16:29 +00:00
|
|
|
stream << filename << "_" << (i + 1);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-04-28 13:16:29 +00:00
|
|
|
stream << fn.substr(0, index) << "_" << (i + 1) << fn.substr(index);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2012-04-28 13:16:29 +00:00
|
|
|
writers.push_back(AUD_FileWriter::createWriter(stream.str(), specs, format, codec, bitrate));
|
|
|
|
}
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
boost::shared_ptr<AUD_IReader> reader = f->createQualityReader();
|
2012-04-28 13:16:29 +00:00
|
|
|
reader->seek(start);
|
|
|
|
AUD_FileWriter::writeReader(reader, writers, length, buffersize);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
catch(AUD_Exception& e)
|
|
|
|
{
|
|
|
|
return e.str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-14 23:11:47 +00:00
|
|
|
AUD_Device *AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound *sequencer, float volume, float start)
|
2011-08-15 21:50:09 +00:00
|
|
|
{
|
2012-09-14 23:11:47 +00:00
|
|
|
try {
|
|
|
|
AUD_ReadDevice *device = new AUD_ReadDevice(specs);
|
2011-08-15 21:50:09 +00:00
|
|
|
device->setQuality(true);
|
|
|
|
device->setVolume(volume);
|
|
|
|
|
2015-11-03 19:24:17 +01:00
|
|
|
AUD_SequencerFactory *f = dynamic_cast<AUD_SequencerFactory *>(sequencer->get());
|
2011-08-15 21:50:09 +00:00
|
|
|
|
2015-11-03 19:24:17 +01:00
|
|
|
f->setSpecs(specs.specs);
|
|
|
|
|
|
|
|
AUD_Handle handle = device->play(f->createQualityReader());
|
2012-11-05 14:24:35 +00:00
|
|
|
if (handle.get()) {
|
2011-08-15 21:50:09 +00:00
|
|
|
handle->seek(start);
|
2012-09-14 23:11:47 +00:00
|
|
|
}
|
2011-08-15 21:50:09 +00:00
|
|
|
|
|
|
|
return new AUD_Device(device);
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-02 11:26:20 +02:00
|
|
|
AUD_Device *AUD_Device_getCurrent(void)
|
|
|
|
{
|
|
|
|
return &AUD_device;
|
|
|
|
}
|
|
|
|
|
2013-03-27 07:19:54 +00:00
|
|
|
int AUD_isJackSupported(void)
|
|
|
|
{
|
|
|
|
#ifdef WITH_JACK
|
|
|
|
return AUD_jack_supported();
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|