From 6c5c58e05799f2b593cd81fcff57e6ef72ad57fb Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Sun, 9 Aug 2009 21:16:39 +0000 Subject: 2.5: Sound branch merge! See mailing list for additional information. --- .../BlenderRoutines/BL_KetsjiEmbedStart.cpp | 24 +- .../Converter/BL_BlenderDataConversion.cpp | 21 +- source/gameengine/Converter/CMakeLists.txt | 1 + .../gameengine/Converter/KX_ConvertActuators.cpp | 154 +----- source/gameengine/Converter/SConscript | 1 + source/gameengine/Ketsji/CMakeLists.txt | 1 + source/gameengine/Ketsji/KX_CDActuator.cpp | 86 +-- source/gameengine/Ketsji/KX_CDActuator.h | 4 - source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 58 +- source/gameengine/Ketsji/KX_KetsjiEngine.h | 2 - source/gameengine/Ketsji/KX_Scene.cpp | 13 - source/gameengine/Ketsji/KX_Scene.h | 11 - source/gameengine/Ketsji/KX_SoundActuator.cpp | 592 +++++++-------------- source/gameengine/Ketsji/KX_SoundActuator.h | 65 ++- source/gameengine/Ketsji/SConscript | 1 + 15 files changed, 297 insertions(+), 737 deletions(-) (limited to 'source/gameengine') diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 086c259c4bb..1c79d97ae55 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -186,19 +186,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw // create a networkdevice NG_NetworkDeviceInterface* networkdevice = new NG_LoopBackNetworkDeviceInterface(); - - // - SYS_SystemHandle hSystem = SYS_GetSystem(); - bool noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0); - if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */ - SND_DeviceManager::SetDeviceType(snd_e_dummydevice); - - // get an audiodevice - SND_DeviceManager::Subscribe(); - SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); - audiodevice->UseCD(); - + // // create a ketsji/blendersystem (only needed for timing and stuff) KX_BlenderSystem* kxsystem = new KX_BlenderSystem(); @@ -213,7 +202,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw ketsjiengine->SetRenderTools(rendertools); ketsjiengine->SetRasterizer(rasterizer); ketsjiengine->SetNetworkDevice(networkdevice); - ketsjiengine->SetAudioDevice(audiodevice); ketsjiengine->SetUseFixedTime(usefixed); ketsjiengine->SetTimingDisplay(frameRate, profile, properties); @@ -374,7 +362,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, networkdevice, - audiodevice, startscenename, blscene); @@ -519,8 +506,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); // clean up some stuff - audiodevice->StopCD(); - if (ketsjiengine) { delete ketsjiengine; @@ -637,11 +622,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, NG_NetworkDeviceInterface* networkdevice = new NG_LoopBackNetworkDeviceInterface(); - // get an audiodevice - SND_DeviceManager::Subscribe(); - SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); - audiodevice->UseCD(); - // create a ketsji/blendersystem (only needed for timing and stuff) KX_BlenderSystem* kxsystem = new KX_BlenderSystem(); @@ -692,7 +672,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, networkdevice, - audiodevice, startscenename, blscene); @@ -756,7 +735,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); // clean up some stuff - audiodevice->StopCD(); if (ketsjiengine) { delete ketsjiengine; diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index e148861ca5a..2c7df80a3fc 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -101,9 +101,6 @@ #include "KX_KetsjiEngine.h" #include "KX_BlenderSceneConverter.h" -#include"SND_Scene.h" -#include "SND_SoundListener.h" - /* This little block needed for linking to Blender... */ #ifdef WIN32 #include "BLI_winstuff.h" @@ -2616,23 +2613,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - sumolist->Release(); - - // convert global sound stuff - - /* XXX, glob is the very very wrong place for this - * to be, re-enable once the listener has been moved into - * the scene. */ -#if 1 - SND_Scene* soundscene = kxscene->GetSoundScene(); - SND_SoundListener* listener = soundscene->GetListener(); - if (listener && G.listener) - { - listener->SetDopplerFactor(G.listener->dopplerfactor); - listener->SetDopplerVelocity(G.listener->dopplervelocity); - listener->SetGain(G.listener->gain); - } -#endif + sumolist->Release(); // convert world KX_WorldInfo* worldinfo = new BlenderWorldInfo(blenderscene->world); diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt index 031c2234ea8..f4aa50cd837 100644 --- a/source/gameengine/Converter/CMakeLists.txt +++ b/source/gameengine/Converter/CMakeLists.txt @@ -32,6 +32,7 @@ SET(INC ../../../intern/string ../../../intern/guardedalloc ../../../source/gameengine/Rasterizer/RAS_OpenGLRasterizer + ../../../intern/audaspace ../../../intern/SoundSystem ../../../intern/SoundSystem/include ../../../intern/SoundSystem/openal diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index c18e4fce8a5..1afadac5c0a 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -38,7 +38,7 @@ #include "KX_BlenderSceneConverter.h" #include "KX_ConvertActuators.h" -#include "SND_Scene.h" +#include "AUD_C-API.h" // Actuators //SCA logiclibrary native logicbricks #include "SCA_PropertyActuator.h" @@ -347,8 +347,7 @@ void BL_ConvertActuators(char* maggiename, { bSoundActuator* soundact = (bSoundActuator*) bact->data; /* get type, and possibly a start and end frame */ - short startFrame = soundact->sta, stopFrame = soundact->end; - KX_SoundActuator::KX_SOUNDACT_TYPE + KX_SoundActuator::KX_SOUNDACT_TYPE soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF; switch(soundact->type) { @@ -378,114 +377,38 @@ void BL_ConvertActuators(char* maggiename, if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF) { - SND_Scene* soundscene = scene->GetSoundScene(); - STR_String samplename = ""; - bool sampleisloaded = false; - - if (soundact->sound) { - /* Need to convert the samplename into absolute path - * before checking if its loaded */ - char fullpath[FILE_MAX]; - - /* dont modify soundact->sound->name, only change a copy */ - BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath)); - BLI_convertstringcode(fullpath, maggiename); - samplename = fullpath; - - /* let's see if the sample was already loaded */ - if (soundscene->IsSampleLoaded(samplename)) - { - sampleisloaded = true; - } - else { - /* if not, make it so */ - PackedFile* pf = soundact->sound->newpackedfile; - - /* but we need a packed file then */ - if (pf) - { - if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1) - sampleisloaded = true; - } - /* or else load it from disk */ - else - { - if (soundscene->LoadSample(samplename, NULL, 0) > -1) { - sampleisloaded = true; - } - else { - std::cout << "WARNING: Sound actuator \"" << bact->name << - "\" from object \"" << blenderobject->id.name+2 << - "\" failed to load sample." << std::endl; - } - } - } - } else { + bSound* sound = soundact->sound; + bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false; + AUD_Sound* snd_sound = NULL; + KX_3DSoundSettings settings; + settings.cone_inner_angle = soundact->sound3D.cone_inner_angle; + settings.cone_outer_angle = soundact->sound3D.cone_outer_angle; + settings.cone_outer_gain = soundact->sound3D.cone_outer_gain; + settings.max_distance = soundact->sound3D.max_distance; + settings.max_gain = soundact->sound3D.max_gain; + settings.min_gain = soundact->sound3D.min_gain; + settings.reference_distance = soundact->sound3D.reference_distance; + settings.rolloff_factor = soundact->sound3D.rolloff_factor; + + if(!sound) + { std::cout << "WARNING: Sound actuator \"" << bact->name << "\" from object \"" << blenderobject->id.name+2 << "\" has no sound datablock." << std::endl; } - - /* Note, allowing actuators for sounds that are not there was added since 2.47 - * This is because python may expect the actuator and raise an exception if it dosnt find it - * better just to add a dummy sound actuator. */ - SND_SoundObject* sndobj = NULL; - if (sampleisloaded) - { - /* setup the SND_SoundObject */ - sndobj = new SND_SoundObject(); - sndobj->SetSampleName(samplename.Ptr()); - sndobj->SetObjectName(bact->name); - if (soundact->sound) { - sndobj->SetRollOffFactor(soundact->sound->attenuation); - sndobj->SetGain(soundact->sound->volume); - sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0))); - // sndobj->SetLoopStart(soundact->sound->loopstart); - // sndobj->SetLoopStart(soundact->sound->loopend); - if (soundact->sound->flags & SOUND_FLAGS_LOOP) - { - if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP) - sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL); - else - sndobj->SetLoopMode(SND_LOOP_NORMAL); - } - else { - sndobj->SetLoopMode(SND_LOOP_OFF); - } - - if (soundact->sound->flags & SOUND_FLAGS_PRIORITY) - sndobj->SetHighPriority(true); - else - sndobj->SetHighPriority(false); - - if (soundact->sound->flags & SOUND_FLAGS_3D) - sndobj->Set3D(true); - else - sndobj->Set3D(false); - } - else { - /* dummy values for a NULL sound - * see editsound.c - defaults are unlikely to change soon */ - sndobj->SetRollOffFactor(1.0); - sndobj->SetGain(1.0); - sndobj->SetPitch(1.0); - sndobj->SetLoopMode(SND_LOOP_OFF); - sndobj->SetHighPriority(false); - sndobj->Set3D(false); - } - } - KX_SoundActuator* tmpsoundact = - new KX_SoundActuator(gameobj, - sndobj, - scene->GetSoundScene(), // needed for replication! - soundActuatorType, - startFrame, - stopFrame); - + else + snd_sound = sound->cache ? sound->cache : sound->snd_sound; + KX_SoundActuator* tmpsoundact = + new KX_SoundActuator(gameobj, + snd_sound, + soundact->volume, + exp((soundact->pitch / 12.0) * log(2.0)), + is3d, + settings, + soundActuatorType); + tmpsoundact->SetName(bact->name); baseact = tmpsoundact; - if (sndobj) - soundscene->AddObject(sndobj); } break; } @@ -525,27 +448,6 @@ void BL_ConvertActuators(char* maggiename, /* This is an error!!! */ cdActuatorType = KX_CDActuator::KX_CDACT_NODEF; } - - if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF) - { - SND_CDObject* pCD = SND_CDObject::Instance(); - - if (pCD) - { - pCD->SetGain(cdact->volume); - - KX_CDActuator* tmpcdact = - new KX_CDActuator(gameobj, - scene->GetSoundScene(), // needed for replication! - cdActuatorType, - cdact->track, - startFrame, - stopFrame); - - tmpcdact->SetName(bact->name); - baseact = tmpcdact; - } - } break; } case ACT_PROPERTY: diff --git a/source/gameengine/Converter/SConscript b/source/gameengine/Converter/SConscript index 05ea01c902a..1c03179ea07 100644 --- a/source/gameengine/Converter/SConscript +++ b/source/gameengine/Converter/SConscript @@ -6,6 +6,7 @@ defs = [] incs = '. #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' +incs += ' #intern/audaspace' incs += ' #intern/SoundSystem #intern/SoundSystem/include #intern/SoundSystem/openal' incs += ' #intern/SoundSystem/dummy #intern/SoundSystem/intern #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf' diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt index f703841c40b..d368e9f4efd 100644 --- a/source/gameengine/Ketsji/CMakeLists.txt +++ b/source/gameengine/Ketsji/CMakeLists.txt @@ -55,6 +55,7 @@ SET(INC ../../../source/gameengine/Physics/Sumo ../../../source/gameengine/Physics/Sumo/Fuzzics/include ../../../source/gameengine/Network/LoopBackNetwork + ../../../intern/audaspace ../../../intern/SoundSystem ../../../source/blender/misc ../../../source/blender/blenloader diff --git a/source/gameengine/Ketsji/KX_CDActuator.cpp b/source/gameengine/Ketsji/KX_CDActuator.cpp index bfca81f45d9..0861a54d848 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.cpp +++ b/source/gameengine/Ketsji/KX_CDActuator.cpp @@ -31,9 +31,7 @@ */ #include "KX_CDActuator.h" -#include "SND_CDObject.h" #include "KX_GameObject.h" -#include "SND_Scene.h" // needed for replication #include #ifdef HAVE_CONFIG_H @@ -44,21 +42,18 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_CDActuator::KX_CDActuator(SCA_IObject* gameobject, - SND_Scene* soundscene, KX_CDACT_TYPE type, int track, short start, short end) : SCA_IActuator(gameobject) { - m_soundscene = soundscene; m_type = type; m_track = track; m_lastEvent = true; m_isplaying = false; m_startFrame = start; m_endFrame = end; - m_gain = SND_CDObject::Instance()->GetGain(); } @@ -82,60 +77,13 @@ bool KX_CDActuator::Update() { bool result = false; bool bNegativeEvent = IsNegativeEvent(); - + RemoveAllEvents(); - + if (!bNegativeEvent) { switch (m_type) { - case KX_CDACT_PLAY_ALL: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(1); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_PLAY_TRACK: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); - SND_CDObject::Instance()->SetTrack(m_track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_LOOP_TRACK: - { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(m_track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); - //result = true; - break; - } - case KX_CDACT_STOP: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); - break; - } - case KX_CDACT_PAUSE: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); - //result = true; - break; - } - case KX_CDACT_RESUME: - { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); - //result = true; - break; - } - case KX_CDACT_VOLUME: - { - SND_CDObject::Instance()->SetGain(m_gain); - //result = true; - break; - } default: // implement me !! break; @@ -196,7 +144,6 @@ PyMethodDef KX_CDActuator::Methods[] = { }; PyAttributeDef KX_CDActuator::Attributes[] = { - KX_PYATTRIBUTE_FLOAT_RW_CHECK("volume", 0.0, 1.0, KX_CDActuator, m_gain,pyattr_setGain), KX_PYATTRIBUTE_INT_RW("track", 1, 99, false, KX_CDActuator, m_track), { NULL } //Sentinel }; @@ -204,7 +151,6 @@ PyAttributeDef KX_CDActuator::Attributes[] = { int KX_CDActuator::pyattr_setGain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_CDActuator* act = static_cast(self); - SND_CDObject::Instance()->SetGain(act->m_gain); return PY_SET_ATTR_SUCCESS; } @@ -212,34 +158,30 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, startCD, "startCD()\n" "\tStarts the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, pauseCD, "pauseCD()\n" "\tPauses the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PAUSE); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, resumeCD, "resumeCD()\n" "\tResumes the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_RESUME); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, stopCD, "stopCD()\n" "\tStops the CD playing.\n") { - SND_CDObject::Instance()->SetPlaystate(SND_MUST_STOP); Py_RETURN_NONE; } @@ -250,9 +192,6 @@ KX_PYMETHODDEF_DOC_O(KX_CDActuator, playTrack, { if (PyLong_Check(value)) { int track = PyLong_AsSsize_t(value); - SND_CDObject::Instance()->SetPlaymode(SND_CD_TRACK); - SND_CDObject::Instance()->SetTrack(track); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); } Py_RETURN_NONE; } @@ -263,11 +202,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_CDActuator, playAll, "playAll()\n" "\tPlays the CD from the beginning.\n") { - SND_CDObject::Instance()->SetPlaymode(SND_CD_ALL); - SND_CDObject::Instance()->SetTrack(1); - SND_CDObject::Instance()->SetPlaystate(SND_MUST_PLAY); Py_RETURN_NONE; -} +} // Deprecated -----> PyObject* KX_CDActuator::PySetGain(PyObject* args) @@ -276,20 +212,18 @@ PyObject* KX_CDActuator::PySetGain(PyObject* args) ShowDeprecationWarning("setGain()", "the volume property"); if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; - - SND_CDObject::Instance()->SetGain(gain); - + Py_RETURN_NONE; -} +} PyObject* KX_CDActuator::PyGetGain(PyObject* args) { - float gain = SND_CDObject::Instance()->GetGain(); + float gain = 1.0; ShowDeprecationWarning("getGain()", "the volume property"); PyObject* result = PyFloat_FromDouble(gain); - + return result; } // <----- diff --git a/source/gameengine/Ketsji/KX_CDActuator.h b/source/gameengine/Ketsji/KX_CDActuator.h index b01ad73777e..bce29adb6e8 100644 --- a/source/gameengine/Ketsji/KX_CDActuator.h +++ b/source/gameengine/Ketsji/KX_CDActuator.h @@ -33,7 +33,6 @@ #define __KX_CDACTUATOR #include "SCA_IActuator.h" -#include "SND_CDObject.h" class KX_CDActuator : public SCA_IActuator { @@ -41,9 +40,7 @@ class KX_CDActuator : public SCA_IActuator bool m_lastEvent; bool m_isplaying; /* just some handles to the audio-data... */ - class SND_Scene* m_soundscene; int m_track; - float m_gain; short m_startFrame; short m_endFrame; @@ -64,7 +61,6 @@ public: KX_CDACT_TYPE m_type; KX_CDActuator(SCA_IObject* gameobject, - SND_Scene* soundscene, KX_CDACT_TYPE type, int track, short start, diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index da72fe2fa50..13643e3a1ac 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -61,8 +61,7 @@ #include "KX_PyConstraintBinding.h" #include "PHY_IPhysicsEnvironment.h" -#include "SND_Scene.h" -#include "SND_IAudioDevice.h" +#include "AUD_C-API.h" #include "NG_NetworkScene.h" #include "NG_NetworkDeviceInterface.h" @@ -113,7 +112,6 @@ KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system) m_rendertools(NULL), m_sceneconverter(NULL), m_networkdevice(NULL), - m_audiodevice(NULL), m_pythondictionary(NULL), m_keyboarddevice(NULL), m_mousedevice(NULL), @@ -211,15 +209,6 @@ void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice) } - -void KX_KetsjiEngine::SetAudioDevice(SND_IAudioDevice* audiodevice) -{ - MT_assert(audiodevice); - m_audiodevice = audiodevice; -} - - - void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas) { MT_assert(canvas); @@ -690,10 +679,7 @@ else if (m_networkdevice) m_networkdevice->NextFrame(); - - if (m_audiodevice) - m_audiodevice->NextFrame(); - + // scene management ProcessScheduledScenes(); @@ -970,13 +956,40 @@ void KX_KetsjiEngine::DoSound(KX_Scene* scene) MT_Vector3 listenervelocity = cam->GetLinearVelocity(); MT_Matrix3x3 listenerorientation = cam->NodeGetWorldOrientation(); - SND_Scene* soundscene = scene->GetSoundScene(); - soundscene->SetListenerTransform( - listenerposition, - listenervelocity, - listenerorientation); + { + AUD_3DData data; + float f; + + listenerorientation.getValue3x3(data.orientation); + listenerposition.getValue(data.position); + listenervelocity.getValue(data.velocity); + + f = data.position[1]; + data.position[1] = data.position[2]; + data.position[2] = -f; + + f = data.velocity[1]; + data.velocity[1] = data.velocity[2]; + data.velocity[2] = -f; + + f = data.orientation[1]; + data.orientation[1] = data.orientation[2]; + data.orientation[2] = -f; - soundscene->Proceed(); + f = data.orientation[3]; + data.orientation[3] = -data.orientation[6]; + data.orientation[6] = f; + + f = data.orientation[4]; + data.orientation[4] = -data.orientation[8]; + data.orientation[8] = -f; + + f = data.orientation[5]; + data.orientation[5] = data.orientation[7]; + data.orientation[7] = f; + + AUD_updateListener(&data); + } } @@ -1595,7 +1608,6 @@ KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename) KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice, m_mousedevice, m_networkdevice, - m_audiodevice, scenename, scene); diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h index abba23ca376..a36b3f163fd 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.h +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h @@ -70,7 +70,6 @@ private: class RAS_IRenderTools* m_rendertools; class KX_ISceneConverter* m_sceneconverter; class NG_NetworkDeviceInterface* m_networkdevice; - class SND_IAudioDevice* m_audiodevice; PyObject* m_pythondictionary; class SCA_IInputDevice* m_keyboarddevice; class SCA_IInputDevice* m_mousedevice; @@ -200,7 +199,6 @@ public: void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice); void SetMouseDevice(SCA_IInputDevice* mousedevice); void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice); - void SetAudioDevice(SND_IAudioDevice* audiodevice); void SetCanvas(RAS_ICanvas* canvas); void SetRenderTools(RAS_IRenderTools* rendertools); void SetRasterizer(RAS_IRasterizer* rasterizer); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 12df262df56..c45e4294d13 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -34,7 +34,6 @@ #include "KX_Scene.h" #include "MT_assert.h" -#include "SND_Scene.h" #include "KX_KetsjiEngine.h" #include "KX_BlenderMaterial.h" #include "RAS_IPolygonMaterial.h" @@ -135,7 +134,6 @@ extern bool gUseVisibilityTemp; KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, class NG_NetworkDeviceInterface *ndi, - class SND_IAudioDevice* adi, const STR_String& sceneName, Scene *scene): PyObjectPlus(), @@ -144,7 +142,6 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_sceneConverter(NULL), m_physicsEnvironment(0), m_sceneName(sceneName), - m_adi(adi), m_networkDeviceInterface(ndi), m_active_camera(NULL), m_ueberExecutionPriority(0), @@ -200,7 +197,6 @@ KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice, m_logicmgr->RegisterEventManager(joymgr); } - m_soundScene = new SND_Scene(adi); MT_assert (m_networkDeviceInterface != NULL); m_networkScene = new NG_NetworkScene(m_networkDeviceInterface); @@ -250,9 +246,6 @@ KX_Scene::~KX_Scene() if (m_physicsEnvironment) delete m_physicsEnvironment; - if (m_soundScene) - delete m_soundScene; - if (m_networkScene) delete m_networkScene; @@ -364,12 +357,6 @@ class KX_WorldInfo* KX_Scene::GetWorldInfo() } - -SND_Scene* KX_Scene::GetSoundScene() -{ - return m_soundScene; -} - const STR_String& KX_Scene::GetName() { return m_sceneName; diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index a2e328fb5d5..f48e9520f53 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -63,8 +63,6 @@ class SCA_TimeEventManager; class SCA_MouseManager; class SCA_ISystem; class SCA_IInputDevice; -class SND_Scene; -class SND_IAudioDevice; class NG_NetworkDeviceInterface; class NG_NetworkScene; class SG_IObject; @@ -160,14 +158,7 @@ protected: * @section Different scenes, linked to ketsji scene */ - /** - * Sound scenes - */ - SND_Scene* m_soundScene; - SND_IAudioDevice* m_adi; - - /** * Network scene. */ NG_NetworkDeviceInterface* m_networkDeviceInterface; @@ -283,7 +274,6 @@ public: KX_Scene(class SCA_IInputDevice* keyboarddevice, class SCA_IInputDevice* mousedevice, class NG_NetworkDeviceInterface* ndi, - class SND_IAudioDevice* adi, const STR_String& scenename, struct Scene* scene); @@ -480,7 +470,6 @@ public: void CalculateVisibleMeshes(RAS_IRasterizer* rasty, KX_Camera *cam, int layer=0); void UpdateMeshTransformations(); KX_Camera* GetpCamera(); - SND_Scene* GetSoundScene(); NG_NetworkDeviceInterface* GetNetworkDeviceInterface(); NG_NetworkScene* GetNetworkScene(); diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 39381182944..db1788629ed 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -46,37 +46,94 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, - SND_SoundObject* sndobj, - SND_Scene* sndscene, - KX_SOUNDACT_TYPE type, - short start, - short end) + AUD_Sound* sound, + float volume, + float pitch, + bool is3d, + KX_3DSoundSettings settings, + KX_SOUNDACT_TYPE type)//, : SCA_IActuator(gameobj) { - m_soundObject = sndobj; - m_soundScene = sndscene; + m_sound = sound; + m_volume = volume; + m_pitch = pitch; + m_is3d = is3d; + m_3d = settings; + m_handle = NULL; m_type = type; - m_lastEvent = true; m_isplaying = false; - m_startFrame = start; - m_endFrame = end; - m_pino = false; - - } KX_SoundActuator::~KX_SoundActuator() { - if (m_soundObject) - { - m_soundScene->RemoveActiveObject(m_soundObject); - m_soundScene->DeleteObject(m_soundObject); - } + if(m_handle) + AUD_stop(m_handle); } +void KX_SoundActuator::play() +{ + if(m_handle) + AUD_stop(m_handle); + + if(!m_sound) + return; + + // this is the sound that will be played and not deleted afterwards + AUD_Sound* sound = m_sound; + // this sounds are for temporary stacked sounds, will be deleted if not NULL + AUD_Sound* sound2 = NULL; + AUD_Sound* sound3 = NULL; + switch (m_type) + { + case KX_SOUNDACT_LOOPBIDIRECTIONAL: + case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: + // create a ping pong sound on sound2 stacked on the orignal sound + sound2 = AUD_pingpongSound(sound); + // create a loop sound on sound3 stacked on the pingpong sound and let that one play (save it to sound) + sound = sound3 = AUD_loopSound(sound2); + break; + case KX_SOUNDACT_LOOPEND: + case KX_SOUNDACT_LOOPSTOP: + // create a loop sound on sound2 stacked on the pingpong sound and let that one play (save it to sound) + sound = sound2 = AUD_loopSound(sound); + break; + case KX_SOUNDACT_PLAYSTOP: + case KX_SOUNDACT_PLAYEND: + default: + break; + } + + if(m_is3d) + { + // sound shall be played 3D + m_handle = AUD_play3D(sound, 0); + + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_GAIN, m_3d.max_gain); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MIN_GAIN, m_3d.min_gain); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_REFERENCE_DISTANCE, m_3d.reference_distance); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_MAX_DISTANCE, m_3d.max_distance); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_ROLLOFF_FACTOR, m_3d.rolloff_factor); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_INNER_ANGLE, m_3d.cone_inner_angle); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_ANGLE, m_3d.cone_outer_angle); + AUD_set3DSourceSetting(m_handle, AUD_3DSS_CONE_OUTER_GAIN, m_3d.cone_outer_gain); + } + else + m_handle = AUD_play(sound, 0); + + AUD_setSoundPitch(m_handle, m_pitch); + AUD_setSoundVolume(m_handle, m_volume); + m_isplaying = true; + + // now we unload the pingpong and loop sounds, as we don't need them anymore + // the started sound will continue playing like it was created, don't worry! + if(sound3) + AUD_unload(sound3); + if(sound2) + AUD_unload(sound2); +} CValue* KX_SoundActuator::GetReplica() { @@ -88,13 +145,8 @@ CValue* KX_SoundActuator::GetReplica() void KX_SoundActuator::ProcessReplica() { SCA_IActuator::ProcessReplica(); - if (m_soundObject) - { - SND_SoundObject* soundobj = new SND_SoundObject(*m_soundObject); - setSoundObject(soundobj); - m_soundScene->AddObject(soundobj); - } -} + m_handle = 0; +} bool KX_SoundActuator::Update(double curtime, bool frame) { @@ -108,22 +160,16 @@ bool KX_SoundActuator::Update(double curtime, bool frame) RemoveAllEvents(); - if (!m_soundObject) + if(!m_sound) return false; // actual audio device playing state - bool isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED && m_soundObject->GetPlaystate() != SND_INITIAL) ? true : false; - - if (m_pino) - { - bNegativeEvent = true; - m_pino = false; - } + bool isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING; if (bNegativeEvent) - { + { // here must be a check if it is still playing - if (m_isplaying && isplaying) + if (m_isplaying && isplaying) { switch (m_type) { @@ -131,19 +177,20 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPSTOP: case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: { - m_soundScene->RemoveActiveObject(m_soundObject); + // stop immediately + AUD_stop(m_handle); break; } case KX_SOUNDACT_PLAYEND: { - m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED); + // do nothing, sound will stop anyway when it's finished break; } case KX_SOUNDACT_LOOPEND: case KX_SOUNDACT_LOOPBIDIRECTIONAL: { - m_soundObject->SetLoopMode(SND_LOOP_OFF); - m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED); + // stop the looping so that the sound stops when it finished + AUD_stopLoop(m_handle); break; } default: @@ -166,50 +213,49 @@ bool KX_SoundActuator::Update(double curtime, bool frame) // the negative pulse is done continuesly #endif if (!m_isplaying) - { - switch (m_type) - { - case KX_SOUNDACT_LOOPBIDIRECTIONAL: - case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: - { - m_soundObject->SetLoopMode(SND_LOOP_BIDIRECTIONAL); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - case KX_SOUNDACT_LOOPEND: - case KX_SOUNDACT_LOOPSTOP: - { - m_soundObject->SetLoopMode(SND_LOOP_NORMAL); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - case KX_SOUNDACT_PLAYSTOP: - case KX_SOUNDACT_PLAYEND: - { - m_soundObject->SetLoopMode(SND_LOOP_OFF); - m_soundScene->AddActiveObject(m_soundObject, curtime); - m_isplaying = true; - result = true; - break; - } - default: - // implement me !! - break; - } - } + play(); } // verify that the sound is still playing - isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED && m_soundObject->GetPlaystate() != SND_INITIAL) ? true : false; + isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING ? true : false; if (isplaying) { - m_soundObject->SetPosition(((KX_GameObject*)this->GetParent())->NodeGetWorldPosition()); - m_soundObject->SetVelocity(((KX_GameObject*)this->GetParent())->GetLinearVelocity()); - m_soundObject->SetOrientation(((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation()); + if(m_is3d) + { + AUD_3DData data; + float f; + ((KX_GameObject*)this->GetParent())->NodeGetWorldPosition().getValue(data.position); + ((KX_GameObject*)this->GetParent())->GetLinearVelocity().getValue(data.velocity); + ((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation().getValue3x3(data.orientation); + + /* + * The 3D data from blender has to be transformed for OpenAL: + * - In blender z is up and y is forwards + * - In OpenAL y is up and z is backwards + * We have to do that for all 5 vectors. + */ + f = data.position[1]; + data.position[1] = data.position[2]; + data.position[2] = -f; + + f = data.velocity[1]; + data.velocity[1] = data.velocity[2]; + data.velocity[2] = -f; + + f = data.orientation[1]; + data.orientation[1] = data.orientation[2]; + data.orientation[2] = -f; + + f = data.orientation[4]; + data.orientation[4] = data.orientation[5]; + data.orientation[5] = -f; + + f = data.orientation[7]; + data.orientation[7] = data.orientation[8]; + data.orientation[8] = -f; + + AUD_update3DSource(m_handle, &data); + } result = true; } else @@ -217,23 +263,11 @@ bool KX_SoundActuator::Update(double curtime, bool frame) m_isplaying = false; result = false; } - /* - if (result && (m_soundObject->IsLifeSpanOver(curtime)) && ((m_type == KX_SOUNDACT_PLAYEND) || (m_type == KX_SOUNDACT_PLAYSTOP))) - { - m_pino = true; - } - */ return result; } -void KX_SoundActuator::setSoundObject(class SND_SoundObject* soundobject) -{ - m_soundObject = soundobject; -} - - /* ------------------------------------------------------------------------- */ /* Python functions */ @@ -272,19 +306,12 @@ PyTypeObject KX_SoundActuator::Type = { PyMethodDef KX_SoundActuator::Methods[] = { // Deprecated -----> - {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL}, - {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_NOARGS,NULL}, {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL}, {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_NOARGS,NULL}, {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL}, {"getPitch",(PyCFunction) KX_SoundActuator::sPyGetPitch,METH_NOARGS,NULL}, {"setRollOffFactor",(PyCFunction) KX_SoundActuator::sPySetRollOffFactor,METH_VARARGS,NULL}, {"getRollOffFactor",(PyCFunction) KX_SoundActuator::sPyGetRollOffFactor,METH_NOARGS,NULL}, - {"setLooping",(PyCFunction) KX_SoundActuator::sPySetLooping,METH_VARARGS,NULL}, - {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_NOARGS,NULL}, - {"setPosition",(PyCFunction) KX_SoundActuator::sPySetPosition,METH_VARARGS,NULL}, - {"setVelocity",(PyCFunction) KX_SoundActuator::sPySetVelocity,METH_VARARGS,NULL}, - {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL}, {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_NOARGS,NULL}, // <----- @@ -296,171 +323,91 @@ PyMethodDef KX_SoundActuator::Methods[] = { }; PyAttributeDef KX_SoundActuator::Attributes[] = { - KX_PYATTRIBUTE_RW_FUNCTION("fileName", KX_SoundActuator, pyattr_get_filename, pyattr_set_filename), KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain), KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor), - KX_PYATTRIBUTE_RW_FUNCTION("looping", KX_SoundActuator, pyattr_get_looping, pyattr_set_looping), - KX_PYATTRIBUTE_RW_FUNCTION("position", KX_SoundActuator, pyattr_get_position, pyattr_set_position), - KX_PYATTRIBUTE_RW_FUNCTION("velocity", KX_SoundActuator, pyattr_get_velocity, pyattr_set_velocity), - KX_PYATTRIBUTE_RW_FUNCTION("orientation", KX_SoundActuator, pyattr_get_orientation, pyattr_set_orientation), KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type), { NULL } //Sentinel }; /* Methods ----------------------------------------------------------------- */ -KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, +KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, "startSound()\n" "\tStarts the sound.\n") { - if (m_soundObject) - // This has no effect if the actuator is not active. - // To start the sound you must activate the actuator. - // This function is to restart the sound. - m_soundObject->StartSound(); + switch(AUD_getStatus(m_handle)) + { + case AUD_STATUS_PLAYING: + break; + case AUD_STATUS_PAUSED: + AUD_resume(m_handle); + break; + default: + play(); + } Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, "pauseSound()\n" "\tPauses the sound.\n") { - if (m_soundObject) - // unfortunately, openal does not implement pause correctly, it is equivalent to a stop - m_soundObject->PauseSound(); + AUD_pause(m_handle); Py_RETURN_NONE; -} +} KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, "stopSound()\n" "\tStops the sound.\n") { - if (m_soundObject) - m_soundObject->StopSound(); + AUD_stop(m_handle); Py_RETURN_NONE; } /* Atribute setting and getting -------------------------------------------- */ -PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast (self); - if (!actuator->m_soundObject) - { - return PyUnicode_FromString(""); - } - STR_String objectname = actuator->m_soundObject->GetObjectName(); - char* name = objectname.Ptr(); - - if (!name) { - PyErr_SetString(PyExc_RuntimeError, "value = actuator.fileName: KX_SoundActuator, unable to get sound fileName"); - return NULL; - } else - return PyUnicode_FromString(name); -} - PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast (self); - float gain = (actuator->m_soundObject) ? actuator->m_soundObject->GetGain() : 1.0f; + float gain = actuator->m_volume; PyObject* result = PyFloat_FromDouble(gain); - + return result; } PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast (self); - float pitch = (actuator->m_soundObject) ? actuator->m_soundObject->GetPitch() : 1.0; + float pitch = actuator->m_pitch; + PyObject* result = PyFloat_FromDouble(pitch); - + return result; } PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast (self); - float rollofffactor = (actuator->m_soundObject) ? actuator->m_soundObject->GetRollOffFactor() : 1.0; + float rollofffactor = actuator->m_3d.rolloff_factor; PyObject* result = PyFloat_FromDouble(rollofffactor); - - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast (self); - int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; - PyObject* result = PyLong_FromSsize_t(looping); - - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast (self); - MT_Vector3 pos(0.0, 0.0, 0.0); - if (actuator->m_soundObject) - pos = actuator->m_soundObject->GetPosition(); - - PyObject * result = PyObjectFrom(pos); return result; } -PyObject* KX_SoundActuator::pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast (self); - MT_Vector3 vel; - - if (actuator->m_soundObject) - vel = actuator->m_soundObject->GetVelocity(); - - PyObject * result = PyObjectFrom(vel); - return result; -} - -PyObject* KX_SoundActuator::pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast (self); - MT_Matrix3x3 ori; - - if (actuator->m_soundObject) - ori = actuator->m_soundObject->GetOrientation(); - - PyObject * result = PyObjectFrom(ori); - return result; -} - -int KX_SoundActuator::pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - char *soundName = NULL; - KX_SoundActuator * actuator = static_cast (self); - // void *soundPointer = NULL; /*unused*/ - - if (!PyArg_Parse(value, "s", &soundName)) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) { - actuator->m_soundObject->SetObjectName(soundName); - } - - return PY_SET_ATTR_SUCCESS; -} - - int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { float gain = 1.0; KX_SoundActuator * actuator = static_cast (self); if (!PyArg_Parse(value, "f", &gain)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetGain(gain); - + + actuator->m_volume = gain; + if(actuator->m_handle) + AUD_setSoundVolume(actuator->m_handle, gain); + return PY_SET_ATTR_SUCCESS; -} +} int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { @@ -468,12 +415,13 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D KX_SoundActuator * actuator = static_cast (self); if (!PyArg_Parse(value, "f", &pitch)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetPitch(pitch); - + + actuator->m_pitch = pitch; + if(actuator->m_handle) + AUD_setSoundPitch(actuator->m_handle, pitch); + return PY_SET_ATTR_SUCCESS; -} +} int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { @@ -481,127 +429,36 @@ int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATT float rollofffactor = 1.0; if (!PyArg_Parse(value, "f", &rollofffactor)) return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetRollOffFactor(rollofffactor); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - KX_SoundActuator * actuator = static_cast (self); - int looping = 1; - if (!PyArg_Parse(value, "i", &looping)) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetLoopMode(looping); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - float pos[3]; - - KX_SoundActuator * actuator = static_cast (self); - - if (!PyArg_ParseTuple(value, "fff", &pos[0], &pos[1], &pos[2])) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetPosition(MT_Vector3(pos)); - - return PY_SET_ATTR_SUCCESS; -} - -int KX_SoundActuator::pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - float vel[3]; - KX_SoundActuator * actuator = static_cast (self); - - - if (!PyArg_ParseTuple(value, "fff", &vel[0], &vel[1], &vel[2])) - return PY_SET_ATTR_FAIL; - - if (actuator->m_soundObject) - actuator->m_soundObject->SetVelocity(MT_Vector3(vel)); - - return PY_SET_ATTR_SUCCESS; - -} - -int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) -{ - MT_Matrix3x3 rot; - KX_SoundActuator * actuator = static_cast (self); + actuator->m_3d.rolloff_factor = rollofffactor; + if(actuator->m_handle) + AUD_set3DSourceSetting(actuator->m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor); - /* if value is not a sequence PyOrientationTo makes an error */ - if (!PyOrientationTo(value, rot, "actuator.orientation = value: KX_SoundActuator")) - return PY_SET_ATTR_FAIL; - - /* Since not having m_soundObject didn't do anything in the old version, - * it probably should be kept that way */ - if (!actuator->m_soundObject) - return PY_SET_ATTR_SUCCESS; - - actuator->m_soundObject->SetOrientation(rot); return PY_SET_ATTR_SUCCESS; } -// Deprecated -----> -PyObject* KX_SoundActuator::PySetFilename(PyObject* args) -{ - char *soundName = NULL; - ShowDeprecationWarning("setFilename()", "the fileName property"); - // void *soundPointer = NULL; /*unused*/ - - if (!PyArg_ParseTuple(args, "s", &soundName)) - return NULL; - - Py_RETURN_NONE; -} - -PyObject* KX_SoundActuator::PyGetFilename() -{ - ShowDeprecationWarning("getFilename()", "the fileName property"); - if (!m_soundObject) - { - return PyUnicode_FromString(""); - } - STR_String objectname = m_soundObject->GetObjectName(); - char* name = objectname.Ptr(); - - if (!name) { - PyErr_SetString(PyExc_RuntimeError, "Unable to get sound fileName"); - return NULL; - } else - return PyUnicode_FromString(name); -} - PyObject* KX_SoundActuator::PySetGain(PyObject* args) { ShowDeprecationWarning("setGain()", "the volume property"); float gain = 1.0; if (!PyArg_ParseTuple(args, "f:setGain", &gain)) return NULL; - - if (m_soundObject) - m_soundObject->SetGain(gain); - + + m_volume = gain; + if(m_handle) + AUD_setSoundVolume(m_handle, gain); + Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetGain() { ShowDeprecationWarning("getGain()", "the volume property"); - float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f; + float gain = m_volume; PyObject* result = PyFloat_FromDouble(gain); - + return result; } @@ -613,21 +470,22 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* args) float pitch = 1.0; if (!PyArg_ParseTuple(args, "f:setPitch", &pitch)) return NULL; - - if (m_soundObject) - m_soundObject->SetPitch(pitch); - + + m_pitch = pitch; + if(m_handle) + AUD_setSoundPitch(m_handle, pitch); + Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetPitch() { ShowDeprecationWarning("getPitch()", "the pitch property"); - float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0; + float pitch = m_pitch; PyObject* result = PyFloat_FromDouble(pitch); - + return result; } @@ -639,113 +497,27 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* args) float rollofffactor = 1.0; if (!PyArg_ParseTuple(args, "f:setRollOffFactor", &rollofffactor)) return NULL; - - if (m_soundObject) - m_soundObject->SetRollOffFactor(rollofffactor); + + m_3d.rolloff_factor = rollofffactor; + if(m_handle) + AUD_set3DSourceSetting(m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor); Py_RETURN_NONE; -} +} PyObject* KX_SoundActuator::PyGetRollOffFactor() { ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property"); - float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0; + float rollofffactor = m_3d.rolloff_factor; PyObject* result = PyFloat_FromDouble(rollofffactor); - - return result; -} - - - -PyObject* KX_SoundActuator::PySetLooping(PyObject* args) -{ - ShowDeprecationWarning("setLooping()", "the looping property"); - bool looping = 1; - if (!PyArg_ParseTuple(args, "i:setLooping", &looping)) - return NULL; - - if (m_soundObject) - m_soundObject->SetLoopMode(looping); - - Py_RETURN_NONE; -} - - -PyObject* KX_SoundActuator::PyGetLooping() -{ - ShowDeprecationWarning("getLooping()", "the looping property"); - int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; - PyObject* result = PyLong_FromSsize_t(looping); - return result; } -PyObject* KX_SoundActuator::PySetPosition(PyObject* args) -{ - MT_Point3 pos; - ShowDeprecationWarning("setPosition()", "the position property"); - pos[0] = 0.0; - pos[1] = 0.0; - pos[2] = 0.0; - - if (!PyArg_ParseTuple(args, "fff:setPosition", &pos[0], &pos[1], &pos[2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetPosition(pos); - - Py_RETURN_NONE; -} - - - -PyObject* KX_SoundActuator::PySetVelocity(PyObject* args) -{ - MT_Vector3 vel; - ShowDeprecationWarning("setVelocity()", "the velocity property"); - vel[0] = 0.0; - vel[1] = 0.0; - vel[2] = 0.0; - - if (!PyArg_ParseTuple(args, "fff:setVelocity", &vel[0], &vel[1], &vel[2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetVelocity(vel); - - Py_RETURN_NONE; -} - - - -PyObject* KX_SoundActuator::PySetOrientation(PyObject* args) -{ - MT_Matrix3x3 ori; - ShowDeprecationWarning("setOrientation()", "the orientation property"); - ori[0][0] = 1.0; - ori[0][1] = 0.0; - ori[0][2] = 0.0; - ori[1][0] = 0.0; - ori[1][1] = 1.0; - ori[1][2] = 0.0; - ori[2][0] = 0.0; - ori[2][1] = 0.0; - ori[2][2] = 1.0; - - if (!PyArg_ParseTuple(args, "fffffffff:setOrientation", &ori[0][0], &ori[0][1], &ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], &ori[2][2])) - return NULL; - - if (m_soundObject) - m_soundObject->SetOrientation(ori); - - Py_RETURN_NONE; -} - PyObject* KX_SoundActuator::PySetType(PyObject* args) { int typeArg; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index adafee0a30b..ddf8330072e 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -34,17 +34,41 @@ #include "SCA_IActuator.h" +#include "AUD_C-API.h" +#include "BKE_sound.h" + +typedef struct KX_3DSoundSettings +{ + float min_gain; + float max_gain; + float reference_distance; + float max_distance; + float rolloff_factor; + float cone_inner_angle; + float cone_outer_angle; + float cone_outer_gain; +} KX_3DSoundSettings; + class KX_SoundActuator : public SCA_IActuator { Py_Header; - bool m_lastEvent; +// bool m_lastEvent; bool m_isplaying; /* just some handles to the audio-data... */ - class SND_SoundObject* m_soundObject; - class SND_Scene* m_soundScene; - short m_startFrame; - short m_endFrame; - bool m_pino; + AUD_Sound* m_sound; + float m_volume; + float m_pitch; + bool m_is3d; + KX_3DSoundSettings m_3d; + AUD_Handle* m_handle; +// class SND_SoundObject* m_soundObject; +// class SND_Scene* m_soundScene; +// short m_startFrame; +// short m_endFrame; +// bool m_pino; + + void play(); + public: enum KX_SOUNDACT_TYPE @@ -62,15 +86,15 @@ public: KX_SOUNDACT_TYPE m_type; KX_SoundActuator(SCA_IObject* gameobj, - class SND_SoundObject* sndobj, - class SND_Scene* sndscene, - KX_SOUNDACT_TYPE type, - short start, - short end); + AUD_Sound* sound, + float volume, + float pitch, + bool is3d, + KX_3DSoundSettings settings, + KX_SOUNDACT_TYPE type); ~KX_SoundActuator(); - void setSoundObject(class SND_SoundObject* soundobject); virtual bool Update(double curtime, bool frame); CValue* GetReplica(); @@ -84,40 +108,23 @@ public: KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound); KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound); - static int pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static int pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); - static PyObject* pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - static PyObject* pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); // Deprecated -----> - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetFilename); - KX_PYMETHOD_NOARGS(KX_SoundActuator,GetFilename); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetGain); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetGain); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPitch); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetPitch); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetRollOffFactor); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetRollOffFactor); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetLooping); - KX_PYMETHOD_NOARGS(KX_SoundActuator,GetLooping); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetPosition); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetVelocity); - KX_PYMETHOD_VARARGS(KX_SoundActuator,SetOrientation); KX_PYMETHOD_VARARGS(KX_SoundActuator,SetType); KX_PYMETHOD_NOARGS(KX_SoundActuator,GetType); // <----- diff --git a/source/gameengine/Ketsji/SConscript b/source/gameengine/Ketsji/SConscript index 1edffe0e587..373f1ca2606 100644 --- a/source/gameengine/Ketsji/SConscript +++ b/source/gameengine/Ketsji/SConscript @@ -11,6 +11,7 @@ incs = '. #source/blender/python/generic' # Only for Mathutils! and bpy_internal incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc' incs += ' #source/gameengine/Rasterizer/RAS_OpenGLRasterizer' incs += ' #intern/SoundSystem #intern/SoundSystem/include #intern/SoundSystem/openal' +incs += ' #intern/audaspace' incs += ' #intern/SoundSystem/dummy #intern/SoundSystem/intern #source/gameengine/Converter' incs += ' #source/gameengine/BlenderRoutines #source/blender/imbuf #intern/moto/include' incs += ' #source/gameengine/Ketsji #source/gameengine/Ketsji/KXNetwork #source/blender/blenlib' -- cgit v1.2.3