aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-05-26 17:31:51 +0200
committerBad Diode <bd@badd10de.dev>2021-05-26 17:31:51 +0200
commit08550442afb4867cdf9873ca8272fd5a02e05433 (patch)
tree13665c1e60812338d06b11400b971ae48861076d
parent0c0a2e17acaa0684f60ccbe8465407c945d6e2d0 (diff)
downloaduxngba-08550442afb4867cdf9873ca8272fd5a02e05433.tar.gz
uxngba-08550442afb4867cdf9873ca8272fd5a02e05433.zip
Add pitch table for audio resampling at 44100Hz
-rw-r--r--src/main.c11
-rw-r--r--src/uxn/devices/apu.c44
2 files changed, 24 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c
index a5a0628..fa82999 100644
--- a/src/main.c
+++ b/src/main.c
@@ -126,11 +126,8 @@ audio_talk(Device *d, u8 b0, u8 w) {
126 // Disable the channel before updating. 126 // Disable the channel before updating.
127 c->data = NULL; 127 c->data = NULL;
128 128
129 // Initialization.
130 c->inc = (44100 << 12) / AUDIO_FREQ;
131 c->pos = 0;
132
133 // Data. 129 // Data.
130 c->pos = 0;
134 c->length = mempeek16(d->dat, 0xa); 131 c->length = mempeek16(d->dat, 0xa);
135 c->length <<= 12; // fixed point. 132 c->length <<= 12; // fixed point.
136 c->data = &d->mem[mempeek16(d->dat, 0xc)]; 133 c->data = &d->mem[mempeek16(d->dat, 0xc)];
@@ -149,8 +146,14 @@ audio_talk(Device *d, u8 b0, u8 w) {
149 146
150 // Pitch 147 // Pitch
151 c->pitch = d->dat[0xf] & 0x7f; 148 c->pitch = d->dat[0xf] & 0x7f;
149
150 // Initialization.
151 c->inc = pitch_table_44100[c->pitch];
152
152 txt_position(0, 0); 153 txt_position(0, 0);
153 txt_printf("note: %d \n", c->pitch); 154 txt_printf("note: %d \n", c->pitch);
155 txt_printf("inc: %ld \n", c->inc);
156 txt_printf("length: %ld \n", c->length >> 12);
154 } 157 }
155} 158}
156 159
diff --git a/src/uxn/devices/apu.c b/src/uxn/devices/apu.c
index 2b1c8ff..96b9058 100644
--- a/src/uxn/devices/apu.c
+++ b/src/uxn/devices/apu.c
@@ -1,32 +1,22 @@
1#define SAMPLE_FREQUENCY 44100 1// Calculated as (44100 << 12) / 18157 for C4
2#define NOTE_PERIOD (SAMPLE_FREQUENCY * 0x4000 / 11025) 2static u32 pitch_table_44100[] = {
3#define ADSR_STEP (SAMPLE_FREQUENCY / 0xf) 3 310, 329, 348, 369, 391, 414, 439, 465,
4 4 493, 522, 553, 586, 621, 658, 697, 739,
5static u16 pitch_table[] = { 5 783, 829, 879, 931, 987, 1045, 1107, 1173,
6 12173, 11490, 10845, 10237, 9662, 9120, 8608, 8125, 6 1243, 1317, 1395, 1478, 1566, 1659, 1758, 1863,
7 7669, 7238, 6832, 6448, 6086, 5745, 5422, 5118, 7 1974, 2091, 2215, 2347, 2487, 2634, 2791, 2957,
8 4831, 4560, 4304, 4062, 3834, 3619, 3416, 3224, 8 3133, 3319, 3517, 3726, 3948, 4182, 4431, 4695,
9 3043, 2872, 2711, 2559, 2415, 2280, 2152, 2031, 9 4974, 5269, 5583, 5915, 6267, 6639, 7034, 7452,
10 1917, 1809, 1708, 1612, 1521, 1436, 1355, 1279, 10 7896, 8365, 8863, 9390, 9948, 10539, 11166, 11830,
11 1207, 1140, 1076, 1015, 958, 904, 854, 806, 11 12534, 13279, 14069, 14905, 15792, 16731, 17726, 18780,
12 760, 718, 677, 639, 603, 570, 538, 507, 12 19896, 21079, 22333, 23661, 25068, 26559, 28138, 29811,
13 479, 452, 427, 403, 380, 359, 338, 319, 13 31584, 33462, 35452, 37560, 39793, 42159, 44666, 47322,
14 301, 285, 269, 253, 239, 226, 213, 201, 14 50136, 53118, 56276, 59623, 63168, 66924, 70904, 75120,
15 190, 179, 169, 159, 150, 142, 134, 126, 15 79587, 84319, 89333, 94645, 100273, 106236, 112553, 119246,
16 119, 113, 106, 100, 95, 89, 84, 79, 16 126337, 133849, 141808, 150241, 159174, 168639, 178667, 189291,
17 75, 71, 67, 63, 59, 56, 53, 50, 17 200547, 212472, 225107, 238492, 252674, 267699, 283617, 300482,
18 47, 44, 42, 39, 37, 35, 33, 31,
19 29, 28, 26, 25, 23, 22, 21, 19,
20 18, 17, 16, 15, 14, 14, 13, 12,
21 2,
22}; 18};
23 19
24s8 square_wave[] = {
25 (s8)0x00 + (s8)0x80, (s8)0xFF + (s8)0x80
26};
27
28#include "text.h"
29
30// 20//
31// REG_TM0D frequency buffer size 21// REG_TM0D frequency buffer size
32// | | | 22// | | |