uxn

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

commit 43cde08b68a7e6c880b01fa736dccbaa47f5707c
parent 2ea85815f6fcaa23e94a86da6e44b351dd9454a2
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Tue, 13 Apr 2021 21:52:54 +0100

Audio.pitch MSB must be 1 to use current synth

Diffstat:
Mprojects/examples/dev.audio.usm | 8++++----
Msrc/apu.c | 4+++-
Msrc/apu.h | 5+++--
Msrc/emulator.c | 2+-
4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/projects/examples/dev.audio.usm b/projects/examples/dev.audio.usm @@ -120,7 +120,7 @@ BRK @play ( pitch -- ) - =Audio.pitch + #80 ORA =Audio.pitch ,triangle-wave =Audio.wave ~track.active =Audio.play @@ -190,7 +190,7 @@ BRK DUP #ff NEQ ^$skip1 JNZ POP ^$listen2 JMP $skip1 - #00 SWP ,notes ADD2 PEK2 =Audio.pitch + #00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch ~volume.ch1 =Audio.volume ,square-wave =Audio.wave #00 =Audio.play @@ -200,7 +200,7 @@ BRK DUP #ff NEQ ^$skip2 JNZ POP ^$listen3 JMP $skip2 - #00 SWP ,notes ADD2 PEK2 =Audio.pitch + #00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch ~volume.ch2 =Audio.volume ,square-wave =Audio.wave #01 =Audio.play @@ -210,7 +210,7 @@ BRK DUP #ff NEQ ^$skip3 JNZ POP ^$end JMP $skip3 - #00 SWP ,notes ADD2 PEK2 =Audio.pitch + #00 SWP ,notes ADD2 PEK2 #80 ORA =Audio.pitch ~volume.ch3 =Audio.volume ,triangle-wave =Audio.wave #02 =Audio.play diff --git a/src/apu.c b/src/apu.c @@ -78,10 +78,12 @@ apu_render(Apu *apu, Uxn *u, Sint16 *samples, int n_samples) } void -apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch) +apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch, Uint8 impl) { int i; + if(pitch >= 108 || impl == 0) return; note->playing = 1; + note->impl = impl; for(i = 0; i < 2; ++i) { note->volume[i] = 0xf & (volume >> 4 * (1 - i)); note->wv[i].count = note->wv[i].period = 0; diff --git a/src/apu.h b/src/apu.h @@ -29,7 +29,8 @@ typedef struct { typedef struct { WaveformGenerator wv[2]; - Sint8 volume[2], playing; + Sint8 volume[2]; + Uint8 playing, impl; } Note; typedef struct { @@ -40,4 +41,4 @@ typedef struct { } Apu; void apu_render(Apu *apu, Uxn *u, Sint16 *samples, int n_samples); -void apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch); +void apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volume, Uint8 pitch, Uint8 impl); diff --git a/src/emulator.c b/src/emulator.c @@ -247,7 +247,7 @@ audio_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) if(b0 == 0xa) { if(b1 >= apu.n_notes) apu.notes = SDL_realloc(apu.notes, (b1 + 1) * sizeof(Note)); while(b1 >= apu.n_notes) SDL_zero(apu.notes[apu.n_notes++]); - apu_play_note(&apu.notes[b1], (m[0x0] << 8) + m[0x1], (m[0x2] << 8) + m[0x3], m[0x8], m[0x9]); + apu_play_note(&apu.notes[b1], (m[0x0] << 8) + m[0x1], (m[0x2] << 8) + m[0x3], m[0x8], m[0x9] & 0x7f, m[0x9] > 0x7f); } else if(b0 == 0xe && apu.queue != NULL) { if(apu.queue->n == apu.queue->sz) { apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2;