frac32 pitch
int32 key
frac32 scaled
int32 C
int32 cis
int32 D
int32 dis
int32 E
int32 F
int32 fis
int32 G
int32 gis
int32 A
int32 ais
int32 B
bool32 C
bool32 cis
bool32 D
bool32 dis
bool32 E
bool32 F
bool32 fis
bool32 G
bool32 gis
bool32 A
bool32 ais
bool32 B
;
int8_t octave;
int8_t semitone;
float32_t freq;
int32_t scaled;
int32_t frac_log(int32_t a) {
Float_t f;
f.f = a;
int32_t r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
int32_t r3 = logt[f.parts.mantissa >> 15] << 10;
return r1 + r3;
}
int16_t lfo;
Float_t f;
float32_t intfreq;
float32_t LOG1;
float32_t LOG2;
float32_t LOG3;
int32_t r1;
int32_t r2;
float32_t base;
float32_t scale[24];
float32_t nt[98] = {1,
(float)(128) / 125,
(float)(40) / 39,
(float)(33) / 32,
(float)(25) / 24,
(float)(21) / 20,
(float)(256) / 243,
(float)(35) / 33,
(float)(17) / 16,
(float)(16) / 15,
(float)(15) / 14,
(float)(14) / 13,
(float)(12) / 11,
(float)(1125) / 1024,
(float)(11) / 10,
(float)(10) / 9,
(float)(28) / 25,
(float)(9) / 8,
(float)(256) / 225,
(float)(8) / 7,
(float)(144) / 125,
(float)(15) / 13,
(float)(7) / 6,
(float)(75) / 64,
(float)(33) / 28,
(float)(13) / 11,
(float)(32) / 27,
(float)(19) / 16,
(float)(25) / 21,
(float)(6) / 5,
(float)(40) / 33,
(float)(11) / 9,
(float)(16) / 13,
(float)(5) / 4,
(float)(81) / 64,
(float)(14) / 11,
(float)(32) / 25,
(float)(9) / 7,
(float)(13) / 10,
(float)(125) / 96,
(float)(21) / 16,
(float)(33) / 25,
(float)(4) / 3,
(float)(27) / 20,
(float)(15) / 11,
(float)(512) / 375,
(float)(11) / 8,
(float)(25) / 18,
(float)(7) / 5,
(float)(45) / 32,
(float)(64) / 45,
(float)(729) / 512,
(float)(10) / 7,
(float)(36) / 25,
(float)(13) / 9,
(float)(16) / 11,
(float)(35) / 24,
(float)(375) / 256,
(float)(3) / 2,
(float)(32) / 21,
(float)(192) / 125,
(float)(20) / 13,
(float)(14) / 9,
(float)(25) / 16,
(float)(11) / 7,
(float)(128) / 81,
(float)(8) / 5,
(float)(21) / 13,
(float)(13) / 8,
(float)(18) / 11,
(float)(33) / 20,
(float)(5) / 3,
(float)(27) / 16,
(float)(128) / 75,
(float)(12) / 7,
(float)(125) / 72,
(float)(7) / 4,
(float)(225) / 128,
(float)(16) / 9,
(float)(24) / 14,
(float)(9) / 5,
(float)(20) / 11,
(float)(2048) / 1125,
(float)(11) / 6,
(float)(24) / 13,
(float)(13) / 7,
(float)(28) / 15,
(float)(15) / 8,
(float)(243) / 128,
(float)(40) / 21,
(float)(21) / 11,
(float)(48) / 25,
(float)(25) / 13,
(float)(35) / 18,
(float)(125) / 64};
base = ((float32_t)330) / 1000;
f.f = 2 << 21;
r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
r2 = logt[f.parts.mantissa >> 15] << 10;
LOG3 = r1 + r2;
f.f = base * (4 << 21);
r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
r2 = logt[f.parts.mantissa >> 15] << 10;
LOG2 = r1 + r2;
lfo = (lfo + 1) & 1023;
int32_t gate;
gate = lfo > 512 ? 1 : 0;
int32_t pitch = (inlet_pitch >> 21) + 48;
octave = pitch / 12;
semitone = pitch - octave * 12;
octave = octave - 4;
int32_t key;
key = inlet_key >= 0 ? inlet_key * 7 : -inlet_key * 5 - 3;
key = key - (key / 12) * 12;
key = key < 0 ? key + 12 : key;
scale[12] = nt[0 + param_C];
scale[13] = nt[9 + param_cis];
scale[14] = nt[18 + param_D];
scale[15] = nt[30 + param_dis];
scale[16] = nt[34 + param_E];
scale[17] = nt[43 + param_F];
scale[18] = nt[52 + param_fis];
scale[19] = nt[60 + param_G];
scale[20] = nt[68 + param_gis];
scale[21] = nt[73 + param_A];
scale[22] = nt[82 + param_ais];
scale[23] = nt[89 + param_B];
int32_t C;
int32_t D;
int32_t E;
int32_t F;
int32_t G;
int32_t A;
int32_t B;
if (inlet_key >= 0) {
C = 0 + key;
D = 2 + key;
E = 4 + key;
F = 5 + key;
G = 7 + key;
A = 9 + key;
B = 11 + key;
}
if (inlet_key < 0) {
C = 0 + key;
D = 2 + key;
E = 3 + key;
F = 5 + key;
G = 7 + key;
A = 8 + key;
B = 10 + key;
}
C = C - (C / 12) * 12;
D = D - (D / 12) * 12;
E = E - (E / 12) * 12;
F = F - (F / 12) * 12;
G = G - (G / 12) * 12;
A = A - (A / 12) * 12;
B = B - (B / 12) * 12;
disp_C = (C == 0) || (D == 0) || (E == 0) || (F == 0) || (G == 0) || (A == 0) ||
(B == 0);
disp_cis = (C == 1) || (D == 1) || (E == 1) || (F == 1) || (G == 1) ||
(A == 1) || (B == 1);
disp_D = (C == 2) || (D == 2) || (E == 2) || (F == 2) || (G == 2) || (A == 2) ||
(B == 2);
disp_dis = (C == 3) || (D == 3) || (E == 3) || (F == 3) || (G == 3) ||
(A == 3) || (B == 3);
disp_E = (C == 4) || (D == 4) || (E == 4) || (F == 4) || (G == 4) || (A == 4) ||
(B == 4);
disp_F = (C == 5) || (D == 5) || (E == 5) || (F == 5) || (G == 5) || (A == 5) ||
(B == 5);
disp_fis = (C == 6) || (D == 6) || (E == 6) || (F == 6) || (G == 6) ||
(A == 6) || (B == 6);
disp_G = (C == 7) || (D == 7) || (E == 7) || (F == 7) || (G == 7) || (A == 7) ||
(B == 7);
disp_gis = (C == 8) || (D == 8) || (E == 8) || (F == 8) || (G == 8) ||
(A == 8) || (B == 8);
disp_A = (C == 9) || (D == 9) || (E == 9) || (F == 9) || (G == 9) || (A == 9) ||
(B == 9);
disp_ais = (C == 10) || (D == 10) || (E == 10) || (F == 10) || (G == 10) ||
(A == 10) || (B == 10);
disp_B = (C == 11) || (D == 11) || (E == 11) || (F == 11) || (G == 11) ||
(A == 11) || (B == 11);
switch (key > 0 ? key : 0) {
case 0:
disp_A = disp_C = gate;
break;
case 1:
disp_cis = gate;
break;
case 2:
disp_D = gate;
break;
case 3:
disp_dis = gate;
break;
case 4:
disp_E = gate;
break;
case 5:
disp_F = gate;
break;
case 6:
disp_fis = gate;
break;
case 7:
disp_G = gate;
break;
case 8:
disp_gis = gate;
break;
case 9:
disp_A = gate;
break;
case 10:
disp_ais = gate;
break;
case 11:
disp_B = gate;
break;
}
C += 12;
D += 12;
E += 12;
F += 12;
G += 12;
A += 12;
B += 12;
scale[0] = scale[C];
scale[1] = scale[C];
scale[2] = scale[D];
scale[3] = scale[D];
scale[4] = scale[E];
scale[5] = scale[F];
scale[6] = scale[F];
scale[7] = scale[G];
scale[8] = scale[G];
scale[9] = scale[A];
scale[10] = scale[A];
scale[11] = scale[B];
if (octave >= 0) {
intfreq = (base * scale[semitone + 12]) * (1 << octave);
}
if (octave < 0) {
intfreq = (base * scale[semitone + 12]) / (1 << -octave);
}
f.f = intfreq * (4 << 21);
r1 = ((f.parts.exponent & 0x7F) - 18) << 24;
r2 = logt[f.parts.mantissa >> 15] << 10;
LOG1 = r1 + r2;
outlet_scaled = ((LOG1 - LOG2) / LOG3) * (36 << 21);