uxn

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

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

Made Audio.value unsigned

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

diff --git a/projects/examples/dev.audio.usm b/projects/examples/dev.audio.usm @@ -470,24 +470,24 @@ RTN RTN @adsr-envelope ( -- ) - #7f ,adsr #00 ~Audio.play #04 MUL ADD2 PEK2 SOUND - #40 ,adsr #00 ~Audio.play #04 MUL ADD2 #0001 ADD2 PEK2 SOUND - #40 ,adsr #00 ~Audio.play #04 MUL ADD2 #0002 ADD2 PEK2 SOUND + #ff ,adsr #00 ~Audio.play #04 MUL ADD2 PEK2 SOUND + #80 ,adsr #00 ~Audio.play #04 MUL ADD2 #0001 ADD2 PEK2 SOUND + #80 ,adsr #00 ~Audio.play #04 MUL ADD2 #0002 ADD2 PEK2 SOUND #00 ,adsr #00 ~Audio.play #04 MUL ADD2 #0003 ADD2 PEK2 SOUND SOUND_FINISH BRK @square-wave ( -- ) - #5800 SOUND - #5880 SOUND #a800 SOUND #a880 SOUND + #5800 SOUND + #5880 SOUND BRK @triangle-wave ( -- ) - #7f40 SOUND - #8180 SOUND - #0040 SOUND + #ff40 SOUND + #0080 SOUND + #8040 SOUND BRK @ch1_txt [ CHN0 00 ] diff --git a/src/apu.c b/src/apu.c @@ -87,9 +87,10 @@ apu_play_note(Note *note, Uint16 wave_vector, Uint16 envelope_vector, Uint8 volu for(i = 0; i < 2; ++i) { note->volume[i] = 0xf & (volume >> 4 * (1 - i)); note->wv[i].count = note->wv[i].period = 0; - note->wv[i].end_value = 0; + note->wv[i].end_value = 0x8000 * (1 - i); note->wv[i].queue.n = note->wv[i].queue.i = 0; note->wv[i].queue.finishes = 0; + note->wv[i].queue.is_envelope = i; } note->wv[0].vector = wave_vector; note->wv[0].advance = note_advances[pitch % 12] >> (8 - pitch / 12); diff --git a/src/apu.h b/src/apu.h @@ -17,7 +17,7 @@ typedef signed int Sint32; typedef struct { Uint16 *dat; - Uint8 i, n, sz, finishes; + Uint8 i, n, sz, finishes, is_envelope; } Queue; typedef struct { diff --git a/src/emulator.c b/src/emulator.c @@ -253,7 +253,10 @@ audio_poke(Uxn *u, Uint16 ptr, Uint8 b0, Uint8 b1) apu.queue->sz = apu.queue->sz < 4 ? 4 : apu.queue->sz * 2; apu.queue->dat = SDL_realloc(apu.queue->dat, apu.queue->sz * sizeof(*apu.queue->dat)); } - apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc]; + if(apu.queue->is_envelope) + apu.queue->dat[apu.queue->n++] = (m[0xb] << 7) + (m[0xc] >> 1); + else + apu.queue->dat[apu.queue->n++] = (m[0xb] << 8) + m[0xc] + 0x8000; apu.queue->dat[apu.queue->n++] = (m[0xd] << 8) + b1; } else if(b0 == 0xf && apu.queue != NULL) apu.queue->finishes = 1;