From: Bastiaan Zapf Date: Sun, 8 May 2005 13:30:41 +0000 (+0000) Subject: - ambient_sound improved (now does silence, volume, X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=ef57f7881d5b4e01729b1f1cced3e868a40fb237;p=supertux.git - ambient_sound improved (now does silence, volume, reasonable latencies when not playing) - new sound effect (lava.wav) put into sounds SVN-Revision: 2441 --- diff --git a/basest/levels/test/ambient_sound.stl b/basest/levels/test/ambient_sound.stl index 3356744ae..e4cd7eeae 100644 --- a/basest/levels/test/ambient_sound.stl +++ b/basest/levels/test/ambient_sound.stl @@ -133,11 +133,34 @@ (speed 0.500000) ) (spawnpoint (name "main") (x 96) (y 160)) - (ambient_sound (x 128) (y 800) (distance_factor "0.1") (distance_bias "200.0") (sample "rain")) - (infoblock (x 128) (y 800) + (ambient_sound (x 128) (y 900) (distance_factor 0.01) + (distance_bias 200.0) (sample "rain")) + (ambient_sound (x 512) (y 900) (distance_factor 0.05) + (distance_bias 100.0) (sample "waterfall") (volume 0.2)) + (ambient_sound (x 800) (y 900) (distance_factor 0.1) + (distance_bias 50.0) (sample "lava")) + (infoblock (x 128) (y 864) (message (_ "-Info -#An ambient sound source -#should be audible here")) +#An ambient sound +#source playing the +#rain effect should +#be audible here. +#Find Waterfall and +#Lava sources with +#smaller geometry +#further right. +")) + ) + (infoblock (x 512) (y 864) + (message (_ "-Info +#Waterfall +#Volume 0.2 +")) + ) + (infoblock (x 800) (y 864) + (message (_ "-Info +#Lava +")) ) ) ) diff --git a/basest/levels/test/messages.pot b/basest/levels/test/messages.pot index b4156b163..afd8d3324 100644 --- a/basest/levels/test/messages.pot +++ b/basest/levels/test/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2005-05-07 18:58+0200\n" +"POT-Creation-Date: 2005-05-08 15:26+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -20,21 +20,6 @@ msgstr "" msgid "Sector Test" msgstr "" -#: basest/levels/test/verticalforest.stl:5 -msgid "Inside The Tree" -msgstr "" - -#: basest/levels/test/ambient_sound.stl:4 -msgid "Ambient Sound Test" -msgstr "" - -#: basest/levels/test/ambient_sound.stl:138 -msgid "" -"-Info\n" -"#An ambient sound source\n" -"#should be audible here" -msgstr "" - #: basest/levels/test/bonusblock.stl:4 msgid "Bonus Block Test" msgstr "" @@ -47,10 +32,44 @@ msgid "" "#This rocks" msgstr "" +#: basest/levels/test/yeti.stl:4 +msgid "Yeti Test" +msgstr "" + #: basest/levels/test/script.stl:4 msgid "Scripting Test" msgstr "" -#: basest/levels/test/yeti.stl:4 -msgid "Yeti Test" +#: basest/levels/test/verticalforest.stl:5 +msgid "Inside The Tree" +msgstr "" + +#: basest/levels/test/ambient_sound.stl:4 +msgid "Ambient Sound Test" +msgstr "" + +#: basest/levels/test/ambient_sound.stl:143 +msgid "" +"-Info\n" +"#An ambient sound \n" +"#source playing the\n" +"#rain effect should \n" +"#be audible here.\n" +"#Find Waterfall and \n" +"#Lava sources with\n" +"#smaller geometry \n" +"#further right.\n" +msgstr "" + +#: basest/levels/test/ambient_sound.stl:155 +msgid "" +"-Info\n" +"#Waterfall\n" +"#Volume 0.2\n" +msgstr "" + +#: basest/levels/test/ambient_sound.stl:161 +msgid "" +"-Info\n" +"#Lava\n" msgstr "" diff --git a/basest/sounds/lava.wav b/basest/sounds/lava.wav new file mode 100644 index 000000000..40a24eab6 Binary files /dev/null and b/basest/sounds/lava.wav differ diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index e50e946f5..0307813cd 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -32,6 +32,7 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) position.y=0; distance_factor=0; distance_bias=0; + maximumvolume=1; sample=""; if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) { @@ -40,16 +41,26 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) lisp.get("distance_factor",distance_factor); lisp.get("distance_bias" ,distance_bias ); lisp.get("sample" ,sample ); + lisp.get("volume" ,maximumvolume ); + + distance_bias*=distance_bias; + distance_factor*=distance_factor; if (distance_factor == 0) silence_distance = 10e99; else - silence_distance = distance_factor*10e2; + silence_distance = 1/distance_factor; + + lisp.get("silence_distance",silence_distance); + + playing=-1; // not playing at the beginning + latency=0; - playing=0; - startPlaying(); } +AmbientSound::~AmbientSound() { + stop_playing(); +} void AmbientSound::hit(Player& ) @@ -57,7 +68,15 @@ AmbientSound::hit(Player& ) } void -AmbientSound::startPlaying() +AmbientSound::stop_playing() { + if (playing>=0) { + Mix_HaltChannel(playing); + playing=-1; + } +} + +void +AmbientSound::start_playing() { playing=sound_manager->play_sound(sample,-1); Mix_Volume(playing,0); @@ -65,24 +84,41 @@ AmbientSound::startPlaying() } void -AmbientSound::action(float) +AmbientSound::action(float deltat) { - float dx=Sector::current()->player->get_pos().x-position.x; - float dy=Sector::current()->player->get_pos().y-position.y; - float distance=sqrt(dx*dx+dy*dy); - - distance-=distance_bias; - - if (distance<0) - distance=0; - - targetvolume=1/(1+distance*distance_factor); - float rise=targetvolume/currentvolume; - currentvolume*=pow(rise,.05); - currentvolume += 1e-30; - // std::cout << currentvolume << " " << targetvolume << std::endl; - Mix_Volume(playing,(int)(currentvolume*MIX_MAX_VOLUME)); + if (latency--<=0) { + + float dx=Sector::current()->player->get_pos().x-position.x; + float dy=Sector::current()->player->get_pos().y-position.y; + float sqrdistance=dx*dx+dy*dy; + + sqrdistance-=distance_bias; + + if (sqrdistance<0) + sqrdistance=0; + + targetvolume=1/(1+sqrdistance*distance_factor); + float rise=targetvolume/currentvolume; + currentvolume*=pow(rise,deltat*10); + currentvolume += 1e-30; + + if (playing>=0) { + Mix_Volume(playing,(int)(currentvolume*maximumvolume*MIX_MAX_VOLUME)); + if (sqrdistance>=silence_distance && currentvolume<0.05) + stop_playing(); + latency=0; + } else { + if (sqrdistance0.001/distance_factor) + latency=(int)(0.001/distance_factor); } void diff --git a/src/object/ambient_sound.h b/src/object/ambient_sound.h index f6fd28508..433e60ece 100644 --- a/src/object/ambient_sound.h +++ b/src/object/ambient_sound.h @@ -24,9 +24,12 @@ * (distance_bias) to the source, then fading proportional to * inverse square distance * - * This is experimental and clicks a little. It is not possible to - * get the clicks out without sample-granular volume adjustment. - * + * - parameters for point source: + * x, y position + * distance_factor high = steep fallofff + * distance_bias high = big "100% disc" + * silence_distance defaults reasonably. + * * basti_ */ @@ -43,22 +46,25 @@ class AmbientSound : public GameObject { public: AmbientSound(const lisp::Lisp& lisp); - + ~AmbientSound(); protected: virtual void hit(Player& player); virtual void action(float time); virtual void draw(DrawingContext&); - virtual void startPlaying(); + virtual void start_playing(); + virtual void stop_playing(); private: Vector position; std::string sample; int playing; + int latency; float distance_factor; /// distance scaling float distance_bias; /// 100% volume disc radius float silence_distance; /// not implemented yet + float maximumvolume; /// maximum volume float targetvolume; /// how loud we want to be float currentvolume; /// how loud we are diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index aae11d85a..8b8263760 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -1,5 +1,5 @@ /** - * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/optimize/miniswig.tmp' - do not change + * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/debug/miniswig.tmp' - do not change */ #include diff --git a/src/scripting/wrapper.h b/src/scripting/wrapper.h index 35f7184a4..f25aea134 100644 --- a/src/scripting/wrapper.h +++ b/src/scripting/wrapper.h @@ -1,5 +1,5 @@ /** - * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/optimize/miniswig.tmp' - do not change + * WARNING: This file is automatically generated from './build/i686-pc-linux-gnu/debug/miniswig.tmp' - do not change */ #ifndef __supertux_WRAPPER_H__ #define __supertux_WRAPPER_H__