diff --git a/projects/examples/dev.audio.usm b/projects/examples/dev.audio.usm index b31c103..57fc83e 100644 --- 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 index 92e40b0..1ef8bf9 100644 --- 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 index 522c9af..a4d033a 100644 --- 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 index 57ca7b4..f95cd3d 100644 --- 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;