22 #include "mozzi_fixmath.h"
31 template<u
int16_t NUM_TABLE_CELLS, u
int16_t UPDATE_RATE,
byte N_OSCIL>
40 current_osc=oscillators[0];};
60 oscillators[current_rank]=first;
61 if (current_rank == 0) current_osc=oscillators[0];
74 cutoff_freqs[current_rank]=first;
80 void setCutoffFreqs() {};
87 cutoff_freqs[rank] = freq;
94 int8_t
next() {
return current_osc->next();}
99 void setTable(
const int8_t * TABLE_NAME,
byte rank) {oscillators[rank]->setTable(TABLE_NAME);}
104 void setPhase(
unsigned int phase) {current_osc->setPhase(phase);}
126 int8_t
phMod(
Q15n16 phmod_proportion) {
return current_osc->phMod(phmod_proportion);}
135 template <
int8_t NI,
int8_t NF, u
int8_t RANGE>
137 int8_t
phMod(SFix<NI,NF,RANGE> phmod_proportion)
139 return current_osc->phMod(phmod_proportion);
151 int8_t
phMod(SFix<15,16> phmod_proportion)
153 return current_osc->phMod(phmod_proportion);
160 void setFreq(
int frequency,
bool apply =
true)
162 if (frequency < cutoff_freqs[0])
164 oscillators[0]->setPhaseFractional(current_osc->getPhaseFractional());
165 current_osc = oscillators[0];
166 current_osc->setFreq(frequency);
169 else if (frequency > cutoff_freqs[N_OSCIL-1])
171 oscillators[N_OSCIL-1]->setPhaseFractional(current_osc->getPhaseFractional());
172 current_osc = oscillators[N_OSCIL-1];
173 current_osc->setFreq(frequency);
177 byte low_point = 0, high_point = N_OSCIL-1, mid_point = (N_OSCIL-1)>>1;
178 while(low_point != high_point)
180 if (frequency > cutoff_freqs[mid_point]) low_point = mid_point+1;
181 else if (frequency < cutoff_freqs[mid_point]) high_point = mid_point;
186 mid_point = (low_point + high_point)>>1;
188 oscillators[mid_point]->setPhaseFractional(current_osc->getPhaseFractional());
189 current_osc = oscillators[mid_point];
190 if (apply) current_osc->setFreq(frequency);
201 setFreq((
int) frequency,
false);
202 current_osc->setFreq(frequency);
209 template <
int8_t NI,
int8_t NF, u
int64_t RANGE>
213 setFreq(frequency.asInt(),
false);
214 current_osc->setFreq(frequency);
224 setFreq((
int) (frequency>>8),
false);
225 current_osc->setFreq_Q24n8(frequency);
235 setFreq((
int) (frequency>>16),
false);
236 current_osc->setFreq_Q16n16(frequency);
246 int8_t
atIndex(
unsigned int index) {
return current_osc->atIndex(index);}
253 unsigned long phaseIncFromFreq(
int frequency) {
return current_osc->phaseIncFromFreq(frequency);}
259 void setPhaseInc(
unsigned long phaseinc_fractional) {current_osc->setPhaseInc(phaseinc_fractional);}
266 int cutoff_freqs[N_OSCIL];
267 byte current_rank = 0;
Oscil plays a wavetable, cycling through the table to generate an audio or control signal.
int32_t Q15n16
signed fractional number using 15 integer bits and 16 fractional bits, represents -32767....
uint32_t Q24n8
unsigned fractional number using 24 integer bits and 8 fractional bits, represents 0 to 16777215
uint32_t Q16n16
unsigned fractional number using 16 integer bits and 16 fractional bits, represents 0 to 65535....