[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21721] branches/soundsystem: New (updated ) C-API!
Jörg Müller
nexyon at gmail.com
Mon Jul 20 18:06:04 CEST 2009
Revision: 21721
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21721
Author: nexyon
Date: 2009-07-20 18:06:03 +0200 (Mon, 20 Jul 2009)
Log Message:
-----------
New (updated) C-API!
Modified Paths:
--------------
branches/soundsystem/CMake/macros.cmake
branches/soundsystem/intern/audaspace/AUD_C-API.h
branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
branches/soundsystem/intern/audaspace/intern/AUD_I3DDevice.h
branches/soundsystem/intern/audaspace/intern/AUD_Space.h
branches/soundsystem/source/blender/windowmanager/intern/wm_init_exit.c
Modified: branches/soundsystem/CMake/macros.cmake
===================================================================
--- branches/soundsystem/CMake/macros.cmake 2009-07-20 14:07:30 UTC (rev 21720)
+++ branches/soundsystem/CMake/macros.cmake 2009-07-20 16:06:03 UTC (rev 21721)
@@ -43,7 +43,7 @@
CMAKE_POLICY(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
LINK_DIRECTORIES(${PYTHON_LIBPATH} ${SDL_LIBPATH} ${JPEG_LIBPATH} ${PNG_LIBPATH} ${ZLIB_LIBPATH} ${ICONV_LIBPATH} ${OPENEXR_LIBPATH} ${QUICKTIME_LIBPATH} ${FFMPEG_LIBPATH})
- LINK_DIRECTORIES(${FREETYPE_LIBPATH})
+ LINK_DIRECTORIES(${FREETYPE_LIBPATH} ${LIBSAMPLERATE_LIBPATH})
IF(WITH_INTERNATIONAL)
LINK_DIRECTORIES(${GETTEXT_LIBPATH})
ENDIF(WITH_INTERNATIONAL)
@@ -79,7 +79,7 @@
TARGET_LINK_LIBRARIES(${target} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY} ${PYTHON_LINKFLAGS} ${JPEG_LIB} ${PNG_LIB} ${ZLIB_LIB} ${SDL_LIB} ${LLIBS})
- TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIB})
+ TARGET_LINK_LIBRARIES(${target} ${FREETYPE_LIB} ${LIBSAMPLERATE_LIB})
# since we are using the local libs for python when compiling msvc projects, we need to add _d when compiling debug versions
Modified: branches/soundsystem/intern/audaspace/AUD_C-API.h
===================================================================
--- branches/soundsystem/intern/audaspace/AUD_C-API.h 2009-07-20 14:07:30 UTC (rev 21720)
+++ branches/soundsystem/intern/audaspace/AUD_C-API.h 2009-07-20 16:06:03 UTC (rev 21721)
@@ -32,18 +32,35 @@
#include "intern/AUD_Space.h"
+typedef enum
+{
+ AUD_NULL_DEVICE = 0,
+ AUD_SDL_DEVICE,
+ AUD_OPENAL_DEVICE
+} AUD_DeviceType;
+
#ifndef AUD_CAPI_IMPLEMENTATION
typedef void AUD_Sound;
typedef void AUD_Handle;
+ typedef void AUD_Device;
#endif
/**
* Initializes an audio device.
+ * \param device The device type that should be used.
+ * \param specs The audio specification to be used.
+ * \param buffersize The buffersize for the device.
* \return Whether the device has been initialized.
*/
-extern int AUD_init();
+extern int AUD_init(AUD_DeviceType device, AUD_Specs specs, int buffersize);
/**
+ * Returns a integer list with available sound devices. The last one is always
+ * AUD_NULL_DEVICE.
+ */
+extern int* AUD_enumDevices();
+
+/**
* Unitinitializes an audio device.
*/
extern void AUD_exit();
@@ -64,9 +81,54 @@
extern AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size);
/**
- * Unloads a sound file.
- * \param sound The handle of the sound file.
+ * Buffers a sound.
+ * \param sound The sound to buffer.
+ * \return A handle of the sound buffer.
*/
+extern AUD_Sound* AUD_bufferSound(AUD_Sound* sound);
+
+/**
+ * Delays a sound.
+ * \param sound The sound to dealy.
+ * \param delay The delay in seconds.
+ * \return A handle of the delayed sound.
+ */
+extern AUD_Sound* AUD_delaySound(AUD_Sound* sound, float delay);
+
+/**
+ * Limits a sound.
+ * \param sound The sound to limit.
+ * \param start The start time in seconds.
+ * \param end The stop time in seconds.
+ * \return A handle of the limited sound.
+ */
+extern AUD_Sound* AUD_limitSound(AUD_Sound* sound, float start, float end);
+
+/**
+ * Ping pongs a sound.
+ * \param sound The sound to ping pong.
+ * \return A handle of the ping pong sound.
+ */
+extern AUD_Sound* AUD_pingpongSound(AUD_Sound* sound);
+
+/**
+ * Loops a sound.
+ * \param sound The sound to loop.
+ * \return A handle of the looped sound.
+ */
+extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
+
+/**
+ * Stops a looping sound when the current playback finishes.
+ * \param handle The playback handle.
+ * \return Whether the handle is valid.
+ */
+extern int AUD_stopLoop(AUD_Handle* handle);
+
+/**
+ * Unloads a sound of any type.
+ * \param sound The handle of the sound.
+ */
extern void AUD_unload(AUD_Sound* sound);
/**
@@ -125,6 +187,114 @@
*/
extern AUD_Status AUD_getStatus(AUD_Handle* handle);
+/**
+ * Plays a 3D sound.
+ * \param sound The handle of the sound file.
+ * \param keep When keep is true the sound source will not be deleted but set to
+ * paused when its end has been reached.
+ * \return A handle to the played back sound.
+ * \note The factory must provide a mono (single channel) source and the device
+ * must support 3D audio, otherwise the sound is played back normally.
+ */
+extern AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep);
+
+/**
+ * Updates the listener 3D data.
+ * \param data The 3D data.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_updateListener(AUD_3DData* data);
+
+/**
+ * Sets a 3D device setting.
+ * \param setting The setting type.
+ * \param value The new setting value.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_set3DSetting(AUD_3DSetting setting, float value);
+
+/**
+ * Retrieves a 3D device setting.
+ * \param setting The setting type.
+ * \return The setting value.
+ */
+extern float AUD_get3DSetting(AUD_3DSetting setting);
+
+/**
+ * Updates a listeners 3D data.
+ * \param handle The source handle.
+ * \param data The 3D data.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
+
+/**
+ * Sets a 3D source setting.
+ * \param handle The source handle.
+ * \param setting The setting type.
+ * \param value The new setting value.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_set3DSourceSetting(AUD_Handle* handle,
+ AUD_3DSourceSetting setting, float value);
+
+/**
+ * Retrieves a 3D source setting.
+ * \param handle The source handle.
+ * \param setting The setting type.
+ * \return The setting value.
+ */
+extern float AUD_get3DSourceSetting(AUD_Handle* handle,
+ AUD_3DSourceSetting setting);
+
+/**
+ * Sets the volume of a played back sound.
+ * \param handle The handle to the sound.
+ * \param volume The new volume, must be between 0.0 and 1.0.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_setSoundVolume(AUD_Handle* handle, float volume);
+
+/**
+ * Sets the pitch of a played back sound.
+ * \param handle The handle to the sound.
+ * \param pitch The new pitch.
+ * \return Whether the action succeeded.
+ */
+extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch);
+
+/**
+ * Opens a read device, with which audio data can be read.
+ * \param specs The specification of the audio data.
+ * \return A device handle.
+ */
+extern AUD_Device* AUD_openReadDevice(AUD_Specs specs);
+
+/**
+ * Plays back a sound file through a read device.
+ * \param device The read device.
+ * \param sound The handle of the sound file.
+ * \return Whether the sound could be played back.
+ */
+extern int AUD_playDevice(AUD_Device* device, AUD_Sound* sound);
+
+/**
+ * Reads the next samples into the supplied buffer.
+ * \param device The read device.
+ * \param buffer The target buffer.
+ * \param length The length in samples to be filled.
+ * \return True if the reading succeeded, false if there are no sounds
+ * played back currently, in that case the buffer is filled with
+ * silence.
+ */
+extern int AUD_readDevice(AUD_Device* device, sample_t* buffer, int length);
+
+/**
+ * Closes a read device.
+ * \param device The read device.
+ */
+extern void AUD_closeReadDevice(AUD_Device* device);
+
#ifdef __cplusplus
}
#endif
Modified: branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp 2009-07-20 14:07:30 UTC (rev 21720)
+++ branches/soundsystem/intern/audaspace/intern/AUD_C-API.cpp 2009-07-20 16:06:03 UTC (rev 21721)
@@ -23,31 +23,91 @@
* ***** END LGPL LICENSE BLOCK *****
*/
-#include "AUD_FFMPEGFactory.h"
+/*#define WITH_SDL
+#define WITH_FFMPEG
+#define WITH_OPENAL*/
+
+#include "AUD_NULLDevice.h"
+#include "AUD_I3DDevice.h"
+#include "AUD_StreamBufferFactory.h"
+#include "AUD_DelayFactory.h"
+#include "AUD_LimiterFactory.h"
+#include "AUD_PingPongFactory.h"
+#include "AUD_LoopFactory.h"
+#include "AUD_ReadDevice.h"
+
+/*
+#define WITH_SDL
+#define WITH_OPENAL
+#define WITH_FFMPEG
+//*/
+
+#ifdef WITH_SDL
#include "AUD_SDLDevice.h"
+#include "AUD_FloatMixer.h"
+#endif
+#ifdef WITH_OPENAL
+#include "AUD_OpenALDevice.h"
+#endif
+
+#ifdef WITH_FFMPEG
+#include "AUD_FFMPEGFactory.h"
extern "C" {
#include <libavformat/avformat.h>
}
+#endif
+
#include <assert.h>
typedef AUD_IFactory AUD_Sound;
+typedef AUD_ReadDevice AUD_Device;
#define AUD_CAPI_IMPLEMENTATION
#include "AUD_C-API.h"
+#ifndef NULL
+#define NULL 0
+#endif
+
static AUD_IDevice* AUD_device = NULL;
+static int AUD_available_devices[3];
+static AUD_I3DDevice* AUD_3ddevice = NULL;
-int AUD_init()
+int AUD_init(AUD_DeviceType device, AUD_Specs specs, int buffersize)
{
+#ifdef WITH_FFMPEG
av_register_all();
+#endif
+
try
{
- AUD_Specs specs;
- specs.channels = AUD_CHANNELS_STEREO;
- specs.format = AUD_FORMAT_S16;
- specs.rate = AUD_RATE_44100;
- AUD_device = new AUD_SDLDevice(specs);
+ switch(device)
+ {
+ case AUD_NULL_DEVICE:
+ AUD_device = new AUD_NULLDevice();
+ break;
+#ifdef WITH_SDL
+ case AUD_SDL_DEVICE:
+ {
+ AUD_device = new AUD_SDLDevice(specs, buffersize);
+ AUD_FloatMixer* mixer = new AUD_FloatMixer();
+ ((AUD_SDLDevice*)AUD_device)->setMixer(mixer);
+ break;
+ }
+#endif
+#ifdef WITH_OPENAL
+ case AUD_OPENAL_DEVICE:
+ AUD_device = new AUD_OpenALDevice(specs, buffersize);
+ break;
+#endif
+ default:
+ return false;
+ }
+
+ if(AUD_device->checkCapability(AUD_CAPS_3D_DEVICE))
+ AUD_3ddevice = (AUD_I3DDevice*) AUD_device;
+
return true;
}
catch(AUD_Exception e)
@@ -56,24 +116,135 @@
}
}
+int* AUD_enumDevices()
+{
+ int i = 0;
+#ifdef WITH_SDL
+ AUD_available_devices[i++] = AUD_SDL_DEVICE;
+#endif
+#ifdef WITH_OPENAL
+ AUD_available_devices[i++] = AUD_OPENAL_DEVICE;
+#endif
+ AUD_available_devices[i++] = AUD_NULL_DEVICE;
+ return AUD_available_devices;
+}
+
void AUD_exit()
{
assert(AUD_device);
delete AUD_device;
+ AUD_device = NULL;
+ AUD_3ddevice = NULL;
}
AUD_Sound* AUD_load(const char* filename)
{
assert(filename);
+#ifdef WITH_FFMPEG
return new AUD_FFMPEGFactory(filename);
+#else
+ return NULL;
+#endif
}
AUD_Sound* AUD_loadBuffer(unsigned char* buffer, int size)
{
assert(buffer);
+#ifdef WITH_FFMPEG
return new AUD_FFMPEGFactory(buffer, size);
+#else
+ return NULL;
+#endif
}
+AUD_Sound* AUD_bufferSound(AUD_Sound* sound)
+{
+ assert(sound);
+
+ try
+ {
+ return new AUD_StreamBufferFactory(sound);
+ }
+ catch(AUD_Exception e)
+ {
+ return NULL;
+ }
+}
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list