26 #ifdef OSCIL_DITHER_PHASE 27 #include "mozzi_rand.h" 31 #define OSCIL_F_BITS 16
32 #define OSCIL_F_BITS_AS_MULTIPLIER 65536
35 #define OSCIL_PHMOD_BITS 16
61 template <uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
114 phase_fractional = (
unsigned long)phase <<
OSCIL_F_BITS;
125 phase_fractional = phase;
134 return phase_fractional;
153 return FLASH_OR_RAM_READ<
const int8_t>(table + (((phase_fractional+(phmod_proportion * NUM_TABLE_CELLS))>>
OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
182 phase_increment_fractional = (
unsigned long)((((
float)NUM_TABLE_CELLS * frequency)/UPDATE_RATE) *
OSCIL_F_BITS_AS_MULTIPLIER);
203 if ((256UL*NUM_TABLE_CELLS) >= UPDATE_RATE) {
204 phase_increment_fractional = ((
unsigned long)frequency) * ((256UL*NUM_TABLE_CELLS)/UPDATE_RATE);
206 phase_increment_fractional = ((
unsigned long)frequency) / (UPDATE_RATE/(256UL*NUM_TABLE_CELLS));
227 if (NUM_TABLE_CELLS >= UPDATE_RATE) {
228 phase_increment_fractional = ((
unsigned long)frequency) * (NUM_TABLE_CELLS/UPDATE_RATE);
230 phase_increment_fractional = ((
unsigned long)frequency) / (UPDATE_RATE/NUM_TABLE_CELLS);
247 return FLASH_OR_RAM_READ<
const int8_t>(table + (index & (NUM_TABLE_CELLS - 1)));
277 phase_increment_fractional = phaseinc_fractional;
287 static const uint8_t ADJUST_FOR_NUM_TABLE_CELLS = (
NUM_TABLE_CELLS<2048) ? 8 : 0;
293 void incrementPhase()
296 phase_fractional += phase_increment_fractional;
305 #ifdef OSCIL_DITHER_PHASE 306 return FLASH_OR_RAM_READ<
const int8_t>(table + (((phase_fractional + ((
int)(xorshift96()>>16))) >> OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
308 return FLASH_OR_RAM_READ<
const int8_t>(table + ((phase_fractional >>
OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
314 unsigned long phase_fractional;
315 unsigned long phase_increment_fractional;
316 const int8_t * table;
int8_t next()
Updates the phase according to the current frequency and returns the sample at the new phase position...
unsigned long getPhaseFractional()
Get the phase of the Oscil in fractional format.
Oscil plays a wavetable, cycling through the table to generate an audio or control signal...
void setFreq(int frequency)
Set the oscillator frequency with an unsigned int.
void setPhaseFractional(unsigned long phase)
Set the phase of the Oscil.
unsigned long phaseIncFromFreq(int frequency)
phaseIncFromFreq() and setPhaseInc() are for saving processor time when sliding between frequencies...
void setPhase(unsigned int phase)
Set the phase of the Oscil.
int8_t phMod(Q15n16 phmod_proportion)
Returns the next sample given a phase modulation value.
Oscil(const int8_t *TABLE_NAME)
Constructor.
void setTable(const int8_t *TABLE_NAME)
Change the sound table which will be played by the Oscil.
void setFreq(float frequency)
Set the oscillator frequency with a float.
int8_t atIndex(unsigned int index)
Returns the sample at the given table index.
#define OSCIL_F_BITS_AS_MULTIPLIER
uint32_t Q24n8
unsigned fractional number using 24 integer bits and 8 fractional bits, represents 0 to 16777215 ...
void setFreq_Q16n16(Q16n16 frequency)
Set the frequency using Q16n16 fixed-point number format.
void setPhaseInc(unsigned long phaseinc_fractional)
Set a specific phase increment.
uint32_t Q16n16
unsigned fractional number using 16 integer bits and 16 fractional bits, represents 0 to 65535...
void setFreq_Q24n8(Q24n8 frequency)
Set the frequency using Q24n8 fixed-point number format.