X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Faudio%2Fstream_sound_source.cpp;h=958ef6f58f8c00960a78ead45faa419482ff1112;hb=ca86583fae991aa3280c5d70bf20dbf0504a93cb;hp=d27856342649ce4023c659639e79adf256973f15;hpb=07ddaed2a657e4d2a3d038fed223fc5827159caf;p=supertux.git diff --git a/src/audio/stream_sound_source.cpp b/src/audio/stream_sound_source.cpp index d27856342..958ef6f58 100644 --- a/src/audio/stream_sound_source.cpp +++ b/src/audio/stream_sound_source.cpp @@ -25,6 +25,7 @@ #include "stream_sound_source.hpp" #include "sound_manager.hpp" #include "sound_file.hpp" +#include "timer.hpp" #include "log.hpp" StreamSoundSource::StreamSoundSource() @@ -32,10 +33,14 @@ StreamSoundSource::StreamSoundSource() { alGenBuffers(STREAMFRAGMENTS, buffers); SoundManager::check_al_error("Couldn't allocate audio buffers: "); + //add me to update list + sound_manager->register_for_update( this ); } StreamSoundSource::~StreamSoundSource() { + //don't update me any longer + sound_manager->remove_from_update( this ); delete file; stop(); alDeleteBuffers(STREAMFRAGMENTS, buffers); @@ -73,15 +78,14 @@ StreamSoundSource::update() if(!playing()) { if(processed == 0 || !looping) return; - - // we might have to restart the source if we had a buffer underrun + + // we might have to restart the source if we had a buffer underrun log_info << "Restarting audio source because of buffer underrun" << std::endl; play(); } if(fade_state == FadingOn) { - Uint32 ticks = SDL_GetTicks(); - float time = (ticks - fade_start_ticks) / 1000.0; + float time = real_time - fade_start_time; if(time >= fade_time) { set_gain(1.0); fade_state = NoFading; @@ -89,8 +93,7 @@ StreamSoundSource::update() set_gain(time / fade_time); } } else if(fade_state == FadingOff) { - Uint32 ticks = SDL_GetTicks(); - float time = (ticks - fade_start_ticks) / 1000.0; + float time = real_time - fade_start_time; if(time >= fade_time) { stop(); fade_state = NoFading; @@ -105,7 +108,7 @@ StreamSoundSource::set_fading(FadeState state, float fade_time) { this->fade_state = state; this->fade_time = fade_time; - this->fade_start_ticks = SDL_GetTicks(); + this->fade_start_time = real_time; } bool @@ -139,4 +142,3 @@ StreamSoundSource::fillBufferAndQueue(ALuint buffer) // return false if there aren't more buffers to fill return bytesread >= STREAMFRAGMENTSIZE; } -