diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apu.c | 33 |
1 files changed, 20 insertions, 13 deletions
@@ -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 | ||