Bugfixes for libgme by Mauricio Garrido: added missing call of Blip_set_modified(), correctly set PSG voices in vgm_emu, correctly set current_track in vgm_emu, correct call of Sound_mute_voices() in nsf_emu. Additionally migrate few floating point code to fixed point -- even though this is unused and therefor commented out.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30490 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Andree Buschmann 2011-09-09 17:57:33 +00:00
parent 544a52d9eb
commit c97c5e5d17
7 changed files with 30 additions and 20 deletions

View file

@ -44,13 +44,15 @@ void Apu_init( struct Nes_Apu* this )
Apu_reset( this, false, 0 );
}
void Apu_enable_nonlinear_( struct Nes_Apu* this, double sq, double tnd )
#if 0
// sq and tnd must use a fixed point frac where 1.0 = FP_ONE_VOLUME
void Apu_enable_nonlinear_( struct Nes_Apu* this, int sq, int tnd )
{
this->dmc.nonlinear = true;
Synth_volume( &this->square_synth, (int)((long long)(sq * FP_ONE_VOLUME) / amp_range) );
Synth_volume( &this->square_synth, sq );
Synth_volume( &this->triangle.synth, tnd * 2.752 );
Synth_volume( &this->noise.synth , tnd * 1.849 );
Synth_volume( &this->triangle.synth, (int)((long long)(FP_ONE_VOLUME * 2.752) * tnd / FP_ONE_VOLUME) );
Synth_volume( &this->noise.synth , (int)((long long)(FP_ONE_VOLUME * 1.849) * tnd / FP_ONE_VOLUME) );
Synth_volume( &this->dmc.synth , tnd );
this->square1 .osc.last_amp = 0;
@ -59,15 +61,16 @@ void Apu_enable_nonlinear_( struct Nes_Apu* this, double sq, double tnd )
this->noise .osc.last_amp = 0;
this->dmc .osc.last_amp = 0;
}
#endif
void Apu_volume( struct Nes_Apu* this, int v )
{
if ( !this->dmc.nonlinear )
{
Synth_volume( &this->square_synth, (int)((long long)((0.125 * (1.0 /1.11)) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.1128 1.108
Synth_volume( &this->triangle.synth,(int)((long long)((0.150 * (1.0 /1.11)) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.12765 1.175
Synth_volume( &this->noise.synth, (int)((long long)((0.095 * (1.0 /1.11)) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.0741 1.282
Synth_volume( &this->dmc.synth, (int)((long long)((0.450 * (1.0 /1.11)) * FP_ONE_VOLUME) * v / 2048 / FP_ONE_VOLUME) ); // was 0.42545 1.058
Synth_volume( &this->square_synth, (int)((long long)((0.125 / 1.11) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.1128 1.108
Synth_volume( &this->triangle.synth,(int)((long long)((0.150 / 1.11) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.12765 1.175
Synth_volume( &this->noise.synth, (int)((long long)((0.095 / 1.11) * FP_ONE_VOLUME) * v / amp_range / FP_ONE_VOLUME) ); // was 0.0741 1.282
Synth_volume( &this->dmc.synth, (int)((long long)((0.450 / 1.11) * FP_ONE_VOLUME) * v / 2048 / FP_ONE_VOLUME) ); // was 0.42545 1.058
}
}

View file

@ -130,6 +130,8 @@ static inline nes_time_t Dmc_next_read_time( struct Nes_Dmc* this )
static inline nes_time_t Apu_next_dmc_read_time( struct Nes_Apu* this ) { return Dmc_next_read_time( &this->dmc ); }
void Apu_irq_changed( struct Nes_Apu* this );
#if 0
// Experimental
void Apu_enable_nonlinear_( struct Nes_Apu* this, double sq, double tnd );
void Apu_enable_nonlinear_( struct Nes_Apu* this, int sq, int tnd );
#endif
#endif

View file

@ -48,11 +48,14 @@ struct Nes_Cpu {
struct cpu_state_t cpu_state_;
};
static inline void Cpu_init( struct Nes_Cpu* this ) { this->cpu_state = &this->cpu_state_; }
static inline void Cpu_init( struct Nes_Cpu* this )
{
this->cpu_state = &this->cpu_state_;
}
// Clears registers and maps all pages to unmapped_page
void Cpu_reset( struct Nes_Cpu* this, void const* unmapped_page );
// Maps code memory (memory accessed via the program counter). Start and size
// must be multiple of page_size. If mirror_size is non-zero, the first
// mirror_size bytes are repeated over the range. mirror_size must be a
@ -101,6 +104,6 @@ static inline void Cpu_set_end_time( struct Nes_Cpu* this, nes_time_t t )
{
this->end_time = t;
Cpu_update_end_time( this, t, this->irq_time );
}
}
#endif

View file

@ -565,7 +565,7 @@ void Noise_run( struct Nes_Noise* this, nes_time_t time, nes_time_t end_time )
int noise = this->noise;
int delta = amp * 2 - volume;
const int tap = (osc->regs [2] & mode_flag ? 8 : 13);
Blip_set_modified( osc->output );
Blip_set_modified( output );
do {
int feedback = (noise << tap) ^ (noise << 14);

View file

@ -107,6 +107,7 @@ void run_square( struct Nes_Vrc6_Apu* this, struct Vrc6_Osc* osc, blip_time_t en
if ( time < end_time )
{
int phase = osc->phase;
Blip_set_modified( output );
do
{

View file

@ -299,10 +299,6 @@ blargg_err_t Nsf_post_load( struct Nsf_Emu* this )
blargg_err_t err = init_sound( this );
if ( err )
return err;
// Post load
Sound_set_tempo( this, this->tempo );
Sound_mute_voices( this, this->mute_mask_ );
// Set track_count
this->track_count = this->header.track_count;
@ -312,6 +308,10 @@ blargg_err_t Nsf_post_load( struct Nsf_Emu* this )
Buffer_clock_rate( &this->stereo_buf, this->clock_rate__ );
RETURN_ERR( Buffer_set_channel_count( &this->stereo_buf, this->voice_count, this->voice_types ) );
this->buf_changed_count = Buffer_channels_changed_count( &this->stereo_buf );
// Post load
Sound_set_tempo( this, this->tempo );
Sound_mute_voices( this, this->mute_mask_ );
return 0;
}

View file

@ -215,9 +215,7 @@ static blargg_err_t check_vgm_header( struct header_t* h )
static void set_voice( struct Vgm_Emu* this, int i, struct Blip_Buffer* c, struct Blip_Buffer* l, struct Blip_Buffer* r )
{
if ( i < sms_osc_count ) {
int j;
for ( j = sms_osc_count; --j >= 0; )
Sms_apu_set_output( &this->psg, j, c, l, r );
Sms_apu_set_output( &this->psg, i, c, l, r );
}
}
@ -294,6 +292,9 @@ blargg_err_t Vgm_load_mem( struct Vgm_Emu* this, byte const* new_data, long new_
// Post load
Sound_set_tempo( this, this->tempo );
Sound_mute_voices( this, this->mute_mask_ );
// so we can start playback
this->current_track = 0;
return 0;
}