diff options
| author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-11 06:18:39 +0000 |
|---|---|---|
| committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-11 06:18:39 +0000 |
| commit | 631d22b8e55f695a43d0e8ecc353f79688f32507 (patch) | |
| tree | b11a9209680eb888253bd5355d71d80fde200a99 | |
| parent | 4ca2367e34e095419fa7e4de240dd7416575398a (diff) | |
| download | rockbox-631d22b8e55f695a43d0e8ecc353f79688f32507.zip rockbox-631d22b8e55f695a43d0e8ecc353f79688f32507.tar.gz rockbox-631d22b8e55f695a43d0e8ecc353f79688f32507.tar.bz2 rockbox-631d22b8e55f695a43d0e8ecc353f79688f32507.tar.xz | |
4th part of FS#12176. Volume settings migrated to fixed point for libgme.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30278 a1c6a512-1295-4272-9138-f99709370657
36 files changed, 79 insertions, 88 deletions
diff --git a/apps/codecs/libgme/ay_apu.c b/apps/codecs/libgme/ay_apu.c index a2ec299..8906c98 100644 --- a/apps/codecs/libgme/ay_apu.c +++ b/apps/codecs/libgme/ay_apu.c @@ -100,7 +100,7 @@ void Ay_apu_init( struct Ay_Apu* this ) } set_output( this, NULL ); - Ay_apu_volume( this, 1.0 ); + Ay_apu_volume( this, (int)FP_ONE_VOLUME ); Ay_apu_reset( this ); } diff --git a/apps/codecs/libgme/ay_apu.h b/apps/codecs/libgme/ay_apu.h index ccdd204..a18e3e7 100644 --- a/apps/codecs/libgme/ay_apu.h +++ b/apps/codecs/libgme/ay_apu.h @@ -57,7 +57,7 @@ int Ay_apu_read( struct Ay_Apu* this ); void Ay_apu_reset( struct Ay_Apu* this ); // Sets overall volume, where 1.0 is normal -static inline void Ay_apu_volume( struct Ay_Apu* this, double v ) { Synth_volume( &this->synth_, 0.7/ay_osc_count/ay_amp_range * v ); } +static inline void Ay_apu_volume( struct Ay_Apu* this, int v ) { Synth_volume( &this->synth_, (v*7)/10 /ay_osc_count/ay_amp_range ); } static inline void Ay_apu_set_output( struct Ay_Apu* this, int i, struct Blip_Buffer* out ) { diff --git a/apps/codecs/libgme/ay_emu.c b/apps/codecs/libgme/ay_emu.c index 3c43984..06946a9 100644 --- a/apps/codecs/libgme/ay_emu.c +++ b/apps/codecs/libgme/ay_emu.c @@ -144,7 +144,7 @@ blargg_err_t Ay_load_mem( struct Ay_Emu *this, byte const in [], int size ) warning( "Unknown file version" ); */
this->voice_count = ay_osc_count + 1; // +1 for beeper
- Ay_apu_volume( &this->apu, ((double)this->gain)/FP_ONE_GAIN);
+ Ay_apu_volume( &this->apu, this->gain);
// Setup buffer
change_clock_rate( this, spectrum_clock );
@@ -483,7 +483,7 @@ blargg_err_t Ay_start_track( struct Ay_Emu *this, int track ) Z80_map_mem( &this->cpu, 0, mem_size, this->mem.ram, this->mem.ram );
this->cpu.r = r;
- this->beeper_delta = (int) (ay_amp_range * 0.8);
+ this->beeper_delta = (int) ((ay_amp_range*4)/5);
this->last_beeper = 0;
this->next_play = this->play_period;
this->spectrum_mode = false;
diff --git a/apps/codecs/libgme/blargg_common.h b/apps/codecs/libgme/blargg_common.h index 190af65..0f955e5 100644 --- a/apps/codecs/libgme/blargg_common.h +++ b/apps/codecs/libgme/blargg_common.h @@ -21,8 +21,9 @@ #endif // common defines -#define FP_ONE_TEMPO (1LL <<24) -#define FP_ONE_GAIN (1LL <<24) +#define FP_ONE_TEMPO (1LL << 24) +#define FP_ONE_GAIN (1LL << 24) +#define FP_ONE_VOLUME FP_ONE_GAIN #if 1 /* IRAM configuration is not yet active for all libGME codecs. */ #undef ICODE_ATTR diff --git a/apps/codecs/libgme/blip_buffer.c b/apps/codecs/libgme/blip_buffer.c index 2a015d7..d8ecbb8 100644 --- a/apps/codecs/libgme/blip_buffer.c +++ b/apps/codecs/libgme/blip_buffer.c @@ -106,18 +106,9 @@ blargg_err_t Blip_set_sample_rate( struct Blip_Buffer* this, long new_rate, int return 0; // success } -/* Not sure if this affects sound quality */ -#if defined(ROCKBOX) -double floor(double x) { - if ( x > 0 ) return (int)x; - return (int)(x-0.9999999999999999); -} -#endif - blip_resampled_time_t Blip_clock_rate_factor( struct Blip_Buffer* this, long rate ) { - double ratio = (double) this->sample_rate_ / rate; - blip_long factor = (blip_long) floor( ratio * (1L << BLIP_BUFFER_ACCURACY) + 0.5 ); + blip_long factor = (blip_long) ( this->sample_rate_ * (1LL << BLIP_BUFFER_ACCURACY) / rate); assert( factor > 0 || !this->sample_rate_ ); // fails if clock/output ratio is too large return (blip_resampled_time_t) factor; } @@ -279,7 +270,7 @@ void Synth_init( struct Blip_Synth* this ) } // Set overall volume of waveform -void Synth_volume( struct Blip_Synth* this, double v ) +void Synth_volume( struct Blip_Synth* this, int v ) { - this->delta_factor = (int) (v * (1L << blip_sample_bits) + 0.5); + this->delta_factor = (int) (v * (1LL << blip_sample_bits) / FP_ONE_VOLUME); } diff --git a/apps/codecs/libgme/blip_buffer.h b/apps/codecs/libgme/blip_buffer.h index 84ed6e6..d03e1c0 100644 --- a/apps/codecs/libgme/blip_buffer.h +++ b/apps/codecs/libgme/blip_buffer.h @@ -170,7 +170,7 @@ struct Blip_Synth { void Synth_init( struct Blip_Synth* this ); // Set overall volume of waveform -void Synth_volume( struct Blip_Synth* this, double v ) ICODE_ATTR; +void Synth_volume( struct Blip_Synth* this, int v ) ICODE_ATTR; // Get/set Blip_Buffer used for output const struct Blip_Buffer* Synth_output( struct Blip_Synth* this ) ICODE_ATTR; diff --git a/apps/codecs/libgme/gb_apu.c b/apps/codecs/libgme/gb_apu.c index adc3071..f6da1b0 100644 --- a/apps/codecs/libgme/gb_apu.c +++ b/apps/codecs/libgme/gb_apu.c @@ -51,7 +51,7 @@ void Apu_set_output( struct Gb_Apu* this, int i, struct Blip_Buffer* center, str void synth_volume( struct Gb_Apu* this, int iv ) { - double v = this->volume_ * 0.60 / osc_count / 15 /*steps*/ / 8 /*master vol range*/ * iv; + int v = (this->volume_ * 6) / 10 / osc_count / 15 /*steps*/ / 8 /*master vol range*/ * iv; Synth_volume( &this->synth, v ); } @@ -67,7 +67,7 @@ void apply_volume( struct Gb_Apu* this ) synth_volume( this, max( left, right ) + 1 ); } -void Apu_volume( struct Gb_Apu* this, double v ) +void Apu_volume( struct Gb_Apu* this, int v ) { if ( this->volume_ != v ) { @@ -185,7 +185,7 @@ void Apu_init( struct Gb_Apu* this ) this->reduce_clicks_ = false; Apu_set_tempo( this, (int)FP_ONE_TEMPO ); - this->volume_ = 1.0; + this->volume_ = (int)FP_ONE_VOLUME; Apu_reset( this, mode_cgb, false ); } diff --git a/apps/codecs/libgme/gb_apu.h b/apps/codecs/libgme/gb_apu.h index 028be29..642db8f 100644 --- a/apps/codecs/libgme/gb_apu.h +++ b/apps/codecs/libgme/gb_apu.h @@ -27,7 +27,7 @@ struct Gb_Apu { struct Gb_Osc* oscs [osc_count]; blip_time_t last_time; // time sound emulator has been run to blip_time_t frame_period; // clocks between each frame sequencer step - double volume_; + int volume_; bool reduce_clicks_; struct Gb_Square square1; @@ -69,7 +69,7 @@ void Apu_set_output( struct Gb_Apu* this, int chan, struct Blip_Buffer* center, struct Blip_Buffer* left, struct Blip_Buffer* right ); // Sets overall volume, where 1.0 is normal -void Apu_volume( struct Gb_Apu* this, double v ); +void Apu_volume( struct Gb_Apu* this, int v ); // If true, reduces clicking by disabling DAC biasing. Note that this reduces // emulation accuracy, since the clicks are authentic. diff --git a/apps/codecs/libgme/gbs_emu.c b/apps/codecs/libgme/gbs_emu.c index 664510d..a0e7f18 100644 --- a/apps/codecs/libgme/gbs_emu.c +++ b/apps/codecs/libgme/gbs_emu.c @@ -112,7 +112,7 @@ blargg_err_t Gbs_load( struct Gbs_Emu* this, void* data, long size ) Rom_set_addr( &this->rom, load_addr ); this->voice_count_ = osc_count; - Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN ); + Apu_volume( &this->apu, this->gain_ ); // Change clock rate & setup buffer this->clock_rate_ = 4194304; diff --git a/apps/codecs/libgme/hes_apu.h b/apps/codecs/libgme/hes_apu.h index 8a49a5a..fcdcbab 100644 --- a/apps/codecs/libgme/hes_apu.h +++ b/apps/codecs/libgme/hes_apu.h @@ -51,5 +51,5 @@ void Apu_osc_output( struct Hes_Apu* this, int index, struct Blip_Buffer* center void Apu_write_data( struct Hes_Apu* this, blip_time_t, int addr, int data ) ICODE_ATTR; void Apu_end_frame( struct Hes_Apu* this, blip_time_t ) ICODE_ATTR; -static inline void Apu_volume( struct Hes_Apu* this, double v ) { Synth_volume( &this->synth, 1.8 / osc_count / amp_range * v ); } +static inline void Apu_volume( struct Hes_Apu* this, int v ) { Synth_volume( &this->synth, (v*9)/5 / osc_count / amp_range ); } #endif diff --git a/apps/codecs/libgme/hes_apu_adpcm.h b/apps/codecs/libgme/hes_apu_adpcm.h index 5478f2b..38b8839 100644 --- a/apps/codecs/libgme/hes_apu_adpcm.h +++ b/apps/codecs/libgme/hes_apu_adpcm.h @@ -85,5 +85,5 @@ int Adpcm_read_data( struct Hes_Apu_Adpcm* this, blip_time_t t, int addr ) ICODE void Adpcm_end_frame( struct Hes_Apu_Adpcm* this,blip_time_t t ) ICODE_ATTR; // Sets overall volume, where 1.0 is normal -static inline void Adpcm_volume( struct Hes_Apu_Adpcm* this, double v ) { Synth_volume( &this->synth, 0.6 / adpcm_osc_count / adpcm_amp_range * v ); } +static inline void Adpcm_volume( struct Hes_Apu_Adpcm* this, int v ) { Synth_volume( &this->synth, (v*3)/5 / adpcm_osc_count / adpcm_amp_range ); } #endif diff --git a/apps/codecs/libgme/hes_emu.c b/apps/codecs/libgme/hes_emu.c index ae4e68e..10ec9a2 100644 --- a/apps/codecs/libgme/hes_emu.c +++ b/apps/codecs/libgme/hes_emu.c @@ -131,8 +131,8 @@ blargg_err_t Hes_load( struct Hes_Emu* this, void* data, long size ) this->voice_count_ = osc_count + adpcm_osc_count; - Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN ); - Adpcm_volume( &this->adpcm, (double)(this->gain_)/FP_ONE_GAIN ); + Apu_volume( &this->apu, this->gain_ ); + Adpcm_volume( &this->adpcm, this->gain_ ); // Setup buffer this->clock_rate_ = 7159091; diff --git a/apps/codecs/libgme/kss_emu.c b/apps/codecs/libgme/kss_emu.c index 00991be..102fbf9 100644 --- a/apps/codecs/libgme/kss_emu.c +++ b/apps/codecs/libgme/kss_emu.c @@ -110,12 +110,12 @@ void update_gain( struct Kss_Emu* this ) g = (g*6) / 5; //g *= 1.2; } - 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 ); + 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 ); } blargg_err_t Kss_load_mem( struct Kss_Emu* this, const void* data, long size ) diff --git a/apps/codecs/libgme/kss_scc_apu.c b/apps/codecs/libgme/kss_scc_apu.c index 0e71b1c..1bec9b7 100644 --- a/apps/codecs/libgme/kss_scc_apu.c +++ b/apps/codecs/libgme/kss_scc_apu.c @@ -28,9 +28,9 @@ static void set_output( struct Scc_Apu* this, struct Blip_Buffer* buf ) Scc_set_output( this, i, buf ); } -void Scc_volume( struct Scc_Apu* this, double v ) +void Scc_volume( struct Scc_Apu* this, int v ) { - Synth_volume( &this->synth, 0.43 / scc_osc_count / scc_amp_range * v ); + Synth_volume( &this->synth, (v/2 - (v*7)/100) / scc_osc_count / scc_amp_range ); } void Scc_reset( struct Scc_Apu* this ) @@ -49,7 +49,7 @@ void Scc_init( struct Scc_Apu* this ) Synth_init( &this->synth); set_output( this, NULL ); - Scc_volume( this, 1.0 ); + Scc_volume( this, (int)FP_ONE_VOLUME ); Scc_reset( this ); } diff --git a/apps/codecs/libgme/kss_scc_apu.h b/apps/codecs/libgme/kss_scc_apu.h index f31228a..26425b3 100644 --- a/apps/codecs/libgme/kss_scc_apu.h +++ b/apps/codecs/libgme/kss_scc_apu.h @@ -33,7 +33,7 @@ void Scc_init( struct Scc_Apu* this ); void Scc_reset( struct Scc_Apu* this ); // Set overall volume, where 1.0 is normal -void Scc_volume( struct Scc_Apu* this, double v ); +void Scc_volume( struct Scc_Apu* this, int v ); static inline void Scc_set_output( struct Scc_Apu* this, int index, struct Blip_Buffer* b ) { diff --git a/apps/codecs/libgme/nes_apu.c b/apps/codecs/libgme/nes_apu.c index 826c768..2e30432 100644 --- a/apps/codecs/libgme/nes_apu.c +++ b/apps/codecs/libgme/nes_apu.c @@ -39,19 +39,18 @@ void Apu_init( struct Nes_Apu* this ) this->oscs [4] = &this->dmc.osc; Apu_output( this, NULL ); - Apu_volume( this, 1.0 ); + Apu_volume( this, (int)FP_ONE_VOLUME ); Apu_reset( this, false, 0 ); } -static double nonlinear_tnd_gain( void ) { return 0.75; } -void Apu_enable_nonlinear( struct Nes_Apu* this, double v ) +void Apu_enable_nonlinear( struct Nes_Apu* this, int v ) { this->dmc.nonlinear = true; - Synth_volume( &this->square_synth, 1.3 * 0.25751258 / 0.742467605 * 0.25 / amp_range * v ); + Synth_volume( &this->square_synth, (int)((1.3 * 0.25751258 / 0.742467605 * 0.25 * FP_ONE_VOLUME) / amp_range * v) ); - const double tnd = 0.48 / 202 * nonlinear_tnd_gain(); - Synth_volume( &this->triangle.synth, 3.0 * tnd ); - Synth_volume( &this->noise.synth, 2.0 * tnd ); + const int tnd = (int)(0.48 / 202 * 0.75 * FP_ONE_VOLUME); + Synth_volume( &this->triangle.synth, 3 * tnd ); + Synth_volume( &this->noise.synth, 2 * tnd ); Synth_volume( &this->dmc.synth, tnd ); this->square1 .osc.last_amp = 0; @@ -61,13 +60,13 @@ void Apu_enable_nonlinear( struct Nes_Apu* this, double v ) this->dmc .osc.last_amp = 0; } -void Apu_volume( struct Nes_Apu* this, double v ) +void Apu_volume( struct Nes_Apu* this, int v ) { this->dmc.nonlinear = false; - Synth_volume( &this->square_synth, 0.1128 / amp_range * v ); - Synth_volume( &this->triangle.synth,0.12765 / amp_range * v ); - Synth_volume( &this->noise.synth, 0.0741 / amp_range * v ); - Synth_volume( &this->dmc.synth, 0.42545 / 127 * v ); + Synth_volume( &this->square_synth, (int)((long long)(0.1128 *FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); + Synth_volume( &this->triangle.synth,(int)((long long)(0.12765*FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); + Synth_volume( &this->noise.synth, (int)((long long)(0.0741 *FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); + Synth_volume( &this->dmc.synth, (int)((long long)(0.42545*FP_ONE_VOLUME) * v / 127 / FP_ONE_VOLUME) ); } void Apu_output( struct Nes_Apu* this, struct Blip_Buffer* buffer ) diff --git a/apps/codecs/libgme/nes_apu.h b/apps/codecs/libgme/nes_apu.h index 8653afc..eb85a03 100644 --- a/apps/codecs/libgme/nes_apu.h +++ b/apps/codecs/libgme/nes_apu.h @@ -77,7 +77,7 @@ void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ); void Apu_set_tempo( struct Nes_Apu* this, int ); // Set overall volume (default is 1.0) -void Apu_volume( struct Nes_Apu* this, double ); +void Apu_volume( struct Nes_Apu* this, int ); // Run DMC until specified time, so that any DMC memory reads can be // accounted for (i.e. inserting cpu wait states). diff --git a/apps/codecs/libgme/nes_fds_apu.c b/apps/codecs/libgme/nes_fds_apu.c index f78e962..d021cfd 100644 --- a/apps/codecs/libgme/nes_fds_apu.c +++ b/apps/codecs/libgme/nes_fds_apu.c @@ -23,7 +23,7 @@ void Fds_init( struct Nes_Fds_Apu* this ) this->lfo_tempo = lfo_base_tempo; Fds_set_output( this, 0, NULL ); - Fds_volume( this, 1.0 ); + Fds_volume( this, (int)FP_ONE_VOLUME ); Fds_reset( this ); } diff --git a/apps/codecs/libgme/nes_fds_apu.h b/apps/codecs/libgme/nes_fds_apu.h index 47b17eb..951aff0 100644 --- a/apps/codecs/libgme/nes_fds_apu.h +++ b/apps/codecs/libgme/nes_fds_apu.h @@ -53,9 +53,9 @@ void Fds_set_tempo( struct Nes_Fds_Apu* this, int t ); // emulation void Fds_reset( struct Nes_Fds_Apu* this ); -static inline void Fds_volume( struct Nes_Fds_Apu* this, double v ) +static inline void Fds_volume( struct Nes_Fds_Apu* this, int v ) { - Synth_volume( &this->synth, 0.14 / fds_master_vol_max / fds_vol_max / fds_wave_sample_max * v ); + Synth_volume( &this->synth, (v*14) / 100 / fds_master_vol_max / fds_vol_max / fds_wave_sample_max ); } static inline void Fds_set_output( struct Nes_Fds_Apu* this, int i, struct Blip_Buffer* b ) diff --git a/apps/codecs/libgme/nes_fme7_apu.c b/apps/codecs/libgme/nes_fme7_apu.c index cb5ed93..068a21f 100644 --- a/apps/codecs/libgme/nes_fme7_apu.c +++ b/apps/codecs/libgme/nes_fme7_apu.c @@ -22,7 +22,7 @@ void Fme7_init( struct Nes_Fme7_Apu* this ) Synth_init( &this->synth ); Fme7_output( this, NULL ); - Fme7_volume( this, 1.0 ); + Fme7_volume( this, (int)FP_ONE_VOLUME ); Fme7_reset( this ); } diff --git a/apps/codecs/libgme/nes_fme7_apu.h b/apps/codecs/libgme/nes_fme7_apu.h index 47b93e5..0d6bef0 100644 --- a/apps/codecs/libgme/nes_fme7_apu.h +++ b/apps/codecs/libgme/nes_fme7_apu.h @@ -41,9 +41,9 @@ struct Nes_Fme7_Apu { void Fme7_init( struct Nes_Fme7_Apu* this ); void Fme7_reset( struct Nes_Fme7_Apu* this ); -static inline void Fme7_volume( struct Nes_Fme7_Apu* this, double v ) +static inline void Fme7_volume( struct Nes_Fme7_Apu* this, int v ) { - Synth_volume( &this->synth, 0.38 / amp_range * v ); // to do: fine-tune + Synth_volume( &this->synth, (v/2 - (v*3)/25) / amp_range ); // to do: fine-tune } static inline void Fme7_osc_output( struct Nes_Fme7_Apu* this, int i, struct Blip_Buffer* buf ) diff --git a/apps/codecs/libgme/nes_namco_apu.c b/apps/codecs/libgme/nes_namco_apu.c index 0fca501..0f64d3c 100644 --- a/apps/codecs/libgme/nes_namco_apu.c +++ b/apps/codecs/libgme/nes_namco_apu.c @@ -20,7 +20,7 @@ void Namco_init( struct Nes_Namco_Apu* this ) Synth_init( &this->synth ); Namco_output( this, NULL ); - Namco_volume( this, 1.0 ); + Namco_volume( this, (int)FP_ONE_VOLUME ); Namco_reset( this ); } diff --git a/apps/codecs/libgme/nes_namco_apu.h b/apps/codecs/libgme/nes_namco_apu.h index b53b698..5f9f1c8 100644 --- a/apps/codecs/libgme/nes_namco_apu.h +++ b/apps/codecs/libgme/nes_namco_apu.h @@ -47,7 +47,7 @@ static inline uint8_t* namco_access( struct Nes_Namco_Apu* this ) return &this->reg [addr]; } -static inline void Namco_volume( struct Nes_Namco_Apu* this, double v ) { Synth_volume( &this->synth, 0.10 / namco_osc_count * v / 15.0 ); } +static inline void Namco_volume( struct Nes_Namco_Apu* this, int v ) { Synth_volume( &this->synth, v / 10 / namco_osc_count / 15 ); } // Write-only address register is at 0xF800 static inline void Namco_write_addr( struct Nes_Namco_Apu* this, int v ) { this->addr_reg = v; } diff --git a/apps/codecs/libgme/nes_vrc6_apu.c b/apps/codecs/libgme/nes_vrc6_apu.c index 0aba81e..25b0cc4 100644 --- a/apps/codecs/libgme/nes_vrc6_apu.c +++ b/apps/codecs/libgme/nes_vrc6_apu.c @@ -21,7 +21,7 @@ void Vrc6_init( struct Nes_Vrc6_Apu* this ) Synth_init( &this->square_synth ); Vrc6_output( this, NULL ); - Vrc6_volume( this, 1.0 ); + Vrc6_volume( this, (int)FP_ONE_VOLUME ); Vrc6_reset( this ); } diff --git a/apps/codecs/libgme/nes_vrc6_apu.h b/apps/codecs/libgme/nes_vrc6_apu.h index 540438f..39ed006 100644 --- a/apps/codecs/libgme/nes_vrc6_apu.h +++ b/apps/codecs/libgme/nes_vrc6_apu.h @@ -52,11 +52,11 @@ static inline void Vrc6_osc_output( struct Nes_Vrc6_Apu* this, int i, struct Bli this->oscs [i].output = buf; } -static inline void Vrc6_volume( struct Nes_Vrc6_Apu* this, double v ) +static inline void Vrc6_volume( struct Nes_Vrc6_Apu* this, int v ) { - double const factor = 0.0967 * 2; - Synth_volume( &this->saw_synth, factor / 31 * v ); - Synth_volume( &this->square_synth, factor * 0.5 / 15 * v ); + long long const factor = (long long)(FP_ONE_VOLUME * 0.0967 * 2); + Synth_volume( &this->saw_synth, (int)(v * factor / 31 / FP_ONE_VOLUME) ); + Synth_volume( &this->square_synth, (int)(v * factor / 2 / 15 / FP_ONE_VOLUME) ); } #endif diff --git a/apps/codecs/libgme/nes_vrc7_apu.c b/apps/codecs/libgme/nes_vrc7_apu.c index d8768bf..6148a6b 100644 --- a/apps/codecs/libgme/nes_vrc7_apu.c +++ b/apps/codecs/libgme/nes_vrc7_apu.c @@ -15,7 +15,7 @@ void Vrc7_init( struct Nes_Vrc7_Apu* this ) this->osc.last_amp = 0;
this->mask = 0;
- Vrc7_volume( this, 1.0 );
+ Vrc7_volume( this, (int)FP_ONE_VOLUME );
Vrc7_reset( this );
}
diff --git a/apps/codecs/libgme/nes_vrc7_apu.h b/apps/codecs/libgme/nes_vrc7_apu.h index 5453e6b..aa8bb76 100644 --- a/apps/codecs/libgme/nes_vrc7_apu.h +++ b/apps/codecs/libgme/nes_vrc7_apu.h @@ -47,6 +47,6 @@ static inline void Vrc7_set_output( struct Nes_Vrc7_Apu* this, int i, struct Bli } // DB2LIN_AMP_BITS == 11, * 2 -static inline void Vrc7_volume( struct Nes_Vrc7_Apu* this, double v ) { Synth_volume( &this->synth, 1.0 / 3 / 4096 * v ); } +static inline void Vrc7_volume( struct Nes_Vrc7_Apu* this, int v ) { Synth_volume( &this->synth, v / 3 / 4096 ); } #endif diff --git a/apps/codecs/libgme/nsf_emu.c b/apps/codecs/libgme/nsf_emu.c index f3e1db7..ec32ef3 100644 --- a/apps/codecs/libgme/nsf_emu.c +++ b/apps/codecs/libgme/nsf_emu.c @@ -150,19 +150,19 @@ blargg_err_t init_sound( struct Nsf_Emu* this ) this->voice_count += vrc7_osc_count; } - 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 ); + 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 ); } #endif if ( adjusted_gain > this->gain ) adjusted_gain = this->gain; - Apu_volume( &this->apu, (double)adjusted_gain/FP_ONE_GAIN ); + Apu_volume( &this->apu, adjusted_gain ); return 0; } diff --git a/apps/codecs/libgme/opl_apu.c b/apps/codecs/libgme/opl_apu.c index bde5e9e..64b2714 100644 --- a/apps/codecs/libgme/opl_apu.c +++ b/apps/codecs/libgme/opl_apu.c @@ -13,7 +13,7 @@ blargg_err_t Opl_init( struct Opl_Apu* this, long clock, long rate, blip_time_t this->rate_ = rate;
this->period_ = period;
Opl_set_output( this, 0 );
- Opl_volume( this, 1.0 );
+ Opl_volume( this, (int)FP_ONE_VOLUME );
switch (type)
{
diff --git a/apps/codecs/libgme/opl_apu.h b/apps/codecs/libgme/opl_apu.h index 3f5a751..6185a99 100644 --- a/apps/codecs/libgme/opl_apu.h +++ b/apps/codecs/libgme/opl_apu.h @@ -38,7 +38,7 @@ struct Opl_Apu { blargg_err_t Opl_init( struct Opl_Apu* this, long clock, long rate, blip_time_t period, enum opl_type_t type );
void Opl_reset( struct Opl_Apu* this );
-static inline void Opl_volume( struct Opl_Apu* this, double v ) { Synth_volume( &this->synth, 1.0 / (4096 * 6) * v ); }
+static inline void Opl_volume( struct Opl_Apu* this, int v ) { Synth_volume( &this->synth, v / (4096 * 6) ); }
static inline void Opl_osc_output( struct Opl_Apu* this, int i, struct Blip_Buffer* buf )
{
diff --git a/apps/codecs/libgme/sgc_emu.c b/apps/codecs/libgme/sgc_emu.c index 1086683..ff8db0b 100644 --- a/apps/codecs/libgme/sgc_emu.c +++ b/apps/codecs/libgme/sgc_emu.c @@ -96,8 +96,8 @@ blargg_err_t Sgc_load_mem( struct Sgc_Emu* this, const void* data, long size ) this->track_count = this->header.song_count;
this->voice_count = sega_mapping( this ) ? osc_count : sms_osc_count;
- Sms_apu_volume( &this->apu, (double)(this->gain)/FP_ONE_GAIN );
- Fm_apu_volume( &this->fm_apu, (double)(this->gain)/FP_ONE_GAIN );
+ Sms_apu_volume( &this->apu, this->gain );
+ Fm_apu_volume( &this->fm_apu, this->gain );
// Setup buffer
this->clock_rate_ = clock_rate( this );
diff --git a/apps/codecs/libgme/sms_apu.c b/apps/codecs/libgme/sms_apu.c index 4be63db..0950659 100644 --- a/apps/codecs/libgme/sms_apu.c +++ b/apps/codecs/libgme/sms_apu.c @@ -17,9 +17,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ int const noise_osc = 3; -void Sms_apu_volume( struct Sms_Apu* this, double vol ) +void Sms_apu_volume( struct Sms_Apu* this, int vol ) { - vol *= 0.85 / sms_osc_count / 64; + vol = (vol - (vol*3)/20) / sms_osc_count / 64; Synth_volume( &this->synth, vol ); } @@ -116,7 +116,7 @@ void Sms_apu_init( struct Sms_Apu* this ) for ( i = sms_osc_count; --i >= 0; ) Sms_apu_set_output( this, i, NULL, NULL, NULL ); - Sms_apu_volume( this, 1.0 ); + Sms_apu_volume( this, (int)FP_ONE_VOLUME ); Sms_apu_reset( this, 0, 0 ); } diff --git a/apps/codecs/libgme/sms_apu.h b/apps/codecs/libgme/sms_apu.h index 25f4e74..e022513 100644 --- a/apps/codecs/libgme/sms_apu.h +++ b/apps/codecs/libgme/sms_apu.h @@ -58,6 +58,6 @@ void Sms_apu_end_frame( struct Sms_Apu* this, blip_time_t t ) ICODE_ATTR; void Sms_apu_reset( struct Sms_Apu* this, unsigned noise_feedback, int noise_width ); // Sets overall volume, where 1.0 is normal -void Sms_apu_volume( struct Sms_Apu* this, double vol ); +void Sms_apu_volume( struct Sms_Apu* this, int vol ); #endif diff --git a/apps/codecs/libgme/sms_fm_apu.c b/apps/codecs/libgme/sms_fm_apu.c index b15fc56..93689cd 100644 --- a/apps/codecs/libgme/sms_fm_apu.c +++ b/apps/codecs/libgme/sms_fm_apu.c @@ -14,7 +14,7 @@ blargg_err_t Fm_apu_init( struct Sms_Fm_Apu* this, double clock_rate, double sam CHECK_ALLOC( !Ym2413_set_rate( &this->apu, sample_rate, clock_rate ) );
Fm_apu_set_output( this, 0 );
- Fm_apu_volume( this, 1.0 );
+ Fm_apu_volume( this, (int)FP_ONE_VOLUME );
Fm_apu_reset( this );
return 0;
}
diff --git a/apps/codecs/libgme/sms_fm_apu.h b/apps/codecs/libgme/sms_fm_apu.h index 95e1f95..f78af30 100644 --- a/apps/codecs/libgme/sms_fm_apu.h +++ b/apps/codecs/libgme/sms_fm_apu.h @@ -31,7 +31,7 @@ static inline void Fm_apu_set_output( struct Sms_Fm_Apu* this, struct Blip_Buffe this->output_ = b;
}
-static inline void Fm_apu_volume( struct Sms_Fm_Apu* this, double v ) { Synth_volume( &this->synth, 0.4 / 4096 * v ); }
+static inline void Fm_apu_volume( struct Sms_Fm_Apu* this, int v ) { Synth_volume( &this->synth, (v*2) / 5 / 4096 ); }
void Fm_apu_reset( struct Sms_Fm_Apu* this );
diff --git a/apps/codecs/libgme/vgm_emu.c b/apps/codecs/libgme/vgm_emu.c index 9c4e1fe..5d230ed 100644 --- a/apps/codecs/libgme/vgm_emu.c +++ b/apps/codecs/libgme/vgm_emu.c @@ -21,7 +21,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ const char* const gme_wrong_file_type = "Wrong file type for this emulator"; -double const fm_gain = 3.0; // FM emulators are internally quieter to avoid 16-bit overflow +int const fm_gain = 3; // FM emulators are internally quieter to avoid 16-bit overflow double const rolloff = 0.990; double const oversample_factor = 1.5; @@ -352,11 +352,11 @@ blargg_err_t setup_fm( struct Vgm_Emu* this ) this->voice_count = 8; 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 * (double)(this->gain)/FP_ONE_GAIN ); + Sms_apu_volume( &this->psg, ((this->gain/5)-(this->gain*5)/1000) * fm_gain ); } else { - Sms_apu_volume( &this->psg, (double)(this->gain)/FP_ONE_GAIN ); + Sms_apu_volume( &this->psg, this->gain ); } return 0; @@ -717,7 +717,7 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask ) 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 * (double)(this->gain)/FP_ONE_GAIN ); + Synth_volume( &this->pcm, (mask & 0x40) ? 0 : (int)((long long)(0.1115*FP_ONE_VOLUME) / 256 * fm_gain * this->gain / FP_ONE_VOLUME) ); Ym2612_mute_voices( &this->ym2612, mask ); } |