aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-26 18:37:53 +0200
committerBad Diode <bd@badd10de.dev>2021-05-26 18:37:53 +0200
commit8fc709cc1d69c911ac36d18ea3fd6e3da3efc3f4 (patch)
tree917605be74c11d6407a4fe0ff09fdfc91d28e3a8 /src
parent08550442afb4867cdf9873ca8272fd5a02e05433 (diff)
downloaduxngba-8fc709cc1d69c911ac36d18ea3fd6e3da3efc3f4.tar.gz
uxngba-8fc709cc1d69c911ac36d18ea3fd6e3da3efc3f4.zip
[WIP] Add variable sample support and multichannel
Diffstat (limited to 'src')
-rw-r--r--src/main.c12
-rw-r--r--src/uxn/devices/apu.c18
2 files changed, 27 insertions, 3 deletions
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) {
114 114
115static void 115static void
116audio_talk(Device *d, u8 b0, u8 w) { 116audio_talk(Device *d, u8 b0, u8 w) {
117 AudioChannel *c = &channels[0]; 117 AudioChannel *c = &channels[d - devaudio];
118 if(!w) { 118 if(!w) {
119 if(b0 == 0x2) { 119 if(b0 == 0x2) {
120 mempoke16(d->dat, 0x2, c->pos); 120 mempoke16(d->dat, 0x2, c->pos);
@@ -123,12 +123,14 @@ audio_talk(Device *d, u8 b0, u8 w) {
123 // d->dat[0x4] = apu_get_vu(c); 123 // d->dat[0x4] = apu_get_vu(c);
124 } 124 }
125 } else if(b0 == 0xf) { 125 } else if(b0 == 0xf) {
126 u16 length = mempeek16(d->dat, 0xa);
127
126 // Disable the channel before updating. 128 // Disable the channel before updating.
127 c->data = NULL; 129 c->data = NULL;
128 130
129 // Data. 131 // Data.
130 c->pos = 0; 132 c->pos = 0;
131 c->length = mempeek16(d->dat, 0xa); 133 c->length = length;
132 c->length <<= 12; // fixed point. 134 c->length <<= 12; // fixed point.
133 c->data = &d->mem[mempeek16(d->dat, 0xc)]; 135 c->data = &d->mem[mempeek16(d->dat, 0xc)];
134 136
@@ -148,7 +150,11 @@ audio_talk(Device *d, u8 b0, u8 w) {
148 c->pitch = d->dat[0xf] & 0x7f; 150 c->pitch = d->dat[0xf] & 0x7f;
149 151
150 // Initialization. 152 // Initialization.
151 c->inc = pitch_table_44100[c->pitch]; 153 if (length > 256) {
154 c->inc = pitch_table_44100[c->pitch];
155 } else {
156 c->inc = pitch_table_variable[c->pitch] * length / AUDIO_FREQ;
157 }
152 158
153 txt_position(0, 0); 159 txt_position(0, 0);
154 txt_printf("note: %d \n", c->pitch); 160 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[] = {
17 200547, 212472, 225107, 238492, 252674, 267699, 283617, 300482, 17 200547, 212472, 225107, 238492, 252674, 267699, 283617, 300482,
18}; 18};
19 19
20static u32 pitch_table_variable[] = {
21 33484, 35475, 37585, 39820, 42188, 44696, 47354, 50170,
22 53153, 56314, 59663, 63210, 66969, 70951, 75170, 79640,
23 84376, 89393, 94709, 100341, 106307, 112628, 119326, 126421,
24 133939, 141903, 150341, 159281, 168752, 178787, 189418, 200682,
25 212615, 225257, 238652, 252843, 267878, 283807, 300683, 318562,
26 337505, 357574, 378837, 401364, 425230, 450515, 477305, 505687,
27 535756, 567614, 601366, 637125, 675011, 715149, 757674, 802728,
28 850460, 901031, 954610, 1011374, 1071513, 1135229, 1202733, 1274251,
29 1350022, 1430299, 1515349, 1605456, 1700921, 1802063, 1909220, 2022748,
30 2143027, 2270458, 2405466, 2548503, 2700045, 2860598, 3030698, 3210912,
31 3401843, 3604127, 3818440, 4045496, 4286054, 4540916, 4810933, 5097006,
32 5400090, 5721196, 6061396, 6421825, 6803687, 7208255, 7636880, 8090993,
33 8572108, 9081832, 9621866, 10194012, 10800180, 11442392, 12122792, 12843651,
34 13607374, 14416511, 15273761, 16181986, 17144217, 18163665, 19243733, 20388025,
35 21600360, 22884784, 24245585, 25687302, 27214749, 28833022, 30547522, 32363973,
36};
37
20// 38//
21// REG_TM0D frequency buffer size 39// REG_TM0D frequency buffer size
22// | | | 40// | | |