From 8fc709cc1d69c911ac36d18ea3fd6e3da3efc3f4 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Wed, 26 May 2021 18:37:53 +0200 Subject: [WIP] Add variable sample support and multichannel --- src/main.c | 12 +++++++++--- src/uxn/devices/apu.c | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index fa82999..222ffd4 100644 --- a/src/main.c +++ b/src/main.c @@ -114,7 +114,7 @@ screen_talk(Device *d, u8 b0, u8 w) { static void audio_talk(Device *d, u8 b0, u8 w) { - AudioChannel *c = &channels[0]; + AudioChannel *c = &channels[d - devaudio]; if(!w) { if(b0 == 0x2) { mempoke16(d->dat, 0x2, c->pos); @@ -123,12 +123,14 @@ audio_talk(Device *d, u8 b0, u8 w) { // d->dat[0x4] = apu_get_vu(c); } } else if(b0 == 0xf) { + u16 length = mempeek16(d->dat, 0xa); + // Disable the channel before updating. c->data = NULL; // Data. c->pos = 0; - c->length = mempeek16(d->dat, 0xa); + c->length = length; c->length <<= 12; // fixed point. c->data = &d->mem[mempeek16(d->dat, 0xc)]; @@ -148,7 +150,11 @@ audio_talk(Device *d, u8 b0, u8 w) { c->pitch = d->dat[0xf] & 0x7f; // Initialization. - c->inc = pitch_table_44100[c->pitch]; + if (length > 256) { + c->inc = pitch_table_44100[c->pitch]; + } else { + c->inc = pitch_table_variable[c->pitch] * length / AUDIO_FREQ; + } txt_position(0, 0); txt_printf("note: %d \n", c->pitch); diff --git a/src/uxn/devices/apu.c b/src/uxn/devices/apu.c index 96b9058..15eed20 100644 --- a/src/uxn/devices/apu.c +++ b/src/uxn/devices/apu.c @@ -17,6 +17,24 @@ static u32 pitch_table_44100[] = { 200547, 212472, 225107, 238492, 252674, 267699, 283617, 300482, }; +static u32 pitch_table_variable[] = { + 33484, 35475, 37585, 39820, 42188, 44696, 47354, 50170, + 53153, 56314, 59663, 63210, 66969, 70951, 75170, 79640, + 84376, 89393, 94709, 100341, 106307, 112628, 119326, 126421, + 133939, 141903, 150341, 159281, 168752, 178787, 189418, 200682, + 212615, 225257, 238652, 252843, 267878, 283807, 300683, 318562, + 337505, 357574, 378837, 401364, 425230, 450515, 477305, 505687, + 535756, 567614, 601366, 637125, 675011, 715149, 757674, 802728, + 850460, 901031, 954610, 1011374, 1071513, 1135229, 1202733, 1274251, + 1350022, 1430299, 1515349, 1605456, 1700921, 1802063, 1909220, 2022748, + 2143027, 2270458, 2405466, 2548503, 2700045, 2860598, 3030698, 3210912, + 3401843, 3604127, 3818440, 4045496, 4286054, 4540916, 4810933, 5097006, + 5400090, 5721196, 6061396, 6421825, 6803687, 7208255, 7636880, 8090993, + 8572108, 9081832, 9621866, 10194012, 10800180, 11442392, 12122792, 12843651, + 13607374, 14416511, 15273761, 16181986, 17144217, 18163665, 19243733, 20388025, + 21600360, 22884784, 24245585, 25687302, 27214749, 28833022, 30547522, 32363973, +}; + // // REG_TM0D frequency buffer size // | | | -- cgit v1.2.1