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 *****
33 #include "AUD_Space.h"
49 #ifndef AUD_CAPI_IMPLEMENTATION
50 typedef void AUD_Sound;
51 typedef void AUD_Handle;
52 typedef void AUD_Device;
53 typedef void AUD_SequencerEntry;
54 typedef float (*AUD_volumeFunction)(void*, void*, float);
55 typedef void (*AUD_syncFunction)(void*, int, float);
59 * Initializes FFMPEG if it is enabled.
61 extern void AUD_initOnce();
64 * Initializes an audio device.
65 * \param device The device type that should be used.
66 * \param specs The audio specification to be used.
67 * \param buffersize The buffersize for the device.
68 * \return Whether the device has been initialized.
70 extern int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize);
73 * Returns a integer list with available sound devices. The last one is always
76 extern int* AUD_enumDevices();
79 * Unitinitializes an audio device.
81 extern void AUD_exit();
84 * Locks the playback device.
86 extern void AUD_lock();
91 extern void AUD_unlock();
94 * Returns information about a sound.
95 * \param sound The sound to get the info about.
96 * \return The AUD_SoundInfo structure with filled in data.
98 extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound);
101 * Loads a sound file.
102 * \param filename The filename of the sound file.
103 * \return A handle of the sound file.
105 extern AUD_Sound* AUD_load(const char* filename);
108 * Loads a sound file.
109 * \param buffer The buffer which contains the sound file.
110 * \param size The size of the buffer.
111 * \return A handle of the sound file.
113 extern AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size);
117 * \param sound The sound to buffer.
118 * \return A handle of the sound buffer.
120 extern AUD_Sound* AUD_bufferSound(AUD_Sound* sound);
124 * \param sound The sound to dealy.
125 * \param delay The delay in seconds.
126 * \return A handle of the delayed sound.
128 extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay);
132 * \param sound The sound to limit.
133 * \param start The start time in seconds.
134 * \param end The stop time in seconds.
135 * \return A handle of the limited sound.
137 extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end);
140 * Ping pongs a sound.
141 * \param sound The sound to ping pong.
142 * \return A handle of the ping pong sound.
144 extern AUD_Sound* AUD_pingpongSound(AUD_Sound* sound);
148 * \param sound The sound to loop.
149 * \return A handle of the looped sound.
151 extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
154 * Sets a remaining loop count of a looping sound that currently plays.
155 * \param handle The playback handle.
156 * \param loops The count of remaining loops, -1 for infinity.
157 * \param time The time after which playback should stop, -1 for infinity.
158 * \return Whether the handle is valid.
160 extern int AUD_setLoop(AUD_Handle* handle, int loops, float time);
164 * \param sound The sound to rectify.
165 * \return A handle of the rectified sound.
167 extern AUD_Sound* AUD_rectifySound(AUD_Sound* sound);
170 * Unloads a sound of any type.
171 * \param sound The handle of the sound.
173 extern void AUD_unload(AUD_Sound* sound);
176 * Plays back a sound file.
177 * \param sound The handle of the sound file.
178 * \param keep When keep is true the sound source will not be deleted but set to
179 * paused when its end has been reached.
180 * \return A handle to the played back sound.
182 extern AUD_Handle* AUD_play(AUD_Sound* sound, int keep);
185 * Pauses a played back sound.
186 * \param handle The handle to the sound.
187 * \return Whether the handle has been playing or not.
189 extern int AUD_pause(AUD_Handle* handle);
192 * Resumes a paused sound.
193 * \param handle The handle to the sound.
194 * \return Whether the handle has been paused or not.
196 extern int AUD_resume(AUD_Handle* handle);
199 * Stops a playing or paused sound.
200 * \param handle The handle to the sound.
201 * \return Whether the handle has been valid or not.
203 extern int AUD_stop(AUD_Handle* handle);
206 * Sets the end behaviour of a playing or paused sound.
207 * \param handle The handle to the sound.
208 * \param keep When keep is true the sound source will not be deleted but set to
209 * paused when its end has been reached.
210 * \return Whether the handle has been valid or not.
212 extern int AUD_setKeep(AUD_Handle* handle, int keep);
215 * Seeks a playing or paused sound.
216 * \param handle The handle to the sound.
217 * \param seekTo From where the sound file should be played back in seconds.
218 * \return Whether the handle has been valid or not.
220 extern int AUD_seek(AUD_Handle* handle, float seekTo);
223 * Retrieves the playback position of a handle.
224 * \param handle The handle to the sound.
225 * \return The current playback position in seconds or 0.0 if the handle is
228 extern float AUD_getPosition(AUD_Handle* handle);
231 * Returns the status of a playing, paused or stopped sound.
232 * \param handle The handle to the sound.
233 * \return The status of the sound behind the handle.
235 extern AUD_Status AUD_getStatus(AUD_Handle* handle);
239 * \param sound The handle of the sound file.
240 * \param keep When keep is true the sound source will not be deleted but set to
241 * paused when its end has been reached.
242 * \return A handle to the played back sound.
243 * \note The factory must provide a mono (single channel) source and the device
244 * must support 3D audio, otherwise the sound is played back normally.
246 extern AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep);
249 * Updates the listener 3D data.
250 * \param data The 3D data.
251 * \return Whether the action succeeded.
253 extern int AUD_updateListener(AUD_3DData* data);
256 * Sets a 3D device setting.
257 * \param setting The setting type.
258 * \param value The new setting value.
259 * \return Whether the action succeeded.
261 extern int AUD_set3DSetting(AUD_3DSetting setting, float value);
264 * Retrieves a 3D device setting.
265 * \param setting The setting type.
266 * \return The setting value.
268 extern float AUD_get3DSetting(AUD_3DSetting setting);
271 * Updates a listeners 3D data.
272 * \param handle The source handle.
273 * \param data The 3D data.
274 * \return Whether the action succeeded.
276 extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
279 * Sets a 3D source setting.
280 * \param handle The source handle.
281 * \param setting The setting type.
282 * \param value The new setting value.
283 * \return Whether the action succeeded.
285 extern int AUD_set3DSourceSetting(AUD_Handle* handle,
286 AUD_3DSourceSetting setting, float value);
289 * Retrieves a 3D source setting.
290 * \param handle The source handle.
291 * \param setting The setting type.
292 * \return The setting value.
294 extern float AUD_get3DSourceSetting(AUD_Handle* handle,
295 AUD_3DSourceSetting setting);
298 * Sets the volume of a played back sound.
299 * \param handle The handle to the sound.
300 * \param volume The new volume, must be between 0.0 and 1.0.
301 * \return Whether the action succeeded.
303 extern int AUD_setSoundVolume(AUD_Handle* handle, float volume);
306 * Sets the pitch of a played back sound.
307 * \param handle The handle to the sound.
308 * \param pitch The new pitch.
309 * \return Whether the action succeeded.
311 extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch);
314 * Opens a read device, with which audio data can be read.
315 * \param specs The specification of the audio data.
316 * \return A device handle.
318 extern AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs);
321 * Sets the main volume of a device.
322 * \param device The device.
323 * \param volume The new volume, must be between 0.0 and 1.0.
324 * \return Whether the action succeeded.
326 extern int AUD_setDeviceVolume(AUD_Device* device, float volume);
329 * Plays back a sound file through a read device.
330 * \param device The read device.
331 * \param sound The handle of the sound file.
332 * \param seek The position where the sound should be seeked to.
333 * \return A handle to the played back sound.
335 extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek);
338 * Sets the volume of a played back sound of a read device.
339 * \param device The read device.
340 * \param handle The handle to the sound.
341 * \param volume The new volume, must be between 0.0 and 1.0.
342 * \return Whether the action succeeded.
344 extern int AUD_setDeviceSoundVolume(AUD_Device* device,
349 * Reads the next samples into the supplied buffer.
350 * \param device The read device.
351 * \param buffer The target buffer.
352 * \param length The length in samples to be filled.
353 * \return True if the reading succeeded, false if there are no sounds
354 * played back currently, in that case the buffer is filled with
357 extern int AUD_readDevice(AUD_Device* device, data_t* buffer, int length);
360 * Closes a read device.
361 * \param device The read device.
363 extern void AUD_closeReadDevice(AUD_Device* device);
366 * Reads a sound file into a newly created float buffer.
367 * The sound is therefore bandpassed, rectified and resampled.
369 extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
370 float attack, float release, float threshold,
371 int accumulate, int additive, int square,
372 float sthreshold, int samplerate,
375 extern AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume);
377 extern void AUD_destroySequencer(AUD_Sound* sequencer);
379 extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
380 float begin, float end, float skip, void* data);
382 extern void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry);
384 extern void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
385 float begin, float end, float skip);
387 extern void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
390 extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length);
392 extern void AUD_startPlayback();
394 extern void AUD_stopPlayback();
396 extern void AUD_seekSequencer(AUD_Handle* handle, float time);
398 extern float AUD_getSequencerPosition(AUD_Handle* handle);
401 extern void AUD_setSyncCallback(AUD_syncFunction function, void* data);
404 extern int AUD_doesPlayback();