From 2a7893e230c521bc0f8aed7c4307ccf4cacaa767 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 26 May 2021 13:39:54 +0200 Subject: Prototyping live resampling of uxn samples --- src/main.c | 20 +++++++++++++------- src/uxn/devices/apu.c | 5 +---- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index fc7dad1..a6fb761 100644 --- a/src/main.c +++ b/src/main.c @@ -112,6 +112,8 @@ screen_talk(Device *d, u8 b0, u8 w) { } } +static u8 buf[KB(1)]; + static void audio_talk(Device *d, u8 b0, u8 w) { AudioChannel *c = &apu.chan_0; @@ -126,14 +128,15 @@ audio_talk(Device *d, u8 b0, u8 w) { c->n_samples = mempeek16(d->dat, 0xa); c->samples = &d->mem[mempeek16(d->dat, 0xc)]; // Transform the samples from u8 to s8. - // for (size_t i = 0; i < c->n_samples; ++i) { - // c->samples[i] = c->samples[i] + 0x80; - // } + for (size_t i = 0; i < c->n_samples; ++i) { + buf[i] = (u8)c->samples[i] + 0x80; + } + c->samples = &buf; // c->volume[0] = d->dat[0xe] >> 4; // c->volume[1] = d->dat[0xe] & 0xf; c->loop = !(d->dat[0xf] & 0x80); c->pitch = d->dat[0xf] & 0x7f; - init_sound(c); + // init_sound(c); reset_sound(c); txt_printf("note: %d \n", c->pitch); // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f); @@ -180,6 +183,9 @@ init_uxn(Uxn *u) { // Initialize PPU. initppu(&ppu, 30, 20, 0); + // Enable sound. + SOUND_STATUS = SOUND_ENABLE; + // Copy rom to VM. memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); @@ -188,9 +194,9 @@ init_uxn(Uxn *u) { portuxn(u, 0x1, "console", console_talk); devscreen = portuxn(u, 0x2, "screen", screen_talk); devaudio = portuxn(u, 0x3, "audio0", audio_talk); - portuxn(u, 0x4, "---", nil_talk); - portuxn(u, 0x5, "---", nil_talk); - portuxn(u, 0x6, "---", nil_talk); + portuxn(u, 0x4, "audio1", audio_talk); + portuxn(u, 0x5, "audio2", audio_talk); + portuxn(u, 0x6, "audio3", audio_talk); portuxn(u, 0x7, "---", nil_talk); devctrl = portuxn(u, 0x8, "controller", nil_talk); devmouse = portuxn(u, 0x9, "mouse", nil_talk); diff --git a/src/uxn/devices/apu.c b/src/uxn/devices/apu.c index fbe7c3d..b2ccc18 100644 --- a/src/uxn/devices/apu.c +++ b/src/uxn/devices/apu.c @@ -172,7 +172,7 @@ reset_sound(AudioChannel *chan) { // Prepare DMA copy. dma_transfer_copy(SOUND_FIFO_A, chan->samples, 1, 1, - DMA_CHUNK_32 | DMA_REFRESH | DMA_REPEAT | DMA_ENABLE); + DMA_DST_FIXED | DMA_CHUNK_32 | DMA_REFRESH | DMA_REPEAT | DMA_ENABLE); // Timer 1 used to stop playing samples. u32 sample_duration = chan->n_samples; @@ -196,9 +196,6 @@ u8 square_wave[] = { void init_sound(AudioChannel *chan) { - // Enable sound. - SOUND_STATUS = SOUND_ENABLE; - // chan->samples = &square_wave; // chan->n_samples = 2; // chan->samples = &samples; -- cgit v1.2.1