summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2011-08-10 17:58:36 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2011-08-10 17:58:36 +0000
commit4ca2367e34e095419fa7e4de240dd7416575398a (patch)
tree7d27bc3b8f4e4dfb648d86a8ff1160c5700cc935
parent35c1df9cd5a587aec4f5d0a059f48ca4c40baa2a (diff)
3rd part of FS#12176. Gain setting migrated to fixed point for libgme.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30277 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/codecs/libgme/ay_emu.c4
-rw-r--r--apps/codecs/libgme/ay_emu.h4
-rw-r--r--apps/codecs/libgme/blargg_common.h3
-rw-r--r--apps/codecs/libgme/gbs_emu.c4
-rw-r--r--apps/codecs/libgme/gbs_emu.h4
-rw-r--r--apps/codecs/libgme/hes_emu.c6
-rw-r--r--apps/codecs/libgme/hes_emu.h4
-rw-r--r--apps/codecs/libgme/kss_emu.c20
-rw-r--r--apps/codecs/libgme/kss_emu.h4
-rw-r--r--apps/codecs/libgme/nsf_emu.c32
-rw-r--r--apps/codecs/libgme/nsf_emu.h4
-rw-r--r--apps/codecs/libgme/sgc_emu.c8
-rw-r--r--apps/codecs/libgme/sgc_emu.h4
-rw-r--r--apps/codecs/libgme/vgm_emu.c10
-rw-r--r--apps/codecs/libgme/vgm_emu.h4
15 files changed, 58 insertions, 57 deletions
diff --git a/apps/codecs/libgme/ay_emu.c b/apps/codecs/libgme/ay_emu.c
index 78d4556bf5..3c4398471c 100644
--- a/apps/codecs/libgme/ay_emu.c
+++ b/apps/codecs/libgme/ay_emu.c
@@ -55,7 +55,7 @@ void Ay_init( struct Ay_Emu *this )
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 @@ 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, this->gain );
+ Ay_apu_volume( &this->apu, ((double)this->gain)/FP_ONE_GAIN);
// Setup buffer
change_clock_rate( this, spectrum_clock );
diff --git a/apps/codecs/libgme/ay_emu.h b/apps/codecs/libgme/ay_emu.h
index c41debc237..b320e69653 100644
--- a/apps/codecs/libgme/ay_emu.h
+++ b/apps/codecs/libgme/ay_emu.h
@@ -66,7 +66,7 @@ struct Ay_Emu {
int voice_count;
int mute_mask_;
int tempo;
- double gain;
+ int gain;
long sample_rate;
@@ -152,7 +152,7 @@ void Sound_mute_voices( struct Ay_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/blargg_common.h b/apps/codecs/libgme/blargg_common.h
index a9e47b8280..190af65f23 100644
--- a/apps/codecs/libgme/blargg_common.h
+++ b/apps/codecs/libgme/blargg_common.h
@@ -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
diff --git a/apps/codecs/libgme/gbs_emu.c b/apps/codecs/libgme/gbs_emu.c
index 05c9be2d52..664510d5fa 100644
--- a/apps/codecs/libgme/gbs_emu.c
+++ b/apps/codecs/libgme/gbs_emu.c
@@ -55,7 +55,7 @@ void Gbs_init( struct Gbs_Emu* this )
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 @@ 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, this->gain_ );
+ Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN );
// Change clock rate & setup buffer
this->clock_rate_ = 4194304;
diff --git a/apps/codecs/libgme/gbs_emu.h b/apps/codecs/libgme/gbs_emu.h
index dcbc5b06b5..5a4ac2dfd9 100644
--- a/apps/codecs/libgme/gbs_emu.h
+++ b/apps/codecs/libgme/gbs_emu.h
@@ -63,7 +63,7 @@ struct Gbs_Emu {
long sample_rate_;
unsigned buf_changed_count;
int voice_count_;
- double gain_;
+ int gain_;
int tempo_;
// track-specific
@@ -169,7 +169,7 @@ void Sound_mute_voices( struct Gbs_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/hes_emu.c b/apps/codecs/libgme/hes_emu.c
index 112cd75b1d..ae4e68e48e 100644
--- a/apps/codecs/libgme/hes_emu.c
+++ b/apps/codecs/libgme/hes_emu.c
@@ -61,7 +61,7 @@ void Hes_init( struct Hes_Emu* this )
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 @@ 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, 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;
diff --git a/apps/codecs/libgme/hes_emu.h b/apps/codecs/libgme/hes_emu.h
index d16ba6465a..be9264455b 100644
--- a/apps/codecs/libgme/hes_emu.h
+++ b/apps/codecs/libgme/hes_emu.h
@@ -70,7 +70,7 @@ struct Hes_Emu {
unsigned buf_changed_count;
int voice_count_;
int tempo_;
- double gain_;
+ int gain_;
// track-specific
byte track_count;
@@ -179,7 +179,7 @@ void Sound_mute_voices( struct Hes_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/kss_emu.c b/apps/codecs/libgme/kss_emu.c
index e1576adf45..00991be8b5 100644
--- a/apps/codecs/libgme/kss_emu.c
+++ b/apps/codecs/libgme/kss_emu.c
@@ -54,7 +54,7 @@ void Kss_init( struct Kss_Emu* this )
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 @@ static blargg_err_t check_kss_header( void const* header )
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 )
diff --git a/apps/codecs/libgme/kss_emu.h b/apps/codecs/libgme/kss_emu.h
index d0a3de34e4..646b18ea35 100644
--- a/apps/codecs/libgme/kss_emu.h
+++ b/apps/codecs/libgme/kss_emu.h
@@ -98,7 +98,7 @@ struct Kss_Emu {
int voice_count;
int mute_mask_;
int tempo;
- double gain;
+ int gain;
long sample_rate;
@@ -203,7 +203,7 @@ void Sound_mute_voices( struct Kss_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/nsf_emu.c b/apps/codecs/libgme/nsf_emu.c
index 7b9ff1ad3e..f3e1db773b 100644
--- a/apps/codecs/libgme/nsf_emu.c
+++ b/apps/codecs/libgme/nsf_emu.c
@@ -55,7 +55,7 @@ void Nsf_init( struct Nsf_Emu* this )
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 @@ void Nsf_init( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
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;
}
diff --git a/apps/codecs/libgme/nsf_emu.h b/apps/codecs/libgme/nsf_emu.h
index 808ef442a3..05b5e5a920 100644
--- a/apps/codecs/libgme/nsf_emu.h
+++ b/apps/codecs/libgme/nsf_emu.h
@@ -90,7 +90,7 @@ struct Nsf_Emu {
int voice_count;
int mute_mask_;
int tempo;
- double gain;
+ int gain;
long sample_rate;
@@ -200,7 +200,7 @@ void Sound_mute_voices( struct Nsf_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/sgc_emu.c b/apps/codecs/libgme/sgc_emu.c
index 3cd5dc678f..10866836d6 100644
--- a/apps/codecs/libgme/sgc_emu.c
+++ b/apps/codecs/libgme/sgc_emu.c
@@ -47,7 +47,7 @@ void Sgc_init( struct Sgc_Emu* this )
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 @@ void Sgc_init( struct Sgc_Emu* this )
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 @@ 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, 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 );
diff --git a/apps/codecs/libgme/sgc_emu.h b/apps/codecs/libgme/sgc_emu.h
index 89b56f43cb..720e8d2460 100644
--- a/apps/codecs/libgme/sgc_emu.h
+++ b/apps/codecs/libgme/sgc_emu.h
@@ -67,7 +67,7 @@ struct Sgc_Emu {
int voice_count;
int mute_mask_;
int tempo;
- double gain;
+ int gain;
long sample_rate;
@@ -177,7 +177,7 @@ void Sound_mute_voices( struct Sgc_Emu* this, int mask );
// 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;
diff --git a/apps/codecs/libgme/vgm_emu.c b/apps/codecs/libgme/vgm_emu.c
index de5bd290c0..9c4e1fe6b7 100644
--- a/apps/codecs/libgme/vgm_emu.c
+++ b/apps/codecs/libgme/vgm_emu.c
@@ -104,7 +104,7 @@ void Vgm_init( struct Vgm_Emu* this )
// 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 @@ blargg_err_t setup_fm( struct Vgm_Emu* this )
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 @@ 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 * 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 );
}
diff --git a/apps/codecs/libgme/vgm_emu.h b/apps/codecs/libgme/vgm_emu.h
index ee57d5c692..5a0f1e5fa5 100644
--- a/apps/codecs/libgme/vgm_emu.h
+++ b/apps/codecs/libgme/vgm_emu.h
@@ -94,7 +94,7 @@ struct Vgm_Emu {
int voice_count;
int mute_mask_;
int tempo;
- double gain;
+ int gain;
long sample_rate;
@@ -201,7 +201,7 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask );
// 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;