diff options
author | Jörg Müller <nexyon@gmail.com> | 2014-03-04 02:57:59 +0400 |
---|---|---|
committer | Jörg Müller <nexyon@gmail.com> | 2015-07-28 15:01:52 +0300 |
commit | 96dd213e7ecabeffc682aee40b4102296ab062de (patch) | |
tree | ab07e2786bcd81b137c40f8ce2084ccec62075e6 /source/gameengine | |
parent | d3acfa1d87ccc7932b61311b7084951dcce67eba (diff) |
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.
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp | 14 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_ConvertActuators.cpp | 26 | ||||
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_Application.cpp | 12 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 1 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.cpp | 193 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.h | 9 |
6 files changed, 116 insertions, 139 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 9b99574b790..f275d0a0f0c 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -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); diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index 10ee228b33f..1acbd0b1608 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -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; } diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp index b8ce67743de..f06a153431e 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp @@ -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 diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index c2ca9b82c8b..acf65817c49 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -64,7 +64,6 @@ #ifdef WITH_AUDASPACE # include "AUD_C-API.h" -# include "AUD_I3DDevice.h" #endif #include "NG_NetworkScene.h" diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 4e5cd0ac5e1..611467d7167 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -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; } diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index 68eff56797b..bd7b28680f6 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -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, |