Audaspace:

* Renamed AUD_Handle to AUD_Channel in the C-API to prevent errors with the C++ version of AUD_Handle.
* Added Python API!!!
This commit is contained in:
Joerg Mueller
2010-07-09 12:35:40 +00:00
parent 5460994095
commit 9772eb4d5f
11 changed files with 3354 additions and 48 deletions

View File

@@ -60,6 +60,12 @@ IF(WITH_FFTW3)
ADD_DEFINITIONS(-DWITH_FFTW3)
ENDIF(WITH_FFTW3)
SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${FFTW3SRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC})
IF(WITH_PYTHON)
SET(INC ${INC} Python ${PYTHON_INC})
FILE(GLOB PYTHONSRC Python/*.cpp)
ADD_DEFINITIONS(-DWITH_PYTHON)
ENDIF(WITH_PYTHON)
SET(SRC ${SRC} ${FFMPEGSRC} ${SNDFILESRC} ${FFTW3SRC} ${SDLSRC} ${OPENALSRC} ${JACKSRC} ${PYTHONSRC})
BLENDERLIB(bf_audaspace "${SRC}" "${INC}")

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,67 @@
/*
* $Id$
*
* ***** BEGIN LGPL LICENSE BLOCK *****
*
* Copyright 2009 Jörg Hermann Müller
*
* This file is part of AudaSpace.
*
* AudaSpace is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AudaSpace is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
*
* ***** END LGPL LICENSE BLOCK *****
*/
#ifndef AUD_PYAPI
#define AUD_PYAPI
#include "Python.h"
#ifdef __cplusplus
extern "C" {
#include "AUD_IDevice.h"
#else
typedef void AUD_IFactory;
typedef void AUD_IDevice;
typedef void AUD_Handle;
#endif
typedef struct {
PyObject_HEAD
PyObject* child_list;
AUD_IFactory* factory;
} Sound;
typedef struct {
PyObject_HEAD
AUD_Handle* handle;
PyObject* device;
} Handle;
typedef struct {
PyObject_HEAD
AUD_IDevice* device;
} Device;
PyMODINIT_FUNC
PyInit_aud(void);
extern PyObject *
Device_empty();
#ifdef __cplusplus
}
#endif
#endif //AUD_PYAPI

View File

@@ -36,6 +36,11 @@ if env['WITH_BF_FFTW3']:
incs += ' fftw ' + env['BF_FFTW3_INC']
defs.append('WITH_FFTW3')
if env['WITH_BF_PYTHON']:
sources += env.Glob('Python/*.cpp')
incs += ' Python ' + env['BF_PYTHON_INC']
defs.append('WITH_PYTHON')
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
incs += ' ' + env['BF_PTHREADS_INC']

View File

@@ -23,11 +23,18 @@
* ***** END LGPL LICENSE BLOCK *****
*/
#ifdef WITH_PYTHON
#include "AUD_PyAPI.h"
Device* g_device;
bool g_pyinitialized = false;
#endif
#include <cstdlib>
#include <cstring>
#include <cmath>
#ifdef WITH_FFMPEG
#ifndef __STDC_CONSTANT_MACROS
// needed for INT64_C
#define __STDC_CONSTANT_MACROS
#endif
@@ -78,6 +85,7 @@ extern "C" {
typedef AUD_IFactory AUD_Sound;
typedef AUD_ReadDevice AUD_Device;
typedef AUD_Handle AUD_Channel;
#define AUD_CAPI_IMPLEMENTATION
#include "AUD_C-API.h"
@@ -134,6 +142,17 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
if(AUD_device->checkCapability(AUD_CAPS_3D_DEVICE))
AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device);
#ifdef WITH_PYTHON
if(g_pyinitialized)
{
g_device = (Device*)Device_empty();
if(g_device != NULL)
{
g_device->device = dev;
}
}
#endif
return true;
}
catch(AUD_Exception)
@@ -160,13 +179,51 @@ int* AUD_enumDevices()
void AUD_exit()
{
#ifdef WITH_PYTHON
if(g_device)
{
Py_XDECREF(g_device);
g_device = NULL;
}
else
#endif
if(AUD_device)
delete AUD_device;
AUD_device = NULL;
AUD_3ddevice = NULL;
}
#ifdef WITH_PYTHON
static PyObject* AUD_getCDevice(PyObject* self)
{
if(g_device)
{
Py_INCREF(g_device);
return (PyObject*)g_device;
}
Py_RETURN_NONE;
}
static PyMethodDef meth_getcdevice[] = {{ "getCDevice", (PyCFunction)AUD_getCDevice, METH_NOARGS, "Returns the C API Device."}};
PyObject* AUD_initPython()
{
PyObject* module = PyInit_aud();
PyModule_AddObject(module, "getCDevice", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
PyDict_SetItemString(PySys_GetObject("modules"), "aud", module);
if(AUD_device)
{
delete AUD_device;
AUD_device = NULL;
AUD_3ddevice = NULL;
g_device = (Device*)Device_empty();
if(g_device != NULL)
{
g_device->device = AUD_device;
}
}
g_pyinitialized = true;
return module;
}
#endif
void AUD_lock()
{
@@ -285,7 +342,7 @@ AUD_Sound* AUD_loopSound(AUD_Sound* sound)
}
}
int AUD_setLoop(AUD_Handle* handle, int loops, float time)
int AUD_setLoop(AUD_Channel* handle, int loops, float time)
{
if(handle)
{
@@ -325,7 +382,7 @@ void AUD_unload(AUD_Sound* sound)
delete sound;
}
AUD_Handle* AUD_play(AUD_Sound* sound, int keep)
AUD_Channel* AUD_play(AUD_Sound* sound, int keep)
{
assert(AUD_device);
assert(sound);
@@ -339,50 +396,50 @@ AUD_Handle* AUD_play(AUD_Sound* sound, int keep)
}
}
int AUD_pause(AUD_Handle* handle)
int AUD_pause(AUD_Channel* handle)
{
assert(AUD_device);
return AUD_device->pause(handle);
}
int AUD_resume(AUD_Handle* handle)
int AUD_resume(AUD_Channel* handle)
{
assert(AUD_device);
return AUD_device->resume(handle);
}
int AUD_stop(AUD_Handle* handle)
int AUD_stop(AUD_Channel* handle)
{
if(AUD_device)
return AUD_device->stop(handle);
return false;
}
int AUD_setKeep(AUD_Handle* handle, int keep)
int AUD_setKeep(AUD_Channel* handle, int keep)
{
assert(AUD_device);
return AUD_device->setKeep(handle, keep);
}
int AUD_seek(AUD_Handle* handle, float seekTo)
int AUD_seek(AUD_Channel* handle, float seekTo)
{
assert(AUD_device);
return AUD_device->seek(handle, seekTo);
}
float AUD_getPosition(AUD_Handle* handle)
float AUD_getPosition(AUD_Channel* handle)
{
assert(AUD_device);
return AUD_device->getPosition(handle);
}
AUD_Status AUD_getStatus(AUD_Handle* handle)
AUD_Status AUD_getStatus(AUD_Channel* handle)
{
assert(AUD_device);
return AUD_device->getStatus(handle);
}
AUD_Handle* AUD_play3D(AUD_Sound* sound, int keep)
AUD_Channel* AUD_play3D(AUD_Sound* sound, int keep)
{
assert(AUD_device);
assert(sound);
@@ -446,7 +503,7 @@ float AUD_get3DSetting(AUD_3DSetting setting)
return 0.0f;
}
int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data)
int AUD_update3DSource(AUD_Channel* handle, AUD_3DData* data)
{
if(handle)
{
@@ -465,7 +522,7 @@ int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data)
return false;
}
int AUD_set3DSourceSetting(AUD_Handle* handle,
int AUD_set3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting, float value)
{
if(handle)
@@ -484,7 +541,7 @@ int AUD_set3DSourceSetting(AUD_Handle* handle,
return false;
}
float AUD_get3DSourceSetting(AUD_Handle* handle, AUD_3DSourceSetting setting)
float AUD_get3DSourceSetting(AUD_Channel* handle, AUD_3DSourceSetting setting)
{
if(handle)
{
@@ -502,7 +559,7 @@ float AUD_get3DSourceSetting(AUD_Handle* handle, AUD_3DSourceSetting setting)
return 0.0f;
}
int AUD_setSoundVolume(AUD_Handle* handle, float volume)
int AUD_setSoundVolume(AUD_Channel* handle, float volume)
{
if(handle)
{
@@ -520,7 +577,7 @@ int AUD_setSoundVolume(AUD_Handle* handle, float volume)
return false;
}
int AUD_setSoundPitch(AUD_Handle* handle, float pitch)
int AUD_setSoundPitch(AUD_Channel* handle, float pitch)
{
if(handle)
{
@@ -550,14 +607,14 @@ AUD_Device* AUD_openReadDevice(AUD_DeviceSpecs specs)
}
}
AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
AUD_Channel* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek)
{
assert(device);
assert(sound);
try
{
AUD_Handle* handle = device->play(sound);
AUD_Channel* handle = device->play(sound);
device->seek(handle, seek);
return handle;
}
@@ -580,7 +637,7 @@ int AUD_setDeviceVolume(AUD_Device* device, float volume)
return false;
}
int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Handle* handle,
int AUD_setDeviceSoundVolume(AUD_Device* device, AUD_Channel* handle,
float volume)
{
if(handle)
@@ -789,7 +846,7 @@ void AUD_stopPlayback()
#endif
}
void AUD_seekSequencer(AUD_Handle* handle, float time)
void AUD_seekSequencer(AUD_Channel* handle, float time)
{
#ifdef WITH_JACK
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);
@@ -802,7 +859,7 @@ void AUD_seekSequencer(AUD_Handle* handle, float time)
}
}
float AUD_getSequencerPosition(AUD_Handle* handle)
float AUD_getSequencerPosition(AUD_Channel* handle)
{
#ifdef WITH_JACK
AUD_JackDevice* device = dynamic_cast<AUD_JackDevice*>(AUD_device);

View File

@@ -26,6 +26,10 @@
#ifndef AUD_CAPI
#define AUD_CAPI
#ifdef WITH_PYTHON
#include "Python.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -48,7 +52,7 @@ typedef struct
#ifndef AUD_CAPI_IMPLEMENTATION
typedef void AUD_Sound;
typedef void AUD_Handle;
typedef void AUD_Channel;
typedef void AUD_Device;
typedef void AUD_SequencerEntry;
typedef float (*AUD_volumeFunction)(void*, void*, float);
@@ -80,6 +84,13 @@ extern int* AUD_enumDevices();
*/
extern void AUD_exit();
#ifdef WITH_PYTHON
/**
* Initalizes the Python module.
*/
extern PyObject* AUD_initPython();
#endif
/**
* Locks the playback device.
*/
@@ -157,7 +168,7 @@ extern AUD_Sound* AUD_loopSound(AUD_Sound* sound);
* \param time The time after which playback should stop, -1 for infinity.
* \return Whether the handle is valid.
*/
extern int AUD_setLoop(AUD_Handle* handle, int loops, float time);
extern int AUD_setLoop(AUD_Channel* handle, int loops, float time);
/**
* Rectifies a sound.
@@ -179,28 +190,28 @@ extern void AUD_unload(AUD_Sound* sound);
* paused when its end has been reached.
* \return A handle to the played back sound.
*/
extern AUD_Handle* AUD_play(AUD_Sound* sound, int keep);
extern AUD_Channel* AUD_play(AUD_Sound* sound, int keep);
/**
* Pauses a played back sound.
* \param handle The handle to the sound.
* \return Whether the handle has been playing or not.
*/
extern int AUD_pause(AUD_Handle* handle);
extern int AUD_pause(AUD_Channel* handle);
/**
* Resumes a paused sound.
* \param handle The handle to the sound.
* \return Whether the handle has been paused or not.
*/
extern int AUD_resume(AUD_Handle* handle);
extern int AUD_resume(AUD_Channel* handle);
/**
* Stops a playing or paused sound.
* \param handle The handle to the sound.
* \return Whether the handle has been valid or not.
*/
extern int AUD_stop(AUD_Handle* handle);
extern int AUD_stop(AUD_Channel* handle);
/**
* Sets the end behaviour of a playing or paused sound.
@@ -209,7 +220,7 @@ extern int AUD_stop(AUD_Handle* handle);
* paused when its end has been reached.
* \return Whether the handle has been valid or not.
*/
extern int AUD_setKeep(AUD_Handle* handle, int keep);
extern int AUD_setKeep(AUD_Channel* handle, int keep);
/**
* Seeks a playing or paused sound.
@@ -217,7 +228,7 @@ extern int AUD_setKeep(AUD_Handle* handle, int keep);
* \param seekTo From where the sound file should be played back in seconds.
* \return Whether the handle has been valid or not.
*/
extern int AUD_seek(AUD_Handle* handle, float seekTo);
extern int AUD_seek(AUD_Channel* handle, float seekTo);
/**
* Retrieves the playback position of a handle.
@@ -225,14 +236,14 @@ extern int AUD_seek(AUD_Handle* handle, float seekTo);
* \return The current playback position in seconds or 0.0 if the handle is
* invalid.
*/
extern float AUD_getPosition(AUD_Handle* handle);
extern float AUD_getPosition(AUD_Channel* handle);
/**
* 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);
extern AUD_Status AUD_getStatus(AUD_Channel* handle);
/**
* Plays a 3D sound.
@@ -243,7 +254,7 @@ extern AUD_Status AUD_getStatus(AUD_Handle* handle);
* \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);
extern AUD_Channel* AUD_play3D(AUD_Sound* sound, int keep);
/**
* Updates the listener 3D data.
@@ -273,7 +284,7 @@ extern float AUD_get3DSetting(AUD_3DSetting setting);
* \param data The 3D data.
* \return Whether the action succeeded.
*/
extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
extern int AUD_update3DSource(AUD_Channel* handle, AUD_3DData* data);
/**
* Sets a 3D source setting.
@@ -282,7 +293,7 @@ extern int AUD_update3DSource(AUD_Handle* handle, AUD_3DData* data);
* \param value The new setting value.
* \return Whether the action succeeded.
*/
extern int AUD_set3DSourceSetting(AUD_Handle* handle,
extern int AUD_set3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting, float value);
/**
@@ -291,7 +302,7 @@ extern int AUD_set3DSourceSetting(AUD_Handle* handle,
* \param setting The setting type.
* \return The setting value.
*/
extern float AUD_get3DSourceSetting(AUD_Handle* handle,
extern float AUD_get3DSourceSetting(AUD_Channel* handle,
AUD_3DSourceSetting setting);
/**
@@ -300,7 +311,7 @@ extern float AUD_get3DSourceSetting(AUD_Handle* handle,
* \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);
extern int AUD_setSoundVolume(AUD_Channel* handle, float volume);
/**
* Sets the pitch of a played back sound.
@@ -308,7 +319,7 @@ extern int AUD_setSoundVolume(AUD_Handle* handle, float volume);
* \param pitch The new pitch.
* \return Whether the action succeeded.
*/
extern int AUD_setSoundPitch(AUD_Handle* handle, float pitch);
extern int AUD_setSoundPitch(AUD_Channel* handle, float pitch);
/**
* Opens a read device, with which audio data can be read.
@@ -332,7 +343,7 @@ extern int AUD_setDeviceVolume(AUD_Device* device, float volume);
* \param seek The position where the sound should be seeked to.
* \return A handle to the played back sound.
*/
extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek);
extern AUD_Channel* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float seek);
/**
* Sets the volume of a played back sound of a read device.
@@ -342,7 +353,7 @@ extern AUD_Handle* AUD_playDevice(AUD_Device* device, AUD_Sound* sound, float se
* \return Whether the action succeeded.
*/
extern int AUD_setDeviceSoundVolume(AUD_Device* device,
AUD_Handle* handle,
AUD_Channel* handle,
float volume);
/**
@@ -393,9 +404,9 @@ extern void AUD_startPlayback();
extern void AUD_stopPlayback();
extern void AUD_seekSequencer(AUD_Handle* handle, float time);
extern void AUD_seekSequencer(AUD_Channel* handle, float time);
extern float AUD_getSequencerPosition(AUD_Handle* handle);
extern float AUD_getSequencerPosition(AUD_Channel* handle);
#ifdef WITH_JACK
extern void AUD_setSyncCallback(AUD_syncFunction function, void* data);

View File

@@ -36,6 +36,7 @@ SET(INC
../windowmanager
../editors/include
../../../intern/guardedalloc
../../../intern/audaspace/intern
${PYTHON_INC}
)

View File

@@ -6,7 +6,7 @@ sources = env.Glob('intern/*.c')
incs = '. ../editors/include ../makesdna ../makesrna ../blenlib ../blenkernel ../nodes'
incs += ' ../imbuf ../blenloader ../render/extern/include ../windowmanager'
incs += ' #intern/guardedalloc #intern/memutil #extern/glew/include'
incs += ' ' + env['BF_PYTHON_INC']
incs += ' #intern/audaspace/intern ' + env['BF_PYTHON_INC']
defs = []

View File

@@ -41,6 +41,11 @@
#include "../generic/blf_api.h"
#include "../generic/IDProp.h"
#ifndef DISABLE_PYTHON
#define WITH_PYTHON
#endif
#include "AUD_C-API.h"
static char bpy_home_paths_doc[] =
".. function:: home_paths(subfolder)\n"
"\n"
@@ -162,7 +167,7 @@ void BPy_init_modules( void )
BGL_Init();
BLF_Init();
IDProp_Init_Types();
AUD_initPython();
mod = PyModule_New("_bpy");

View File

@@ -45,6 +45,10 @@ extern "C" {
#include "marshal.h" /* python header for loading/saving dicts */
}
#define WITH_PYTHON
#include "AUD_C-API.h"
#endif
#include "KX_PythonInit.h"
@@ -1989,6 +1993,7 @@ void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene* startscene, Main *
initGeometry();
initBGL();
initBLF();
AUD_initPython();
#ifdef WITH_FFMPEG
initVideoTexture();

View File

@@ -58,7 +58,7 @@ class KX_SoundActuator : public SCA_IActuator
float m_pitch;
bool m_is3d;
KX_3DSoundSettings m_3d;
AUD_Handle* m_handle;
AUD_Channel* m_handle;
void play();