Audaspace: preparing to use standalone library.

- Renamed some functions.
- Using C API instead of C++ in the game engine, as the standalone is C++11.
This commit is contained in:
Joerg Mueller 2014-03-03 23:57:59 +01:00
parent d3acfa1d87
commit 96dd213e7e
Notes: blender-bot 2023-02-14 00:13:36 +01:00
Referenced by commit e32430df34, Fix T46458: BGE Crash on load
9 changed files with 187 additions and 213 deletions

View File

@ -130,7 +130,7 @@ void AUD_exitOnce()
#endif
}
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
int AUD_init(const char* device, const char* name, AUD_DeviceSpecs specs, int buffersize)
{
boost::shared_ptr<AUD_IDevice> dev;
@ -138,47 +138,46 @@ int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
AUD_exit();
}
std::string dname = device;
try {
switch(device) {
case AUD_NULL_DEVICE:
if(dname == "Null") {
dev = boost::shared_ptr<AUD_IDevice>(new AUD_NULLDevice());
break;
}
#ifdef WITH_SDL
case AUD_SDL_DEVICE:
if (SDL_Init == (void *)0) {
printf("Warning: SDL libraries are not installed\n");
// No break, fall through to default, to return false
}
else {
dev = boost::shared_ptr<AUD_IDevice>(new AUD_SDLDevice(specs, buffersize));
break;
}
else if(dname == "SDL")
{
dev = boost::shared_ptr<AUD_IDevice>(new AUD_SDLDevice(specs, buffersize));
}
#endif
#ifdef WITH_OPENAL
case AUD_OPENAL_DEVICE:
else if(dname == "OpenAL")
{
dev = boost::shared_ptr<AUD_IDevice>(new AUD_OpenALDevice(specs, buffersize));
break;
}
#endif
#ifdef WITH_JACK
case AUD_JACK_DEVICE:
else if(dname == "Jack")
{
#ifdef __APPLE__
struct stat st;
if (stat("/Library/Frameworks/Jackmp.framework", &st) != 0) {
printf("Warning: Jack Framework not installed\n");
// No break, fall through to default, to return false
return false;
}
else
#endif
if (!AUD_jack_supported()) {
printf("Warning: Jack client not installed\n");
// No break, fall through to default, to return false
printf("Warning: Jack cllient not installed\n");
return false;
}
else {
dev = boost::shared_ptr<AUD_IDevice>(new AUD_JackDevice("Blender", specs, buffersize));
break;
dev = boost::shared_ptr<AUD_IDevice>(new AUD_JackDevice(name, specs, buffersize));
}
}
#endif
default:
else
{
return false;
}
@ -266,7 +265,7 @@ PyObject *AUD_initPython()
return module;
}
void *AUD_getPythonFactory(AUD_Sound *sound)
void *AUD_getPythonSound(AUD_Sound *sound)
{
if (sound) {
Factory *obj = (Factory *) Factory_empty();
@ -279,7 +278,7 @@ void *AUD_getPythonFactory(AUD_Sound *sound)
return NULL;
}
AUD_Sound *AUD_getPythonSound(void *sound)
AUD_Sound *AUD_getSoundFromPython(void *sound)
{
Factory *factory = checkFactory((PyObject *)sound);
@ -488,6 +487,11 @@ int AUD_stop(AUD_Handle *handle)
return result;
}
void AUD_stopAll(void)
{
AUD_device->stopAll();
}
int AUD_setKeep(AUD_Handle *handle, int keep)
{
assert(handle);
@ -1015,7 +1019,7 @@ void AUD_setSequencerSpecs(AUD_Sound *sequencer, AUD_Specs specs)
dynamic_cast<AUD_SequencerFactory *>(sequencer->get())->setSpecs(specs);
}
void AUD_seekSequencer(AUD_Handle *handle, float time)
void AUD_seekSynchronizer(AUD_Handle *handle, float time)
{
#ifdef WITH_JACK
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
@ -1030,7 +1034,7 @@ void AUD_seekSequencer(AUD_Handle *handle, float time)
}
}
float AUD_getSequencerPosition(AUD_Handle *handle)
float AUD_getSynchronizerPosition(AUD_Handle *handle)
{
#ifdef WITH_JACK
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
@ -1045,7 +1049,7 @@ float AUD_getSequencerPosition(AUD_Handle *handle)
}
}
void AUD_startPlayback()
void AUD_playSynchronizer()
{
#ifdef WITH_JACK
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
@ -1055,7 +1059,7 @@ void AUD_startPlayback()
#endif
}
void AUD_stopPlayback()
void AUD_stopSynchronizer()
{
#ifdef WITH_JACK
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
@ -1066,7 +1070,7 @@ void AUD_stopPlayback()
}
#ifdef WITH_JACK
void AUD_setSyncCallback(AUD_syncFunction function, void *data)
void AUD_setSynchronizerCallback(AUD_syncFunction function, void *data)
{
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
if (device) {
@ -1075,7 +1079,7 @@ void AUD_setSyncCallback(AUD_syncFunction function, void *data)
}
#endif
int AUD_doesPlayback()
int AUD_isSynchronizerPlaying()
{
#ifdef WITH_JACK
AUD_JackDevice *device = dynamic_cast<AUD_JackDevice *>(AUD_device.get());
@ -1283,16 +1287,6 @@ AUD_Device *AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound *sequencer, f
}
}
boost::shared_ptr<AUD_IDevice> AUD_getDevice()
{
return AUD_device;
}
AUD_I3DDevice *AUD_get3DDevice()
{
return AUD_3ddevice;
}
int AUD_isJackSupported(void)
{
#ifdef WITH_JACK

View File

@ -77,7 +77,7 @@ extern void AUD_exitOnce(void);
* \param buffersize The buffersize for the device.
* \return Whether the device has been initialized.
*/
extern int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize);
extern int AUD_init(const char* device, const char* name, AUD_DeviceSpecs specs, int buffersize);
/**
* Unitinitializes an audio device.
@ -212,6 +212,8 @@ extern int AUD_resume(AUD_Handle *handle);
*/
extern int AUD_stop(AUD_Handle *handle);
extern void AUD_stopAll(void);
/**
* Sets the end behaviour of a playing or paused sound.
* \param handle The handle to the sound.
@ -604,24 +606,24 @@ extern void AUD_setSequencerSpecs(AUD_Sound *sequencer, AUD_Specs specs);
* \param handle Playback handle.
* \param time Time in seconds to seek to.
*/
extern void AUD_seekSequencer(AUD_Handle *handle, float time);
extern void AUD_seekSynchronizer(AUD_Handle *handle, float time);
/**
* Returns the current sound scene playback time.
* \param handle Playback handle.
* \return The playback time in seconds.
*/
extern float AUD_getSequencerPosition(AUD_Handle *handle);
extern float AUD_getSynchronizerPosition(AUD_Handle *handle);
/**
* Starts the playback of jack transport if possible.
*/
extern void AUD_startPlayback(void);
extern void AUD_playSynchronizer(void);
/**
* Stops the playback of jack transport if possible.
*/
extern void AUD_stopPlayback(void);
extern void AUD_stopSynchronizer(void);
#ifdef WITH_JACK
/**
@ -629,14 +631,14 @@ extern void AUD_stopPlayback(void);
* \param function The callback function.
* \param data The data parameter for the callback.
*/
extern void AUD_setSyncCallback(AUD_syncFunction function, void *data);
extern void AUD_setSynchronizerCallback(AUD_syncFunction function, void *data);
#endif
/**
* Returns whether jack transport is currently playing.
* \return Whether jack transport is currently playing.
*/
extern int AUD_doesPlayback(void);
extern int AUD_isSynchronizerPlaying(void);
/**
* Reads a sound into a buffer for drawing at a specific sampling rate.
@ -747,36 +749,20 @@ extern AUD_Device *AUD_openMixdownDevice(AUD_DeviceSpecs specs, AUD_Sound *seque
* \param sound The sound factory.
* \return The python factory.
*/
extern void *AUD_getPythonFactory(AUD_Sound *sound);
extern void *AUD_getPythonSound(AUD_Sound *sound);
/**
* Retrieves the sound factory of a python factory.
* \param sound The python factory.
* \return The sound factory.
*/
extern AUD_Sound *AUD_getPythonSound(void *sound);
extern AUD_Sound *AUD_getSoundFromPython(void *sound);
#endif
extern int AUD_isJackSupported(void);
#ifdef __cplusplus
}
#include <boost/shared_ptr.hpp>
class AUD_IDevice;
class AUD_I3DDevice;
/**
* Returns the current playback device.
* \return The playback device.
*/
boost::shared_ptr<AUD_IDevice> AUD_getDevice();
/**
* Returns the current playback 3D device.
* \return The playback 3D device.
*/
AUD_I3DDevice *AUD_get3DDevice();
#endif
#endif //__AUD_C_API_H__

