4 * ***** BEGIN LGPL LICENSE BLOCK *****
6 * Copyright 2009 Jörg Hermann Müller
8 * This file is part of AudaSpace.
10 * AudaSpace is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * AudaSpace is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
23 * ***** END LGPL LICENSE BLOCK *****
26 #include "AUD_NULLDevice.h"
27 #include "AUD_I3DDevice.h"
28 #include "AUD_FileFactory.h"
29 #include "AUD_StreamBufferFactory.h"
30 #include "AUD_DelayFactory.h"
31 #include "AUD_LimiterFactory.h"
32 #include "AUD_PingPongFactory.h"
33 #include "AUD_LoopFactory.h"
34 #include "AUD_ReadDevice.h"
35 #include "AUD_SourceCaps.h"
36 #include "AUD_IReader.h"
39 #include "AUD_SDLDevice.h"
40 #include "AUD_FloatMixer.h"
44 #include "AUD_OpenALDevice.h"
48 #include "AUD_JackDevice.h"
53 #include <libavformat/avformat.h>
59 typedef AUD_IFactory AUD_Sound;
60 typedef AUD_ReadDevice AUD_Device;
62 #define AUD_CAPI_IMPLEMENTATION
63 #include "AUD_C-API.h"
69 static AUD_IDevice* AUD_device = NULL;
70 static int AUD_available_devices[4];
71 static AUD_I3DDevice* AUD_3ddevice = NULL;
73 int AUD_init(AUD_DeviceType device, AUD_Specs specs, int buffersize)
78 AUD_IDevice* dev = NULL;
88 dev = new AUD_NULLDevice();
93 dev = new AUD_SDLDevice(specs, buffersize);
94 AUD_FloatMixer* mixer = new AUD_FloatMixer();
95 ((AUD_SDLDevice*)dev)->setMixer(mixer);
100 case AUD_OPENAL_DEVICE:
101 dev = new AUD_OpenALDevice(specs, buffersize);
105 case AUD_JACK_DEVICE:
106 dev = new AUD_JackDevice(specs);
114 if(AUD_device->checkCapability(AUD_CAPS_3D_DEVICE))
115 AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device);
125 int* AUD_enumDevices()
129 AUD_available_devices[i++] = AUD_SDL_DEVICE;
132 AUD_available_devices[i++] = AUD_OPENAL_DEVICE;
135 AUD_available_devices[i++] = AUD_JACK_DEVICE;
137 AUD_available_devices[i++] = AUD_NULL_DEVICE;
138 return AUD_available_devices;
160 AUD_device->unlock();
163 AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
167 AUD_IReader* reader = sound->createReader();
173 info.specs = reader->getSpecs();
174 info.length = reader->getLength() / (float) info.specs.rate;
178 info.specs.channels = AUD_CHANNELS_INVALID;
179 info.specs.format = AUD_FORMAT_INVALID;
180 info.specs.rate = AUD_RATE_INVALID;
187 AUD_Sound* AUD_load(const char* filename)
190 return new AUD_FileFactory(filename);
193 AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
196 return new AUD_FileFactory(buffer, size);
199 AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
205 return new AUD_StreamBufferFactory(sound);
213 AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay)
219 return new AUD_DelayFactory(sound, delay);
227 extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end)
233 return new AUD_LimiterFactory(sound, start, end);
241 AUD_Sound* AUD_pingpongSound(AUD_Sound* sound)
247 return new AUD_PingPongFactory(sound);
255 AUD_Sound* AUD_loopSound(AUD_Sound* sound)
261 return new AUD_LoopFactory(sound);
269 int AUD_stopLoop(AUD_Handle* handle)
274 message.type = AUD_MSG_LOOP;
275 message.loopcount = 0;
279 return AUD_device->sendMessage(handle, message);
288 void AUD_unload(AUD_Sound* sound)
294 AUD_Handle* AUD_play(AUD_Sound* sound, int keep)
300 return AUD_device->play(sound, keep);
308 int AUD_pause(AUD_Handle* handle)
311 return AUD_device->pause(handle);
314 int AUD_resume(AUD_Handle* handle)
317 return AUD_device->resume(handle);
320 int AUD_stop(AUD_Handle* handle)
323 return AUD_device->stop(handle);
327 int AUD_setKeep(AUD_Handle* handle, int keep)
330 return AUD_device->setKeep(handle, keep);
333 int AUD_seek(AUD_Handle* handle, float seekTo)
336 return AUD_device->seek(handle, seekTo);
339 float AUD_getPosition(AUD_Handle* handle)
342 return AUD_device->getPosition(handle);
345 AUD_Status AUD_getStatus(AUD_Handle* handle)
348 return AUD_device->getStatus(handle);
351 AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep)
359 return AUD_3ddevice->play3D(sound, keep);
361 return AUD_device->play(sound, keep);
369 int AUD_updateListener(AUD_3DData* data)
377 return AUD_3ddevice->updateListener(*data);
385 int AUD_set3DSetting(AUD_3DSetting setting, float value)
392 return AUD_3ddevice->setSetting(setting, value);
400 float AUD_get3DSetting(AUD_3DSetting setting)
407 return AUD_3ddevice->getSetting(setting);
415 int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data)
425 return AUD_3ddevice->updateSource(handle, *data);
434 int AUD_set3DSourceSetting(AUD_Handle* handle,
435 AUD_3DSourceSetting setting, float value)
444 return AUD_3ddevice->setSourceSetting(handle, setting, value);
453 float AUD_get3DSourceSetting(AUD_Handle* handle, AUD_3DSourceSetting setting)
462 return AUD_3ddevice->getSourceSetting(handle, setting);
471 int AUD_setSoundVolume(AUD_Handle* handle, float volume)
477 caps.handle = handle;
482 return AUD_device->setCapability(AUD_CAPS_SOURCE_VOLUME, &caps);
484 catch(AUD_Exception) {}
489 int AUD_setSoundPitch(AUD_Handle* handle, float pitch)
495 caps.handle = handle;
500 return AUD_device->setCapability(AUD_CAPS_SOURCE_PITCH, &caps);
502 catch(AUD_Exception) {}
507 AUD_Device* AUD_openReadDevice(AUD_Specs specs)
511 return new AUD_ReadDevice(specs);
519 AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound)
526 return device->play(sound);
534 int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Handle* handle,
541 caps.handle = handle;
546 return device->setCapability(AUD_CAPS_SOURCE_VOLUME, &caps);
548 catch(AUD_Exception) {}
553 int AUD_readDevice(AUD_Device* device, sample_t* buffer, int length)
560 return device->read(buffer, length);
568 void AUD_closeReadDevice(AUD_Device* device)