aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-26 13:39:54 +0200
committerBad Diode <bd@badd10de.dev>2021-05-26 13:39:54 +0200
commit2a7893e230c521bc0f8aed7c4307ccf4cacaa767 (patch)
tree54784b195f5617a44945c0f4ed032acdfc0b1859 /src
parent5497bf0faae483daf44b4909cee81da48fdc86be (diff)
downloaduxngba-2a7893e230c521bc0f8aed7c4307ccf4cacaa767.tar.gz
uxngba-2a7893e230c521bc0f8aed7c4307ccf4cacaa767.zip
Prototyping live resampling of uxn samples
Diffstat (limited to 'src')
-rw-r--r--src/main.c20
-rw-r--r--src/uxn/devices/apu.c5
2 files changed, 14 insertions, 11 deletions
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) {
112 } 112 }
113} 113}
114 114
115static u8 buf[KB(1)];
116
115static void 117static void
116audio_talk(Device *d, u8 b0, u8 w) { 118audio_talk(Device *d, u8 b0, u8 w) {
117 AudioChannel *c = &apu.chan_0; 119 AudioChannel *c = &apu.chan_0;
@@ -126,14 +128,15 @@ audio_talk(Device *d, u8 b0, u8 w) {
126 c->n_samples = mempeek16(d->dat, 0xa); 128 c->n_samples = mempeek16(d->dat, 0xa);
127 c->samples = &d->mem[mempeek16(d->dat, 0xc)]; 129 c->samples = &d->mem[mempeek16(d->dat, 0xc)];
128 // Transform the samples from u8 to s8. 130 // Transform the samples from u8 to s8.
129 // for (size_t i = 0; i < c->n_samples; ++i) { 131 for (size_t i = 0; i < c->n_samples; ++i) {
130 // c->samples[i] = c->samples[i] + 0x80; 132 buf[i] = (u8)c->samples[i] + 0x80;
131 // } 133 }
134 c->samples = &buf;
132 // c->volume[0] = d->dat[0xe] >> 4; 135 // c->volume[0] = d->dat[0xe] >> 4;
133 // c->volume[1] = d->dat[0xe] & 0xf; 136 // c->volume[1] = d->dat[0xe] & 0xf;
134 c->loop = !(d->dat[0xf] & 0x80); 137 c->loop = !(d->dat[0xf] & 0x80);
135 c->pitch = d->dat[0xf] & 0x7f; 138 c->pitch = d->dat[0xf] & 0x7f;
136 init_sound(c); 139 // init_sound(c);
137 reset_sound(c); 140 reset_sound(c);
138 txt_printf("note: %d \n", c->pitch); 141 txt_printf("note: %d \n", c->pitch);
139 // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f); 142 // apu_start(c, mempeek16(d->dat, 0x8), d->dat[0xf] & 0x7f);
@@ -180,6 +183,9 @@ init_uxn(Uxn *u) {
180 // Initialize PPU. 183 // Initialize PPU.
181 initppu(&ppu, 30, 20, 0); 184 initppu(&ppu, 30, 20, 0);
182 185
186 // Enable sound.
187 SOUND_STATUS = SOUND_ENABLE;
188
183 // Copy rom to VM. 189 // Copy rom to VM.
184 memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom)); 190 memcpy(u->ram.dat + PAGE_PROGRAM, uxn_rom, sizeof(uxn_rom));
185 191
@@ -188,9 +194,9 @@ init_uxn(Uxn *u) {
188 portuxn(u, 0x1, "console", console_talk); 194 portuxn(u, 0x1, "console", console_talk);
189 devscreen = portuxn(u, 0x2, "screen", screen_talk); 195 devscreen = portuxn(u, 0x2, "screen", screen_talk);
190 devaudio = portuxn(u, 0x3, "audio0", audio_talk); 196 devaudio = portuxn(u, 0x3, "audio0", audio_talk);
191 portuxn(u, 0x4, "---", nil_talk); 197 portuxn(u, 0x4, "audio1", audio_talk);
192 portuxn(u, 0x5, "---", nil_talk); 198 portuxn(u, 0x5, "audio2", audio_talk);
193 portuxn(u, 0x6, "---", nil_talk); 199 portuxn(u, 0x6, "audio3", audio_talk);
194 portuxn(u, 0x7, "---", nil_talk); 200 portuxn(u, 0x7, "---", nil_talk);
195 devctrl = portuxn(u, 0x8, "controller", nil_talk); 201 devctrl = portuxn(u, 0x8, "controller", nil_talk);
196 devmouse = portuxn(u, 0x9, "mouse", nil_talk); 202 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) {
172 172
173 // Prepare DMA copy. 173 // Prepare DMA copy.
174 dma_transfer_copy(SOUND_FIFO_A, chan->samples, 1, 1, 174 dma_transfer_copy(SOUND_FIFO_A, chan->samples, 1, 1,
175 DMA_CHUNK_32 | DMA_REFRESH | DMA_REPEAT | DMA_ENABLE); 175 DMA_DST_FIXED | DMA_CHUNK_32 | DMA_REFRESH | DMA_REPEAT | DMA_ENABLE);
176 176
177 // Timer 1 used to stop playing samples. 177 // Timer 1 used to stop playing samples.
178 u32 sample_duration = chan->n_samples; 178 u32 sample_duration = chan->n_samples;
@@ -196,9 +196,6 @@ u8 square_wave[] = {
196 196
197void 197void
198init_sound(AudioChannel *chan) { 198init_sound(AudioChannel *chan) {
199 // Enable sound.
200 SOUND_STATUS = SOUND_ENABLE;
201
202 // chan->samples = &square_wave; 199 // chan->samples = &square_wave;
203 // chan->n_samples = 2; 200 // chan->n_samples = 2;
204 // chan->samples = &samples; 201 // chan->samples = &samples;