From 044887b5a4b1df57fce408f29f59bce1d7fa0085 Mon Sep 17 00:00:00 2001 From: Joerg Mueller Date: Tue, 21 Jun 2011 20:21:43 +0000 Subject: 3D Audio GSoC: - Created Handle classes - Changed Reference counting completely - Fixing some streaming bugs - Completely disabled OpenAL Buffered Factories (they were unused anyway) --- source/blender/blenkernel/intern/sound.c | 59 ++++++++++++++++++++------- source/gameengine/Ketsji/KX_SoundActuator.cpp | 56 +++++++++++++++---------- 2 files changed, 79 insertions(+), 36 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 9e9df24be32..18eab716924 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -51,7 +51,8 @@ static void sound_sync_callback(void* data, int mode, float time) sound_play_scene(scene); else sound_stop_scene(scene); - AUD_seek(scene->sound_scene_handle, time); + if(scene->sound_scene_handle) + AUD_seek(scene->sound_scene_handle, time); } scene = scene->id.next; } @@ -345,7 +346,7 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, AUD_setDeviceVolume(mixdown, volume); - AUD_playDevice(mixdown, scene->sound_scene, start / FPS); + AUD_freeChannel(AUD_playDevice(mixdown, scene->sound_scene, start / FPS)); return mixdown; } @@ -353,12 +354,16 @@ AUD_Device* sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, void sound_create_scene(struct Scene *scene) { scene->sound_scene = AUD_createSequencer(scene->audio.flag & AUDIO_MUTE, scene, (AUD_volumeFunction)&sound_get_volume); + scene->sound_scene_handle = NULL; + scene->sound_scrub_handle = NULL; } void sound_destroy_scene(struct Scene *scene) { if(scene->sound_scene_handle) AUD_stop(scene->sound_scene_handle); + if(scene->sound_scrub_handle) + AUD_stop(scene->sound_scrub_handle); if(scene->sound_scene) AUD_destroySequencer(scene->sound_scene); } @@ -398,8 +403,10 @@ void sound_move_scene_sound(struct Scene *scene, void* handle, int startframe, i static void sound_start_play_scene(struct Scene *scene) { - scene->sound_scene_handle = AUD_play(scene->sound_scene, 1); - AUD_setLoop(scene->sound_scene_handle, -1); + if(scene->sound_scene_handle) + AUD_stop(scene->sound_scene_handle); + if((scene->sound_scene_handle = AUD_play(scene->sound_scene, 1))) + AUD_setLoop(scene->sound_scene_handle, -1); } void sound_play_scene(struct Scene *scene) @@ -407,11 +414,17 @@ void sound_play_scene(struct Scene *scene) AUD_Status status; AUD_lock(); - status = AUD_getStatus(scene->sound_scene_handle); + status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; if(status == AUD_STATUS_INVALID) sound_start_play_scene(scene); + if(!scene->sound_scene_handle) + { + AUD_unlock(); + return; + } + if(status != AUD_STATUS_PLAYING) { AUD_seek(scene->sound_scene_handle, CFRA / FPS); @@ -426,10 +439,13 @@ void sound_play_scene(struct Scene *scene) void sound_stop_scene(struct Scene *scene) { - AUD_pause(scene->sound_scene_handle); + if(scene->sound_scene_handle) + { + AUD_pause(scene->sound_scene_handle); - if(scene->audio.flag & AUDIO_SYNC) - AUD_stopPlayback(); + if(scene->audio.flag & AUDIO_SYNC) + AUD_stopPlayback(); + } } void sound_seek_scene(struct bContext *C) @@ -439,11 +455,18 @@ void sound_seek_scene(struct bContext *C) AUD_lock(); - status = AUD_getStatus(scene->sound_scene_handle); + status = scene->sound_scene_handle ? AUD_getStatus(scene->sound_scene_handle) : AUD_STATUS_INVALID; if(status == AUD_STATUS_INVALID) { sound_start_play_scene(scene); + + if(!scene->sound_scene_handle) + { + AUD_unlock(); + return; + } + AUD_pause(scene->sound_scene_handle); } @@ -457,10 +480,14 @@ void sound_seek_scene(struct bContext *C) else AUD_seek(scene->sound_scene_handle, CFRA / FPS); AUD_resume(scene->sound_scene_handle); - if(AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) + if(scene->sound_scrub_handle && AUD_getStatus(scene->sound_scrub_handle) != AUD_STATUS_INVALID) AUD_seek(scene->sound_scrub_handle, 0); else + { + if(scene->sound_scrub_handle) + AUD_stop(scene->sound_scrub_handle); scene->sound_scrub_handle = AUD_pauseAfter(scene->sound_scene_handle, 1 / FPS); + } } else { @@ -478,10 +505,14 @@ void sound_seek_scene(struct bContext *C) float sound_sync_scene(struct Scene *scene) { - if(scene->audio.flag & AUDIO_SYNC) - return AUD_getSequencerPosition(scene->sound_scene_handle); - else - return AUD_getPosition(scene->sound_scene_handle); + if(scene->sound_scene_handle) + { + if(scene->audio.flag & AUDIO_SYNC) + return AUD_getSequencerPosition(scene->sound_scene_handle); + else + return AUD_getPosition(scene->sound_scene_handle); + } + return 0.0f; } int sound_scene_playing(struct Scene *scene) diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index 5a19337e7a2..6f8bb4bf087 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -75,7 +75,10 @@ KX_SoundActuator::~KX_SoundActuator() void KX_SoundActuator::play() { if(m_handle) + { AUD_stop(m_handle); + m_handle = NULL; + } if(!m_sound) return; @@ -103,11 +106,16 @@ void KX_SoundActuator::play() break; } + m_handle = AUD_play(sound, 0); + + if(sound2) + AUD_unload(sound2); + + if(!m_handle) + return; + if(m_is3d) { - // sound shall be played 3D - m_handle = AUD_play(sound, 0); - AUD_setRelative(m_handle, false); AUD_setVolumeMaximum(m_handle, m_3d.max_gain); AUD_setVolumeMinimum(m_handle, m_3d.min_gain); @@ -118,17 +126,12 @@ void KX_SoundActuator::play() AUD_setConeAngleOuter(m_handle, m_3d.cone_outer_angle); AUD_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain); } - else - m_handle = AUD_play(sound, 0); if(loop) AUD_setLoop(m_handle, -1); AUD_setSoundPitch(m_handle, m_pitch); AUD_setSoundVolume(m_handle, m_volume); m_isplaying = true; - - if(sound2) - AUD_unload(sound2); } CValue* KX_SoundActuator::GetReplica() @@ -160,7 +163,7 @@ bool KX_SoundActuator::Update(double curtime, bool frame) return false; // actual audio device playing state - bool isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING; + bool isplaying = m_handle ? (AUD_getStatus(m_handle) == AUD_STATUS_PLAYING) : false; if (bNegativeEvent) { @@ -174,7 +177,9 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP: { // stop immediately - AUD_stop(m_handle); + if(m_handle) + AUD_stop(m_handle); + m_handle = NULL; break; } case KX_SOUNDACT_PLAYEND: @@ -186,7 +191,8 @@ bool KX_SoundActuator::Update(double curtime, bool frame) case KX_SOUNDACT_LOOPBIDIRECTIONAL: { // stop the looping so that the sound stops when it finished - AUD_setLoop(m_handle, 0); + if(m_handle) + AUD_setLoop(m_handle, 0); break; } default: @@ -212,7 +218,7 @@ bool KX_SoundActuator::Update(double curtime, bool frame) play(); } // verify that the sound is still playing - isplaying = AUD_getStatus(m_handle) == AUD_STATUS_PLAYING ? true : false; + isplaying = m_handle ? (AUD_getStatus(m_handle) == AUD_STATUS_PLAYING) : false; if (isplaying) { @@ -301,15 +307,18 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, "startSound()\n" "\tStarts the sound.\n") { - switch(AUD_getStatus(m_handle)) + if(m_handle) { - case AUD_STATUS_PLAYING: - break; - case AUD_STATUS_PAUSED: - AUD_resume(m_handle); - break; - default: - play(); + switch(AUD_getStatus(m_handle)) + { + case AUD_STATUS_PLAYING: + break; + case AUD_STATUS_PAUSED: + AUD_resume(m_handle); + break; + default: + play(); + } } Py_RETURN_NONE; } @@ -318,7 +327,8 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, "pauseSound()\n" "\tPauses the sound.\n") { - AUD_pause(m_handle); + if(m_handle) + AUD_pause(m_handle); Py_RETURN_NONE; } @@ -326,7 +336,9 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, "stopSound()\n" "\tStops the sound.\n") { - AUD_stop(m_handle); + if(m_handle) + AUD_stop(m_handle); + m_handle = NULL; Py_RETURN_NONE; } -- cgit v1.2.3