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 an audio device.
60 * \param device The device type that should be used.
61 * \param specs The audio specification to be used.
62 * \param buffersize The buffersize for the device.
63 * \return Whether the device has been initialized.
65 extern int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize);
68 * Returns a integer list with available sound devices. The last one is always
71 extern int* AUD_enumDevices();
74 * Unitinitializes an audio device.
76 extern void AUD_exit();
79 * Locks the playback device.
81 extern void AUD_lock();
86 extern void AUD_unlock();
89 * Returns information about a sound.
90 * \param sound The sound to get the info about.
91 * \return The AUD_SoundInfo structure with filled in data.
93 extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound);
97 * \param filename The filename of the sound file.
98 * \return A handle of the sound file.
100 extern AUD_Sound* AUD_load(const char* filename);
103 * Loads a sound file.
104 * \param buffer The buffer which contains the sound file.
105 * \param size The size of the buffer.
106 * \return A handle of the sound file.
108 extern AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size);
112 * \param sound The sound to buffer.
113 * \return A handle of the sound buffer.
115 extern AUD_Sound* AUD_bufferSound(AUD_Sound* sound);
119 * \param sound The sound to dealy.
120 * \param delay The delay in seconds.
121 * \return A handle of the delayed sound.
123 extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay);
127 * \param sound The sound to limit.
128 * \param start The start time in seconds.
129 * \param end The stop time in seconds.
130 * \return A handle of the limited sound.
132 extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end);
135 * Ping pongs a sound.
136 * \param sound The sound to ping pong.
137 * \return A handle of the ping pong sound.
139 extern AUD_Sound* AUD_pingpongSound(AUD_Sound* sound);
143 * \param sound The sound to loop.
144 * \return A handle of the looped sound.
146 extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
149 * Sets a remaining loop count of a looping sound that currently plays.
150 * \param handle The playback handle.
151 * \param loops The count of remaining loops, -1 for infinity.
152 * \param time The time after which playback should stop, -1 for infinity.
153 * \return Whether the handle is valid.
155 extern int AUD_setLoop(AUD_Handle* handle, int loops, float time);
159 * \param sound The sound to rectify.
160 * \return A handle of the rectified sound.
162 extern AUD_Sound* AUD_rectifySound(AUD_Sound* sound);
165 * Unloads a sound of any type.
166 * \param sound The handle of the sound.
168 extern void AUD_unload(AUD_Sound* sound);
171 * Plays back a sound file.
172 * \param sound The handle of the sound file.
173 * \param keep When keep is true the sound source will not be deleted but set to
174 * paused when its end has been reached.
175 * \return A handle to the played back sound.
177 extern AUD_Handle* AUD_play(AUD_Sound* sound, int keep);
180 * Pauses a played back sound.
181 * \param handle The handle to the sound.
182 * \return Whether the handle has been playing or not.
184 extern int AUD_pause(AUD_Handle* handle);
187 * Resumes a paused sound.
188 * \param handle The handle to the sound.
189 * \return Whether the handle has been paused or not.
191 extern int AUD_resume(AUD_Handle* handle);
194 * Stops a playing or paused sound.
195 * \param handle The handle to the sound.
196 * \return Whether the handle has been valid or not.
198 extern int AUD_stop(AUD_Handle* handle);
201 * Sets the end behaviour of a playing or paused sound.
202 * \param handle The handle to the sound.
203 * \param keep When keep is true the sound source will not be deleted but set to
204 * paused when its end has been reached.
205 * \return Whether the handle has been valid or not.
207 extern int AUD_setKeep(AUD_Handle* handle, int keep);
210 * Seeks a playing or paused sound.
211 * \param handle The handle to the sound.
212 * \param seekTo From where the sound file should be played back in seconds.
213 * \return Whether the handle has been valid or not.
215 extern int AUD_seek(AUD_Handle* handle, float seekTo);
218 * Retrieves the playback position of a handle.
219 * \param handle The handle to the sound.
220 * \return The current playback position in seconds or 0.0 if the handle is
223 extern float AUD_getPosition(AUD_Handle* handle);
226 * Returns the status of a playing, paused or stopped sound.
227 * \param handle The handle to the sound.
228 * \return The status of the sound behind the handle.
230 extern AUD_Status AUD_getStatus(AUD_Handle* handle);
234 * \param sound The handle of the sound file.
235 * \param keep When keep is true the sound source will not be deleted but set to
236 * paused when its end has been reached.
237 * \return A handle to the played back sound.
238 * \note The factory must provide a mono (single channel) source and the device
239 * must support 3D audio, otherwise the sound is played back normally.
241 extern AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep);
244 * Updates the listener 3D data.
245 * \param data The 3D data.
246 * \return Whether the action succeeded.
248 extern int AUD_updateListener(AUD_3DData* data);
251 * Sets a 3D device setting.
252 * \param setting The setting type.
253 * \param value The new setting value.
254 * \return Whether the action succeeded.
256 extern int AUD_set3DSetting(AUD_3DSetting setting, float value);
259 * Retrieves a 3D device setting.
260 * \param setting The setting type.
261 * \return The setting value.
263 extern float AUD_get3DSetting(AUD_3DSetting setting);
266 * Updates a listeners 3D data.
267 * \param handle The source handle.
268 * \param data The 3D data.
269 * \return Whether the action succeeded.
271 extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
274 * Sets a 3D source setting.
275 * \param handle The source handle.
276 * \param setting The setting type.
277 * \param value The new setting value.
278 * \return Whether the action succeeded.
280 extern int AUD_set3DSourceSetting(AUD_Handle* handle,
281 AUD_3DSourceSetting setting, float value);
284 * Retrieves a 3D source setting.
285 * \param handle The source handle.
286 * \param setting The setting type.
287 * \return The setting value.
289 extern float AUD_get3DSourceSetting(AUD_Handle* handle,
290 AUD_3DSourceSetting setting);
293 * Sets the volume of a played back sound.
294 * \param handle The handle to the sound.
295 * \param volume The new volume, must be between 0.0 and 1.0.
296 * \return Whether the action succeeded.
298 extern int AUD_setSoundVolume(AUD_Handle* handle, float volume);
301 * Sets the pitch of a played back sound.
302 * \param handle The handle to the sound.
303 * \param pitch The new pitch.
304 * \return Whether the action succeeded.
306 extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch);
309 * Opens a read device, with which audio data can be read.
310 * \param specs The specification of the audio data.
311 * \return A device handle.
313 extern AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs);
316 * Sets the main volume of a device.
317 * \param device The device.
318 * \param volume The new volume, must be between 0.0 and 1.0.
319 * \return Whether the action succeeded.
321 extern int AUD_setDeviceVolume(AUD_Device* device, float volume);
324 * Plays back a sound file through a read device.
325 * \param device The read device.
326 * \param sound The handle of the sound file.
327 * \param seek The position where the sound should be seeked to.
328 * \return A handle to the played back sound.
330 extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek);
333 * Sets the volume of a played back sound of a read device.
334 * \param device The read device.
335 * \param handle The handle to the sound.
336 * \param volume The new volume, must be between 0.0 and 1.0.
337 * \return Whether the action succeeded.
339 extern int AUD_setDeviceSoundVolume(AUD_Device* device,
344 * Reads the next samples into the supplied buffer.
345 * \param device The read device.
346 * \param buffer The target buffer.
347 * \param length The length in samples to be filled.
348 * \return True if the reading succeeded, false if there are no sounds
349 * played back currently, in that case the buffer is filled with
352 extern int AUD_readDevice(AUD_Device* device, data_t* buffer, int length);
355 * Closes a read device.
356 * \param device The read device.
358 extern void AUD_closeReadDevice(AUD_Device* device);
361 * Reads a sound file into a newly created float buffer.
362 * The sound is therefore bandpassed, rectified and resampled.
364 extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
365 float attack, float release, float threshold,
366 int accumulate, int additive, int square,
367 float sthreshold, int samplerate,
370 extern AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume);
372 extern void AUD_destroySequencer(AUD_Sound* sequencer);
374 extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
375 float begin, float end, float skip, void* data);
377 extern void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry);
379 extern void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
380 float begin, float end, float skip);
382 extern void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
385 extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length);
387 extern void AUD_startPlayback();
389 extern void AUD_stopPlayback();
391 extern void AUD_seekSequencer(AUD_Handle* handle, float time);
393 extern float AUD_getSequencerPosition(AUD_Handle* handle);
395 extern void AUD_setSyncCallback(AUD_syncFunction function, void* data);
397 extern int AUD_doesPlayback();