Abolished slow double use
This commit is contained in:
parent
c5f6be1e64
commit
c53d99dbc4
17
Core/apu.c
17
Core/apu.c
@ -765,8 +765,9 @@ void GB_apu_run(GB_gameboy_t *gb)
|
||||
if (gb->apu_output.sample_rate) {
|
||||
gb->apu_output.cycles_since_render += cycles;
|
||||
|
||||
if (gb->apu_output.sample_cycles >= gb->apu_output.cycles_per_sample) {
|
||||
gb->apu_output.sample_cycles -= gb->apu_output.cycles_per_sample;
|
||||
uint32_t clock_rate = GB_get_clock_rate(gb) * 2;
|
||||
if (gb->apu_output.sample_cycles >= clock_rate) {
|
||||
gb->apu_output.sample_cycles -= clock_rate;
|
||||
render(gb);
|
||||
}
|
||||
}
|
||||
@ -1462,8 +1463,6 @@ void GB_set_sample_rate(GB_gameboy_t *gb, unsigned sample_rate)
|
||||
if (sample_rate) {
|
||||
gb->apu_output.highpass_rate = pow(0.999958, GB_get_clock_rate(gb) / (double)sample_rate);
|
||||
}
|
||||
gb->apu_output.rate_set_in_clocks = false;
|
||||
GB_apu_update_cycles_per_sample(gb);
|
||||
}
|
||||
|
||||
void GB_set_sample_rate_by_clocks(GB_gameboy_t *gb, double cycles_per_sample)
|
||||
@ -1473,10 +1472,8 @@ void GB_set_sample_rate_by_clocks(GB_gameboy_t *gb, double cycles_per_sample)
|
||||
GB_set_sample_rate(gb, 0);
|
||||
return;
|
||||
}
|
||||
gb->apu_output.cycles_per_sample = cycles_per_sample;
|
||||
gb->apu_output.sample_rate = GB_get_clock_rate(gb) / cycles_per_sample * 2;
|
||||
gb->apu_output.highpass_rate = pow(0.999958, cycles_per_sample);
|
||||
gb->apu_output.rate_set_in_clocks = true;
|
||||
}
|
||||
|
||||
void GB_apu_set_sample_callback(GB_gameboy_t *gb, GB_sample_callback_t callback)
|
||||
@ -1489,14 +1486,6 @@ void GB_set_highpass_filter_mode(GB_gameboy_t *gb, GB_highpass_mode_t mode)
|
||||
gb->apu_output.highpass_mode = mode;
|
||||
}
|
||||
|
||||
void GB_apu_update_cycles_per_sample(GB_gameboy_t *gb)
|
||||
{
|
||||
if (gb->apu_output.rate_set_in_clocks) return;
|
||||
if (gb->apu_output.sample_rate) {
|
||||
gb->apu_output.cycles_per_sample = 2 * GB_get_clock_rate(gb) / (double)gb->apu_output.sample_rate; /* 2 * because we use 8MHz units */
|
||||
}
|
||||
}
|
||||
|
||||
void GB_set_interference_volume(GB_gameboy_t *gb, double volume)
|
||||
{
|
||||
gb->apu_output.interference_volume = volume;
|
||||
|
@ -143,8 +143,7 @@ typedef enum {
|
||||
typedef struct {
|
||||
unsigned sample_rate;
|
||||
|
||||
double sample_cycles; // In 8 MHz units
|
||||
double cycles_per_sample;
|
||||
unsigned sample_cycles; // Counts by sample_rate until it reaches the clock frequency
|
||||
|
||||
// Samples are NOT normalized to MAX_CH_AMP * 4 at this stage!
|
||||
unsigned cycles_since_render;
|
||||
@ -159,7 +158,6 @@ typedef struct {
|
||||
|
||||
GB_sample_callback_t sample_callback;
|
||||
|
||||
bool rate_set_in_clocks;
|
||||
double interference_volume;
|
||||
double interference_highpass;
|
||||
} GB_apu_output_t;
|
||||
@ -178,7 +176,6 @@ internal void GB_apu_div_event(GB_gameboy_t *gb);
|
||||
internal void GB_apu_div_secondary_event(GB_gameboy_t *gb);
|
||||
internal void GB_apu_init(GB_gameboy_t *gb);
|
||||
internal void GB_apu_run(GB_gameboy_t *gb);
|
||||
internal void GB_apu_update_cycles_per_sample(GB_gameboy_t *gb);
|
||||
#endif
|
||||
|
||||
#endif /* apu_h */
|
||||
|
@ -1653,8 +1653,6 @@ void GB_reset(GB_gameboy_t *gb)
|
||||
|
||||
GB_set_internal_div_counter(gb, 8);
|
||||
|
||||
GB_apu_update_cycles_per_sample(gb);
|
||||
|
||||
if (gb->nontrivial_jump_state) {
|
||||
free(gb->nontrivial_jump_state);
|
||||
gb->nontrivial_jump_state = NULL;
|
||||
@ -1758,7 +1756,6 @@ GB_registers_t *GB_get_registers(GB_gameboy_t *gb)
|
||||
void GB_set_clock_multiplier(GB_gameboy_t *gb, double multiplier)
|
||||
{
|
||||
gb->clock_multiplier = multiplier;
|
||||
GB_apu_update_cycles_per_sample(gb);
|
||||
}
|
||||
|
||||
uint32_t GB_get_clock_rate(GB_gameboy_t *gb)
|
||||
|
@ -423,7 +423,7 @@ void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles)
|
||||
gb->double_speed_alignment += cycles;
|
||||
}
|
||||
gb->hdma_cycles += cycles;
|
||||
gb->apu_output.sample_cycles += cycles;
|
||||
gb->apu_output.sample_cycles += cycles * gb->apu_output.sample_rate;
|
||||
gb->cycles_since_last_sync += cycles;
|
||||
gb->cycles_since_run += cycles;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user