diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_SoundActuator.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.cpp | 664 |
1 files changed, 203 insertions, 461 deletions
diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 9e005cd04bb..024c51cabc1 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -31,10 +31,7 @@ */ #include "KX_SoundActuator.h" -#include "SND_SoundObject.h" #include "KX_GameObject.h" -#include "SND_SoundObject.h" -#include "SND_Scene.h" // needed for replication #include "KX_PyMath.h" // needed for PyObjectFrom() #include <iostream> @@ -46,38 +43,94 @@ /* Native functions */ /* ------------------------------------------------------------------------- */ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, - SND_SoundObject* sndobj, - SND_Scene* sndscene, - KX_SOUNDACT_TYPE type, - short start, - short end, - PyTypeObject* T) - : SCA_IActuator(gameobj,T) -{ - m_soundObject = sndobj; - m_soundScene = sndscene; + AUD_Sound* sound, + float volume, + float pitch, + bool is3d, + KX_3DSoundSettings settings, + KX_SOUNDACT_TYPE type)//, + : SCA_IActuator(gameobj) +{ + 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() { @@ -89,13 +142,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) { @@ -109,22 +157,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) { @@ -132,19 +174,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: @@ -167,50 +210,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 @@ -218,23 +260,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 */ @@ -244,56 +274,35 @@ void KX_SoundActuator::setSoundObject(class SND_SoundObject* soundobject) /* Integration hooks ------------------------------------------------------- */ PyTypeObject KX_SoundActuator::Type = { -#if (PY_VERSION_HEX >= 0x02060000) PyVarObject_HEAD_INIT(NULL, 0) -#else - /* python 2.5 and below */ - PyObject_HEAD_INIT( NULL ) /* required py macro */ - 0, /* ob_size */ -#endif - "KX_SoundActuator", - sizeof(PyObjectPlus_Proxy), - 0, - py_base_dealloc, - 0, - 0, - 0, - 0, - py_base_repr, - 0,0,0,0,0,0, - py_base_getattro, - py_base_setattro, - 0,0,0,0,0,0,0,0,0, - Methods + "KX_SoundActuator", + sizeof(PyObjectPlus_Proxy), + 0, + py_base_dealloc, + 0, + 0, + 0, + 0, + py_base_repr, + 0,0,0,0,0,0,0,0,0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + 0,0,0,0,0,0,0, + Methods, + 0, + 0, + &SCA_IActuator::Type, + 0,0,0,0,0,0, + py_base_new }; - - -PyParentObject KX_SoundActuator::Parents[] = { - &KX_SoundActuator::Type, - &SCA_IActuator::Type, - &SCA_ILogicBrick::Type, - &CValue::Type, - NULL -}; - - - 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}, // <----- @@ -305,183 +314,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::py_getattro(PyObject *attr) -{ - py_getattro_up(SCA_IActuator); -} - -PyObject* KX_SoundActuator::py_getattro_dict() { - py_getattro_dict_up(SCA_IActuator); -} - -int KX_SoundActuator::py_setattro(PyObject *attr, PyObject* value) { - py_setattro_up(SCA_IActuator); -} - -PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); - if (!actuator->m_soundObject) - { - return PyString_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 PyString_FromString(name); -} PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (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<KX_SoundActuator *> (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<KX_SoundActuator *> (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<KX_SoundActuator *> (self); - int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; - PyObject* result = PyInt_FromLong(looping); - return result; } -PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef) -{ - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (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<KX_SoundActuator *> (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<KX_SoundActuator *> (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<KX_SoundActuator*> (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<KX_SoundActuator *> (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) { @@ -489,12 +406,13 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (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) { @@ -502,104 +420,12 @@ 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<KX_SoundActuator *> (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]; + actuator->m_3d.rolloff_factor = rollofffactor; + if(actuator->m_handle) + AUD_set3DSourceSetting(actuator->m_handle, AUD_3DSS_ROLLOFF_FACTOR, rollofffactor); - KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (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<KX_SoundActuator *> (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<KX_SoundActuator *> (self); - - /* 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 PyString_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 PyString_FromString(name); } PyObject* KX_SoundActuator::PySetGain(PyObject* args) @@ -608,21 +434,22 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* args) 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; } @@ -634,21 +461,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; } @@ -660,113 +488,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 = PyInt_FromLong(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; @@ -787,7 +529,7 @@ PyObject* KX_SoundActuator::PySetType(PyObject* args) PyObject* KX_SoundActuator::PyGetType() { ShowDeprecationWarning("getType()", "the mode property"); - return PyInt_FromLong(m_type); + return PyLong_FromSsize_t(m_type); } // <----- |