Revision: 21484 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21484 Author: nexyon Date: 2009-07-10 13:50:51 +0200 (Fri, 10 Jul 2009)
Log Message: ----------- Implemented a basic C API. Modified Paths: -------------- branches/soundsystem/intern/audaspace/AUD_C-API.h branches/soundsystem/intern/audaspace/SDL/AUD_SDLDevice.h branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp branches/soundsystem/intern/audaspace/intern/AUD_SinusReader.h Modified: branches/soundsystem/intern/audaspace/AUD_C-API.h =================================================================== --- branches/soundsystem/intern/audaspace/AUD_C-API.h 2009-07-10 11:36:02 UTC (rev 21483) +++ branches/soundsystem/intern/audaspace/AUD_C-API.h 2009-07-10 11:50:51 UTC (rev 21484) @@ -32,19 +32,95 @@ #include "AUD_Space.h" -typedef struct {} AUD_Sound; -typedef struct {} AUD_Device; +//#ifndef AUD_CAPI_IMPLEMENTATION +typedef struct AUD_Sound; +//#endif -extern AUD_Device* AUD_init(); +/** + * Initializes an audio device. + * \return Whether the device has been initialized. + */ +extern bool AUD_init(); -extern void AUD_exit(AUD_Device* device); +/** + * Unitinitializes an audio device. + */ +extern void AUD_exit(); -extern AUD_Sound* openSound(const char* filename); +/** + * Loads a sound file. + * \param filename The filename of the sound file. + * \return A handle of the sound file. + */ +extern AUD_Sound* AUD_load(const char* filename); -extern void closeSound(AUD_Sound* sound); +/** + * Unloads a sound file. + * \param sound The handle of the sound file. + */ +extern void AUD_unload(AUD_Sound* sound); -extern void playSound(AUD_Device* device, AUD_Sound* sound); +/** + * Plays back a sound file. + * \param sound The handle of the sound file. + * \param endBehaviour The behaviour after the end of the sound file has been + * reached. + * \param seekTo From where the sound file should be played back in seconds. + * A negative value indicates the seconds that should be waited + * before playback starts. + * \return A handle to the played back sound. + */ +extern AUD_Handle* AUD_play(AUD_Sound* sound, + AUD_EndBehaviour endBehaviour = AUD_BEHAVIOUR_STOP, + double seekTo = 0); +/** + * Pauses a played back sound. + * \param handle The handle to the sound. + * \return Whether the handle has been playing or not. + */ +extern bool AUD_pause(AUD_Handle* handle); + +/** + * Resumes a paused sound. + * \param handle The handle to the sound. + * \return Whether the handle has been paused or not. + */ +extern bool AUD_resume(AUD_Handle* handle); + +/** + * Stops a playing or paused sound. + * \param handle The handle to the sound. + * \return Whether the handle has been valid or not. + */ +extern bool AUD_stop(AUD_Handle* handle); + +/** + * Sets the end behaviour of a playing or paused sound. + * \param handle The handle to the sound. + * \param endBehaviour The behaviour after the end of the file has been reached. + * \return Whether the handle has been valid or not. + */ +extern bool AUD_setEndBehaviour(AUD_Handle* handle, + AUD_EndBehaviour endBehaviour); + +/** + * Seeks a playing or paused sound. + * \param handle The handle to the sound. + * \param seekTo From where the sound file should be played back in seconds. + * A negative value indicates the seconds that should be waited + * before playback starts. + * \return Whether the handle has been valid or not. + */ +extern bool AUD_seek(AUD_Handle* handle, int seekTo); + +/** + * Returns the status of a playing, paused or stopped sound. + * \param handle The handle to the sound. + * \return The status of the sound behind the handle. + */ +extern AUD_Status AUD_getStatus(AUD_Handle* handle); + #ifdef __cplusplus } #endif Modified: branches/soundsystem/intern/audaspace/SDL/AUD_SDLDevice.h =================================================================== --- branches/soundsystem/intern/audaspace/SDL/AUD_SDLDevice.h 2009-07-10 11:36:02 UTC (rev 21483) +++ branches/soundsystem/intern/audaspace/SDL/AUD_SDLDevice.h 2009-07-10 11:50:51 UTC (rev 21484) @@ -62,7 +62,7 @@ /** * Closes the SDL audio device. */ - ~AUD_SDLDevice(); + virtual ~AUD_SDLDevice(); /** * Mixes the next bytes into the buffer. Modified: branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp =================================================================== --- branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp 2009-07-10 11:36:02 UTC (rev 21483) +++ branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp 2009-07-10 11:50:51 UTC (rev 21484) @@ -23,6 +23,7 @@ * ***** END LGPL LICENSE BLOCK ***** */ +//#define AUD_CAPI_IMPLEMENTATION //#include "AUD_C-API.h" #include "AUD_FFMPEGFactory.h" #include "AUD_SDLDevice.h" @@ -32,36 +33,93 @@ } #include <assert.h> -typedef AUD_IDevice AUD_Device; typedef AUD_IFactory AUD_Sound; -AUD_Device* AUD_init() +AUD_IDevice* AUD_device = NULL; + +bool AUD_init() { av_register_all(); - return new AUD_SDLDevice(); + try + { + AUD_device = new AUD_SDLDevice(); + return true; + } + catch(AUD_Exception e) + { + return false; + } } -void AUD_exit(AUD_Device* device) +void AUD_exit() { - assert(device); - delete device; + assert(AUD_device); + delete AUD_device; } -AUD_Sound* openSound(const char* filename) +AUD_Sound* AUD_load(const char* filename) { assert(filename); return new AUD_FFMPEGFactory(filename); } -void closeSound(AUD_Sound* sound) +void AUD_unload(AUD_Sound* sound) { assert(sound); delete sound; } -void playSound(AUD_Device* device, AUD_Sound* sound) +AUD_Handle* AUD_play(AUD_Sound* sound, + AUD_EndBehaviour endBehaviour, + double seekTo) { - assert(device); + assert(AUD_device); assert(sound); - device->play(sound); + int position = (int)(seekTo * AUD_device->getSpecs().rate); + try + { + return AUD_device->play(sound, endBehaviour, position); + } + catch(AUD_Exception e) + { + return NULL; + } } + +bool AUD_pause(AUD_Handle* handle) +{ + assert(AUD_device); + return AUD_device->pause(handle); +} + +bool AUD_resume(AUD_Handle* handle) +{ + assert(AUD_device); + return AUD_device->resume(handle); +} + +bool AUD_stop(AUD_Handle* handle) +{ + assert(AUD_device); + return AUD_device->stop(handle); +} + +bool AUD_setEndBehaviour(AUD_Handle* handle, + AUD_EndBehaviour endBehaviour) +{ + assert(AUD_device); + return AUD_device->setEndBehaviour(handle, endBehaviour); +} + +bool AUD_seek(AUD_Handle* handle, double seekTo) +{ + assert(AUD_device); + int position = (int)(seekTo * AUD_device->getSpecs().rate); + return AUD_device->seek(handle, position); +} + +AUD_Status AUD_getStatus(AUD_Handle* handle) +{ + assert(AUD_device); + return AUD_device->getStatus(handle); +} Modified: branches/soundsystem/intern/audaspace/intern/AUD_SinusReader.h =================================================================== --- branches/soundsystem/intern/audaspace/intern/AUD_SinusReader.h 2009-07-10 11:36:02 UTC (rev 21483) +++ branches/soundsystem/intern/audaspace/intern/AUD_SinusReader.h 2009-07-10 11:50:51 UTC (rev 21484) @@ -71,7 +71,7 @@ /** * Destroys the reader. */ - ~AUD_SinusReader(); + virtual ~AUD_SinusReader(); virtual bool isSeekable(); virtual void seek(int position); _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs