uxn

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

commit 87157258b89bcba34854c95ea4fb339977b4dada
parent ad4ff821384dec0976300610071020a2b0889368
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Fri, 20 Aug 2021 22:45:39 +0100

Implemented Audio*/vector which runs when notes finish playing

Diffstat:
Msrc/devices/apu.c | 3++-
Msrc/devices/apu.h | 1+
Msrc/uxnemu.c | 13++++++++++++-
3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/devices/apu.c b/src/devices/apu.c @@ -49,7 +49,7 @@ apu_render(Apu *c, Sint16 *sample, Sint16 *end) if(c->i >= c->len) { if(!c->repeat) { c->advance = 0; - return 1; + break; } c->i %= c->len; } @@ -57,6 +57,7 @@ apu_render(Apu *c, Sint16 *sample, Sint16 *end) *sample++ += s * c->volume[0] / 0x180; *sample++ += s * c->volume[1] / 0x180; } + if(!c->advance) apu_finished_handler(c); return 1; } diff --git a/src/devices/apu.h b/src/devices/apu.h @@ -26,3 +26,4 @@ typedef struct { int apu_render(Apu *c, Sint16 *sample, Sint16 *end); void apu_start(Apu *c, Uint16 adsr, Uint8 pitch); Uint8 apu_get_vu(Apu *c); +void apu_finished_handler(Apu *c); diff --git a/src/uxnemu.c b/src/uxnemu.c @@ -32,7 +32,7 @@ static SDL_Rect gRect; static Ppu ppu; static Apu apu[POLYPHONY]; static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole; -static Uint32 stdin_event; +static Uint32 stdin_event, audio0_event; static Uint8 zoom = 1, reqdraw = 0; @@ -410,6 +410,14 @@ nil_talk(Device *d, Uint8 b0, Uint8 w) #pragma mark - Generics +void +apu_finished_handler(Apu *c) +{ + SDL_Event event; + event.type = audio0_event + (c - apu); + SDL_PushEvent(&event); +} + static int stdin_handler(void *p) { @@ -474,6 +482,8 @@ run(Uxn *u) if(event.type == stdin_event) { devconsole->dat[0x2] = event.cbutton.button; uxn_eval(u, mempeek16(devconsole->dat, 0)); + } else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) { + uxn_eval(u, mempeek16((devaudio0 + (event.type - audio0_event))->dat, 0)); } } } @@ -504,6 +514,7 @@ main(int argc, char **argv) Uxn u; stdin_event = SDL_RegisterEvents(1); + audio0_event = SDL_RegisterEvents(POLYPHONY); SDL_CreateThread(stdin_handler, "stdin", NULL); if(argc < 2)