commit d01eb6cc45ed26fd296fefd8eeea68062dc0f6df
parent 7034a0cbfb365e2abf7a0bbb347dcf8f6193d2c4
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date: Sun, 25 Apr 2021 21:52:39 +0100
Added currently playing volume readout
Diffstat:
4 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/projects/demos/musictracker.usm b/projects/demos/musictracker.usm
@@ -72,6 +72,7 @@ BRK
@on-screen ( -> )
;move-head JSR2
+ ;draw-vu JSR2
.head/pos PEK #08 MOD #00 NEQ ,&skip JNZ
;bang JSR2
&skip
@@ -421,6 +422,16 @@ RTN
RTN
+@draw-vu ( -- )
+ .ctlframe/x1 PEK2 #0088 ADD2 .ctlframe/y1 PEK2 #0010 ADD2
+ .Audio/volume DEI DUP STH #04 SFT
+ ;draw-knob/force JSR2
+ .ctlframe/x1 PEK2 #0098 ADD2 .ctlframe/y1 PEK2 #0010 ADD2
+ STHr #0f AND
+ ;draw-knob/force JSR2
+
+RTN
+
@draw-channels
.chnframe/x1 PEK2 .chnframe/y1 PEK2 .chnframe/x2 PEK2 .chnframe/y2 PEK2 #01 ;line-rect JSR2
diff --git a/src/apu.c b/src/apu.c
@@ -79,3 +79,20 @@ apu_start(Apu *c, Uint16 adsr, Uint8 pitch)
else /* sample repeat mode */
c->period = NOTE_PERIOD;
}
+
+Uint8
+apu_get_vu(Apu *c, Apu *end)
+{
+ size_t i;
+ Sint32 sum[2] = {0, 0};
+ for(; c < end; ++c) {
+ if(!c->advance) continue;
+ sum[0] += envelope(c, c->age) * c->volume_l;
+ sum[1] += envelope(c, c->age) * c->volume_r;
+ }
+ for(i = 0; i < 2; ++i) {
+ sum[i] /= 0x800;
+ if(sum[i] > 0xf) sum[i] = 0xf;
+ }
+ return (sum[0] << 4) | sum[1];
+}
diff --git a/src/apu.h b/src/apu.h
@@ -20,8 +20,10 @@ typedef struct {
Uint8 *addr;
Uint32 count, advance, period, age, a, d, s, r;
Uint16 i, len;
- Uint8 volume_l, volume_r, pitch, repeat;
+ Sint8 volume_l, volume_r;
+ Uint8 pitch, repeat;
} Apu;
void apu_render(Apu *c, Sint16 *sample, Sint16 *end);
void apu_start(Apu *c, Uint16 adsr, Uint8 pitch);
+Uint8 apu_get_vu(Apu *c, Apu *end);
diff --git a/src/emulator.c b/src/emulator.c
@@ -248,7 +248,10 @@ static void
audio_talk(Device *d, Uint8 b0, Uint8 w)
{
Apu *c;
- if(!w) return;
+ if(!w) {
+ if(b0 == 0xe) d->dat[0xe] = apu_get_vu(apu, apu + POLYPHONY);
+ return;
+ }
c = &apu[d->dat[0x7] % POLYPHONY];
SDL_LockAudioDevice(audio_id);
if(b0 == 0x1) c->period -= (Sint16)mempeek16(d->dat, 0x0);