frac32 phase
frac32buffer.bipolar sine wave
frac32.u.map phase
objref Table containing the amplitudes (32bit)
objref Tuning table
class osc {
public:
void init();
};
class osc_one : public osc {
public:
int32_t prev;
void init() { prev = 0; }
void render(int32_t *pOut, int32_t amp, uint32_t freq, uint32_t phase,
float invfreq) {
// out: pointer to s32 output buffer, adds values
// amp: s32 amplitude
int32_t a = (int)(invfreq * amp);
int32_t _prev = prev;
int i = BUFSIZE;
while (i--) {
int32_t out = *pOut;
int32_t v2 = ___SMMUL(phase, phase);
int32_t d = (v2 - _prev);
out = __SMMLA(d, a, out);
_prev = v2;
phase += freq;
*pOut++ = out;
}
prev = _prev;
}
};
static const int n_octaves = 7;
class chroma {
int phase;
public:
osc_one octaves[n_octaves];
void init() {
phase = 0;
int i;
for (i = 0; i < n_octaves; i++) {
octaves[i].init();
}
};
void render(int freq, int32_t *out, int32_t *pAmp, uint32_t x) {
pAmp += 24;
phase += freq << 4;
uint32_t p = phase;
uint32_t f = freq;
float invfreq = (1 << 25) / (float)freq;
int i;
for (i = 0; i < n_octaves; i++) {
octaves[i].render(out, *pAmp, f, p + x, invfreq);
pAmp += 12;
p = p << 1;
f = f << 1;
invfreq = invfreq * 0.5f;
}
}
};
chroma chromas[12];
int i;
for (i = 0; i < 12; i++) {
chromas[i].init();
}
int i;
// clear
for (i = 0; i < BUFSIZE; i++) {
outlet_wave[i] = 0;
}
// sum into output buffer
for (i = 0; i < 12; i++) {
chromas[i].render(attr_tuning.array[i] >> 3, &outlet_wave[0],
&attr_amplitudes.array[i],
(param_phase + inlet_phase) << 5);
}
// output gain
for (i = 0; i < BUFSIZE; i++) {
outlet_wave[i] = outlet_wave[i] << 2;
}