From dbf1c72f2144ec95e9153c2172ee1da8595bc867 Mon Sep 17 00:00:00 2001 From: d_m Date: Fri, 20 Oct 2023 12:24:39 -0400 Subject: [PATCH] Detect duration for note_off as well as note_on. --- src/devices/audio.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/devices/audio.c b/src/devices/audio.c index 9f9faed..1473a98 100644 --- a/src/devices/audio.c +++ b/src/devices/audio.c @@ -112,9 +112,9 @@ env_off(Envelope *env) } void -note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 vol, Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop) +note_on(AudioChannel *channel, float duration, Uint8 *data, Uint16 len, Uint8 vol, Uint8 attack, Uint8 decay, Uint8 sustain, Uint8 release, Uint8 pitch, bool loop) { - channel->duration = duration > 0 ? duration : len / 44.1f; + channel->duration = duration; channel->vol_l = (vol >> 4) / 15.0f; channel->vol_r = (vol & 0xf) / 15.0f; @@ -147,7 +147,7 @@ note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 v } void -note_off(AudioChannel *channel, Uint16 duration) +note_off(AudioChannel *channel, float duration) { channel->duration = duration; env_off(&channel->sample.env); @@ -294,13 +294,14 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) void audio_start(int idx, Uint8 *d, Uxn *u) { - Uint16 duration = PEEK2(d + 0x5); + Uint16 dur = PEEK2(d + 0x5); Uint8 off = d[0xf] == 0x00; + Uint16 len = PEEK2(d + 0xa); + float duration = dur > 0 ? dur : len / 44.1f; if(!off) { Uint16 addr = PEEK2(d + 0xc); Uint8 *data = &u->ram[addr]; - Uint16 len = PEEK2(d + 0xa); Uint8 volume = d[0xe]; bool loop = !(d[0xf] & 0x80); Uint8 pitch = d[0xf] & 0x7f;