diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-09 20:21:55 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-09 20:21:55 +0000 |
commit | 012df14a5f49fb7ab5a20eb08c7b829fd49baf7a (patch) | |
tree | 2e3380d8e9a536283e93f371b84dbd17a9493cc2 | |
parent | 964a5e6dfb73983cfd5a14ed9e1af266cf4f9485 (diff) | |
download | rockbox-012df14a5f49fb7ab5a20eb08c7b829fd49baf7a.tar.gz rockbox-012df14a5f49fb7ab5a20eb08c7b829fd49baf7a.zip |
2nd part of FS#12176. Tempo setting migrated to fixed point for libgme.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30274 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/libgme/ay_emu.c | 10 | ||||
-rw-r--r-- | apps/codecs/libgme/ay_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/blargg_common.h | 3 | ||||
-rw-r--r-- | apps/codecs/libgme/gb_apu.c | 8 | ||||
-rw-r--r-- | apps/codecs/libgme/gb_apu.h | 2 | ||||
-rw-r--r-- | apps/codecs/libgme/gbs_emu.c | 10 | ||||
-rw-r--r-- | apps/codecs/libgme/gbs_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/hes_emu.c | 12 | ||||
-rw-r--r-- | apps/codecs/libgme/hes_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/kss_emu.c | 10 | ||||
-rw-r--r-- | apps/codecs/libgme/kss_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/nes_apu.c | 8 | ||||
-rw-r--r-- | apps/codecs/libgme/nes_apu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/nes_fds_apu.c | 6 | ||||
-rw-r--r-- | apps/codecs/libgme/nes_fds_apu.h | 2 | ||||
-rw-r--r-- | apps/codecs/libgme/nsf_emu.c | 10 | ||||
-rw-r--r-- | apps/codecs/libgme/nsf_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/sgc_emu.c | 10 | ||||
-rw-r--r-- | apps/codecs/libgme/sgc_emu.h | 4 | ||||
-rw-r--r-- | apps/codecs/libgme/vgm_emu.c | 17 | ||||
-rw-r--r-- | apps/codecs/libgme/vgm_emu.h | 4 |
21 files changed, 71 insertions, 69 deletions
diff --git a/apps/codecs/libgme/ay_emu.c b/apps/codecs/libgme/ay_emu.c index dc775cbf79..78d4556bf5 100644 --- a/apps/codecs/libgme/ay_emu.c +++ b/apps/codecs/libgme/ay_emu.c | |||
@@ -54,7 +54,7 @@ void Ay_init( struct Ay_Emu *this ) | |||
54 | { | 54 | { |
55 | this->sample_rate = 0; | 55 | this->sample_rate = 0; |
56 | this->mute_mask_ = 0; | 56 | this->mute_mask_ = 0; |
57 | this->tempo = 1.0; | 57 | this->tempo = (int)FP_ONE_TEMPO; |
58 | this->gain = 1.0; | 58 | this->gain = 1.0; |
59 | this->track_count = 0; | 59 | this->track_count = 0; |
60 | 60 | ||
@@ -343,11 +343,11 @@ void Sound_mute_voices( struct Ay_Emu *this, int mask ) | |||
343 | } | 343 | } |
344 | } | 344 | } |
345 | 345 | ||
346 | void Sound_set_tempo( struct Ay_Emu *this, double t ) | 346 | void Sound_set_tempo( struct Ay_Emu *this, int t ) |
347 | { | 347 | { |
348 | require( this->sample_rate ); // sample rate must be set first | 348 | require( this->sample_rate ); // sample rate must be set first |
349 | double const min = 0.02; | 349 | int const min = (int)(FP_ONE_TEMPO*0.02); |
350 | double const max = 4.00; | 350 | int const max = (int)(FP_ONE_TEMPO*4.00); |
351 | if ( t < min ) t = min; | 351 | if ( t < min ) t = min; |
352 | if ( t > max ) t = max; | 352 | if ( t > max ) t = max; |
353 | this->tempo = t; | 353 | this->tempo = t; |
@@ -356,7 +356,7 @@ void Sound_set_tempo( struct Ay_Emu *this, double t ) | |||
356 | if ( this->clock_rate_ != spectrum_clock ) | 356 | if ( this->clock_rate_ != spectrum_clock ) |
357 | p = this->clock_rate_ / 50; | 357 | p = this->clock_rate_ / 50; |
358 | 358 | ||
359 | this->play_period = (blip_time_t) (p / t); | 359 | this->play_period = (blip_time_t) ((p * FP_ONE_TEMPO) / t); |
360 | } | 360 | } |
361 | 361 | ||
362 | void fill_buf( struct Ay_Emu *this ) ICODE_ATTR;; | 362 | void fill_buf( struct Ay_Emu *this ) ICODE_ATTR;; |
diff --git a/apps/codecs/libgme/ay_emu.h b/apps/codecs/libgme/ay_emu.h index 91252166e4..c41debc237 100644 --- a/apps/codecs/libgme/ay_emu.h +++ b/apps/codecs/libgme/ay_emu.h | |||
@@ -65,7 +65,7 @@ struct Ay_Emu { | |||
65 | int max_initial_silence; | 65 | int max_initial_silence; |
66 | int voice_count; | 66 | int voice_count; |
67 | int mute_mask_; | 67 | int mute_mask_; |
68 | double tempo; | 68 | int tempo; |
69 | double gain; | 69 | double gain; |
70 | 70 | ||
71 | long sample_rate; | 71 | long sample_rate; |
@@ -141,7 +141,7 @@ long Track_get_length( struct Ay_Emu* this, int n ); | |||
141 | 141 | ||
142 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 142 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
143 | // Track length as returned by track_info() assumes a tempo of 1.0. | 143 | // Track length as returned by track_info() assumes a tempo of 1.0. |
144 | void Sound_set_tempo( struct Ay_Emu* this, double t ); | 144 | void Sound_set_tempo( struct Ay_Emu* this, int t ); |
145 | 145 | ||
146 | // Mute/unmute voice i, where voice 0 is first voice | 146 | // Mute/unmute voice i, where voice 0 is first voice |
147 | void Sound_mute_voice( struct Ay_Emu* this, int index, bool mute ); | 147 | void Sound_mute_voice( struct Ay_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/blargg_common.h b/apps/codecs/libgme/blargg_common.h index be34379441..a9e47b8280 100644 --- a/apps/codecs/libgme/blargg_common.h +++ b/apps/codecs/libgme/blargg_common.h | |||
@@ -20,6 +20,9 @@ | |||
20 | #include "codeclib.h" | 20 | #include "codeclib.h" |
21 | #endif | 21 | #endif |
22 | 22 | ||
23 | // common defines | ||
24 | #define FP_ONE_TEMPO (1LL <<16) | ||
25 | |||
23 | #if 1 /* IRAM configuration is not yet active for all libGME codecs. */ | 26 | #if 1 /* IRAM configuration is not yet active for all libGME codecs. */ |
24 | #undef ICODE_ATTR | 27 | #undef ICODE_ATTR |
25 | #define ICODE_ATTR | 28 | #define ICODE_ATTR |
diff --git a/apps/codecs/libgme/gb_apu.c b/apps/codecs/libgme/gb_apu.c index a441645e3e..adc307156c 100644 --- a/apps/codecs/libgme/gb_apu.c +++ b/apps/codecs/libgme/gb_apu.c | |||
@@ -152,11 +152,11 @@ void Apu_reset( struct Gb_Apu* this, enum gb_mode_t mode, bool agb_wave ) | |||
152 | } | 152 | } |
153 | } | 153 | } |
154 | 154 | ||
155 | void Apu_set_tempo( struct Gb_Apu* this, double t ) | 155 | void Apu_set_tempo( struct Gb_Apu* this, int t ) |
156 | { | 156 | { |
157 | this->frame_period = 4194304 / 512; // 512 Hz | 157 | this->frame_period = 4194304 / 512; // 512 Hz |
158 | if ( t != 1.0 ) | 158 | if ( t != (int)FP_ONE_TEMPO ) |
159 | this->frame_period = t ? (blip_time_t) (this->frame_period / t) : (blip_time_t) (0); | 159 | this->frame_period = t ? (blip_time_t) ((this->frame_period * FP_ONE_TEMPO) / t) : (blip_time_t) (0); |
160 | } | 160 | } |
161 | 161 | ||
162 | void Apu_init( struct Gb_Apu* this ) | 162 | void Apu_init( struct Gb_Apu* this ) |
@@ -184,7 +184,7 @@ void Apu_init( struct Gb_Apu* this ) | |||
184 | } | 184 | } |
185 | 185 | ||
186 | this->reduce_clicks_ = false; | 186 | this->reduce_clicks_ = false; |
187 | Apu_set_tempo( this, 1.0 ); | 187 | Apu_set_tempo( this, (int)FP_ONE_TEMPO ); |
188 | this->volume_ = 1.0; | 188 | this->volume_ = 1.0; |
189 | Apu_reset( this, mode_cgb, false ); | 189 | Apu_reset( this, mode_cgb, false ); |
190 | } | 190 | } |
diff --git a/apps/codecs/libgme/gb_apu.h b/apps/codecs/libgme/gb_apu.h index f1457a2bbe..028be29d7c 100644 --- a/apps/codecs/libgme/gb_apu.h +++ b/apps/codecs/libgme/gb_apu.h | |||
@@ -77,7 +77,7 @@ void Apu_reduce_clicks( struct Gb_Apu* this, bool reduce ); | |||
77 | 77 | ||
78 | // Sets frame sequencer rate, where 1.0 is normal. Meant for adjusting the | 78 | // Sets frame sequencer rate, where 1.0 is normal. Meant for adjusting the |
79 | // tempo in a music player. | 79 | // tempo in a music player. |
80 | void Apu_set_tempo( struct Gb_Apu* this, double t ); | 80 | void Apu_set_tempo( struct Gb_Apu* this, int t ); |
81 | 81 | ||
82 | 82 | ||
83 | void write_osc( struct Gb_Apu* this, int reg, int old_data, int data ) ICODE_ATTR; | 83 | void write_osc( struct Gb_Apu* this, int reg, int old_data, int data ) ICODE_ATTR; |
diff --git a/apps/codecs/libgme/gbs_emu.c b/apps/codecs/libgme/gbs_emu.c index f5e214e5d1..05c9be2d52 100644 --- a/apps/codecs/libgme/gbs_emu.c +++ b/apps/codecs/libgme/gbs_emu.c | |||
@@ -46,7 +46,7 @@ void Gbs_init( struct Gbs_Emu* this ) | |||
46 | { | 46 | { |
47 | this->sample_rate_ = 0; | 47 | this->sample_rate_ = 0; |
48 | this->mute_mask_ = 0; | 48 | this->mute_mask_ = 0; |
49 | this->tempo_ = 1.0; | 49 | this->tempo_ = (int)(FP_ONE_TEMPO); |
50 | 50 | ||
51 | // Unload | 51 | // Unload |
52 | this->header.timer_mode = 0; | 52 | this->header.timer_mode = 0; |
@@ -304,16 +304,16 @@ void Sound_mute_voices( struct Gbs_Emu* this, int mask ) | |||
304 | } | 304 | } |
305 | } | 305 | } |
306 | 306 | ||
307 | void Sound_set_tempo( struct Gbs_Emu* this, double t ) | 307 | void Sound_set_tempo( struct Gbs_Emu* this, int t ) |
308 | { | 308 | { |
309 | require( this->sample_rate_ ); // sample rate must be set first | 309 | require( this->sample_rate_ ); // sample rate must be set first |
310 | double const min = 0.02; | 310 | int const min = (int)(FP_ONE_TEMPO*0.02); |
311 | double const max = 4.00; | 311 | int const max = (int)(FP_ONE_TEMPO*4.00); |
312 | if ( t < min ) t = min; | 312 | if ( t < min ) t = min; |
313 | if ( t > max ) t = max; | 313 | if ( t > max ) t = max; |
314 | this->tempo_ = t; | 314 | this->tempo_ = t; |
315 | 315 | ||
316 | this->tempo = (int) (tempo_unit / t + 0.5 ); | 316 | this->tempo = (int) ((tempo_unit * FP_ONE_TEMPO) / t); |
317 | Apu_set_tempo( &this->apu, t ); | 317 | Apu_set_tempo( &this->apu, t ); |
318 | Update_timer( this ); | 318 | Update_timer( this ); |
319 | } | 319 | } |
diff --git a/apps/codecs/libgme/gbs_emu.h b/apps/codecs/libgme/gbs_emu.h index c107264f9f..dcbc5b06b5 100644 --- a/apps/codecs/libgme/gbs_emu.h +++ b/apps/codecs/libgme/gbs_emu.h | |||
@@ -64,7 +64,7 @@ struct Gbs_Emu { | |||
64 | unsigned buf_changed_count; | 64 | unsigned buf_changed_count; |
65 | int voice_count_; | 65 | int voice_count_; |
66 | double gain_; | 66 | double gain_; |
67 | double tempo_; | 67 | int tempo_; |
68 | 68 | ||
69 | // track-specific | 69 | // track-specific |
70 | byte track_count; | 70 | byte track_count; |
@@ -158,7 +158,7 @@ static inline long Track_get_length( struct Gbs_Emu* this, int n ) | |||
158 | // Sound customization | 158 | // Sound customization |
159 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 159 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
160 | // Track length as returned by track_info() assumes a tempo of 1.0. | 160 | // Track length as returned by track_info() assumes a tempo of 1.0. |
161 | void Sound_set_tempo( struct Gbs_Emu* this, double ); | 161 | void Sound_set_tempo( struct Gbs_Emu* this, int ); |
162 | 162 | ||
163 | // Mute/unmute voice i, where voice 0 is first voice | 163 | // Mute/unmute voice i, where voice 0 is first voice |
164 | void Sound_mute_voice( struct Gbs_Emu* this, int index, bool mute ); | 164 | void Sound_mute_voice( struct Gbs_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/hes_emu.c b/apps/codecs/libgme/hes_emu.c index 324027888d..112cd75b1d 100644 --- a/apps/codecs/libgme/hes_emu.c +++ b/apps/codecs/libgme/hes_emu.c | |||
@@ -49,7 +49,7 @@ void Hes_init( struct Hes_Emu* this ) | |||
49 | { | 49 | { |
50 | this->sample_rate_ = 0; | 50 | this->sample_rate_ = 0; |
51 | this->mute_mask_ = 0; | 51 | this->mute_mask_ = 0; |
52 | this->tempo_ = 1.0; | 52 | this->tempo_ = (int)(FP_ONE_TEMPO); |
53 | 53 | ||
54 | // defaults | 54 | // defaults |
55 | this->max_initial_silence = 2; | 55 | this->max_initial_silence = 2; |
@@ -544,15 +544,15 @@ void Sound_mute_voices( struct Hes_Emu* this, int mask ) | |||
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | void Sound_set_tempo( struct Hes_Emu* this, double t ) | 547 | void Sound_set_tempo( struct Hes_Emu* this, int t ) |
548 | { | 548 | { |
549 | require( this->sample_rate_ ); // sample rate must be set first | 549 | require( this->sample_rate_ ); // sample rate must be set first |
550 | double const min = 0.02; | 550 | int const min = (int)(FP_ONE_TEMPO*0.02); |
551 | double const max = 4.00; | 551 | int const max = (int)(FP_ONE_TEMPO*4.00); |
552 | if ( t < min ) t = min; | 552 | if ( t < min ) t = min; |
553 | if ( t > max ) t = max; | 553 | if ( t > max ) t = max; |
554 | this->play_period = (hes_time_t) (period_60hz / t); | 554 | this->play_period = (hes_time_t) ((period_60hz*FP_ONE_TEMPO) / t); |
555 | this->timer_base = (int) (1024 / t); | 555 | this->timer_base = (int) ((1024*FP_ONE_TEMPO) / t); |
556 | recalc_timer_load( this ); | 556 | recalc_timer_load( this ); |
557 | this->tempo_ = t; | 557 | this->tempo_ = t; |
558 | } | 558 | } |
diff --git a/apps/codecs/libgme/hes_emu.h b/apps/codecs/libgme/hes_emu.h index 18dbe0d506..d16ba6465a 100644 --- a/apps/codecs/libgme/hes_emu.h +++ b/apps/codecs/libgme/hes_emu.h | |||
@@ -69,7 +69,7 @@ struct Hes_Emu { | |||
69 | long sample_rate_; | 69 | long sample_rate_; |
70 | unsigned buf_changed_count; | 70 | unsigned buf_changed_count; |
71 | int voice_count_; | 71 | int voice_count_; |
72 | double tempo_; | 72 | int tempo_; |
73 | double gain_; | 73 | double gain_; |
74 | 74 | ||
75 | // track-specific | 75 | // track-specific |
@@ -168,7 +168,7 @@ static inline long Track_get_length( struct Hes_Emu* this, int n ) | |||
168 | // Sound customization | 168 | // Sound customization |
169 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 169 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
170 | // Track length as returned by track_info() assumes a tempo of 1.0. | 170 | // Track length as returned by track_info() assumes a tempo of 1.0. |
171 | void Sound_set_tempo( struct Hes_Emu* this, double ); | 171 | void Sound_set_tempo( struct Hes_Emu* this, int ); |
172 | 172 | ||
173 | // Mute/unmute voice i, where voice 0 is first voice | 173 | // Mute/unmute voice i, where voice 0 is first voice |
174 | void Sound_mute_voice( struct Hes_Emu* this, int index, bool mute ); | 174 | void Sound_mute_voice( struct Hes_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/kss_emu.c b/apps/codecs/libgme/kss_emu.c index b01034234a..e1576adf45 100644 --- a/apps/codecs/libgme/kss_emu.c +++ b/apps/codecs/libgme/kss_emu.c | |||
@@ -53,7 +53,7 @@ void Kss_init( struct Kss_Emu* this ) | |||
53 | { | 53 | { |
54 | this->sample_rate = 0; | 54 | this->sample_rate = 0; |
55 | this->mute_mask_ = 0; | 55 | this->mute_mask_ = 0; |
56 | this->tempo = 1.0; | 56 | this->tempo = (int)(FP_ONE_TEMPO); |
57 | this->gain = 1.0; | 57 | this->gain = 1.0; |
58 | this->chip_flags = 0; | 58 | this->chip_flags = 0; |
59 | 59 | ||
@@ -509,18 +509,18 @@ void Sound_mute_voices( struct Kss_Emu* this, int mask ) | |||
509 | } | 509 | } |
510 | } | 510 | } |
511 | 511 | ||
512 | void Sound_set_tempo( struct Kss_Emu* this, double t ) | 512 | void Sound_set_tempo( struct Kss_Emu* this, int t ) |
513 | { | 513 | { |
514 | require( this->sample_rate ); // sample rate must be set first | 514 | require( this->sample_rate ); // sample rate must be set first |
515 | double const min = 0.02; | 515 | int const min = (int)(FP_ONE_TEMPO*0.02); |
516 | double const max = 4.00; | 516 | int const max = (int)(FP_ONE_TEMPO*4.00); |
517 | if ( t < min ) t = min; | 517 | if ( t < min ) t = min; |
518 | if ( t > max ) t = max; | 518 | if ( t > max ) t = max; |
519 | this->tempo = t; | 519 | this->tempo = t; |
520 | 520 | ||
521 | blip_time_t period = | 521 | blip_time_t period = |
522 | (this->header.device_flags & 0x40 ? clock_rate / 50 : clock_rate / 60); | 522 | (this->header.device_flags & 0x40 ? clock_rate / 50 : clock_rate / 60); |
523 | this->play_period = (blip_time_t) (period / t); | 523 | this->play_period = (blip_time_t) ((period * FP_ONE_TEMPO) / t); |
524 | } | 524 | } |
525 | 525 | ||
526 | void fill_buf( struct Kss_Emu* this ); | 526 | void fill_buf( struct Kss_Emu* this ); |
diff --git a/apps/codecs/libgme/kss_emu.h b/apps/codecs/libgme/kss_emu.h index 81db2ae708..d0a3de34e4 100644 --- a/apps/codecs/libgme/kss_emu.h +++ b/apps/codecs/libgme/kss_emu.h | |||
@@ -97,7 +97,7 @@ struct Kss_Emu { | |||
97 | int max_initial_silence; | 97 | int max_initial_silence; |
98 | int voice_count; | 98 | int voice_count; |
99 | int mute_mask_; | 99 | int mute_mask_; |
100 | double tempo; | 100 | int tempo; |
101 | double gain; | 101 | double gain; |
102 | 102 | ||
103 | long sample_rate; | 103 | long sample_rate; |
@@ -192,7 +192,7 @@ static inline long Track_get_length( struct Kss_Emu* this, int n ) | |||
192 | 192 | ||
193 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 193 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
194 | // Track length as returned by track_info() assumes a tempo of 1.0. | 194 | // Track length as returned by track_info() assumes a tempo of 1.0. |
195 | void Sound_set_tempo( struct Kss_Emu* this, double t ); | 195 | void Sound_set_tempo( struct Kss_Emu* this, int t ); |
196 | 196 | ||
197 | // Mute/unmute voice i, where voice 0 is first voice | 197 | // Mute/unmute voice i, where voice 0 is first voice |
198 | void Sound_mute_voice( struct Kss_Emu* this, int index, bool mute ); | 198 | void Sound_mute_voice( struct Kss_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/nes_apu.c b/apps/codecs/libgme/nes_apu.c index 8f1f37645e..826c768770 100644 --- a/apps/codecs/libgme/nes_apu.c +++ b/apps/codecs/libgme/nes_apu.c | |||
@@ -19,7 +19,7 @@ int const amp_range = 15; | |||
19 | 19 | ||
20 | void Apu_init( struct Nes_Apu* this ) | 20 | void Apu_init( struct Nes_Apu* this ) |
21 | { | 21 | { |
22 | this->tempo_ = 1.0; | 22 | this->tempo_ = (int)(FP_ONE_TEMPO); |
23 | this->dmc.apu = this; | 23 | this->dmc.apu = this; |
24 | this->dmc.prg_reader = NULL; | 24 | this->dmc.prg_reader = NULL; |
25 | this->irq_notifier_ = NULL; | 25 | this->irq_notifier_ = NULL; |
@@ -77,12 +77,12 @@ void Apu_output( struct Nes_Apu* this, struct Blip_Buffer* buffer ) | |||
77 | Apu_osc_output( this, i, buffer ); | 77 | Apu_osc_output( this, i, buffer ); |
78 | } | 78 | } |
79 | 79 | ||
80 | void Apu_set_tempo( struct Nes_Apu* this, double t ) | 80 | void Apu_set_tempo( struct Nes_Apu* this, int t ) |
81 | { | 81 | { |
82 | this->tempo_ = t; | 82 | this->tempo_ = t; |
83 | this->frame_period = (this->dmc.pal_mode ? 8314 : 7458); | 83 | this->frame_period = (this->dmc.pal_mode ? 8314 : 7458); |
84 | if ( t != 1.0 ) | 84 | if ( t != (int)FP_ONE_TEMPO ) |
85 | this->frame_period = (int) (this->frame_period / t) & ~1; // must be even | 85 | this->frame_period = (int) ((this->frame_period * FP_ONE_TEMPO) / t) & ~1; // must be even |
86 | } | 86 | } |
87 | 87 | ||
88 | void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ) | 88 | void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ) |
diff --git a/apps/codecs/libgme/nes_apu.h b/apps/codecs/libgme/nes_apu.h index 6a2c2805e1..8653afc41d 100644 --- a/apps/codecs/libgme/nes_apu.h +++ b/apps/codecs/libgme/nes_apu.h | |||
@@ -28,7 +28,7 @@ struct Nes_Apu { | |||
28 | struct Nes_Triangle triangle; | 28 | struct Nes_Triangle triangle; |
29 | struct Nes_Dmc dmc; | 29 | struct Nes_Dmc dmc; |
30 | 30 | ||
31 | double tempo_; | 31 | int tempo_; |
32 | nes_time_t last_time; // has been run until this time in current frame | 32 | nes_time_t last_time; // has been run until this time in current frame |
33 | nes_time_t earliest_irq_; | 33 | nes_time_t earliest_irq_; |
34 | nes_time_t next_irq; | 34 | nes_time_t next_irq; |
@@ -74,7 +74,7 @@ void Apu_end_frame( struct Nes_Apu* this, nes_time_t ) ICODE_ATTR; | |||
74 | void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ); | 74 | void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ); |
75 | 75 | ||
76 | // Adjust frame period | 76 | // Adjust frame period |
77 | void Apu_set_tempo( struct Nes_Apu* this, double ); | 77 | void Apu_set_tempo( struct Nes_Apu* this, int ); |
78 | 78 | ||
79 | // Set overall volume (default is 1.0) | 79 | // Set overall volume (default is 1.0) |
80 | void Apu_volume( struct Nes_Apu* this, double ); | 80 | void Apu_volume( struct Nes_Apu* this, double ); |
diff --git a/apps/codecs/libgme/nes_fds_apu.c b/apps/codecs/libgme/nes_fds_apu.c index 51421415e6..f78e962455 100644 --- a/apps/codecs/libgme/nes_fds_apu.c +++ b/apps/codecs/libgme/nes_fds_apu.c | |||
@@ -108,12 +108,12 @@ void Fds_write_( struct Nes_Fds_Apu* this, unsigned addr, int data ) | |||
108 | } | 108 | } |
109 | } | 109 | } |
110 | 110 | ||
111 | void Fds_set_tempo( struct Nes_Fds_Apu* this, double t ) | 111 | void Fds_set_tempo( struct Nes_Fds_Apu* this, int t ) |
112 | { | 112 | { |
113 | this->lfo_tempo = lfo_base_tempo; | 113 | this->lfo_tempo = lfo_base_tempo; |
114 | if ( t != 1.0 ) | 114 | if ( t != (int)FP_ONE_TEMPO ) |
115 | { | 115 | { |
116 | this->lfo_tempo = (int) ((double) lfo_base_tempo / t + 0.5); | 116 | this->lfo_tempo = (int) ((lfo_base_tempo * FP_ONE_TEMPO) / t); |
117 | if ( this->lfo_tempo <= 0 ) | 117 | if ( this->lfo_tempo <= 0 ) |
118 | this->lfo_tempo = 1; | 118 | this->lfo_tempo = 1; |
119 | } | 119 | } |
diff --git a/apps/codecs/libgme/nes_fds_apu.h b/apps/codecs/libgme/nes_fds_apu.h index 1360e443db..47b17eb754 100644 --- a/apps/codecs/libgme/nes_fds_apu.h +++ b/apps/codecs/libgme/nes_fds_apu.h | |||
@@ -48,7 +48,7 @@ struct Nes_Fds_Apu { | |||
48 | // init | 48 | // init |
49 | void Fds_init( struct Nes_Fds_Apu* this ); | 49 | void Fds_init( struct Nes_Fds_Apu* this ); |
50 | // setup | 50 | // setup |
51 | void Fds_set_tempo( struct Nes_Fds_Apu* this, double t ); | 51 | void Fds_set_tempo( struct Nes_Fds_Apu* this, int t ); |
52 | 52 | ||
53 | // emulation | 53 | // emulation |
54 | void Fds_reset( struct Nes_Fds_Apu* this ); | 54 | void Fds_reset( struct Nes_Fds_Apu* this ); |
diff --git a/apps/codecs/libgme/nsf_emu.c b/apps/codecs/libgme/nsf_emu.c index c805780cb1..7b9ff1ad3e 100644 --- a/apps/codecs/libgme/nsf_emu.c +++ b/apps/codecs/libgme/nsf_emu.c | |||
@@ -54,7 +54,7 @@ void Nsf_init( struct Nsf_Emu* this ) | |||
54 | { | 54 | { |
55 | this->sample_rate = 0; | 55 | this->sample_rate = 0; |
56 | this->mute_mask_ = 0; | 56 | this->mute_mask_ = 0; |
57 | this->tempo = 1.0; | 57 | this->tempo = (int)(FP_ONE_TEMPO); |
58 | this->gain = 1.0; | 58 | this->gain = 1.0; |
59 | 59 | ||
60 | // defaults | 60 | // defaults |
@@ -474,16 +474,16 @@ void Sound_mute_voices( struct Nsf_Emu* this, int mask ) | |||
474 | } | 474 | } |
475 | } | 475 | } |
476 | 476 | ||
477 | void Sound_set_tempo( struct Nsf_Emu* this, double t ) | 477 | void Sound_set_tempo( struct Nsf_Emu* this, int t ) |
478 | { | 478 | { |
479 | require( this->sample_rate ); // sample rate must be set first | 479 | require( this->sample_rate ); // sample rate must be set first |
480 | double const min = 0.02; | 480 | int const min = (int)(FP_ONE_TEMPO*0.02); |
481 | double const max = 4.00; | 481 | int const max = (int)(FP_ONE_TEMPO*4.00); |
482 | if ( t < min ) t = min; | 482 | if ( t < min ) t = min; |
483 | if ( t > max ) t = max; | 483 | if ( t > max ) t = max; |
484 | this->tempo = t; | 484 | this->tempo = t; |
485 | 485 | ||
486 | set_play_period( this, (int) (play_period( &this->header ) / t) ); | 486 | set_play_period( this, (int) ((play_period( &this->header ) * FP_ONE_TEMPO) / t) ); |
487 | 487 | ||
488 | Apu_set_tempo( &this->apu, t ); | 488 | Apu_set_tempo( &this->apu, t ); |
489 | 489 | ||
diff --git a/apps/codecs/libgme/nsf_emu.h b/apps/codecs/libgme/nsf_emu.h index 421425e339..808ef442a3 100644 --- a/apps/codecs/libgme/nsf_emu.h +++ b/apps/codecs/libgme/nsf_emu.h | |||
@@ -89,7 +89,7 @@ struct Nsf_Emu { | |||
89 | int max_initial_silence; | 89 | int max_initial_silence; |
90 | int voice_count; | 90 | int voice_count; |
91 | int mute_mask_; | 91 | int mute_mask_; |
92 | double tempo; | 92 | int tempo; |
93 | double gain; | 93 | double gain; |
94 | 94 | ||
95 | long sample_rate; | 95 | long sample_rate; |
@@ -189,7 +189,7 @@ long Track_length( struct Nsf_Emu* this, int n ); | |||
189 | 189 | ||
190 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 190 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
191 | // Track length as returned by track_info() assumes a tempo of 1.0. | 191 | // Track length as returned by track_info() assumes a tempo of 1.0. |
192 | void Sound_set_tempo( struct Nsf_Emu* this, double t ); | 192 | void Sound_set_tempo( struct Nsf_Emu* this, int t ); |
193 | 193 | ||
194 | // Mute/unmute voice i, where voice 0 is first voice | 194 | // Mute/unmute voice i, where voice 0 is first voice |
195 | void Sound_mute_voice( struct Nsf_Emu* this, int index, bool mute ); | 195 | void Sound_mute_voice( struct Nsf_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/sgc_emu.c b/apps/codecs/libgme/sgc_emu.c index 9abfc00d2c..3cd5dc678f 100644 --- a/apps/codecs/libgme/sgc_emu.c +++ b/apps/codecs/libgme/sgc_emu.c | |||
@@ -46,7 +46,7 @@ void Sgc_init( struct Sgc_Emu* this ) | |||
46 | 46 | ||
47 | this->sample_rate = 0; | 47 | this->sample_rate = 0; |
48 | this->mute_mask_ = 0; | 48 | this->mute_mask_ = 0; |
49 | this->tempo = 1.0; | 49 | this->tempo = (int)FP_ONE_TEMPO; |
50 | this->gain = 1.0; | 50 | this->gain = 1.0; |
51 | this->voice_count = 0; | 51 | this->voice_count = 0; |
52 | 52 | ||
@@ -294,16 +294,16 @@ void Sound_mute_voices( struct Sgc_Emu* this, int mask ) | |||
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | void Sound_set_tempo( struct Sgc_Emu* this, double t ) | 297 | void Sound_set_tempo( struct Sgc_Emu* this, int t ) |
298 | { | 298 | { |
299 | require( this->sample_rate ); // sample rate must be set first | 299 | require( this->sample_rate ); // sample rate must be set first |
300 | double const min = 0.02; | 300 | int const min = (int)(FP_ONE_TEMPO*0.02); |
301 | double const max = 4.00; | 301 | int const max = (int)(FP_ONE_TEMPO*4.00); |
302 | if ( t < min ) t = min; | 302 | if ( t < min ) t = min; |
303 | if ( t > max ) t = max; | 303 | if ( t > max ) t = max; |
304 | this->tempo = t; | 304 | this->tempo = t; |
305 | 305 | ||
306 | this->play_period = (int) (clock_rate( this ) / (this->header.rate ? 50 : 60) / t); | 306 | this->play_period = (int) ((clock_rate( this ) * FP_ONE_TEMPO) / (this->header.rate ? 50 : 60) / t); |
307 | } | 307 | } |
308 | 308 | ||
309 | void fill_buf( struct Sgc_Emu* this ) ICODE_ATTR; | 309 | void fill_buf( struct Sgc_Emu* this ) ICODE_ATTR; |
diff --git a/apps/codecs/libgme/sgc_emu.h b/apps/codecs/libgme/sgc_emu.h index 957e7438ef..89b56f43cb 100644 --- a/apps/codecs/libgme/sgc_emu.h +++ b/apps/codecs/libgme/sgc_emu.h | |||
@@ -66,7 +66,7 @@ struct Sgc_Emu { | |||
66 | // general | 66 | // general |
67 | int voice_count; | 67 | int voice_count; |
68 | int mute_mask_; | 68 | int mute_mask_; |
69 | double tempo; | 69 | int tempo; |
70 | double gain; | 70 | double gain; |
71 | 71 | ||
72 | long sample_rate; | 72 | long sample_rate; |
@@ -166,7 +166,7 @@ static inline long Track_get_length( struct Sgc_Emu* this, int n ) | |||
166 | 166 | ||
167 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 167 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
168 | // Track length as returned by track_info() assumes a tempo of 1.0. | 168 | // Track length as returned by track_info() assumes a tempo of 1.0. |
169 | void Sound_set_tempo( struct Sgc_Emu* this, double t ); | 169 | void Sound_set_tempo( struct Sgc_Emu* this, int t ); |
170 | 170 | ||
171 | // Mute/unmute voice i, where voice 0 is first voice | 171 | // Mute/unmute voice i, where voice 0 is first voice |
172 | void Sound_mute_voice( struct Sgc_Emu* this, int index, bool mute ); | 172 | void Sound_mute_voice( struct Sgc_Emu* this, int index, bool mute ); |
diff --git a/apps/codecs/libgme/vgm_emu.c b/apps/codecs/libgme/vgm_emu.c index 7fed4ef6d1..de5bd290c0 100644 --- a/apps/codecs/libgme/vgm_emu.c +++ b/apps/codecs/libgme/vgm_emu.c | |||
@@ -76,7 +76,7 @@ void Vgm_init( struct Vgm_Emu* this ) | |||
76 | { | 76 | { |
77 | this->sample_rate = 0; | 77 | this->sample_rate = 0; |
78 | this->mute_mask_ = 0; | 78 | this->mute_mask_ = 0; |
79 | this->tempo = 1.0; | 79 | this->tempo = (int)(FP_ONE_TEMPO); |
80 | 80 | ||
81 | // defaults | 81 | // defaults |
82 | this->max_initial_silence = 2; | 82 | this->max_initial_silence = 2; |
@@ -288,7 +288,7 @@ blargg_err_t Vgm_load_mem( struct Vgm_Emu* this, byte const* new_data, long new_ | |||
288 | Ym2612_enable( &this->ym2612, false ); | 288 | Ym2612_enable( &this->ym2612, false ); |
289 | Ym2413_enable( &this->ym2413, false ); | 289 | Ym2413_enable( &this->ym2413, false ); |
290 | 290 | ||
291 | Sound_set_tempo( this, 1 ); | 291 | Sound_set_tempo( this, (int)(FP_ONE_TEMPO) ); |
292 | 292 | ||
293 | this->voice_count = sms_osc_count; | 293 | this->voice_count = sms_osc_count; |
294 | 294 | ||
@@ -733,27 +733,26 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask ) | |||
733 | } | 733 | } |
734 | } | 734 | } |
735 | 735 | ||
736 | void Sound_set_tempo( struct Vgm_Emu* this, double t ) | 736 | void Sound_set_tempo( struct Vgm_Emu* this, int t ) |
737 | { | 737 | { |
738 | require( this->sample_rate ); // sample rate must be set first | 738 | require( this->sample_rate ); // sample rate must be set first |
739 | double const min = 0.02; | 739 | int const min = (int)(FP_ONE_TEMPO*0.02); |
740 | double const max = 4.00; | 740 | int const max = (int)(FP_ONE_TEMPO*4.00); |
741 | if ( t < min ) t = min; | 741 | if ( t < min ) t = min; |
742 | if ( t > max ) t = max; | 742 | if ( t > max ) t = max; |
743 | this->tempo = t; | 743 | this->tempo = t; |
744 | 744 | ||
745 | if ( this->file_begin ) | 745 | if ( this->file_begin ) |
746 | { | 746 | { |
747 | this->vgm_rate = (long) (44100 * t + 0.5); | 747 | this->vgm_rate = (long) ((44100LL * t) / FP_ONE_TEMPO); |
748 | this->blip_time_factor = (int) ((double) | 748 | this->blip_time_factor = (int) (((1LL << blip_time_bits) * Blip_clock_rate( &this->stereo_buf.bufs [0] )) / this->vgm_rate); |
749 | (1 << blip_time_bits) / this->vgm_rate * Blip_clock_rate( &this->stereo_buf.bufs [0] ) + 0.5); | ||
750 | //debug_printf( "blip_time_factor: %ld\n", blip_time_factor ); | 749 | //debug_printf( "blip_time_factor: %ld\n", blip_time_factor ); |
751 | //debug_printf( "vgm_rate: %ld\n", vgm_rate ); | 750 | //debug_printf( "vgm_rate: %ld\n", vgm_rate ); |
752 | // TODO: remove? calculates vgm_rate more accurately (above differs at most by one Hz only) | 751 | // TODO: remove? calculates vgm_rate more accurately (above differs at most by one Hz only) |
753 | //blip_time_factor = (long) floor( double (1L << blip_time_bits) * psg_rate / 44100 / t + 0.5 ); | 752 | //blip_time_factor = (long) floor( double (1L << blip_time_bits) * psg_rate / 44100 / t + 0.5 ); |
754 | //vgm_rate = (long) floor( double (1L << blip_time_bits) * psg_rate / blip_time_factor + 0.5 ); | 753 | //vgm_rate = (long) floor( double (1L << blip_time_bits) * psg_rate / blip_time_factor + 0.5 ); |
755 | 754 | ||
756 | this->fm_time_factor = 2 + (int) (this->fm_rate * (1 << fm_time_bits) / this->vgm_rate + 0.5); | 755 | this->fm_time_factor = 2 + (int) ((this->fm_rate * (1LL << fm_time_bits)) / this->vgm_rate); |
757 | } | 756 | } |
758 | } | 757 | } |
759 | 758 | ||
diff --git a/apps/codecs/libgme/vgm_emu.h b/apps/codecs/libgme/vgm_emu.h index deb64bc7e0..ee57d5c692 100644 --- a/apps/codecs/libgme/vgm_emu.h +++ b/apps/codecs/libgme/vgm_emu.h | |||
@@ -93,7 +93,7 @@ struct Vgm_Emu { | |||
93 | int max_initial_silence; | 93 | int max_initial_silence; |
94 | int voice_count; | 94 | int voice_count; |
95 | int mute_mask_; | 95 | int mute_mask_; |
96 | double tempo; | 96 | int tempo; |
97 | double gain; | 97 | double gain; |
98 | 98 | ||
99 | long sample_rate; | 99 | long sample_rate; |
@@ -190,7 +190,7 @@ static inline long Track_get_length( struct Vgm_Emu* this ) | |||
190 | 190 | ||
191 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. | 191 | // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. |
192 | // Track length as returned by track_info() assumes a tempo of 1.0. | 192 | // Track length as returned by track_info() assumes a tempo of 1.0. |
193 | void Sound_set_tempo( struct Vgm_Emu* this, double t ); | 193 | void Sound_set_tempo( struct Vgm_Emu* this, int t ); |
194 | 194 | ||
195 | // Mute/unmute voice i, where voice 0 is first voice | 195 | // Mute/unmute voice i, where voice 0 is first voice |
196 | void Sound_mute_voice( struct Vgm_Emu* this, int index, bool mute ); | 196 | void Sound_mute_voice( struct Vgm_Emu* this, int index, bool mute ); |