Browse code

added microtonality to the audio device

Cellmaker authored on 28/07/2023 16:09:09 • Devine Lu Linvega committed on 30/07/2023 22:03:34
Showing 1 changed files
... ...
@@ -30,6 +30,95 @@ static Uint32 advances[12] = {
30 30
 	0xb504f, 0xbfc88, 0xcb2ff, 0xd7450, 0xe411f, 0xf1a1c
31 31
 };
32 32
 
33
+static double detunes[256] = {
34
+1.0000000000000000, 1.0002256593050698, 1.0004513695322617, 
35
+1.0006771306930664, 1.0009029427989777, 1.0011288058614922, 
36
+1.0013547198921082, 1.0015806849023274, 1.0018067009036538, 
37
+1.002032767907594 , 1.0022588859256572, 1.0024850549693551, 
38
+1.0027112750502025, 1.0029375461797159, 1.0031638683694153, 
39
+1.0033902416308227, 1.0036166659754628, 1.0038431414148634, 
40
+1.004069667960554 , 1.0042962456240678, 1.0045228744169397, 
41
+1.0047495543507072, 1.004976285436911 , 1.0052030676870944, 
42
+1.0054299011128027, 1.0056567857255843, 1.0058837215369900, 
43
+1.006110708558573 , 1.0063377468018897, 1.0065648362784985, 
44
+1.0067919769999607, 1.0070191689778405, 1.007246412223704 , 
45
+1.0074737067491204, 1.0077010525656616, 1.0079284496849015, 
46
+1.0081558981184175, 1.008383397877789 , 1.008610948974598 , 
47
+1.0088385514204294, 1.0090662052268706, 1.0092939104055114, 
48
+1.0095216669679448, 1.0097494749257656, 1.009977334290572 , 
49
+1.0102052450739643, 1.0104332072875455, 1.0106612209429215, 
50
+1.0108892860517005, 1.0111174026254934, 1.0113455706759138, 
51
+1.011573790214578 , 1.0118020612531047, 1.0120303838031153, 
52
+1.0122587578762337, 1.012487183484087 , 1.012715660638304 , 
53
+1.0129441893505169, 1.0131727696323602, 1.0134014014954713, 
54
+1.0136300849514894, 1.0138588200120575, 1.0140876066888203, 
55
+1.0143164449934257, 1.0145453349375237, 1.0147742765327674, 
56
+1.0150032697908125, 1.015232314723317 , 1.015461411341942 , 
57
+1.0156905596583505, 1.0159197596842091, 1.0161490114311862, 
58
+1.016378314910953 , 1.0166076701351838, 1.0168370771155553, 
59
+1.0170665358637463, 1.0172960463914391, 1.017525608710318 , 
60
+1.0177552228320703, 1.0179848887683858, 1.0182146065309567, 
61
+1.0184443761314785, 1.0186741975816487, 1.0189040708931674, 
62
+1.019133996077738 , 1.0193639731470658, 1.0195940021128593, 
63
+1.0198240829868295, 1.0200542157806898, 1.0202844005061564, 
64
+1.0205146371749483, 1.0207449257987866, 1.0209752663893958, 
65
+1.0212056589585028, 1.0214361035178368, 1.0216666000791297, 
66
+1.0218971486541166, 1.0221277492545349, 1.0223584018921241, 
67
+1.0225891065786274, 1.02281986332579  , 1.0230506721453596, 
68
+1.023281533049087 , 1.0235124460487257, 1.0237434111560313, 
69
+1.0239744283827625, 1.0242054977406807, 1.0244366192415495, 
70
+1.0246677928971357, 1.0248990187192082, 1.025130296719539 , 
71
+1.0253616269099028, 1.0255930093020766, 1.0258244439078401, 
72
+1.026055930738976 , 1.0262874698072693, 1.0265190611245079, 
73
+1.0267507047024822, 1.0269824005529853, 1.027214148687813 , 
74
+1.0274459491187637, 1.0276778018576387, 1.0279097069162415, 
75
+1.0281416643063788, 1.0283736740398595, 1.0286057361284953, 
76
+1.028837850584101 , 1.0290700174184932, 1.029302236643492 , 
77
+1.0295345082709197, 1.0297668323126017, 1.029999208780365 , 
78
+1.030231637686041 , 1.030464119041462 , 1.0306966528584645, 
79
+1.0309292391488862, 1.0311618779245688, 1.0313945691973556, 
80
+1.0316273129790936, 1.0318601092816313, 1.0320929581168212, 
81
+1.0323258594965172, 1.0325588134325767, 1.0327918199368598, 
82
+1.0330248790212284, 1.033257990697548 , 1.0334911549776868, 
83
+1.033724371873515 , 1.0339576413969056, 1.0341909635597348, 
84
+1.0344243383738811, 1.034657765851226 , 1.034891246003653 , 
85
+1.0351247788430489, 1.0353583643813031, 1.0355920026303078, 
86
+1.0358256936019572, 1.0360594373081489, 1.0362932337607829, 
87
+1.0365270829717617, 1.0367609849529913, 1.0369949397163791, 
88
+1.0372289472738365, 1.0374630076372766, 1.0376971208186156, 
89
+1.0379312868297725, 1.0381655056826686, 1.0383997773892284, 
90
+1.0386341019613787, 1.0388684794110492, 1.039102909750172 , 
91
+1.0393373929906822, 1.0395719291445176, 1.0398065182236185, 
92
+1.0400411602399278, 1.0402758552053915, 1.0405106031319582, 
93
+1.0407454040315787, 1.040980257916207 , 1.0412151647977996, 
94
+1.041450124688316 , 1.0416851375997183, 1.0419202035439705, 
95
+1.0421553225330404, 1.042390494578898 , 1.042625719693516 , 
96
+1.0428609978888699, 1.043096329176938 , 1.043331713569701 , 
97
+1.0435671510791424, 1.0438026417172486, 1.0440381854960086, 
98
+1.0442737824274138, 1.044509432523459 , 1.044745135796141 , 
99
+1.04498089225746  , 1.045216701919418 , 1.0454525647940205, 
100
+1.0456884808932754, 1.0459244502291931, 1.0461604728137874, 
101
+1.046396548659074 , 1.046632677777072 , 1.0468688601798024, 
102
+1.0471050958792898, 1.047341384887561 , 1.0475777272166455, 
103
+1.047814122878576 , 1.048050571885387 , 1.0482870742491166, 
104
+1.0485236299818055, 1.0487602390954964, 1.0489969016022356, 
105
+1.0492336175140715, 1.0494703868430555, 1.0497072096012419, 
106
+1.0499440858006872, 1.0501810154534512, 1.050417998571596 , 
107
+1.0506550351671864, 1.0508921252522903, 1.0511292688389782, 
108
+1.051366465939323 , 1.0516037165654004, 1.0518410207292894, 
109
+1.052078378443071 , 1.0523157897188296, 1.0525532545686513, 
110
+1.0527907730046264, 1.0530283450388465, 1.0532659706834067, 
111
+1.053503649950405 , 1.053741382851941 , 1.0539791694001188, 
112
+1.0542170096070436, 1.0544549034848243, 1.0546928510455722, 
113
+1.0549308523014012, 1.0551689072644284, 1.0554070159467728, 
114
+1.0556451783605572, 1.0558833945179062, 1.056121664430948 , 
115
+1.0563599881118126, 1.0565983655726334, 1.0568367968255465, 
116
+1.0570752818826903, 1.0573138207562065, 1.057552413458239 , 
117
+1.0577910600009348, 1.0580297603964437, 1.058268514656918 , 
118
+1.0585073227945128, 1.0587461848213857, 1.058985100749698 , 
119
+1.0592240705916123, 
120
+};
121
+
33 122
 static UxnAudio uxn_audio[POLYPHONY];
34 123
 
35 124
 /* clang-format on */
... ...
@@ -76,6 +165,7 @@ audio_start(int instance, Uint8 *d, Uxn *u)
76 165
 {
77 166
 	UxnAudio *c = &uxn_audio[instance];
78 167
 	Uint8 pitch = d[0xf] & 0x7f;
168
+	Uint8 detune = d[0x5];
79 169
 	Uint16 addr = PEEK2(d + 0xc), adsr = PEEK2(d + 0x8);
80 170
 	c->len = PEEK2(d + 0xa);
81 171
 	if(c->len > 0x10000 - addr)
... ...
@@ -85,7 +175,7 @@ audio_start(int instance, Uint8 *d, Uxn *u)
85 175
 	c->volume[1] = d[0xe] & 0xf;
86 176
 	c->repeat = !(d[0xf] & 0x80);
87 177
 	if(pitch < 108 && c->len)
88
-		c->advance = advances[pitch % 12] >> (8 - pitch / 12);
178
+		c->advance = (Uint32)((double)(advances[pitch % 12]) * detunes[detune]) >> (8 - pitch / 12);
89 179
 	else {
90 180
 		c->advance = 0;
91 181
 		return;