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)
downloadrockbox-4ca2367e34e095419fa7e4de240dd7416575398a.tar.gz
rockbox-4ca2367e34e095419fa7e4de240dd7416575398a.zip
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 )
55 this->sample_rate = 0; 55 this->sample_rate = 0;
56 this->mute_mask_ = 0; 56 this->mute_mask_ = 0;
57 this->tempo = (int)FP_ONE_TEMPO; 57 this->tempo = (int)FP_ONE_TEMPO;
58 this->gain = 1.0; 58 this->gain = (int)FP_ONE_GAIN;
59 this->track_count = 0; 59 this->track_count = 0;
60 60
61 // defaults 61 // defaults
@@ -144,7 +144,7 @@ blargg_err_t Ay_load_mem( struct Ay_Emu *this, byte const in [], int size )
144 warning( "Unknown file version" ); */ 144 warning( "Unknown file version" ); */
145 145
146 this->voice_count = ay_osc_count + 1; // +1 for beeper 146 this->voice_count = ay_osc_count + 1; // +1 for beeper
147 Ay_apu_volume( &this->apu, this->gain ); 147 Ay_apu_volume( &this->apu, ((double)this->gain)/FP_ONE_GAIN);
148 148
149 // Setup buffer 149 // Setup buffer
150 change_clock_rate( this, spectrum_clock ); 150 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 {
66 int voice_count; 66 int voice_count;
67 int mute_mask_; 67 int mute_mask_;
68 int tempo; 68 int tempo;
69 double gain; 69 int gain;
70 70
71 long sample_rate; 71 long sample_rate;
72 72
@@ -152,7 +152,7 @@ void Sound_mute_voices( struct Ay_Emu* this, int mask );
152 152
153// Change overall output amplitude, where 1.0 results in minimal clamping. 153// Change overall output amplitude, where 1.0 results in minimal clamping.
154// Must be called before set_sample_rate(). 154// Must be called before set_sample_rate().
155static inline void Sound_set_gain( struct Ay_Emu* this, double g ) 155static inline void Sound_set_gain( struct Ay_Emu* this, int g )
156{ 156{
157 assert( !this->sample_rate ); // you must set gain before setting sample rate 157 assert( !this->sample_rate ); // you must set gain before setting sample rate
158 this->gain = g; 158 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 @@
21#endif 21#endif
22 22
23// common defines 23// common defines
24#define FP_ONE_TEMPO (1LL <<16) 24#define FP_ONE_TEMPO (1LL <<24)
25#define FP_ONE_GAIN (1LL <<24)
25 26
26#if 1 /* IRAM configuration is not yet active for all libGME codecs. */ 27#if 1 /* IRAM configuration is not yet active for all libGME codecs. */
27 #undef ICODE_ATTR 28 #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 )
55 this->ignore_silence = false; 55 this->ignore_silence = false;
56 this->silence_lookahead = 6; 56 this->silence_lookahead = 6;
57 this->max_initial_silence = 21; 57 this->max_initial_silence = 21;
58 Sound_set_gain( this, 1.2 ); 58 Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) );
59 59
60 Rom_init( &this->rom, 0x4000 ); 60 Rom_init( &this->rom, 0x4000 );
61 61
@@ -112,7 +112,7 @@ blargg_err_t Gbs_load( struct Gbs_Emu* this, void* data, long size )
112 Rom_set_addr( &this->rom, load_addr ); 112 Rom_set_addr( &this->rom, load_addr );
113 113
114 this->voice_count_ = osc_count; 114 this->voice_count_ = osc_count;
115 Apu_volume( &this->apu, this->gain_ ); 115 Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN );
116 116
117 // Change clock rate & setup buffer 117 // Change clock rate & setup buffer
118 this->clock_rate_ = 4194304; 118 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 {
63 long sample_rate_; 63 long sample_rate_;
64 unsigned buf_changed_count; 64 unsigned buf_changed_count;
65 int voice_count_; 65 int voice_count_;
66 double gain_; 66 int gain_;
67 int tempo_; 67 int tempo_;
68 68
69 // track-specific 69 // track-specific
@@ -169,7 +169,7 @@ void Sound_mute_voices( struct Gbs_Emu* this, int mask );
169 169
170// Change overall output amplitude, where 1.0 results in minimal clamping. 170// Change overall output amplitude, where 1.0 results in minimal clamping.
171// Must be called before set_sample_rate(). 171// Must be called before set_sample_rate().
172static inline void Sound_set_gain( struct Gbs_Emu* this, double g ) 172static inline void Sound_set_gain( struct Gbs_Emu* this, int g )
173{ 173{
174 assert( !this->sample_rate_ ); // you must set gain before setting sample rate 174 assert( !this->sample_rate_ ); // you must set gain before setting sample rate
175 this->gain_ = g; 175 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 )
61 61
62 this->timer.raw_load = 0; 62 this->timer.raw_load = 0;
63 this->silence_lookahead = 6; 63 this->silence_lookahead = 6;
64 Sound_set_gain( this, 1.11 ); 64 Sound_set_gain( this, (int)(FP_ONE_GAIN*1.11) );
65 65
66 Rom_init( &this->rom, 0x2000 ); 66 Rom_init( &this->rom, 0x2000 );
67 67
@@ -131,8 +131,8 @@ blargg_err_t Hes_load( struct Hes_Emu* this, void* data, long size )
131 131
132 this->voice_count_ = osc_count + adpcm_osc_count; 132 this->voice_count_ = osc_count + adpcm_osc_count;
133 133
134 Apu_volume( &this->apu, this->gain_ ); 134 Apu_volume( &this->apu, (double)(this->gain_)/FP_ONE_GAIN );
135 Adpcm_volume( &this->adpcm, this->gain_ ); 135 Adpcm_volume( &this->adpcm, (double)(this->gain_)/FP_ONE_GAIN );
136 136
137 // Setup buffer 137 // Setup buffer
138 this->clock_rate_ = 7159091; 138 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 {
70 unsigned buf_changed_count; 70 unsigned buf_changed_count;
71 int voice_count_; 71 int voice_count_;
72 int tempo_; 72 int tempo_;
73 double gain_; 73 int gain_;
74 74
75 // track-specific 75 // track-specific
76 byte track_count; 76 byte track_count;
@@ -179,7 +179,7 @@ void Sound_mute_voices( struct Hes_Emu* this, int mask );
179 179
180// Change overall output amplitude, where 1.0 results in minimal clamping. 180// Change overall output amplitude, where 1.0 results in minimal clamping.
181// Must be called before set_sample_rate(). 181// Must be called before set_sample_rate().
182static inline void Sound_set_gain( struct Hes_Emu* this, double g ) 182static inline void Sound_set_gain( struct Hes_Emu* this, int g )
183{ 183{
184 assert( !this->sample_rate_ ); // you must set gain before setting sample rate 184 assert( !this->sample_rate_ ); // you must set gain before setting sample rate
185 this->gain_ = g; 185 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 )
54 this->sample_rate = 0; 54 this->sample_rate = 0;
55 this->mute_mask_ = 0; 55 this->mute_mask_ = 0;
56 this->tempo = (int)(FP_ONE_TEMPO); 56 this->tempo = (int)(FP_ONE_TEMPO);
57 this->gain = 1.0; 57 this->gain = (int)FP_ONE_GAIN;
58 this->chip_flags = 0; 58 this->chip_flags = 0;
59 59
60 // defaults 60 // defaults
@@ -98,24 +98,24 @@ static blargg_err_t check_kss_header( void const* header )
98 98
99void update_gain( struct Kss_Emu* this ) 99void update_gain( struct Kss_Emu* this )
100{ 100{
101 double g = this->gain; 101 int g = this->gain;
102 if ( msx_music_enabled( this ) || msx_audio_enabled( this ) 102 if ( msx_music_enabled( this ) || msx_audio_enabled( this )
103 || sms_fm_enabled( this ) ) 103 || sms_fm_enabled( this ) )
104 { 104 {
105 g *= 0.75; 105 g = (g*3) / 4; //g *= 0.75;
106 } 106 }
107 else 107 else
108 { 108 {
109 if ( this->scc_accessed ) 109 if ( this->scc_accessed )
110 g *= 1.2; 110 g = (g*6) / 5; //g *= 1.2;
111 } 111 }
112 112
113 if ( sms_psg_enabled( this ) ) Sms_apu_volume( &this->sms.psg, g ); 113 if ( sms_psg_enabled( this ) ) Sms_apu_volume( &this->sms.psg, (double)(g)/FP_ONE_GAIN );
114 if ( sms_fm_enabled( this ) ) Opl_volume( &this->sms.fm, g ); 114 if ( sms_fm_enabled( this ) ) Opl_volume( &this->sms.fm, (double)(g)/FP_ONE_GAIN );
115 if ( msx_psg_enabled( this ) ) Ay_apu_volume( &this->msx.psg, g ); 115 if ( msx_psg_enabled( this ) ) Ay_apu_volume( &this->msx.psg, (double)(g)/FP_ONE_GAIN );
116 if ( msx_scc_enabled( this ) ) Scc_volume( &this->msx.scc, g ); 116 if ( msx_scc_enabled( this ) ) Scc_volume( &this->msx.scc, (double)(g)/FP_ONE_GAIN );
117 if ( msx_music_enabled( this ) ) Opl_volume( &this->msx.music, g ); 117 if ( msx_music_enabled( this ) ) Opl_volume( &this->msx.music, (double)(g)/FP_ONE_GAIN );
118 if ( msx_audio_enabled( this ) ) Opl_volume( &this->msx.audio, g ); 118 if ( msx_audio_enabled( this ) ) Opl_volume( &this->msx.audio, (double)(g)/FP_ONE_GAIN );
119} 119}
120 120
121blargg_err_t Kss_load_mem( struct Kss_Emu* this, const void* data, long size ) 121blargg_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 {
98 int voice_count; 98 int voice_count;
99 int mute_mask_; 99 int mute_mask_;
100 int tempo; 100 int tempo;
101 double gain; 101 int gain;
102 102
103 long sample_rate; 103 long sample_rate;
104 104
@@ -203,7 +203,7 @@ void Sound_mute_voices( struct Kss_Emu* this, int mask );
203 203
204// Change overall output amplitude, where 1.0 results in minimal clamping. 204// Change overall output amplitude, where 1.0 results in minimal clamping.
205// Must be called before set_sample_rate(). 205// Must be called before set_sample_rate().
206static inline void Sound_set_gain( struct Kss_Emu* this, double g ) 206static inline void Sound_set_gain( struct Kss_Emu* this, int g )
207{ 207{
208 assert( !this->sample_rate ); // you must set gain before setting sample rate 208 assert( !this->sample_rate ); // you must set gain before setting sample rate
209 this->gain = g; 209 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 )
55 this->sample_rate = 0; 55 this->sample_rate = 0;
56 this->mute_mask_ = 0; 56 this->mute_mask_ = 0;
57 this->tempo = (int)(FP_ONE_TEMPO); 57 this->tempo = (int)(FP_ONE_TEMPO);
58 this->gain = 1.0; 58 this->gain = (int)(FP_ONE_GAIN);
59 59
60 // defaults 60 // defaults
61 this->max_initial_silence = 2; 61 this->max_initial_silence = 2;
@@ -63,7 +63,7 @@ void Nsf_init( struct Nsf_Emu* this )
63 this->voice_count = 0; 63 this->voice_count = 0;
64 64
65 // Set sound gain 65 // Set sound gain
66 Sound_set_gain( this, 1.2 ); 66 Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) );
67 67
68 // Unload 68 // Unload
69 clear_track_vars( this ); 69 clear_track_vars( this );
@@ -89,7 +89,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
89 89
90 this->voice_count = apu_osc_count; 90 this->voice_count = apu_osc_count;
91 91
92 double adjusted_gain = 1.0 / 0.75 * this->gain; 92 int adjusted_gain = (this->gain * 4) / 3;
93 93
94 #ifdef NSF_EMU_APU_ONLY 94 #ifdef NSF_EMU_APU_ONLY
95 { 95 {
@@ -101,7 +101,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
101 if ( vrc6_enabled( this ) ) 101 if ( vrc6_enabled( this ) )
102 { 102 {
103 Vrc6_init( &this->vrc6 ); 103 Vrc6_init( &this->vrc6 );
104 adjusted_gain *= 0.75; 104 adjusted_gain = (adjusted_gain*3) / 4;
105 105
106 this->voice_count += vrc6_osc_count; 106 this->voice_count += vrc6_osc_count;
107 } 107 }
@@ -109,7 +109,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
109 if ( fme7_enabled( this ) ) 109 if ( fme7_enabled( this ) )
110 { 110 {
111 Fme7_init( &this->fme7 ); 111 Fme7_init( &this->fme7 );
112 adjusted_gain *= 0.75; 112 adjusted_gain = (adjusted_gain*3) / 4;
113 113
114 this->voice_count += fme7_osc_count; 114 this->voice_count += fme7_osc_count;
115 } 115 }
@@ -117,7 +117,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
117 if ( mmc5_enabled( this ) ) 117 if ( mmc5_enabled( this ) )
118 { 118 {
119 Mmc5_init( &this->mmc5 ); 119 Mmc5_init( &this->mmc5 );
120 adjusted_gain *= 0.75; 120 adjusted_gain = (adjusted_gain*3) / 4;
121 121
122 this->voice_count += mmc5_osc_count; 122 this->voice_count += mmc5_osc_count;
123 } 123 }
@@ -125,7 +125,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
125 if ( fds_enabled( this ) ) 125 if ( fds_enabled( this ) )
126 { 126 {
127 Fds_init( &this->fds ); 127 Fds_init( &this->fds );
128 adjusted_gain *= 0.75; 128 adjusted_gain = (adjusted_gain*3) / 4;
129 129
130 this->voice_count += fds_osc_count ; 130 this->voice_count += fds_osc_count ;
131 } 131 }
@@ -133,7 +133,7 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
133 if ( namco_enabled( this ) ) 133 if ( namco_enabled( this ) )
134 { 134 {
135 Namco_init( &this->namco ); 135 Namco_init( &this->namco );
136 adjusted_gain *= 0.75; 136 adjusted_gain = (adjusted_gain*3) / 4;
137 137
138 this->voice_count += namco_osc_count; 138 this->voice_count += namco_osc_count;
139 } 139 }
@@ -145,24 +145,24 @@ blargg_err_t init_sound( struct Nsf_Emu* this )
145 Vrc7_set_rate( &this->vrc7, this->sample_rate ); 145 Vrc7_set_rate( &this->vrc7, this->sample_rate );
146 #endif 146 #endif
147 147
148 adjusted_gain *= 0.75; 148 adjusted_gain = (adjusted_gain*3) / 4;
149 149
150 this->voice_count += vrc7_osc_count; 150 this->voice_count += vrc7_osc_count;
151 } 151 }
152 152
153 if ( vrc7_enabled( this ) ) Vrc7_volume( &this->vrc7, adjusted_gain ); 153 if ( vrc7_enabled( this ) ) Vrc7_volume( &this->vrc7, (double)adjusted_gain/FP_ONE_GAIN );
154 if ( namco_enabled( this ) ) Namco_volume( &this->namco, adjusted_gain ); 154 if ( namco_enabled( this ) ) Namco_volume( &this->namco, (double)adjusted_gain/FP_ONE_GAIN );
155 if ( vrc6_enabled( this ) ) Vrc6_volume( &this->vrc6, adjusted_gain ); 155 if ( vrc6_enabled( this ) ) Vrc6_volume( &this->vrc6, (double)adjusted_gain/FP_ONE_GAIN );
156 if ( fme7_enabled( this ) ) Fme7_volume( &this->fme7, adjusted_gain ); 156 if ( fme7_enabled( this ) ) Fme7_volume( &this->fme7, (double)adjusted_gain/FP_ONE_GAIN );
157 if ( mmc5_enabled( this ) ) Apu_volume( &this->mmc5.apu, adjusted_gain ); 157 if ( mmc5_enabled( this ) ) Apu_volume( &this->mmc5.apu, (double)adjusted_gain/FP_ONE_GAIN );
158 if ( fds_enabled( this ) ) Fds_volume( &this->fds, adjusted_gain ); 158 if ( fds_enabled( this ) ) Fds_volume( &this->fds, (double)adjusted_gain/FP_ONE_GAIN );
159 } 159 }
160 #endif 160 #endif
161 161
162 if ( adjusted_gain > this->gain ) 162 if ( adjusted_gain > this->gain )
163 adjusted_gain = this->gain; 163 adjusted_gain = this->gain;
164 164
165 Apu_volume( &this->apu, adjusted_gain ); 165 Apu_volume( &this->apu, (double)adjusted_gain/FP_ONE_GAIN );
166 166
167 return 0; 167 return 0;
168} 168}
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 {
90 int voice_count; 90 int voice_count;
91 int mute_mask_; 91 int mute_mask_;
92 int tempo; 92 int tempo;
93 double gain; 93 int gain;
94 94
95 long sample_rate; 95 long sample_rate;
96 96
@@ -200,7 +200,7 @@ void Sound_mute_voices( struct Nsf_Emu* this, int mask );
200 200
201// Change overall output amplitude, where 1.0 results in minimal clamping. 201// Change overall output amplitude, where 1.0 results in minimal clamping.
202// Must be called before set_sample_rate(). 202// Must be called before set_sample_rate().
203static inline void Sound_set_gain( struct Nsf_Emu* this, double g ) 203static inline void Sound_set_gain( struct Nsf_Emu* this, int g )
204{ 204{
205 assert( !this->sample_rate ); // you must set gain before setting sample rate 205 assert( !this->sample_rate ); // you must set gain before setting sample rate
206 this->gain = g; 206 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 )
47 this->sample_rate = 0; 47 this->sample_rate = 0;
48 this->mute_mask_ = 0; 48 this->mute_mask_ = 0;
49 this->tempo = (int)FP_ONE_TEMPO; 49 this->tempo = (int)FP_ONE_TEMPO;
50 this->gain = 1.0; 50 this->gain = (int)FP_ONE_GAIN;
51 this->voice_count = 0; 51 this->voice_count = 0;
52 52
53 // defaults 53 // defaults
@@ -61,7 +61,7 @@ void Sgc_init( struct Sgc_Emu* this )
61 Rom_init( &this->rom, 0x4000 ); 61 Rom_init( &this->rom, 0x4000 );
62 Z80_init( &this->cpu ); 62 Z80_init( &this->cpu );
63 63
64 Sound_set_gain( this, 1.2 ); 64 Sound_set_gain( this, (int)(FP_ONE_GAIN*1.2) );
65 65
66 // Unload 66 // Unload
67 clear_track_vars( this ); 67 clear_track_vars( this );
@@ -96,8 +96,8 @@ blargg_err_t Sgc_load_mem( struct Sgc_Emu* this, const void* data, long size )
96 this->track_count = this->header.song_count; 96 this->track_count = this->header.song_count;
97 this->voice_count = sega_mapping( this ) ? osc_count : sms_osc_count; 97 this->voice_count = sega_mapping( this ) ? osc_count : sms_osc_count;
98 98
99 Sms_apu_volume( &this->apu, this->gain ); 99 Sms_apu_volume( &this->apu, (double)(this->gain)/FP_ONE_GAIN );
100 Fm_apu_volume( &this->fm_apu, this->gain ); 100 Fm_apu_volume( &this->fm_apu, (double)(this->gain)/FP_ONE_GAIN );
101 101
102 // Setup buffer 102 // Setup buffer
103 this->clock_rate_ = clock_rate( this ); 103 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 {
67 int voice_count; 67 int voice_count;
68 int mute_mask_; 68 int mute_mask_;
69 int tempo; 69 int tempo;
70 double gain; 70 int gain;
71 71
72 long sample_rate; 72 long sample_rate;
73 73
@@ -177,7 +177,7 @@ void Sound_mute_voices( struct Sgc_Emu* this, int mask );
177 177
178// Change overall output amplitude, where 1.0 results in minimal clamping. 178// Change overall output amplitude, where 1.0 results in minimal clamping.
179// Must be called before set_sample_rate(). 179// Must be called before set_sample_rate().
180static inline void Sound_set_gain( struct Sgc_Emu* this, double g ) 180static inline void Sound_set_gain( struct Sgc_Emu* this, int g )
181{ 181{
182 assert( !this->sample_rate ); // you must set gain before setting sample rate 182 assert( !this->sample_rate ); // you must set gain before setting sample rate
183 this->gain = g; 183 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 )
104 104
105 // Set sound gain, a value too high 105 // Set sound gain, a value too high
106 // will cause saturation 106 // will cause saturation
107 Sound_set_gain(this, 1.0); 107 Sound_set_gain(this, (int)FP_ONE_GAIN);
108 108
109 // Unload 109 // Unload
110 this->voice_count = 0; 110 this->voice_count = 0;
@@ -350,13 +350,13 @@ blargg_err_t setup_fm( struct Vgm_Emu* this )
350 if ( uses_fm( this ) ) 350 if ( uses_fm( this ) )
351 { 351 {
352 this->voice_count = 8; 352 this->voice_count = 8;
353 RETURN_ERR( Resampler_setup( &this->resampler, fm_rate / this->sample_rate, rolloff, fm_gain * this->gain ) ); 353 RETURN_ERR( Resampler_setup( &this->resampler, fm_rate / this->sample_rate, rolloff, fm_gain * (double)(this->gain)/FP_ONE_GAIN ) );
354 RETURN_ERR( Resampler_reset( &this->resampler, Buffer_length( &this->stereo_buf ) * this->sample_rate / 1000 ) ); 354 RETURN_ERR( Resampler_reset( &this->resampler, Buffer_length( &this->stereo_buf ) * this->sample_rate / 1000 ) );
355 Sms_apu_volume( &this->psg, 0.195 * fm_gain * this->gain ); 355 Sms_apu_volume( &this->psg, 0.195 * fm_gain * (double)(this->gain)/FP_ONE_GAIN );
356 } 356 }
357 else 357 else
358 { 358 {
359 Sms_apu_volume( &this->psg, this->gain ); 359 Sms_apu_volume( &this->psg, (double)(this->gain)/FP_ONE_GAIN );
360 } 360 }
361 361
362 return 0; 362 return 0;
@@ -717,7 +717,7 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask )
717 Sms_apu_set_output( &this->psg, i, ( mask & 0x80 ) ? 0 : &this->stereo_buf.bufs [0], NULL, NULL ); 717 Sms_apu_set_output( &this->psg, i, ( mask & 0x80 ) ? 0 : &this->stereo_buf.bufs [0], NULL, NULL );
718 if ( Ym2612_enabled( &this->ym2612 ) ) 718 if ( Ym2612_enabled( &this->ym2612 ) )
719 { 719 {
720 Synth_volume( &this->pcm, (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * this->gain ); 720 Synth_volume( &this->pcm, (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * (double)(this->gain)/FP_ONE_GAIN );
721 Ym2612_mute_voices( &this->ym2612, mask ); 721 Ym2612_mute_voices( &this->ym2612, mask );
722 } 722 }
723 723
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 {
94 int voice_count; 94 int voice_count;
95 int mute_mask_; 95 int mute_mask_;
96 int tempo; 96 int tempo;
97 double gain; 97 int gain;
98 98
99 long sample_rate; 99 long sample_rate;
100 100
@@ -201,7 +201,7 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask );
201 201
202// Change overall output amplitude, where 1.0 results in minimal clamping. 202// Change overall output amplitude, where 1.0 results in minimal clamping.
203// Must be called before set_sample_rate(). 203// Must be called before set_sample_rate().
204static inline void Sound_set_gain( struct Vgm_Emu* this, double g ) 204static inline void Sound_set_gain( struct Vgm_Emu* this, int g )
205{ 205{
206 assert( !this->sample_rate ); // you must set gain before setting sample rate 206 assert( !this->sample_rate ); // you must set gain before setting sample rate
207 this->gain = g; 207 this->gain = g;