musyx: link synth_ac.c

This commit is contained in:
Phillip Stephens 2022-09-04 02:30:03 -07:00
parent 174a2d98f7
commit 1179a651b3
2 changed files with 41 additions and 40 deletions

View File

@ -791,7 +791,7 @@ MUSYX_FILES :=\
$(BUILD_DIR)/asm/musyx/synthdata.o\
$(BUILD_DIR)/asm/musyx/synthmacros.o\
$(BUILD_DIR)/asm/musyx/synthvoice.o\
$(BUILD_DIR)/asm/musyx/synth_ac.o\
$(BUILD_DIR)/src/musyx/synth_ac.o\
$(BUILD_DIR)/asm/musyx/synth_adsr.o\
$(BUILD_DIR)/asm/musyx/synth_vsamples.o\
$(BUILD_DIR)/src/musyx/synth_dbtab.o\

View File

@ -2,53 +2,54 @@
extern SynthInfo synthInfo;
static float toneup_tab[128] = {
1.000000, 1.059464, 1.122462, 1.189207, 1.259921, 1.334840, 1.414214, 1.498307, 1.587401, 1.681793,
1.781798, 1.887749, 2.000001, 2.118927, 2.244925, 2.378415, 2.519843, 2.669681, 2.828428, 2.996615,
3.174804, 3.363587, 3.563597, 3.775498, 4.000002, 4.237854, 4.489850, 4.756830, 5.039686, 5.339362,
5.656857, 5.993231, 6.349607, 6.727175, 7.127193, 7.550998, 8.000004, 8.475709, 8.979701, 9.513661,
10.079373, 10.678724, 11.313714, 11.986463, 12.699215, 13.454350, 14.254387, 15.101996, 16.000008, 16.951418,
17.959402, 19.027323, 20.158747, 21.357449, 22.627428, 23.972925, 25.398430, 26.908699, 28.508774, 30.203993,
32.000015, 33.902836, 35.918804, 38.054646, 40.317493, 42.714897, 45.254856, 47.945850, 50.796860, 53.817398,
57.017548, 60.407986, 64.000031, 67.805672, 71.837608, 76.109291, 80.634987, 85.429794, 90.509712, 95.891701,
101.593719, 107.634796, 114.035095, 120.815971, 128.000061, 135.611343, 143.675217, 152.218582, 161.269974, 170.859589,
181.019424, 191.783401, 203.187439, 215.269592, 228.070190, 241.631943, 256.000122, 271.222687, 287.350433, 304.437164,
322.539948, 341.719177, 362.038849, 383.566803, 406.374878, 430.539185, 456.140381, 483.263885, 512.000244, 542.445374,
574.700867, 608.874329, 645.079895, 683.438354, 724.077698, 767.133606, 812.749756, 861.078369, 912.280762, 966.527771,
1024.000488, 1084.890747, 1149.401733, 1217.748657, 1290.159790, 1366.876709, 1448.155396, 1534.267212,
float toneup_tab[128] = {
1.0f, 1.0594635f, 1.1224623f, 1.1892071f, 1.2599211f, 1.3348398f, 1.4142141f, 1.4983072f, 1.5874014f, 1.6817932f, 1.7817984f,
1.8877487f, 2.000001f, 2.118927f, 2.2449245f, 2.378415f, 2.519843f, 2.6696806f, 2.8284283f, 2.9966154f, 3.1748037f, 3.3635874f,
3.5635967f, 3.7754984f, 4.000002f, 4.237854f, 4.48985f, 4.75683f, 5.039686f, 5.339362f, 5.6568565f, 5.993231f, 6.3496075f,
6.7271748f, 7.1271935f, 7.5509977f, 8.000004f, 8.475709f, 8.979701f, 9.513661f, 10.079373f, 10.678724f, 11.313714f, 11.986463f,
12.699215f, 13.4543495f, 14.254387f, 15.101996f, 16.000008f, 16.951418f, 17.959402f, 19.027323f, 20.158747f, 21.357449f, 22.627428f,
23.972925f, 25.39843f, 26.908699f, 28.508774f, 30.203993f, 32.000015f, 33.902836f, 35.918804f, 38.054646f, 40.317493f, 42.714897f,
45.254856f, 47.94585f, 50.79686f, 53.817398f, 57.017548f, 60.407986f, 64.00003f, 67.80567f, 71.83761f, 76.10929f, 80.63499f,
85.429794f, 90.50971f, 95.8917f, 101.59372f, 107.634796f, 114.035095f, 120.81597f, 128.00006f, 135.61134f, 143.67522f, 152.21858f,
161.26997f, 170.85959f, 181.01942f, 191.7834f, 203.18744f, 215.26959f, 228.07019f, 241.63194f, 256.00012f, 271.2227f, 287.35043f,
304.43716f, 322.53995f, 341.71918f, 362.03885f, 383.5668f, 406.37488f, 430.53918f, 456.14038f, 483.2639f, 512.00024f, 542.4454f,
574.70087f, 608.8743f, 645.0799f, 683.43835f, 724.0777f, 767.1336f, 812.74976f, 861.07837f, 912.28076f, 966.5278f, 1024.0005f,
1084.8907f, 1149.4017f, 1217.7487f, 1290.1598f, 1366.8767f, 1448.1554f, 1534.2672f,
};
static float tonedown_tab[128] = {
1.000000, 0.943874, 0.890899, 0.840897, 0.793700, 0.749153, 0.707107, 0.667419, 0.629960, 0.594604, 0.561231, 0.529732, 0.500000,
0.471937, 0.445449, 0.420448, 0.396851, 0.374577, 0.353553, 0.333710, 0.314981, 0.297301, 0.280616, 0.264866, 0.250000, 0.235969,
0.222725, 0.210224, 0.198425, 0.187288, 0.176777, 0.166855, 0.157490, 0.148651, 0.140307, 0.132433, 0.125000, 0.117984, 0.111362,
0.105112, 0.099213, 0.093644, 0.088388, 0.083427, 0.078745, 0.074326, 0.070154, 0.066216, 0.062500, 0.058992, 0.055681, 0.052556,
0.049606, 0.046823, 0.044194, 0.041714, 0.039372, 0.037163, 0.035077, 0.033108, 0.031250, 0.029496, 0.027841, 0.026278, 0.024803,
0.023411, 0.022097, 0.020857, 0.019687, 0.018581, 0.017538, 0.016554, 0.015625, 0.014748, 0.013920, 0.013139, 0.012402, 0.011705,
0.011048, 0.010428, 0.009843, 0.009291, 0.008769, 0.008277, 0.007812, 0.007374, 0.006960, 0.006570, 0.006201, 0.005853, 0.005525,
0.005215, 0.004922, 0.004645, 0.004385, 0.004139, 0.003906, 0.003687, 0.003480, 0.003284, 0.003100, 0.002927, 0.002762, 0.002607,
0.002460, 0.002322, 0.002192, 0.002069, 0.001953, 0.001843, 0.001740, 0.001642, 0.001550, 0.001463, 0.001381, 0.001304, 0.001230,
0.001162, 0.001096, 0.001035, 0.000977, 0.000922, 0.000870, 0.000821, 0.000775, 0.000731, 0.000690, 0.000651,
float tonedown_tab[128] = {
1.0f, 0.94387436f, 0.8908987f, 0.8408966f, 0.7937002f, 0.74915314f, 0.7071066f, 0.66741943f,
0.62996006f, 0.59460354f, 0.56123066f, 0.52973175f, 0.5f, 0.47193718f, 0.44544888f, 0.4204483f,
0.3968506f, 0.37457657f, 0.35355282f, 0.33370972f, 0.3149805f, 0.2973013f, 0.2806158f, 0.26486588f,
0.25f, 0.23596859f, 0.22272491f, 0.21022415f, 0.1984253f, 0.18728828f, 0.17677689f, 0.16685486f,
0.15748978f, 0.14865112f, 0.14030743f, 0.13243294f, 0.125f, 0.11798382f, 0.11136246f, 0.105112076f,
0.09921265f, 0.09364414f, 0.08838844f, 0.08342743f, 0.07874489f, 0.07432556f, 0.07015419f, 0.06621647f,
0.0625f, 0.058992386f, 0.05568123f, 0.052556038f, 0.049606323f, 0.046822548f, 0.04419422f, 0.041713715f,
0.039372444f, 0.03716278f, 0.035077095f, 0.033107758f, 0.03125f, 0.029496193f, 0.027840614f, 0.026277542f,
0.024803162f, 0.023410797f, 0.022096634f, 0.020856857f, 0.019686699f, 0.01858139f, 0.01753807f, 0.016553879f,
0.015625f, 0.01474762f, 0.01391983f, 0.013138771f, 0.012401581f, 0.011705399f, 0.011048317f, 0.010428429f,
0.009842873f, 0.009290695f, 0.008769035f, 0.008276939f, 0.0078125f, 0.00737381f, 0.006959915f, 0.0065698624f,
0.0062007904f, 0.0058526993f, 0.0055246353f, 0.005214691f, 0.004921913f, 0.0046453476f, 0.0043849945f, 0.0041389465f,
0.00390625f, 0.003686905f, 0.0034799576f, 0.0032844543f, 0.0031003952f, 0.0029268265f, 0.0027618408f, 0.0026073456f,
0.0024604797f, 0.002322197f, 0.0021924973f, 0.0020694733f, 0.001953125f, 0.0018434525f, 0.0017404556f, 0.0016422272f,
0.0015497208f, 0.0014629364f, 0.0013809204f, 0.0013036728f, 0.0012302399f, 0.0011615753f, 0.0010957718f, 0.0010347366f,
9.765625E-4f, 9.2220306E-4f, 8.69751E-4f, 8.211136E-4f, 7.753372E-4f, 7.314682E-4f, 6.904602E-4f, 6.5135956E-4f,
};
s32 sndPitchUpOne(u16 note) { return note * 1.059463f; }
s32 sndPitchUpOne(u16 note) { return note * 1.0594631f; }
/* non-matching https://decomp.me/scratch/6pRdi */
u32 sndGetPitch(u8 arg0, u32 arg1) {
f32 var_f0;
float scale;
f32 pitch;
double tmp;
u32 temp_r6;
float freq;
if (arg1 == 0xFFFFFFFF) {
arg1 = 0x40005622;
}
scale = 4096.f;
temp_r6 = (arg1 >> 0x18U);
if (arg0 != temp_r6) {
var_f0 = (f32)((arg1 & 0xFFFFFF) * (temp_r6 < arg0 ? toneup_tab[(arg0 - temp_r6)] : tonedown_tab[temp_r6 - arg0]));
} else {
var_f0 = (f32)(arg1 & 0xFFFFFF);
}
scale *= var_f0;
return (u32)(scale / synthInfo.freq);
pitch = 4096.f;
temp_r6 = (arg1 >> 24);
pitch *= (f32)(arg0 != temp_r6 ? (f32)((arg1 & 0xFFFFFF) * (temp_r6 < arg0 ? toneup_tab[(arg0 - temp_r6)] : tonedown_tab[temp_r6 - arg0]))
: (f32)(arg1 & 0xFFFFFF));
return pitch / synthInfo.freq;
}