Index: apps/codecs/libgme/sgc_emu.c =================================================================== --- apps/codecs/libgme/sgc_emu.c (Revision 30274) +++ apps/codecs/libgme/sgc_emu.c (Arbeitskopie) @@ -47,7 +47,7 @@ this->sample_rate = 0; this->mute_mask_ = 0; this->tempo = (int)FP_ONE_TEMPO; - this->gain = 1.0; + this->gain = (int)FP_ONE_GAIN; this->voice_count = 0; // defaults @@ -61,7 +61,7 @@ Rom_init( &this->rom, 0x4000 ); Z80_init( &this->cpu ); - Sound_set_gain( this, 1.2 ); + Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) ); // Unload clear_track_vars( this ); @@ -96,8 +96,8 @@ this->track_count = this->header.song_count; this->voice_count = sega_mapping( this ) ? osc_count : sms_osc_count; - Sms_apu_volume( &this->apu, this->gain ); - Fm_apu_volume( &this->fm_apu, this->gain ); + Sms_apu_volume( &this->apu, (double)(this->gain)/FP_ONE_GAIN ); + Fm_apu_volume( &this->fm_apu, (double)(this->gain)/FP_ONE_GAIN ); // Setup buffer this->clock_rate_ = clock_rate( this ); Index: apps/codecs/libgme/sgc_emu.h =================================================================== --- apps/codecs/libgme/sgc_emu.h (Revision 30274) +++ apps/codecs/libgme/sgc_emu.h (Arbeitskopie) @@ -67,7 +67,7 @@ int voice_count; int mute_mask_; int tempo; - double gain; + int gain; long sample_rate; @@ -177,7 +177,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Sgc_Emu* this, double g ) +static inline void Sound_set_gain( struct Sgc_Emu* this, int g ) { assert( !this->sample_rate ); // you must set gain before setting sample rate this->gain = g; Index: apps/codecs/libgme/vgm_emu.c =================================================================== --- apps/codecs/libgme/vgm_emu.c (Revision 30274) +++ apps/codecs/libgme/vgm_emu.c (Arbeitskopie) @@ -104,7 +104,7 @@ // Set sound gain, a value too high // will cause saturation - Sound_set_gain(this, 1.0); + Sound_set_gain(this, (int)FP_ONE_GAIN); // Unload this->voice_count = 0; @@ -350,13 +350,13 @@ if ( uses_fm( this ) ) { this->voice_count = 8; - RETURN_ERR( Resampler_setup( &this->resampler, fm_rate / this->sample_rate, rolloff, fm_gain * this->gain ) ); + RETURN_ERR( Resampler_setup( &this->resampler, fm_rate / this->sample_rate, rolloff, fm_gain * (double)(this->gain)/FP_ONE_GAIN ) ); RETURN_ERR( Resampler_reset( &this->resampler, Buffer_length( &this->stereo_buf ) * this->sample_rate / 1000 ) ); - Sms_apu_volume( &this->psg, 0.195 * fm_gain * this->gain ); + Sms_apu_volume( &this->psg, 0.195 * fm_gain * (double)(this->gain)/FP_ONE_GAIN ); } else { - Sms_apu_volume( &this->psg, this->gain ); + Sms_apu_volume( &this->psg, (double)(this->gain)/FP_ONE_GAIN ); } return 0; @@ -717,7 +717,7 @@ Sms_apu_set_output( &this->psg, i, ( mask & 0x80 ) ? 0 : &this->stereo_buf.bufs [0], NULL, NULL ); if ( Ym2612_enabled( &this->ym2612 ) ) { - Synth_volume( &this->pcm, (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * this->gain ); + Synth_volume( &this->pcm, (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * (double)(this->gain)/FP_ONE_GAIN ); Ym2612_mute_voices( &this->ym2612, mask ); } Index: apps/codecs/libgme/vgm_emu.h =================================================================== --- apps/codecs/libgme/vgm_emu.h (Revision 30274) +++ apps/codecs/libgme/vgm_emu.h (Arbeitskopie) @@ -94,7 +94,7 @@ int voice_count; int mute_mask_; int tempo; - double gain; + int gain; long sample_rate; @@ -201,7 +201,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Vgm_Emu* this, double g ) +static inline void Sound_set_gain( struct Vgm_Emu* this, int g ) { assert( !this->sample_rate ); // you must set gain before setting sample rate this->gain = g; Index: apps/codecs/libgme/kss_emu.c =================================================================== --- apps/codecs/libgme/kss_emu.c (Revision 30274) +++ apps/codecs/libgme/kss_emu.c (Arbeitskopie) @@ -54,7 +54,7 @@ this->sample_rate = 0; this->mute_mask_ = 0; this->tempo = (int)(FP_ONE_TEMPO); - this->gain = 1.0; + this->gain = (int)FP_ONE_GAIN; this->chip_flags = 0; // defaults @@ -98,24 +98,24 @@ void update_gain( struct Kss_Emu* this ) { - double g = this->gain; + int g = this->gain; if ( msx_music_enabled( this ) || msx_audio_enabled( this ) || sms_fm_enabled( this ) ) { - g *= 0.75; + g = (g*3) / 4; //g *= 0.75; } else { if ( this->scc_accessed ) - g *= 1.2; + g = (g*6) / 5; //g *= 1.2; } - if ( sms_psg_enabled( this ) ) Sms_apu_volume( &this->sms.psg, g ); - if ( sms_fm_enabled( this ) ) Opl_volume( &this->sms.fm, g ); - if ( msx_psg_enabled( this ) ) Ay_apu_volume( &this->msx.psg, g ); - if ( msx_scc_enabled( this ) ) Scc_volume( &this->msx.scc, g ); - if ( msx_music_enabled( this ) ) Opl_volume( &this->msx.music, g ); - if ( msx_audio_enabled( this ) ) Opl_volume( &this->msx.audio, g ); + if ( sms_psg_enabled( this ) ) Sms_apu_volume( &this->sms.psg, (double)(g)/FP_ONE_GAIN ); + if ( sms_fm_enabled( this ) ) Opl_volume( &this->sms.fm, (double)(g)/FP_ONE_GAIN ); + if ( msx_psg_enabled( this ) ) Ay_apu_volume( &this->msx.psg, (double)(g)/FP_ONE_GAIN ); + if ( msx_scc_enabled( this ) ) Scc_volume( &this->msx.scc, (double)(g)/FP_ONE_GAIN ); + if ( msx_music_enabled( this ) ) Opl_volume( &this->msx.music, (double)(g)/FP_ONE_GAIN ); + if ( msx_audio_enabled( this ) ) Opl_volume( &this->msx.audio, (double)(g)/FP_ONE_GAIN ); } blargg_err_t Kss_load_mem( struct Kss_Emu* this, const void* data, long size ) Index: apps/codecs/libgme/blargg_common.h =================================================================== --- apps/codecs/libgme/blargg_common.h (Revision 30274) +++ apps/codecs/libgme/blargg_common.h (Arbeitskopie) @@ -21,7 +21,8 @@ #endif // common defines -#define FP_ONE_TEMPO (1LL <<16) +#define FP_ONE_TEMPO (1LL <<24) +#define FP_ONE_GAIN (1LL <<24) #if 1 /* IRAM configuration is not yet active for all libGME codecs. */ #undef ICODE_ATTR Index: apps/codecs/libgme/kss_emu.h =================================================================== --- apps/codecs/libgme/kss_emu.h (Revision 30274) +++ apps/codecs/libgme/kss_emu.h (Arbeitskopie) @@ -98,7 +98,7 @@ int voice_count; int mute_mask_; int tempo; - double gain; + int gain; long sample_rate; @@ -203,7 +203,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Kss_Emu* this, double g ) +static inline void Sound_set_gain( struct Kss_Emu* this, int g ) { assert( !this->sample_rate ); // you must set gain before setting sample rate this->gain = g; Index: apps/codecs/libgme/gbs_emu.c =================================================================== --- apps/codecs/libgme/gbs_emu.c (Revision 30274) +++ apps/codecs/libgme/gbs_emu.c (Arbeitskopie) @@ -55,7 +55,7 @@ this->ignore_silence = false; this->silence_lookahead = 6; this->max_initial_silence = 21; - Sound_set_gain( this, 1.2 ); + Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) ); Rom_init( &this->rom, 0x4000 ); @@ -112,7 +112,7 @@ Rom_set_addr( &this->rom, load_addr ); this->voice_count_ = osc_count; - Apu_volume( &this->apu, this->gain_ ); + Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN ); // Change clock rate & setup buffer this->clock_rate_ = 4194304; Index: apps/codecs/libgme/gbs_emu.h =================================================================== --- apps/codecs/libgme/gbs_emu.h (Revision 30274) +++ apps/codecs/libgme/gbs_emu.h (Arbeitskopie) @@ -63,7 +63,7 @@ long sample_rate_; unsigned buf_changed_count; int voice_count_; - double gain_; + int gain_; int tempo_; // track-specific @@ -169,7 +169,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Gbs_Emu* this, double g ) +static inline void Sound_set_gain( struct Gbs_Emu* this, int g ) { assert( !this->sample_rate_ ); // you must set gain before setting sample rate this->gain_ = g; Index: apps/codecs/libgme/hes_emu.c =================================================================== --- apps/codecs/libgme/hes_emu.c (Revision 30274) +++ apps/codecs/libgme/hes_emu.c (Arbeitskopie) @@ -61,7 +61,7 @@ this->timer.raw_load = 0; this->silence_lookahead = 6; - Sound_set_gain( this, 1.11 ); + Sound_set_gain( this, (int)(FP_ONE_GAIN*1.11) ); Rom_init( &this->rom, 0x2000 ); @@ -131,8 +131,8 @@ this->voice_count_ = osc_count + adpcm_osc_count; - Apu_volume( &this->apu, this->gain_ ); - Adpcm_volume( &this->adpcm, this->gain_ ); + Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN ); + Adpcm_volume( &this->adpcm, (double)(this->gain_)/FP_ONE_GAIN ); // Setup buffer this->clock_rate_ = 7159091; Index: apps/codecs/libgme/hes_emu.h =================================================================== --- apps/codecs/libgme/hes_emu.h (Revision 30274) +++ apps/codecs/libgme/hes_emu.h (Arbeitskopie) @@ -70,7 +70,7 @@ unsigned buf_changed_count; int voice_count_; int tempo_; - double gain_; + int gain_; // track-specific byte track_count; @@ -179,7 +179,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Hes_Emu* this, double g ) +static inline void Sound_set_gain( struct Hes_Emu* this, int g ) { assert( !this->sample_rate_ ); // you must set gain before setting sample rate this->gain_ = g; Index: apps/codecs/libgme/nsf_emu.c =================================================================== --- apps/codecs/libgme/nsf_emu.c (Revision 30274) +++ apps/codecs/libgme/nsf_emu.c (Arbeitskopie) @@ -55,7 +55,7 @@ this->sample_rate = 0; this->mute_mask_ = 0; this->tempo = (int)(FP_ONE_TEMPO); - this->gain = 1.0; + this->gain = (int)(FP_ONE_GAIN); // defaults this->max_initial_silence = 2; @@ -63,7 +63,7 @@ this->voice_count = 0; // Set sound gain - Sound_set_gain( this, 1.2 ); + Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) ); // Unload clear_track_vars( this ); @@ -89,7 +89,7 @@ this->voice_count = apu_osc_count; - double adjusted_gain = 1.0 / 0.75 * this->gain; + int adjusted_gain = (this->gain * 4) / 3; #ifdef NSF_EMU_APU_ONLY { @@ -101,7 +101,7 @@ if ( vrc6_enabled( this ) ) { Vrc6_init( &this->vrc6 ); - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += vrc6_osc_count; } @@ -109,7 +109,7 @@ if ( fme7_enabled( this ) ) { Fme7_init( &this->fme7 ); - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += fme7_osc_count; } @@ -117,7 +117,7 @@ if ( mmc5_enabled( this ) ) { Mmc5_init( &this->mmc5 ); - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += mmc5_osc_count; } @@ -125,7 +125,7 @@ if ( fds_enabled( this ) ) { Fds_init( &this->fds ); - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += fds_osc_count ; } @@ -133,7 +133,7 @@ if ( namco_enabled( this ) ) { Namco_init( &this->namco ); - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += namco_osc_count; } @@ -145,24 +145,24 @@ Vrc7_set_rate( &this->vrc7, this->sample_rate ); #endif - adjusted_gain *= 0.75; + adjusted_gain = (adjusted_gain*3) / 4; this->voice_count += vrc7_osc_count; } - if ( vrc7_enabled( this ) ) Vrc7_volume( &this->vrc7, adjusted_gain ); - if ( namco_enabled( this ) ) Namco_volume( &this->namco, adjusted_gain ); - if ( vrc6_enabled( this ) ) Vrc6_volume( &this->vrc6, adjusted_gain ); - if ( fme7_enabled( this ) ) Fme7_volume( &this->fme7, adjusted_gain ); - if ( mmc5_enabled( this ) ) Apu_volume( &this->mmc5.apu, adjusted_gain ); - if ( fds_enabled( this ) ) Fds_volume( &this->fds, adjusted_gain ); + if ( vrc7_enabled( this ) ) Vrc7_volume( &this->vrc7, (double)adjusted_gain/FP_ONE_GAIN ); + if ( namco_enabled( this ) ) Namco_volume( &this->namco, (double)adjusted_gain/FP_ONE_GAIN ); + if ( vrc6_enabled( this ) ) Vrc6_volume( &this->vrc6, (double)adjusted_gain/FP_ONE_GAIN ); + if ( fme7_enabled( this ) ) Fme7_volume( &this->fme7, (double)adjusted_gain/FP_ONE_GAIN ); + if ( mmc5_enabled( this ) ) Apu_volume( &this->mmc5.apu, (double)adjusted_gain/FP_ONE_GAIN ); + if ( fds_enabled( this ) ) Fds_volume( &this->fds, (double)adjusted_gain/FP_ONE_GAIN ); } #endif if ( adjusted_gain > this->gain ) adjusted_gain = this->gain; - Apu_volume( &this->apu, adjusted_gain ); + Apu_volume( &this->apu, (double)adjusted_gain/FP_ONE_GAIN ); return 0; } Index: apps/codecs/libgme/nsf_emu.h =================================================================== --- apps/codecs/libgme/nsf_emu.h (Revision 30274) +++ apps/codecs/libgme/nsf_emu.h (Arbeitskopie) @@ -90,7 +90,7 @@ int voice_count; int mute_mask_; int tempo; - double gain; + int gain; long sample_rate; @@ -200,7 +200,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Nsf_Emu* this, double g ) +static inline void Sound_set_gain( struct Nsf_Emu* this, int g ) { assert( !this->sample_rate ); // you must set gain before setting sample rate this->gain = g; Index: apps/codecs/libgme/ay_emu.c =================================================================== --- apps/codecs/libgme/ay_emu.c (Revision 30274) +++ apps/codecs/libgme/ay_emu.c (Arbeitskopie) @@ -55,7 +55,7 @@ this->sample_rate = 0; this->mute_mask_ = 0; this->tempo = (int)FP_ONE_TEMPO; - this->gain = 1.0; + this->gain = (int)FP_ONE_GAIN; this->track_count = 0; // defaults @@ -144,7 +144,7 @@ warning( "Unknown file version" ); */ this->voice_count = ay_osc_count + 1; // +1 for beeper - Ay_apu_volume( &this->apu, this->gain ); + Ay_apu_volume( &this->apu, ((double)this->gain)/FP_ONE_GAIN); // Setup buffer change_clock_rate( this, spectrum_clock ); Index: apps/codecs/libgme/ay_emu.h =================================================================== --- apps/codecs/libgme/ay_emu.h (Revision 30274) +++ apps/codecs/libgme/ay_emu.h (Arbeitskopie) @@ -66,7 +66,7 @@ int voice_count; int mute_mask_; int tempo; - double gain; + int gain; long sample_rate; @@ -152,7 +152,7 @@ // Change overall output amplitude, where 1.0 results in minimal clamping. // Must be called before set_sample_rate(). -static inline void Sound_set_gain( struct Ay_Emu* this, double g ) +static inline void Sound_set_gain( struct Ay_Emu* this, int g ) { assert( !this->sample_rate ); // you must set gain before setting sample rate this->gain = g;