aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-29 07:26:08 +0200
committerBad Diode <bd@badd10de.dev>2021-05-29 07:26:08 +0200
commit450c5a1422b6a976485015085c02bb6b53aee124 (patch)
treea84217099a614efb595d68eddbaf9681469cdaaf
parent59e1991f7ba8bcd6bc4aab611b904c7419b719a9 (diff)
downloaduxngba-450c5a1422b6a976485015085c02bb6b53aee124.tar.gz
uxngba-450c5a1422b6a976485015085c02bb6b53aee124.zip
Add back long sample optimization on sound mixer
-rw-r--r--src/apu.c33
1 files 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) {
251 } 251 }
252 } 252 }
253 253
254 for(size_t i = 0; i < AUDIO_BUF_LEN; i++) { 254 if (ch->pos + ch->inc * AUDIO_BUF_LEN >= ch->length) {
255 // Remember we are using fixed point values. 255 for(size_t i = 0; i < AUDIO_BUF_LEN; i++) {
256 mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol; 256 // Remember we are using fixed point values.
257 ch->pos += ch->inc; 257 mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol;
258 ch->pos += ch->inc;
258 259
259 if (ch->pos >= ch->length) { 260 if (ch->pos >= ch->length) {
260 // If looping is not active disable the channel. 261 // If looping is not active disable the channel.
261 if (ch->loop_length == 0) { 262 if (ch->loop_length == 0) {
262 ch->data = NULL; 263 ch->data = NULL;
263 break; 264 break;
264 } 265 }
265 266
266 // Loop the sample. 267 // Loop the sample.
267 while (ch->pos >= ch->length) { 268 while (ch->pos >= ch->length) {
268 ch->pos -= ch->loop_length; 269 ch->pos -= ch->loop_length;
270 }
269 } 271 }
270 } 272 }
273 } else {
274 for(size_t i = 0; i < AUDIO_BUF_LEN; i++) {
275 mix_buffer[i] += (0x80 ^ (s8)ch->data[ch->pos >> 12]) * vol;
276 ch->pos += ch->inc;
277 }
271 } 278 }
272 } 279 }
273 280