Fix audio not playing

This commit is contained in:
Bad Diode 2021-11-17 16:54:44 +01:00 committed by Nihilazo
parent ff847d5812
commit 3dbd536edd
1 changed files with 24 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* Varvara plugin for rockbox. I have no idea what I'm doing. /* Varvara plugin for rockbox. I have no idea what I'm doing.
copyright (c) 2021 Devine Lu Linvega copyright (c) 2021 Devine Lu Linvega
copyright (c) 2021 nihilazo copyright (c) 2021 nihilazo
@ -35,13 +35,13 @@ static Device *devctrl, *devsystem, *devconsole, *devscreen, *devaudio0;
unsigned int palette[3]; unsigned int palette[3];
static Uint8 framebuffer[LCD_HEIGHT * LCD_WIDTH * 4]; static Uint8 framebuffer[LCD_HEIGHT * LCD_WIDTH * 4];
static fb_data *lcd_fb = NULL; static fb_data *lcd_fb = NULL;
int audio_buf[AUDIO_BUF_SIZE]; char audio_buf[AUDIO_BUF_SIZE];
static unsigned long starttick; static unsigned long starttick;
static long sleeptime; static long sleeptime;
static void static void
memzero8(void *src, uint64_t n) memzero8(void *src, uint64_t n)
{ {
uint8_t * ptr = src; uint8_t * ptr = src;
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
@ -66,7 +66,7 @@ inspect(Stack *s, char *name)
} }
static void static void
set_palette(Uint8 *addr) set_palette(Uint8 *addr)
{ {
#if LCD_DEPTH > 4 #if LCD_DEPTH > 4
int i; int i;
@ -104,7 +104,7 @@ static Uint8 system_dei(Device *d, Uint8 port) {
switch(port) { switch(port) {
case 0x2: return d->u->wst.ptr; break; case 0x2: return d->u->wst.ptr; break;
case 0x3: return d->u->rst.ptr; break; case 0x3: return d->u->rst.ptr; break;
} }
} }
/* taken from uxncli */ /* taken from uxncli */
@ -220,17 +220,11 @@ apu_finished_handler(Apu *c)
} }
void audio_callback(const void** start, size_t *size) { void audio_callback(const void** start, size_t *size) {
int high = 32000;
int low = 0;
for (size_t i = 0; i < AUDIO_BUF_SIZE; i++) { for (size_t i = 0; i < AUDIO_BUF_SIZE; i++) {
if (i & 1) { audio_buf[i] = i;
audio_buf[i] = high;
} else {
audio_buf[i] = low;
}
} }
*start = &audio_buf; *start = audio_buf;
*size = AUDIO_BUF_SIZE; *size = AUDIO_BUF_SIZE;
} }
@ -290,7 +284,7 @@ static void redraw(void)
rb->lcd_update(); rb->lcd_update();
#endif #endif
ppu.reqdraw = 0; ppu.reqdraw = 0;
} }
int int
@ -311,40 +305,40 @@ static void run() {
// TODO allow scrolls (that don't have a button release) to be mapped as buttons // TODO allow scrolls (that don't have a button release) to be mapped as buttons
if(b == VARVARA_MENU) if(b == VARVARA_MENU)
return; return;
if(b == VARVARA_A) if(b == VARVARA_A)
devctrl->dat[2] += 0x01; devctrl->dat[2] += 0x01;
if(b == (VARVARA_A | BUTTON_REL)) if(b == (VARVARA_A | BUTTON_REL))
devctrl->dat[2] -= 0x01; devctrl->dat[2] -= 0x01;
if(b == VARVARA_B) if(b == VARVARA_B)
devctrl->dat[2] += 0x02; devctrl->dat[2] += 0x02;
if(b == (VARVARA_B | BUTTON_REL)) if(b == (VARVARA_B | BUTTON_REL))
devctrl->dat[2] -= 0x02; devctrl->dat[2] -= 0x02;
if(b == VARVARA_START) if(b == VARVARA_START)
devctrl->dat[2] += 0x04; devctrl->dat[2] += 0x04;
if(b == (VARVARA_START | BUTTON_REL)) if(b == (VARVARA_START | BUTTON_REL))
devctrl->dat[2] -= 0x04; devctrl->dat[2] -= 0x04;
if(b == VARVARA_SELECT) if(b == VARVARA_SELECT)
devctrl->dat[2] += 0x08; devctrl->dat[2] += 0x08;
if(b == (VARVARA_SELECT | BUTTON_REL)) if(b == (VARVARA_SELECT | BUTTON_REL))
devctrl->dat[2] -= 0x08; devctrl->dat[2] -= 0x08;
if(b == VARVARA_UP) if(b == VARVARA_UP)
devctrl->dat[2] += 0x10; devctrl->dat[2] += 0x10;
if(b == (VARVARA_UP | BUTTON_REL)) if(b == (VARVARA_UP | BUTTON_REL))
devctrl->dat[2] -= 0x10; devctrl->dat[2] -= 0x10;
if(b == VARVARA_DOWN) if(b == VARVARA_DOWN)
devctrl->dat[2] += 0x20; devctrl->dat[2] += 0x20;
if(b == (VARVARA_DOWN | BUTTON_REL)) if(b == (VARVARA_DOWN | BUTTON_REL))
devctrl->dat[2] -= 0x20; devctrl->dat[2] -= 0x20;
if(b == VARVARA_LEFT) if(b == VARVARA_LEFT)
devctrl->dat[2] += 0x40; devctrl->dat[2] += 0x40;
if(b == (VARVARA_LEFT | BUTTON_REL)) if(b == (VARVARA_LEFT | BUTTON_REL))
devctrl->dat[2] -= 0x40; devctrl->dat[2] -= 0x40;
if(b == VARVARA_RIGHT) if(b == VARVARA_RIGHT)
devctrl->dat[2] += 0x80; devctrl->dat[2] += 0x80;
if(b == (VARVARA_RIGHT | BUTTON_REL)) if(b == (VARVARA_RIGHT | BUTTON_REL))
devctrl->dat[2] -= 0x80; devctrl->dat[2] -= 0x80;
uxn_eval(&u, peek16(devctrl->dat, 0)); uxn_eval(&u, peek16(devctrl->dat, 0));
} }
sleeptime = (HZ/60)-(*rb->current_tick-starttick); sleeptime = (HZ/60)-(*rb->current_tick-starttick);
@ -372,7 +366,8 @@ enum plugin_status plugin_start(const void* parameter)
rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
#endif #endif
rb->pcmbuf_fade(false, true);
rb->pcm_play_stop(); rb->pcm_play_stop();
rb->mixer_set_frequency(44100); rb->mixer_set_frequency(44100);
rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, audio_callback, NULL, 0); rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, audio_callback, NULL, 0);
@ -380,10 +375,10 @@ enum plugin_status plugin_start(const void* parameter)
/* uxn init */ /* uxn init */
DEBUGF("zeroing\n"); DEBUGF("zeroing\n");
memzero8(&u, sizeof(Uxn)); memzero8(&u, sizeof(Uxn));
DEBUGF("loading ROM\n"); DEBUGF("loading ROM\n");
char* filename = (char*) parameter; char* filename = (char*) parameter;
int fd = rb->open(filename, O_RDONLY); int fd = rb->open(filename, O_RDONLY);
if (fd < 0) { if (fd < 0) {
rb->splash(HZ, "File Error"); rb->splash(HZ, "File Error");
@ -395,7 +390,7 @@ enum plugin_status plugin_start(const void* parameter)
return PLUGIN_ERROR; return PLUGIN_ERROR;
} }
rb->close(fd); rb->close(fd);
ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer); ppu_init(&ppu, LCD_WIDTH, LCD_HEIGHT, framebuffer);
// Register ports // Register ports