Skip to content

Commit

Permalink
Disable filtering on raw audio output
Browse files Browse the repository at this point in the history
  • Loading branch information
LIJI32 committed Nov 16, 2024
1 parent 2b3ec9d commit 2e6ff5f
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions Core/apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ static void band_limited_update(GB_band_limited_t *band_limited, const GB_sample
}
}

static void band_limited_update_unfiltered(GB_band_limited_t *band_limited, const GB_sample_t *input, unsigned delay)
{
if (input->packed == band_limited->input.packed) return;

GB_sample_t delta = {
.left = input->left - band_limited->input.left,
.right = input->right - band_limited->input.right,
};
band_limited->input.packed = input->packed;

unsigned offset = (band_limited->pos + delay) & (sizeof(band_limited->buffer) / sizeof(band_limited->buffer[0]) - 1);
band_limited->buffer[offset].left += delta.left * GB_BAND_LIMITED_ONE;
band_limited->buffer[offset].right += delta.right * GB_BAND_LIMITED_ONE;
}

static void band_limited_read(GB_band_limited_t *band_limited, GB_sample_t *output, uint32_t multiplier)
{
band_limited->output.left += band_limited->buffer[band_limited->pos].left;
Expand Down Expand Up @@ -161,9 +176,14 @@ static void update_sample(GB_gameboy_t *gb, GB_channel_t index, int8_t value, un
output.left = output.right = 0;
}

band_limited_update(&gb->apu_output.band_limited[index],
&output,
(gb->apu_output.cycles_since_render + cycles_offset) * GB_BAND_LIMITED_PHASES / gb->apu_output.max_cycles_per_sample);
if (unlikely(gb->apu_output.max_cycles_per_sample == 1)) {
band_limited_update_unfiltered(&gb->apu_output.band_limited[index], &output, cycles_offset);
}
else {
band_limited_update(&gb->apu_output.band_limited[index],
&output,
(gb->apu_output.cycles_since_render + cycles_offset) * GB_BAND_LIMITED_PHASES / gb->apu_output.max_cycles_per_sample);
}
}

return;
Expand Down Expand Up @@ -191,9 +211,14 @@ static void update_sample(GB_gameboy_t *gb, GB_channel_t index, int8_t value, un
if (likely(!gb->apu_output.channel_muted[index])) {
output = (GB_sample_t){(0xF - value * 2) * left_volume, (0xF - value * 2) * right_volume};
}
band_limited_update(&gb->apu_output.band_limited[index],
&output,
(gb->apu_output.cycles_since_render + cycles_offset) * GB_BAND_LIMITED_PHASES / gb->apu_output.max_cycles_per_sample);
if (unlikely(gb->apu_output.max_cycles_per_sample == 1)) {
band_limited_update_unfiltered(&gb->apu_output.band_limited[index], &output, cycles_offset);
}
else {
band_limited_update(&gb->apu_output.band_limited[index],
&output,
(gb->apu_output.cycles_since_render + cycles_offset) * GB_BAND_LIMITED_PHASES / gb->apu_output.max_cycles_per_sample);
}
}
}

Expand Down

0 comments on commit 2e6ff5f

Please sign in to comment.