From 450c5a1422b6a976485015085c02bb6b53aee124 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Sat, 29 May 2021 07:26:08 +0200 Subject: Add back long sample optimization on sound mixer --- src/apu.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/apu.c b/src/apu.c index d107e1e..d40b2fa 100644 --- a/src/apu.c +++ b/src/apu.c @@ -251,23 +251,30 @@ sound_mix(void) { } } - for(size_t i = 0; i < AUDIO_BUF_LEN; i++) { - // Remember we are using fixed point values. - mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol; - ch->pos += ch->inc; + if (ch->pos + ch->inc * AUDIO_BUF_LEN >= ch->length) { + for(size_t i = 0; i < AUDIO_BUF_LEN; i++) { + // Remember we are using fixed point values. + mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol; + ch->pos += ch->inc; - if (ch->pos >= ch->length) { - // If looping is not active disable the channel. - if (ch->loop_length == 0) { - ch->data = NULL; - break; - } + if (ch->pos >= ch->length) { + // If looping is not active disable the channel. + if (ch->loop_length == 0) { + ch->data = NULL; + break; + } - // Loop the sample. - while (ch->pos >= ch->length) { - ch->pos -= ch->loop_length; + // Loop the sample. + while (ch->pos >= ch->length) { + ch->pos -= ch->loop_length; + } } } + } else { + for(size_t i = 0; i < AUDIO_BUF_LEN; i++) { + mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol; + ch->pos += ch->inc; + } } } -- cgit v1.2.1