commit 4b64ced6699d892de817f802c08da4a63e5ed628
parent 9d1013d3bfcaa7fdaa96b3ef61cacd29af7291fb
Author: Bad Diode <bd@badd10de.dev>
Date: Mon, 16 Oct 2023 15:35:46 +0200
Restore audio port layout and use 0x5 for duration
Diffstat:
2 files changed, 23 insertions(+), 34 deletions(-)
diff --git a/projects/examples/devices/audio-tests.tal b/projects/examples/devices/audio-tests.tal
@@ -6,10 +6,10 @@
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 ]
-|30 @Audio0 [ &vector $2 &duration $2 &attack $1 &decay $1 &sustain $1 &release $1 &length $2 &addr $2 &expansion $1 &volume $1 &detune $1 &pitch $1 ]
-|40 @Audio1 [ &vector $2 &duration $2 &attack $1 &decay $1 &sustain $1 &release $1 &length $2 &addr $2 &expansion $1 &volume $1 &detune $1 &pitch $1 ]
-|50 @Audio2 [ &vector $2 &duration $2 &attack $1 &decay $1 &sustain $1 &release $1 &length $2 &addr $2 &expansion $1 &volume $1 &detune $1 &pitch $1 ]
-|60 @Audio3 [ &vector $2 &duration $2 &attack $1 &decay $1 &sustain $1 &release $1 &length $2 &addr $2 &expansion $1 &volume $1 &detune $1 &pitch $1 ]
+|30 @Audio0 [ &vector $2 &position $2 &output $1 &duration $2 &pad $1 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
+|40 @Audio1 [ &vector $2 &position $2 &output $1 &duration $2 &pad $1 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
+|50 @Audio2 [ &vector $2 &position $2 &output $1 &duration $2 &pad $1 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
+|60 @Audio3 [ &vector $2 &position $2 &output $1 &duration $2 &pad $1 &adsr $2 &length $2 &addr $2 &volume $1 &pitch $1 ]
|80 @Controller &vector $2 &button $1 &key $1
( variables )
@@ -40,36 +40,24 @@
;kick/end ;kick SUB2
.Audio0/length DEO2
#ff .Audio0/volume DEO
- #00 .Audio0/attack DEO
- #f0 .Audio0/decay DEO
- #ff .Audio0/sustain DEO
- #1e .Audio0/release DEO
+ #00ff .Audio0/adsr DEO2
;sine .Audio1/addr DEO2
#0054 .Audio1/length DEO2
#ff .Audio1/volume DEO
- #00 .Audio1/attack DEO
- #11 .Audio1/decay DEO
- #00 .Audio1/sustain DEO
- #1e .Audio1/release DEO
+ #01ff .Audio1/adsr DEO2
#0074 .Audio1/duration DEO2
;sine .Audio2/addr DEO2
#00a8 .Audio2/length DEO2
#ff .Audio2/volume DEO
- #00 .Audio2/attack DEO
- #f0 .Audio2/decay DEO
- #00 .Audio2/sustain DEO
- #1e .Audio2/release DEO
+ #2200 .Audio2/adsr DEO2
#01d0 .Audio2/duration DEO2
;sine .Audio3/addr DEO2
#00a8 .Audio3/length DEO2
#ff .Audio3/volume DEO
- #00 .Audio3/attack DEO
- #f0 .Audio3/decay DEO
- #00 .Audio3/sustain DEO
- #1e .Audio3/release DEO
+ #38ff .Audio3/adsr DEO2
#00e8 .Audio3/duration DEO2
BRK
diff --git a/src/devices/audio.c b/src/devices/audio.c
@@ -117,17 +117,17 @@ 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) {
channel->duration = duration;
- channel->vol_l = (vol >> 4) / 16.0f;
- channel->vol_r = (vol & 0xf) / 16.0f;
+ channel->vol_l = (vol >> 4) / 16.0f * 0.9;
+ channel->vol_r = (vol & 0xf) / 16.0f * 0.9;
Sample sample = {0};
sample.data = data;
sample.len = len;
sample.pos = 0;
- sample.env.a = attack * 10.0f;
- sample.env.d = decay * 10.0f;
- sample.env.s = sustain / 256.0f;
- sample.env.r = release * 10.0f;
+ sample.env.a = attack * 62.0f;
+ sample.env.d = decay * 62.0f;
+ sample.env.s = sustain / 16.0f;
+ sample.env.r = release * 62.0f;
if (loop) {
sample.loop = len;
} else {
@@ -284,20 +284,21 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) {
void
audio_start(int idx, Uint8 *d, Uxn *u)
{
- Uint16 duration = PEEK2(d + 0x2);
+ Uint16 duration = PEEK2(d + 0x5);
Uint8 off = d[0xf] == 0xff;
if (!off) {
- Uint16 addr = PEEK2(d + 0xa);
+ Uint16 addr = PEEK2(d + 0xc);
Uint8 *data = &u->ram[addr];
- Uint16 len = PEEK2(d + 0x8);
- Uint8 volume = d[0xd];
+ Uint16 len = PEEK2(d + 0xa);
+ Uint8 volume = d[0xe];
bool loop = !!(d[0xf] & 0x80);
Uint8 pitch = d[0xf] & 0x7f;
- Uint8 attack = d[0x4];
- Uint8 decay = d[0x5];
- Uint8 sustain = d[0x6];
- Uint8 release = d[0x7];
+ Uint16 adsr = PEEK2(d + 0x8);
+ Uint8 attack = (adsr >> 12) & 0xF;
+ Uint8 decay = (adsr >> 8) & 0xF;
+ Uint8 sustain = (adsr >> 4) & 0xF;
+ Uint8 release = (adsr >> 0) & 0xF;
note_on(&channel[idx], duration, data, len, volume, attack, decay, sustain, release, pitch, loop);
} else {
note_off(&channel[idx], duration);