@@ -76,12 +76,13 @@ static float master_volume = DEFAULT_VOLUME; /* a value in [0,1] affecting all m
7676static float mixer_percentage = DEFAULT_MIXER_PERCENTAGE ; /* a value in [0,1] that controls music & sfx volume */
7777static bool is_globally_muted = false; /* global mute / unmute */
7878static mufflerprofile_t current_muffler_profile = DEFAULT_MUFFLER_PROFILE ;
79- static bool is_muffler_activated = false ;
79+ static int current_muffler_flags = MUFFLE_NOTHING ;
8080
8181static int preload_sample (const char * vpath , void * data );
8282static void set_master_gain (float gain );
8383static void handle_haltresume_event (const ALLEGRO_EVENT * event , void * context );
84- static void set_muffler (mufflerprofile_t profile );
84+ static void update_muffler (mufflerprofile_t profile , int flags );
85+ static void muffle_mixer (ALLEGRO_MIXER * mixer , mufflerprofile_t profile );
8586static const float * muffler_sigma (mufflerprofile_t profile );
8687static void muffler_postprocess (void * buf , unsigned int num_samples , void * data );
8788
@@ -575,9 +576,7 @@ void audio_init()
575576 engine_add_event_listener (ALLEGRO_EVENT_DISPLAY_HALT_DRAWING , NULL , handle_haltresume_event );
576577 engine_add_event_listener (ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING , NULL , handle_haltresume_event );
577578
578- current_muffler_profile = DEFAULT_MUFFLER_PROFILE ;
579- is_muffler_activated = false;
580- set_muffler (MUFFLER_OFF );
579+ update_muffler (DEFAULT_MUFFLER_PROFILE , MUFFLE_NOTHING );
581580}
582581
583582/*
@@ -718,6 +717,15 @@ void audio_set_muted(bool muted)
718717 *
719718 */
720719
720+ /*
721+ * audio_muffler_profile()
722+ * Get the current profile of the muffler
723+ */
724+ mufflerprofile_t audio_muffler_profile ()
725+ {
726+ return current_muffler_profile ;
727+ }
728+
721729/*
722730 * audio_muffler_set_profile()
723731 * Set the profile of the muffler
@@ -732,46 +740,33 @@ void audio_muffler_set_profile(mufflerprofile_t profile)
732740 logfile_message ("Changing the muffler profile to %s" , MUFFLER_PROFILE_NAME [profile ]);
733741
734742 /* update muffler */
735- current_muffler_profile = profile ;
736- if (is_muffler_activated )
737- set_muffler (current_muffler_profile );
743+ update_muffler (profile , current_muffler_flags );
738744}
739745
740746/*
741- * audio_muffler_profile ()
742- * Get the current profile of the muffler
747+ * audio_muffler_is_activated ()
748+ * Check whether or not the muffler is activated at this time
743749 */
744- mufflerprofile_t audio_muffler_profile ()
750+ bool audio_muffler_is_activated ()
745751{
746- return current_muffler_profile ;
752+ return current_muffler_flags != MUFFLE_NOTHING ;
747753}
748754
749755/*
750756 * audio_muffler_activate()
751- * Activate or deactivate the muffler at this time
757+ * Activate or deactivate the muffler
752758 */
753- void audio_muffler_activate (bool on_off )
759+ void audio_muffler_activate (int flags )
754760{
755761 /* nothing to do */
756- if (is_muffler_activated == on_off )
762+ if (current_muffler_flags == flags )
757763 return ;
758764
759765 /* update muffler */
760- is_muffler_activated = on_off ;
761- if (is_muffler_activated )
762- set_muffler (current_muffler_profile );
763- else
764- set_muffler (MUFFLER_OFF );
766+ update_muffler (current_muffler_profile , flags );
765767}
766768
767- /*
768- * audio_muffler_is_activated()
769- * Check whether or not the muffler is activated at this time
770- */
771- bool audio_muffler_is_activated ()
772- {
773- return is_muffler_activated ;
774- }
769+
775770
776771
777772
@@ -817,14 +812,42 @@ void handle_haltresume_event(const ALLEGRO_EVENT* event, void* context)
817812 }
818813}
819814
820- void set_muffler (mufflerprofile_t profile )
815+ void update_muffler (mufflerprofile_t profile , int flags )
821816{
822- size_t num_channels = al_get_channel_count (al_get_mixer_channels (master_mixer ));
823- size_t depth_size = al_get_audio_depth_size (al_get_mixer_depth (master_mixer ));
817+ current_muffler_profile = profile ;
818+ current_muffler_flags = flags ;
819+
820+ /* only one mixer can be muffled at any given time */
821+ if ((flags & MUFFLE_EVERYTHING ) == MUFFLE_EVERYTHING ) {
822+ muffle_mixer (master_mixer , profile );
823+ muffle_mixer (sound_mixer , MUFFLER_OFF );
824+ muffle_mixer (music_mixer , MUFFLER_OFF );
825+ }
826+ else if ((flags & MUFFLE_SOUNDS ) == MUFFLE_SOUNDS ) {
827+ muffle_mixer (master_mixer , MUFFLER_OFF );
828+ muffle_mixer (sound_mixer , profile );
829+ muffle_mixer (music_mixer , MUFFLER_OFF );
830+ }
831+ else if ((flags & MUFFLE_MUSICS ) == MUFFLE_MUSICS ) {
832+ muffle_mixer (master_mixer , MUFFLER_OFF );
833+ muffle_mixer (sound_mixer , MUFFLER_OFF );
834+ muffle_mixer (music_mixer , profile );
835+ }
836+ else {
837+ muffle_mixer (master_mixer , MUFFLER_OFF );
838+ muffle_mixer (sound_mixer , MUFFLER_OFF );
839+ muffle_mixer (music_mixer , MUFFLER_OFF );
840+ }
841+ }
842+
843+ void muffle_mixer (ALLEGRO_MIXER * mixer , mufflerprofile_t profile )
844+ {
845+ size_t num_channels = al_get_channel_count (al_get_mixer_channels (mixer ));
846+ size_t depth_size = al_get_audio_depth_size (al_get_mixer_depth (mixer ));
824847
825848 if (num_channels != 2 || depth_size != sizeof (float ))
826849 logfile_message ("Can't set the mixer postprocess callback: num_channels = %u, depth_size = %u, sizeof(float) = %u" , num_channels , depth_size , sizeof (float ));
827- else if (!al_set_mixer_postprocess_callback (master_mixer , muffler_postprocess , (void * )muffler_sigma (profile )))
850+ else if (!al_set_mixer_postprocess_callback (mixer , profile != MUFFLER_OFF ? muffler_postprocess : NULL , (void * )muffler_sigma (profile )))
828851 logfile_message ("Can't set the mixer postprocess callback." );
829852}
830853
@@ -850,7 +873,8 @@ const float* muffler_sigma(mufflerprofile_t profile)
850873 }
851874}
852875
853- /* this function runs in a dedicated audio thread */
876+ /* this function runs in a dedicated audio thread
877+ Only one mixer can be muffled at any given time - notice the static variables */
854878void muffler_postprocess (void * buf , unsigned int num_samples , void * data )
855879{
856880 /* the input buffer is expected to be float32 stereo, where
@@ -861,16 +885,22 @@ void muffler_postprocess(void* buf, unsigned int num_samples, void* data)
861885 NUM_CHANNELS = 2 ,
862886 DEPTH_SIZE = sizeof (float )
863887 };
864- static bool is_initialized = false;
865888
866889 /* read input */
867890 float sigma = * ((const float * )data ); /* no need of mutexes */
868891
892+ #if 0
869893 /* nothing to do */
894+ static bool is_initialized = false;
870895 if (sigma == 0.0f ) {
871896 is_initialized = false;
872897 return ;
873898 }
899+ #else
900+ /* nothing to do */
901+ if (sigma == 0.0f )
902+ return ;
903+ #endif
874904
875905 /* validate */
876906 if (sigma > MAX_SIGMA )
@@ -880,7 +910,7 @@ void muffler_postprocess(void* buf, unsigned int num_samples, void* data)
880910 return ;
881911
882912 /* calculate a Gaussian */
883- static float g0 [1 + 2 * (3 * MAX_SIGMA )];
913+ static float g0 [1 + 2 * (3 * MAX_SIGMA )] = { 0.0f } ;
884914 const size_t n = sizeof (g0 ) / sizeof (float );
885915 const int c = (n - 1 ) / 2 ;
886916 static int w = -1 ;
@@ -901,10 +931,13 @@ void muffler_postprocess(void* buf, unsigned int num_samples, void* data)
901931 memcpy (samples , samples + num_samples * NUM_CHANNELS , buf_size );
902932 memcpy (samples + num_samples * NUM_CHANNELS , buf , buf_size );
903933
934+ #if 0
935+ /* do we really need this? no audible difference... */
904936 if (!is_initialized ) { /* wait one more frame */
905937 is_initialized = true;
906938 return ;
907939 }
940+ #endif
908941
909942 /* find the initial index of the output. We introduce a small delay.
910943 start is an even number (NUM_CHANNELS is 2) and points to a L sample */
0 commit comments