View File

@ -176,6 +176,7 @@ void BKE_sound_init(struct Main *bmain)
{
AUD_DeviceSpecs specs;
int device, buffersize;
const char* device_name;
device = U.audiodevice;
buffersize = U.mixbufsize;
@ -186,6 +187,22 @@ void BKE_sound_init(struct Main *bmain)
if (force_device >= 0)
device = force_device;
switch(device)
{
case AUD_SDL_DEVICE:
device_name = "SDL";
break;
case AUD_OPENAL_DEVICE:
device_name = "OpenAL";
break;
case AUD_JACK_DEVICE:
device_name = "Jack";
break;
default:
device_name = "Null";
break;
}
if (buffersize < 128)
buffersize = AUD_DEFAULT_BUFFER_SIZE;
@ -198,8 +215,8 @@ void BKE_sound_init(struct Main *bmain)
if (specs.channels <= AUD_CHANNELS_INVALID)
specs.channels = AUD_CHANNELS_STEREO;
if (!AUD_init(device, specs, buffersize))
AUD_init(AUD_NULL_DEVICE, specs, buffersize);
if (!AUD_init(device_name, "Blender", specs, buffersize))
AUD_init("Null", "Blender", specs, buffersize);
BKE_sound_init_main(bmain);
}
@ -207,7 +224,7 @@ void BKE_sound_init(struct Main *bmain)
void BKE_sound_init_main(struct Main *bmain)
{
#ifdef WITH_JACK
AUD_setSyncCallback(sound_sync_callback, bmain);
AUD_setSynchronizerCallback(sound_sync_callback, bmain);
#else
(void)bmain; /* unused */
#endif
@ -557,7 +574,7 @@ void BKE_sound_play_scene(struct Scene *scene)
}
if (scene->audio.flag & AUDIO_SYNC)
AUD_startPlayback();
AUD_playSynchronizer();
AUD_unlock();
}
@ -568,7 +585,7 @@ void BKE_sound_stop_scene(struct Scene *scene)
AUD_pause(scene->playback_handle);
if (scene->audio.flag & AUDIO_SYNC)
AUD_stopPlayback();
AUD_stopSynchronizer();
}
}
@ -607,7 +624,7 @@ void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene)
if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) {
if (scene->audio.flag & AUDIO_SYNC) {
AUD_seek(scene->playback_handle, cur_time);
AUD_seekSequencer(scene->playback_handle, cur_time);
AUD_seekSynchronizer(scene->playback_handle, cur_time);
}
else {
AUD_seek(scene->playback_handle, cur_time);
@ -625,7 +642,7 @@ void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene)
}
else {
if (scene->audio.flag & AUDIO_SYNC) {
AUD_seekSequencer(scene->playback_handle, cur_time);
AUD_seekSynchronizer(scene->playback_handle, cur_time);
}
else {
if (status == AUD_STATUS_PLAYING) {
@ -641,7 +658,7 @@ float BKE_sound_sync_scene(struct Scene *scene)
{
if (scene->playback_handle) {
if (scene->audio.flag & AUDIO_SYNC)
return AUD_getSequencerPosition(scene->playback_handle);
return AUD_getSynchronizerPosition(scene->playback_handle);
else
return AUD_getPosition(scene->playback_handle);
}
@ -651,7 +668,7 @@ float BKE_sound_sync_scene(struct Scene *scene)
int BKE_sound_scene_playing(struct Scene *scene)
{
if (scene->audio.flag & AUDIO_SYNC)
return AUD_doesPlayback();
return AUD_isSynchronizerPlaying();
else
return -1;
}

View File

@ -102,8 +102,6 @@ typedef void * wmUIHandlerRemoveFunc;
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_I3DDevice.h"
# include "AUD_IDevice.h"
#endif
static BlendFileData *load_game_data(char *filename)
@ -502,13 +500,9 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
ketsjiengine->InitDome(scene->gm.dome.res, scene->gm.dome.mode, scene->gm.dome.angle, scene->gm.dome.resbuf, scene->gm.dome.tilt, scene->gm.dome.warptext);
// initialize 3D Audio Settings
AUD_I3DDevice* dev = AUD_get3DDevice();
if (dev)
{
dev->setSpeedOfSound(scene->audio.speed_of_sound);
dev->setDopplerFactor(scene->audio.doppler_factor);
dev->setDistanceModel(AUD_DistanceModel(scene->audio.distance_model));
}
AUD_setSpeedOfSound(scene->audio.speed_of_sound);
AUD_setDopplerFactor(scene->audio.doppler_factor);
AUD_setDistanceModel(AUD_DistanceModel(scene->audio.distance_model));
// from see blender.c:
// FIXME: this version patching should really be part of the file-reading code,
@ -675,7 +669,7 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
}
// stop all remaining playing sounds
AUD_getDevice()->stopAll();
AUD_stopAll();
} while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);

View File

@ -43,7 +43,6 @@
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_ChannelMapperFactory.h"
#endif
// Actuators
@ -385,7 +384,7 @@ void BL_ConvertActuators(const char* maggiename,
{
bSound* sound = soundact->sound;
bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
boost::shared_ptr<AUD_IFactory> snd_sound;
AUD_Sound* snd_sound = NULL;
KX_3DSoundSettings settings;
settings.cone_inner_angle = RAD2DEGF(soundact->sound3D.cone_inner_angle);
settings.cone_outer_angle = RAD2DEGF(soundact->sound3D.cone_outer_angle);
@ -404,27 +403,12 @@ void BL_ConvertActuators(const char* maggiename,
}
else
{
snd_sound = *reinterpret_cast<boost::shared_ptr<AUD_IFactory>*>(sound->playback_handle);
snd_sound = sound->playback_handle;
// if sound shall be 3D but isn't mono, we have to make it mono!
if (is3d)
{
try
{
boost::shared_ptr<AUD_IReader> reader = snd_sound->createReader();
if (reader->getSpecs().channels != AUD_CHANNELS_MONO)
{
AUD_DeviceSpecs specs;
specs.channels = AUD_CHANNELS_MONO;
specs.rate = AUD_RATE_INVALID;
specs.format = AUD_FORMAT_INVALID;
snd_sound = boost::shared_ptr<AUD_IFactory>(new AUD_ChannelMapperFactory(snd_sound, specs));
}
}
catch(AUD_Exception&)
{
// sound cannot be played... ignore
}
snd_sound = AUD_monoSound(snd_sound);
}
}
KX_SoundActuator* tmpsoundact =
@ -436,6 +420,10 @@ void BL_ConvertActuators(const char* maggiename,
settings,
soundActuatorType);
// if we made it mono, we have to free it
if(snd_sound != sound->playback_handle && snd_sound != NULL)
AUD_unload(snd_sound);
tmpsoundact->SetName(bact->name);
baseact = tmpsoundact;
}

View File

@ -101,8 +101,6 @@ extern "C"
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_I3DDevice.h"
# include "AUD_IDevice.h"
#endif
static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
@ -746,13 +744,9 @@ bool GPG_Application::startEngine(void)
m_ketsjiengine->InitDome(m_startScene->gm.dome.res, m_startScene->gm.dome.mode, m_startScene->gm.dome.angle, m_startScene->gm.dome.resbuf, m_startScene->gm.dome.tilt, m_startScene->gm.dome.warptext);
// initialize 3D Audio Settings
AUD_I3DDevice* dev = AUD_get3DDevice();
if (dev)
{
dev->setSpeedOfSound(m_startScene->audio.speed_of_sound);
dev->setDopplerFactor(m_startScene->audio.doppler_factor);
dev->setDistanceModel(AUD_DistanceModel(m_startScene->audio.distance_model));
}
AUD_setSpeedOfSound(m_startScene->audio.speed_of_sound);
AUD_setDopplerFactor(m_startScene->audio.doppler_factor);
AUD_setDistanceModel(AUD_DistanceModel(m_startScene->audio.distance_model));
#ifdef WITH_PYTHON
// Set the GameLogic.globalDict from marshal'd data, so we can

View File

@ -64,7 +64,6 @@
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_I3DDevice.h"
#endif
#include "NG_NetworkScene.h"

View File

@ -38,9 +38,6 @@
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_PingPongFactory.h"
# include "AUD_IDevice.h"
# include "AUD_I3DHandle.h"
#endif
#include "KX_GameObject.h"
@ -53,7 +50,7 @@
/* Native functions */
/* ------------------------------------------------------------------------- */
KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
boost::shared_ptr<AUD_IFactory> sound,
AUD_Sound* sound,
float volume,
float pitch,
bool is3d,
@ -61,7 +58,8 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
KX_SOUNDACT_TYPE type)//,
: SCA_IActuator(gameobj, KX_ACT_SOUND)
{
m_sound = sound;
m_sound = AUD_copy(sound);
m_handle = NULL;
m_volume = volume;
m_pitch = pitch;
m_is3d = is3d;
@ -74,20 +72,30 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
KX_SoundActuator::~KX_SoundActuator()
{
if (m_handle.get())
m_handle->stop();
if(m_handle)
{
AUD_stop(m_handle);
}
if(m_sound)
{
AUD_unload(m_sound);
}
}
void KX_SoundActuator::play()
{
if (m_handle.get())
m_handle->stop();
if(m_handle)
{
AUD_stop(m_handle);
m_handle = NULL;
}
if (!m_sound.get())
if (!m_sound)
return;
// this is the sound that will be played and not deleted afterwards
boost::shared_ptr<AUD_IFactory> sound = m_sound;
AUD_Sound* sound = m_sound;
bool loop = false;
@ -95,7 +103,7 @@ void KX_SoundActuator::play()
{
case KX_SOUNDACT_LOOPBIDIRECTIONAL:
case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
sound = boost::shared_ptr<AUD_IFactory>(new AUD_PingPongFactory(sound));
sound = AUD_pingpongSound(sound);
// fall through
case KX_SOUNDACT_LOOPEND:
case KX_SOUNDACT_LOOPSTOP:
@ -107,36 +115,31 @@ void KX_SoundActuator::play()
break;
}
try
{
m_handle = AUD_getDevice()->play(sound);
}
catch(AUD_Exception&)
{
// cannot play back, ignore
return;
}
m_handle = AUD_play(sound, false);
boost::shared_ptr<AUD_I3DHandle> handle3d = boost::dynamic_pointer_cast<AUD_I3DHandle>(m_handle);
// in case of pingpong, we have to free the sound
if(sound != m_sound)
AUD_unload(sound);
if (m_is3d && handle3d.get())
if (m_handle != NULL)
{
handle3d->setRelative(true);
handle3d->setVolumeMaximum(m_3d.max_gain);
handle3d->setVolumeMinimum(m_3d.min_gain);
handle3d->setDistanceReference(m_3d.reference_distance);
handle3d->setDistanceMaximum(m_3d.max_distance);
handle3d->setAttenuation(m_3d.rolloff_factor);
handle3d->setConeAngleInner(m_3d.cone_inner_angle);
handle3d->setConeAngleOuter(m_3d.cone_outer_angle);
handle3d->setConeVolumeOuter(m_3d.cone_outer_gain);
}
if (m_is3d)
{
AUD_setRelative(m_handle, true);
AUD_setVolumeMaximum(m_handle, m_3d.max_gain);
AUD_setVolumeMinimum(m_handle, m_3d.min_gain);
AUD_setDistanceReference(m_handle, m_3d.reference_distance);
AUD_setDistanceMaximum(m_handle, m_3d.max_distance);
AUD_setAttenuation(m_handle, m_3d.rolloff_factor);
AUD_setConeAngleInner(m_handle, m_3d.cone_inner_angle);
AUD_setConeAngleOuter(m_handle, m_3d.cone_outer_angle);
AUD_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain);
}
if (m_handle.get()) {
if (loop)
m_handle->setLoopCount(-1);
m_handle->setPitch(m_pitch);
m_handle->setVolume(m_volume);
AUD_setLoop(m_handle, -1);
AUD_setSoundPitch(m_handle, m_pitch);
AUD_setSoundVolume(m_handle, m_volume);
}
m_isplaying = true;
@ -152,7 +155,8 @@ CValue* KX_SoundActuator::GetReplica()
void KX_SoundActuator::ProcessReplica()
{
SCA_IActuator::ProcessReplica();
m_handle = boost::shared_ptr<AUD_IHandle>();
m_handle = NULL;
m_sound = AUD_copy(m_sound);
}
bool KX_SoundActuator::Update(double curtime, bool frame)
@ -167,11 +171,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
RemoveAllEvents();
if (!m_sound.get())
if (!m_sound)
return false;
// actual audio device playing state
bool isplaying = m_handle.get() ? (m_handle->getStatus() == AUD_STATUS_PLAYING) : false;
bool isplaying = m_handle ? (AUD_getStatus(m_handle) == AUD_STATUS_PLAYING) : false;
if (bNegativeEvent)
{
@ -185,9 +189,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
{
// stop immediately
if (m_handle.get())
m_handle->stop();
m_handle = boost::shared_ptr<AUD_IHandle>();
if (m_handle)
{
AUD_stop(m_handle);
m_handle = NULL;
}
break;
}
case KX_SOUNDACT_PLAYEND:
@ -199,8 +205,8 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
case KX_SOUNDACT_LOOPBIDIRECTIONAL:
{
// stop the looping so that the sound stops when it finished
if (m_handle.get())
m_handle->setLoopCount(0);
if (m_handle)
AUD_setLoop(m_handle, 0);
break;
}
default:
@ -227,13 +233,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
play();
}
// verify that the sound is still playing
isplaying = m_handle.get() ? (m_handle->getStatus() == AUD_STATUS_PLAYING) : false;
isplaying = m_handle ? (AUD_getStatus(m_handle) == AUD_STATUS_PLAYING) : false;
if (isplaying)
{
boost::shared_ptr<AUD_I3DHandle> handle3d = boost::dynamic_pointer_cast<AUD_I3DHandle>(m_handle);
if (m_is3d && handle3d.get())
if (m_is3d)
{
KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera();
if (cam)
@ -241,20 +245,19 @@ bool KX_SoundActuator::Update(double curtime, bool frame)
KX_GameObject* obj = (KX_GameObject*)this->GetParent();
MT_Point3 p;
MT_Matrix3x3 Mo;
AUD_Vector3 v;
float q[4];
float data[4];
Mo = cam->NodeGetWorldOrientation().inverse();
p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition());
p = Mo * p;
p.getValue(v.get());
handle3d->setSourceLocation(v);
p.getValue(data);
AUD_setSourceLocation(m_handle, data);
p = (obj->GetLinearVelocity() - cam->GetLinearVelocity());
p = Mo * p;
p.getValue(v.get());
handle3d->setSourceVelocity(v);
(Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(q);
handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
p.getValue(data);
AUD_setSourceVelocity(m_handle, data);
(Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(data);
AUD_setSourceOrientation(m_handle, data);
}
}
result = true;
@ -329,11 +332,11 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound,
"startSound()\n"
"\tStarts the sound.\n")
{
switch (m_handle.get() ? m_handle->getStatus() : AUD_STATUS_INVALID) {
switch (m_handle ? AUD_getStatus(m_handle) : AUD_STATUS_INVALID) {
case AUD_STATUS_PLAYING:
break;
case AUD_STATUS_PAUSED:
m_handle->resume();
AUD_resume(m_handle);
break;
default:
play();
@ -345,8 +348,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound,
"pauseSound()\n"
"\tPauses the sound.\n")
{
if (m_handle.get())
m_handle->pause();
if (m_handle)
AUD_pause(m_handle);
Py_RETURN_NONE;
}
@ -354,9 +357,11 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound,
"stopSound()\n"
"\tStops the sound.\n")
{
if (m_handle.get())
m_handle->stop();
m_handle = boost::shared_ptr<AUD_IHandle>();
if (m_handle)
{
AUD_stop(m_handle);
m_handle = NULL;
}
Py_RETURN_NONE;
}
@ -404,8 +409,8 @@ PyObject *KX_SoundActuator::pyattr_get_audposition(void *self, const struct KX_P
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float position = 0.0;
if (actuator->m_handle.get())
position = actuator->m_handle->getPosition();
if (actuator->m_handle)
position = AUD_getPosition(actuator->m_handle);
PyObject *result = PyFloat_FromDouble(position);
@ -435,8 +440,8 @@ PyObject *KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRI
PyObject *KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (actuator->m_sound.get())
return (PyObject *)AUD_getPythonFactory(&actuator->m_sound);
if (actuator->m_sound)
return (PyObject *)AUD_getPythonSound(actuator->m_sound);
else
Py_RETURN_NONE;
}
@ -450,50 +455,49 @@ int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRI
if (!PyArg_Parse(value, "f", &prop_value))
return PY_SET_ATTR_FAIL;
boost::shared_ptr<AUD_I3DHandle> handle3d = boost::dynamic_pointer_cast<AUD_I3DHandle>(actuator->m_handle);
// if sound is working and 3D, set the new setting
if (!actuator->m_is3d)
return PY_SET_ATTR_FAIL;
if (!strcmp(prop, "volume_maximum")) {
actuator->m_3d.max_gain = prop_value;
if (handle3d.get())
handle3d->setVolumeMaximum(prop_value);
if (actuator->m_handle)
AUD_setVolumeMaximum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "volume_minimum")) {
actuator->m_3d.min_gain = prop_value;
if (handle3d.get())
handle3d->setVolumeMinimum(prop_value);
if (actuator->m_handle)
AUD_setVolumeMinimum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "distance_reference")) {
actuator->m_3d.reference_distance = prop_value;
if (handle3d.get())
handle3d->setDistanceReference(prop_value);
if (actuator->m_handle)
AUD_setDistanceReference(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "distance_maximum")) {
actuator->m_3d.max_distance = prop_value;
if (handle3d.get())
handle3d->setDistanceMaximum(prop_value);
if (actuator->m_handle)
AUD_setDistanceMaximum(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "attenuation")) {
actuator->m_3d.rolloff_factor = prop_value;
if (handle3d.get())
handle3d->setAttenuation(prop_value);
if (actuator->m_handle)
AUD_setAttenuation(actuator->m_handle, prop_value);
} else if (!!strcmp(prop, "cone_angle_inner")) {
actuator->m_3d.cone_inner_angle = prop_value;
if (handle3d.get())
handle3d->setConeAngleInner(prop_value);
if (actuator->m_handle)
AUD_setConeAngleInner(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "cone_angle_outer")) {
actuator->m_3d.cone_outer_angle = prop_value;
if (handle3d.get())
handle3d->setConeAngleOuter(prop_value);
if (actuator->m_handle)
AUD_setConeAngleOuter(actuator->m_handle, prop_value);
} else if (!strcmp(prop, "cone_volume_outer")) {
actuator->m_3d.cone_outer_gain = prop_value;
if (handle3d.get())
handle3d->setConeVolumeOuter(prop_value);
if (actuator->m_handle)
AUD_setConeVolumeOuter(actuator->m_handle, prop_value);
} else {
return PY_SET_ATTR_FAIL;
@ -510,8 +514,8 @@ int KX_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRI
if (!PyArg_Parse(value, "f", &position))
return PY_SET_ATTR_FAIL;
if (actuator->m_handle.get())
actuator->m_handle->seek(position);
if (actuator->m_handle)
AUD_seek(actuator->m_handle, position);
return PY_SET_ATTR_SUCCESS;
}
@ -523,8 +527,8 @@ int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DE
return PY_SET_ATTR_FAIL;
actuator->m_volume = gain;
if (actuator->m_handle.get())
actuator->m_handle->setVolume(gain);
if (actuator->m_handle)
AUD_setSoundVolume(actuator->m_handle, gain);
return PY_SET_ATTR_SUCCESS;
}
@ -537,8 +541,8 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D
return PY_SET_ATTR_FAIL;
actuator->m_pitch = pitch;
if (actuator->m_handle.get())
actuator->m_handle->setPitch(pitch);
if (actuator->m_handle)
AUD_setSoundPitch(actuator->m_handle, pitch);
return PY_SET_ATTR_SUCCESS;
}
@ -550,11 +554,12 @@ int KX_SoundActuator::pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_D
if (!PyArg_Parse(value, "O", &sound))
return PY_SET_ATTR_FAIL;
boost::shared_ptr<AUD_IFactory>* snd = reinterpret_cast<boost::shared_ptr<AUD_IFactory>*>(AUD_getPythonSound((void *)sound));
AUD_Sound *snd = AUD_getSoundFromPython((void *)sound);
if (snd)
{
actuator->m_sound = *snd;
delete snd;
AUD_unload(actuator->m_sound);
actuator->m_sound = snd;
return PY_SET_ATTR_SUCCESS;
}

View File

@ -36,9 +36,6 @@
#ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# include "AUD_IFactory.h"
# include "AUD_IHandle.h"
# include <boost/shared_ptr.hpp>
#endif
#include "BKE_sound.h"
@ -58,12 +55,12 @@ class KX_SoundActuator : public SCA_IActuator
{
Py_Header
bool m_isplaying;
boost::shared_ptr<AUD_IFactory> m_sound;
AUD_Sound* m_sound;
float m_volume;
float m_pitch;
bool m_is3d;
KX_3DSoundSettings m_3d;
boost::shared_ptr<AUD_IHandle> m_handle;
AUD_Handle* m_handle;
void play();
@ -84,7 +81,7 @@ public:
KX_SOUNDACT_TYPE m_type;
KX_SoundActuator(SCA_IObject* gameobj,
boost::shared_ptr<AUD_IFactory> sound,
AUD_Sound *sound,
float volume,
float pitch,
bool is3d,