mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-16 11:15:06 +00:00
Implemented Audio*/vector which runs when notes finish playing
This commit is contained in:
parent
ad4ff82138
commit
87157258b8
3 changed files with 15 additions and 2 deletions
|
@ -49,7 +49,7 @@ apu_render(Apu *c, Sint16 *sample, Sint16 *end)
|
||||||
if(c->i >= c->len) {
|
if(c->i >= c->len) {
|
||||||
if(!c->repeat) {
|
if(!c->repeat) {
|
||||||
c->advance = 0;
|
c->advance = 0;
|
||||||
return 1;
|
break;
|
||||||
}
|
}
|
||||||
c->i %= c->len;
|
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[0] / 0x180;
|
||||||
*sample++ += s * c->volume[1] / 0x180;
|
*sample++ += s * c->volume[1] / 0x180;
|
||||||
}
|
}
|
||||||
|
if(!c->advance) apu_finished_handler(c);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,3 +26,4 @@ typedef struct {
|
||||||
int apu_render(Apu *c, Sint16 *sample, Sint16 *end);
|
int apu_render(Apu *c, Sint16 *sample, Sint16 *end);
|
||||||
void apu_start(Apu *c, Uint16 adsr, Uint8 pitch);
|
void apu_start(Apu *c, Uint16 adsr, Uint8 pitch);
|
||||||
Uint8 apu_get_vu(Apu *c);
|
Uint8 apu_get_vu(Apu *c);
|
||||||
|
void apu_finished_handler(Apu *c);
|
||||||
|
|
13
src/uxnemu.c
13
src/uxnemu.c
|
@ -32,7 +32,7 @@ static SDL_Rect gRect;
|
||||||
static Ppu ppu;
|
static Ppu ppu;
|
||||||
static Apu apu[POLYPHONY];
|
static Apu apu[POLYPHONY];
|
||||||
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
static Device *devsystem, *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
|
||||||
static Uint32 stdin_event;
|
static Uint32 stdin_event, audio0_event;
|
||||||
|
|
||||||
static Uint8 zoom = 1, reqdraw = 0;
|
static Uint8 zoom = 1, reqdraw = 0;
|
||||||
|
|
||||||
|
@ -410,6 +410,14 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
|
||||||
|
|
||||||
#pragma mark - Generics
|
#pragma mark - Generics
|
||||||
|
|
||||||
|
void
|
||||||
|
apu_finished_handler(Apu *c)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = audio0_event + (c - apu);
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
stdin_handler(void *p)
|
stdin_handler(void *p)
|
||||||
{
|
{
|
||||||
|
@ -474,6 +482,8 @@ run(Uxn *u)
|
||||||
if(event.type == stdin_event) {
|
if(event.type == stdin_event) {
|
||||||
devconsole->dat[0x2] = event.cbutton.button;
|
devconsole->dat[0x2] = event.cbutton.button;
|
||||||
uxn_eval(u, mempeek16(devconsole->dat, 0));
|
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;
|
Uxn u;
|
||||||
|
|
||||||
stdin_event = SDL_RegisterEvents(1);
|
stdin_event = SDL_RegisterEvents(1);
|
||||||
|
audio0_event = SDL_RegisterEvents(POLYPHONY);
|
||||||
SDL_CreateThread(stdin_handler, "stdin", NULL);
|
SDL_CreateThread(stdin_handler, "stdin", NULL);
|
||||||
|
|
||||||
if(argc < 2)
|
if(argc < 2)
|
||||||
|
|
Loading…
Reference in a new issue