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);}
132 void setFreq(
int frequency,
bool apply =
true)
134 if (frequency < cutoff_freqs[0])
136 oscillators[0]->setPhaseFractional(current_osc->getPhaseFractional());
137 current_osc = oscillators[0];
138 current_osc->setFreq(frequency);
141 else if (frequency > cutoff_freqs[N_OSCIL-1])
143 oscillators[N_OSCIL-1]->setPhaseFractional(current_osc->getPhaseFractional());
144 current_osc = oscillators[N_OSCIL-1];
145 current_osc->setFreq(frequency);
149 byte low_point = 0, high_point = N_OSCIL-1, mid_point = (N_OSCIL-1)>>1;
150 while(low_point != high_point)
152 if (frequency > cutoff_freqs[mid_point]) low_point = mid_point+1;
153 else if (frequency < cutoff_freqs[mid_point]) high_point = mid_point;
158 mid_point = (low_point + high_point)>>1;
160 oscillators[mid_point]->setPhaseFractional(current_osc->getPhaseFractional());
161 current_osc = oscillators[mid_point];
162 if (apply) current_osc->setFreq(frequency);
173 setFreq((
int) frequency,
false);
174 current_osc->setFreq(frequency);
181 template <
int8_t NI,
int8_t NF, u
int64_t RANGE>
185 setFreq(frequency.asInt(),
false);
186 current_osc->setFreq(frequency);
196 setFreq((
int) (frequency>>8),
false);
197 current_osc->setFreq_Q24n8(frequency);
207 setFreq((
int) (frequency>>16),
false);
208 current_osc->setFreq_Q16n16(frequency);
218 int8_t
atIndex(
unsigned int index) {
return current_osc->atIndex(index);}
225 unsigned long phaseIncFromFreq(
int frequency) {
return current_osc->phaseIncFromFreq(frequency);}
231 void setPhaseInc(
unsigned long phaseinc_fractional) {current_osc->setPhaseInc(phaseinc_fractional);}
238 int cutoff_freqs[N_OSCIL];
239 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....