From 9444fc6f336166192f44edb5d7543624959dc1fc Mon Sep 17 00:00:00 2001 From: buschel Date: Tue, 9 Aug 2011 20:21:55 +0000 Subject: [PATCH] 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 --- apps/codecs/libgme/ay_emu.c | 10 +++++----- apps/codecs/libgme/ay_emu.h | 4 ++-- apps/codecs/libgme/blargg_common.h | 3 +++ apps/codecs/libgme/gb_apu.c | 8 ++++---- apps/codecs/libgme/gb_apu.h | 2 +- apps/codecs/libgme/gbs_emu.c | 10 +++++----- apps/codecs/libgme/gbs_emu.h | 4 ++-- apps/codecs/libgme/hes_emu.c | 12 ++++++------ apps/codecs/libgme/hes_emu.h | 4 ++-- apps/codecs/libgme/kss_emu.c | 10 +++++----- apps/codecs/libgme/kss_emu.h | 4 ++-- apps/codecs/libgme/nes_apu.c | 8 ++++---- apps/codecs/libgme/nes_apu.h | 4 ++-- apps/codecs/libgme/nes_fds_apu.c | 6 +++--- apps/codecs/libgme/nes_fds_apu.h | 2 +- apps/codecs/libgme/nsf_emu.c | 10 +++++----- apps/codecs/libgme/nsf_emu.h | 4 ++-- apps/codecs/libgme/sgc_emu.c | 10 +++++----- apps/codecs/libgme/sgc_emu.h | 4 ++-- apps/codecs/libgme/vgm_emu.c | 17 ++++++++--------- 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 dc775cbf7..78d4556bf 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 ) { this->sample_rate = 0; this->mute_mask_ = 0; - this->tempo = 1.0; + this->tempo = (int)FP_ONE_TEMPO; this->gain = 1.0; this->track_count = 0; @@ -343,11 +343,11 @@ void Sound_mute_voices( struct Ay_Emu *this, int mask ) } } -void Sound_set_tempo( struct Ay_Emu *this, double t ) +void Sound_set_tempo( struct Ay_Emu *this, int t ) { require( this->sample_rate ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo = t; @@ -356,7 +356,7 @@ void Sound_set_tempo( struct Ay_Emu *this, double t ) if ( this->clock_rate_ != spectrum_clock ) p = this->clock_rate_ / 50; - this->play_period = (blip_time_t) (p / t); + this->play_period = (blip_time_t) ((p * FP_ONE_TEMPO) / t); } 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 91252166e..c41debc23 100644 --- a/apps/codecs/libgme/ay_emu.h +++ b/apps/codecs/libgme/ay_emu.h @@ -65,7 +65,7 @@ struct Ay_Emu { int max_initial_silence; int voice_count; int mute_mask_; - double tempo; + int tempo; double gain; long sample_rate; @@ -141,7 +141,7 @@ long Track_get_length( struct Ay_Emu* this, int n ); // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Ay_Emu* this, double t ); +void Sound_set_tempo( struct Ay_Emu* this, int t ); // Mute/unmute voice i, where voice 0 is first voice 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 be3437944..a9e47b828 100644 --- a/apps/codecs/libgme/blargg_common.h +++ b/apps/codecs/libgme/blargg_common.h @@ -20,6 +20,9 @@ #include "codeclib.h" #endif +// common defines +#define FP_ONE_TEMPO (1LL <<16) + #if 1 /* IRAM configuration is not yet active for all libGME codecs. */ #undef ICODE_ATTR #define ICODE_ATTR diff --git a/apps/codecs/libgme/gb_apu.c b/apps/codecs/libgme/gb_apu.c index a441645e3..adc307156 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 ) } } -void Apu_set_tempo( struct Gb_Apu* this, double t ) +void Apu_set_tempo( struct Gb_Apu* this, int t ) { this->frame_period = 4194304 / 512; // 512 Hz - if ( t != 1.0 ) - this->frame_period = t ? (blip_time_t) (this->frame_period / t) : (blip_time_t) (0); + if ( t != (int)FP_ONE_TEMPO ) + this->frame_period = t ? (blip_time_t) ((this->frame_period * FP_ONE_TEMPO) / t) : (blip_time_t) (0); } void Apu_init( struct Gb_Apu* this ) @@ -184,7 +184,7 @@ void Apu_init( struct Gb_Apu* this ) } this->reduce_clicks_ = false; - Apu_set_tempo( this, 1.0 ); + Apu_set_tempo( this, (int)FP_ONE_TEMPO ); this->volume_ = 1.0; Apu_reset( this, mode_cgb, false ); } diff --git a/apps/codecs/libgme/gb_apu.h b/apps/codecs/libgme/gb_apu.h index f1457a2bb..028be29d7 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 ); // Sets frame sequencer rate, where 1.0 is normal. Meant for adjusting the // tempo in a music player. -void Apu_set_tempo( struct Gb_Apu* this, double t ); +void Apu_set_tempo( struct Gb_Apu* this, int t ); 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 f5e214e5d..05c9be2d5 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 ) { this->sample_rate_ = 0; this->mute_mask_ = 0; - this->tempo_ = 1.0; + this->tempo_ = (int)(FP_ONE_TEMPO); // Unload this->header.timer_mode = 0; @@ -304,16 +304,16 @@ void Sound_mute_voices( struct Gbs_Emu* this, int mask ) } } -void Sound_set_tempo( struct Gbs_Emu* this, double t ) +void Sound_set_tempo( struct Gbs_Emu* this, int t ) { require( this->sample_rate_ ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo_ = t; - this->tempo = (int) (tempo_unit / t + 0.5 ); + this->tempo = (int) ((tempo_unit * FP_ONE_TEMPO) / t); Apu_set_tempo( &this->apu, t ); Update_timer( this ); } diff --git a/apps/codecs/libgme/gbs_emu.h b/apps/codecs/libgme/gbs_emu.h index c107264f9..dcbc5b06b 100644 --- a/apps/codecs/libgme/gbs_emu.h +++ b/apps/codecs/libgme/gbs_emu.h @@ -64,7 +64,7 @@ struct Gbs_Emu { unsigned buf_changed_count; int voice_count_; double gain_; - double tempo_; + int tempo_; // track-specific byte track_count; @@ -158,7 +158,7 @@ static inline long Track_get_length( struct Gbs_Emu* this, int n ) // Sound customization // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Gbs_Emu* this, double ); +void Sound_set_tempo( struct Gbs_Emu* this, int ); // Mute/unmute voice i, where voice 0 is first voice 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 324027888..112cd75b1 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 ) { this->sample_rate_ = 0; this->mute_mask_ = 0; - this->tempo_ = 1.0; + this->tempo_ = (int)(FP_ONE_TEMPO); // defaults this->max_initial_silence = 2; @@ -544,15 +544,15 @@ void Sound_mute_voices( struct Hes_Emu* this, int mask ) } } -void Sound_set_tempo( struct Hes_Emu* this, double t ) +void Sound_set_tempo( struct Hes_Emu* this, int t ) { require( this->sample_rate_ ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; - this->play_period = (hes_time_t) (period_60hz / t); - this->timer_base = (int) (1024 / t); + this->play_period = (hes_time_t) ((period_60hz*FP_ONE_TEMPO) / t); + this->timer_base = (int) ((1024*FP_ONE_TEMPO) / t); recalc_timer_load( this ); this->tempo_ = t; } diff --git a/apps/codecs/libgme/hes_emu.h b/apps/codecs/libgme/hes_emu.h index 18dbe0d50..d16ba6465 100644 --- a/apps/codecs/libgme/hes_emu.h +++ b/apps/codecs/libgme/hes_emu.h @@ -69,7 +69,7 @@ struct Hes_Emu { long sample_rate_; unsigned buf_changed_count; int voice_count_; - double tempo_; + int tempo_; double gain_; // track-specific @@ -168,7 +168,7 @@ static inline long Track_get_length( struct Hes_Emu* this, int n ) // Sound customization // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Hes_Emu* this, double ); +void Sound_set_tempo( struct Hes_Emu* this, int ); // Mute/unmute voice i, where voice 0 is first voice 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 b01034234..e1576adf4 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 ) { this->sample_rate = 0; this->mute_mask_ = 0; - this->tempo = 1.0; + this->tempo = (int)(FP_ONE_TEMPO); this->gain = 1.0; this->chip_flags = 0; @@ -509,18 +509,18 @@ void Sound_mute_voices( struct Kss_Emu* this, int mask ) } } -void Sound_set_tempo( struct Kss_Emu* this, double t ) +void Sound_set_tempo( struct Kss_Emu* this, int t ) { require( this->sample_rate ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo = t; blip_time_t period = (this->header.device_flags & 0x40 ? clock_rate / 50 : clock_rate / 60); - this->play_period = (blip_time_t) (period / t); + this->play_period = (blip_time_t) ((period * FP_ONE_TEMPO) / t); } void fill_buf( struct Kss_Emu* this ); diff --git a/apps/codecs/libgme/kss_emu.h b/apps/codecs/libgme/kss_emu.h index 81db2ae70..d0a3de34e 100644 --- a/apps/codecs/libgme/kss_emu.h +++ b/apps/codecs/libgme/kss_emu.h @@ -97,7 +97,7 @@ struct Kss_Emu { int max_initial_silence; int voice_count; int mute_mask_; - double tempo; + int tempo; double gain; long sample_rate; @@ -192,7 +192,7 @@ static inline long Track_get_length( struct Kss_Emu* this, int n ) // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Kss_Emu* this, double t ); +void Sound_set_tempo( struct Kss_Emu* this, int t ); // Mute/unmute voice i, where voice 0 is first voice 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 8f1f37645..826c76877 100644 --- a/apps/codecs/libgme/nes_apu.c +++ b/apps/codecs/libgme/nes_apu.c @@ -19,7 +19,7 @@ int const amp_range = 15; void Apu_init( struct Nes_Apu* this ) { - this->tempo_ = 1.0; + this->tempo_ = (int)(FP_ONE_TEMPO); this->dmc.apu = this; this->dmc.prg_reader = NULL; this->irq_notifier_ = NULL; @@ -77,12 +77,12 @@ void Apu_output( struct Nes_Apu* this, struct Blip_Buffer* buffer ) Apu_osc_output( this, i, buffer ); } -void Apu_set_tempo( struct Nes_Apu* this, double t ) +void Apu_set_tempo( struct Nes_Apu* this, int t ) { this->tempo_ = t; this->frame_period = (this->dmc.pal_mode ? 8314 : 7458); - if ( t != 1.0 ) - this->frame_period = (int) (this->frame_period / t) & ~1; // must be even + if ( t != (int)FP_ONE_TEMPO ) + this->frame_period = (int) ((this->frame_period * FP_ONE_TEMPO) / t) & ~1; // must be even } 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 6a2c2805e..8653afc41 100644 --- a/apps/codecs/libgme/nes_apu.h +++ b/apps/codecs/libgme/nes_apu.h @@ -28,7 +28,7 @@ struct Nes_Apu { struct Nes_Triangle triangle; struct Nes_Dmc dmc; - double tempo_; + int tempo_; nes_time_t last_time; // has been run until this time in current frame nes_time_t earliest_irq_; nes_time_t next_irq; @@ -74,7 +74,7 @@ void Apu_end_frame( struct Nes_Apu* this, nes_time_t ) ICODE_ATTR; void Apu_reset( struct Nes_Apu* this, bool pal_mode, int initial_dmc_dac ); // Adjust frame period -void Apu_set_tempo( struct Nes_Apu* this, double ); +void Apu_set_tempo( struct Nes_Apu* this, int ); // Set overall volume (default is 1.0) 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 51421415e..f78e96245 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 ) } } -void Fds_set_tempo( struct Nes_Fds_Apu* this, double t ) +void Fds_set_tempo( struct Nes_Fds_Apu* this, int t ) { this->lfo_tempo = lfo_base_tempo; - if ( t != 1.0 ) + if ( t != (int)FP_ONE_TEMPO ) { - this->lfo_tempo = (int) ((double) lfo_base_tempo / t + 0.5); + this->lfo_tempo = (int) ((lfo_base_tempo * FP_ONE_TEMPO) / t); if ( this->lfo_tempo <= 0 ) this->lfo_tempo = 1; } diff --git a/apps/codecs/libgme/nes_fds_apu.h b/apps/codecs/libgme/nes_fds_apu.h index 1360e443d..47b17eb75 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 { // init void Fds_init( struct Nes_Fds_Apu* this ); // setup -void Fds_set_tempo( struct Nes_Fds_Apu* this, double t ); +void Fds_set_tempo( struct Nes_Fds_Apu* this, int t ); // emulation 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 c805780cb..7b9ff1ad3 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 ) { this->sample_rate = 0; this->mute_mask_ = 0; - this->tempo = 1.0; + this->tempo = (int)(FP_ONE_TEMPO); this->gain = 1.0; // defaults @@ -474,16 +474,16 @@ void Sound_mute_voices( struct Nsf_Emu* this, int mask ) } } -void Sound_set_tempo( struct Nsf_Emu* this, double t ) +void Sound_set_tempo( struct Nsf_Emu* this, int t ) { require( this->sample_rate ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo = t; - set_play_period( this, (int) (play_period( &this->header ) / t) ); + set_play_period( this, (int) ((play_period( &this->header ) * FP_ONE_TEMPO) / t) ); Apu_set_tempo( &this->apu, t ); diff --git a/apps/codecs/libgme/nsf_emu.h b/apps/codecs/libgme/nsf_emu.h index 421425e33..808ef442a 100644 --- a/apps/codecs/libgme/nsf_emu.h +++ b/apps/codecs/libgme/nsf_emu.h @@ -89,7 +89,7 @@ struct Nsf_Emu { int max_initial_silence; int voice_count; int mute_mask_; - double tempo; + int tempo; double gain; long sample_rate; @@ -189,7 +189,7 @@ long Track_length( struct Nsf_Emu* this, int n ); // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Nsf_Emu* this, double t ); +void Sound_set_tempo( struct Nsf_Emu* this, int t ); // Mute/unmute voice i, where voice 0 is first voice 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 9abfc00d2..3cd5dc678 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 ) this->sample_rate = 0; this->mute_mask_ = 0; - this->tempo = 1.0; + this->tempo = (int)FP_ONE_TEMPO; this->gain = 1.0; this->voice_count = 0; @@ -294,16 +294,16 @@ void Sound_mute_voices( struct Sgc_Emu* this, int mask ) } } -void Sound_set_tempo( struct Sgc_Emu* this, double t ) +void Sound_set_tempo( struct Sgc_Emu* this, int t ) { require( this->sample_rate ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo = t; - this->play_period = (int) (clock_rate( this ) / (this->header.rate ? 50 : 60) / t); + this->play_period = (int) ((clock_rate( this ) * FP_ONE_TEMPO) / (this->header.rate ? 50 : 60) / t); } 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 957e7438e..89b56f43c 100644 --- a/apps/codecs/libgme/sgc_emu.h +++ b/apps/codecs/libgme/sgc_emu.h @@ -66,7 +66,7 @@ struct Sgc_Emu { // general int voice_count; int mute_mask_; - double tempo; + int tempo; double gain; long sample_rate; @@ -166,7 +166,7 @@ static inline long Track_get_length( struct Sgc_Emu* this, int n ) // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Sgc_Emu* this, double t ); +void Sound_set_tempo( struct Sgc_Emu* this, int t ); // Mute/unmute voice i, where voice 0 is first voice 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 7fed4ef6d..de5bd290c 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 ) { this->sample_rate = 0; this->mute_mask_ = 0; - this->tempo = 1.0; + this->tempo = (int)(FP_ONE_TEMPO); // defaults 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_ Ym2612_enable( &this->ym2612, false ); Ym2413_enable( &this->ym2413, false ); - Sound_set_tempo( this, 1 ); + Sound_set_tempo( this, (int)(FP_ONE_TEMPO) ); this->voice_count = sms_osc_count; @@ -733,27 +733,26 @@ void Sound_mute_voices( struct Vgm_Emu* this, int mask ) } } -void Sound_set_tempo( struct Vgm_Emu* this, double t ) +void Sound_set_tempo( struct Vgm_Emu* this, int t ) { require( this->sample_rate ); // sample rate must be set first - double const min = 0.02; - double const max = 4.00; + int const min = (int)(FP_ONE_TEMPO*0.02); + int const max = (int)(FP_ONE_TEMPO*4.00); if ( t < min ) t = min; if ( t > max ) t = max; this->tempo = t; if ( this->file_begin ) { - this->vgm_rate = (long) (44100 * t + 0.5); - this->blip_time_factor = (int) ((double) - (1 << blip_time_bits) / this->vgm_rate * Blip_clock_rate( &this->stereo_buf.bufs [0] ) + 0.5); + this->vgm_rate = (long) ((44100LL * t) / FP_ONE_TEMPO); + this->blip_time_factor = (int) (((1LL << blip_time_bits) * Blip_clock_rate( &this->stereo_buf.bufs [0] )) / this->vgm_rate); //debug_printf( "blip_time_factor: %ld\n", blip_time_factor ); //debug_printf( "vgm_rate: %ld\n", vgm_rate ); // TODO: remove? calculates vgm_rate more accurately (above differs at most by one Hz only) //blip_time_factor = (long) floor( double (1L << blip_time_bits) * psg_rate / 44100 / t + 0.5 ); //vgm_rate = (long) floor( double (1L << blip_time_bits) * psg_rate / blip_time_factor + 0.5 ); - this->fm_time_factor = 2 + (int) (this->fm_rate * (1 << fm_time_bits) / this->vgm_rate + 0.5); + this->fm_time_factor = 2 + (int) ((this->fm_rate * (1LL << fm_time_bits)) / this->vgm_rate); } } diff --git a/apps/codecs/libgme/vgm_emu.h b/apps/codecs/libgme/vgm_emu.h index deb64bc7e..ee57d5c69 100644 --- a/apps/codecs/libgme/vgm_emu.h +++ b/apps/codecs/libgme/vgm_emu.h @@ -93,7 +93,7 @@ struct Vgm_Emu { int max_initial_silence; int voice_count; int mute_mask_; - double tempo; + int tempo; double gain; long sample_rate; @@ -190,7 +190,7 @@ static inline long Track_get_length( struct Vgm_Emu* this ) // Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed. // Track length as returned by track_info() assumes a tempo of 1.0. -void Sound_set_tempo( struct Vgm_Emu* this, double t ); +void Sound_set_tempo( struct Vgm_Emu* this, int t ); // Mute/unmute voice i, where voice 0 is first voice void Sound_mute_voice( struct Vgm_Emu* this, int index, bool mute ); -- 2.11.4.GIT