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);
58 * Initializes an audio device.
59 * \param device The device type that should be used.
60 * \param specs The audio specification to be used.
61 * \param buffersize The buffersize for the device.
62 * \return Whether the device has been initialized.
64 extern int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize);
67 * Returns a integer list with available sound devices. The last one is always
70 extern int* AUD_enumDevices();
73 * Unitinitializes an audio device.
75 extern void AUD_exit();
78 * Locks the playback device.
80 extern void AUD_lock();
85 extern void AUD_unlock();
88 * Returns information about a sound.
89 * \param sound The sound to get the info about.
90 * \return The AUD_SoundInfo structure with filled in data.
92 extern AUD_SoundInfo AUD_getInfo(AUD_Sound* sound);
96 * \param filename The filename of the sound file.
97 * \return A handle of the sound file.
99 extern AUD_Sound* AUD_load(const char* filename);
102 * Loads a sound file.
103 * \param buffer The buffer which contains the sound file.
104 * \param size The size of the buffer.
105 * \return A handle of the sound file.
107 extern AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size);
111 * \param sound The sound to buffer.
112 * \return A handle of the sound buffer.
114 extern AUD_Sound* AUD_bufferSound(AUD_Sound* sound);
118 * \param sound The sound to dealy.
119 * \param delay The delay in seconds.
120 * \return A handle of the delayed sound.
122 extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay);
126 * \param sound The sound to limit.
127 * \param start The start time in seconds.
128 * \param end The stop time in seconds.
129 * \return A handle of the limited sound.
131 extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end);
134 * Ping pongs a sound.
135 * \param sound The sound to ping pong.
136 * \return A handle of the ping pong sound.
138 extern AUD_Sound* AUD_pingpongSound(AUD_Sound* sound);
142 * \param sound The sound to loop.
143 * \return A handle of the looped sound.
145 extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
148 * Sets a remaining loop count of a looping sound that currently plays.
149 * \param handle The playback handle.
150 * \param loops The count of remaining loops, -1 for infinity.
151 * \param time The time after which playback should stop, -1 for infinity.
152 * \return Whether the handle is valid.
154 extern int AUD_setLoop(AUD_Handle* handle, int loops, float time);
158 * \param sound The sound to rectify.
159 * \return A handle of the rectified sound.
161 extern AUD_Sound* AUD_rectifySound(AUD_Sound* sound);
164 * Unloads a sound of any type.
165 * \param sound The handle of the sound.
167 extern void AUD_unload(AUD_Sound* sound);
170 * Plays back a sound file.
171 * \param sound The handle of the sound file.
172 * \param keep When keep is true the sound source will not be deleted but set to
173 * paused when its end has been reached.
174 * \return A handle to the played back sound.
176 extern AUD_Handle* AUD_play(AUD_Sound* sound, int keep);
179 * Pauses a played back sound.
180 * \param handle The handle to the sound.
181 * \return Whether the handle has been playing or not.
183 extern int AUD_pause(AUD_Handle* handle);
186 * Resumes a paused sound.
187 * \param handle The handle to the sound.
188 * \return Whether the handle has been paused or not.
190 extern int AUD_resume(AUD_Handle* handle);
193 * Stops a playing or paused sound.
194 * \param handle The handle to the sound.
195 * \return Whether the handle has been valid or not.
197 extern int AUD_stop(AUD_Handle* handle);
200 * Sets the end behaviour of a playing or paused sound.
201 * \param handle The handle to the sound.
202 * \param keep When keep is true the sound source will not be deleted but set to
203 * paused when its end has been reached.
204 * \return Whether the handle has been valid or not.
206 extern int AUD_setKeep(AUD_Handle* handle, int keep);
209 * Seeks a playing or paused sound.
210 * \param handle The handle to the sound.
211 * \param seekTo From where the sound file should be played back in seconds.
212 * \return Whether the handle has been valid or not.
214 extern int AUD_seek(AUD_Handle* handle, float seekTo);
217 * Retrieves the playback position of a handle.
218 * \param handle The handle to the sound.
219 * \return The current playback position in seconds or 0.0 if the handle is
222 extern float AUD_getPosition(AUD_Handle* handle);
225 * Returns the status of a playing, paused or stopped sound.
226 * \param handle The handle to the sound.
227 * \return The status of the sound behind the handle.
229 extern AUD_Status AUD_getStatus(AUD_Handle* handle);
233 * \param sound The handle of the sound file.
234 * \param keep When keep is true the sound source will not be deleted but set to
235 * paused when its end has been reached.
236 * \return A handle to the played back sound.
237 * \note The factory must provide a mono (single channel) source and the device
238 * must support 3D audio, otherwise the sound is played back normally.
240 extern AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep);
243 * Updates the listener 3D data.
244 * \param data The 3D data.
245 * \return Whether the action succeeded.
247 extern int AUD_updateListener(AUD_3DData* data);
250 * Sets a 3D device setting.
251 * \param setting The setting type.
252 * \param value The new setting value.
253 * \return Whether the action succeeded.
255 extern int AUD_set3DSetting(AUD_3DSetting setting, float value);
258 * Retrieves a 3D device setting.
259 * \param setting The setting type.
260 * \return The setting value.
262 extern float AUD_get3DSetting(AUD_3DSetting setting);
265 * Updates a listeners 3D data.
266 * \param handle The source handle.
267 * \param data The 3D data.
268 * \return Whether the action succeeded.
270 extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
273 * Sets a 3D source setting.
274 * \param handle The source handle.
275 * \param setting The setting type.
276 * \param value The new setting value.
277 * \return Whether the action succeeded.
279 extern int AUD_set3DSourceSetting(AUD_Handle* handle,
280 AUD_3DSourceSetting setting, float value);
283 * Retrieves a 3D source setting.
284 * \param handle The source handle.
285 * \param setting The setting type.
286 * \return The setting value.
288 extern float AUD_get3DSourceSetting(AUD_Handle* handle,
289 AUD_3DSourceSetting setting);
292 * Sets the volume of a played back sound.
293 * \param handle The handle to the sound.
294 * \param volume The new volume, must be between 0.0 and 1.0.
295 * \return Whether the action succeeded.
297 extern int AUD_setSoundVolume(AUD_Handle* handle, float volume);
300 * Sets the pitch of a played back sound.
301 * \param handle The handle to the sound.
302 * \param pitch The new pitch.
303 * \return Whether the action succeeded.
305 extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch);
308 * Opens a read device, with which audio data can be read.
309 * \param specs The specification of the audio data.
310 * \return A device handle.
312 extern AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs);
315 * Sets the main volume of a device.
316 * \param device The device.
317 * \param volume The new volume, must be between 0.0 and 1.0.
318 * \return Whether the action succeeded.
320 extern int AUD_setDeviceVolume(AUD_Device* device, float volume);
323 * Plays back a sound file through a read device.
324 * \param device The read device.
325 * \param sound The handle of the sound file.
326 * \param seek The position where the sound should be seeked to.
327 * \return A handle to the played back sound.
329 extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek);
332 * Sets the volume of a played back sound of a read device.
333 * \param device The read device.
334 * \param handle The handle to the sound.
335 * \param volume The new volume, must be between 0.0 and 1.0.
336 * \return Whether the action succeeded.
338 extern int AUD_setDeviceSoundVolume(AUD_Device* device,
343 * Reads the next samples into the supplied buffer.
344 * \param device The read device.
345 * \param buffer The target buffer.
346 * \param length The length in samples to be filled.
347 * \return True if the reading succeeded, false if there are no sounds
348 * played back currently, in that case the buffer is filled with
351 extern int AUD_readDevice(AUD_Device* device, data_t* buffer, int length);
354 * Closes a read device.
355 * \param device The read device.
357 extern void AUD_closeReadDevice(AUD_Device* device);
360 * Reads a sound file into a newly created float buffer.
361 * The sound is therefore bandpassed, rectified and resampled.
363 extern float* AUD_readSoundBuffer(const char* filename, float low, float high,
364 float attack, float release, float threshold,
365 int accumulate, int additive, int square,
366 float sthreshold, int samplerate,
369 extern AUD_Sound* AUD_createSequencer(void* data, AUD_volumeFunction volume);
371 extern void AUD_destroySequencer(AUD_Sound* sequencer);
373 extern AUD_SequencerEntry* AUD_addSequencer(AUD_Sound** sequencer, AUD_Sound* sound,
374 float begin, float end, float skip, void* data);
376 extern void AUD_removeSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry);
378 extern void AUD_moveSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
379 float begin, float end, float skip);
381 extern void AUD_muteSequencer(AUD_Sound* sequencer, AUD_SequencerEntry* entry,
384 extern int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length);