uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit 6a091365a296266cef79004ec2490a42a24f205b
parent dbf1c72f2144ec95e9153c2172ee1da8595bc867
Author: d_m <d_m@plastic-idolatry.com>
Date:   Fri, 20 Oct 2023 19:38:01 -0400

Take pitch into account when computing duration.

Diffstat:
Msrc/devices/audio.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/devices/audio.c b/src/devices/audio.c @@ -291,20 +291,27 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) } } +float +calc_duration(Uint16 len, Uint8 pitch) +{ + float scale = tuning[pitch - 20] / tuning[0x3c - 20]; + return len / (scale * 44.1f); +} + void audio_start(int idx, Uint8 *d, Uxn *u) { Uint16 dur = PEEK2(d + 0x5); Uint8 off = d[0xf] == 0x00; Uint16 len = PEEK2(d + 0xa); - float duration = dur > 0 ? dur : len / 44.1f; + Uint8 pitch = d[0xf] & 0x7f; + float duration = dur > 0 ? dur : calc_duration(len, pitch); if(!off) { Uint16 addr = PEEK2(d + 0xc); Uint8 *data = &u->ram[addr]; Uint8 volume = d[0xe]; bool loop = !(d[0xf] & 0x80); - Uint8 pitch = d[0xf] & 0x7f; Uint16 adsr = PEEK2(d + 0x8); Uint8 attack = (adsr >> 12) & 0xF; Uint8 decay = (adsr >> 8) & 0xF;