18 #include "tables/cos8192_int8.h"
25 enum algorithms {SINGLE,DOUBLE};
35 template <int8_t ALGORITHM>
44 aCos.setTable(COS8192_DATA);
57 void set(
int fundamental,
int bandwidth,
int centrefreq)
72 aPhasor.setFreq(fundamental);
87 Q15n16 bw = invFreq*bandwidth;
90 aBandwidth.set(bw, AUDIO_STEPS_PER_CONTROL);
102 Q15n16 cf = invFreq * centrefreq;
104 aCentrefreq.set(cf, AUDIO_STEPS_PER_CONTROL);
115 gcentrefreq = aCentrefreq.next();
116 gbandwidth = aBandwidth.next();
117 int phase1 = aPhasor.next()>>16;
118 if (ALGORITHM == DOUBLE) {
119 return (signalPath(params1, phase1)+signalPath(params2, phase1+32768))>>1;
121 return signalPath(params1, phase1);
148 const unsigned int AUDIO_STEPS_PER_CONTROL;
150 Oscil <COS8192_NUM_CELLS, MOZZI_AUDIO_RATE> aCos;
151 Phasor <MOZZI_AUDIO_RATE> aPhasor;
155 int signalPath(
struct parameters ¶m,
int phase)
160 if(phase<param.previous_phase)
162 param.centrefreq = gcentrefreq>>8;
165 param.previous_phase = phase;
168 index = (param.centrefreq * phase)>>16;
170 index += COS8192_NUM_CELLS>>1;
171 index &= COS8192_NUM_CELLS-1;
172 int8_t sig1 = aCos.atIndex(index);
175 Q23n8 bwphase = (param.bandwidth * phase)>>8;
176 bwphase += COS8192_NUM_CELLS>>1;
177 index = constrain(bwphase, 0, (COS8192_NUM_CELLS-1));
178 uint8_t packet_width = 128 + aCos.atIndex(index);
185 return ((
int) sig1 * packet_width);