25 #ifdef OSCIL_DITHER_PHASE
26 #include "mozzi_rand.h"
30 #define OSCIL_F_BITS 16
31 #define OSCIL_F_BITS_AS_MULTIPLIER 65536
34 #define OSCIL_PHMOD_BITS 16
60 template <uint16_t NUM_TABLE_CELLS, uint16_t UPDATE_RATE>
124 phase_fractional = phase;
133 return phase_fractional;
152 return FLASH_OR_RAM_READ<
const int8_t>(table + (((phase_fractional+(phmod_proportion * NUM_TABLE_CELLS))>>
OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
162 template <int8_t NI, int8_t NF, uint8_t RANGE>
166 return phMod(SFix<15,16>(phmod_proportion).asRaw());
180 return phMod(phmod_proportion.asRaw());
219 template <int8_t NI, int8_t NF, uint64_t RANGE>
223 setFreq_Q16n16(UFix<16,16>(frequency).asRaw());
245 if ((256UL*NUM_TABLE_CELLS) >= UPDATE_RATE) {
246 phase_increment_fractional = ((uint32_t)frequency) * ((256UL*NUM_TABLE_CELLS)/UPDATE_RATE);
248 phase_increment_fractional = ((uint32_t)frequency) / (UPDATE_RATE/(256UL*NUM_TABLE_CELLS));
259 template <uint64_t RANGE>
263 setFreq_Q24n8(frequency.asRaw());
283 if (NUM_TABLE_CELLS >= UPDATE_RATE) {
284 phase_increment_fractional = ((uint32_t)frequency) * (NUM_TABLE_CELLS/UPDATE_RATE);
286 phase_increment_fractional = ((uint32_t)frequency) / (UPDATE_RATE/NUM_TABLE_CELLS);
299 template <uint64_t RANGE>
303 setFreq_Q16n16(frequency.asRaw());
314 template <int8_t NI, int8_t NF, uint64_t RANGE>
318 setFreq_Q16n16(UFix<16,16>(frequency).asRaw());
335 return FLASH_OR_RAM_READ<
const int8_t>(table + (index & (NUM_TABLE_CELLS - 1)));
365 phase_increment_fractional = phaseinc_fractional;
375 static const uint8_t ADJUST_FOR_NUM_TABLE_CELLS = (
NUM_TABLE_CELLS<2048) ? 8 : 0;
381 void incrementPhase()
384 phase_fractional += phase_increment_fractional;
393 #ifdef OSCIL_DITHER_PHASE
394 return FLASH_OR_RAM_READ<
const int8_t>(table + (((phase_fractional + ((
int)(xorshift96()>>16))) >> OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
396 return FLASH_OR_RAM_READ<
const int8_t>(table + ((phase_fractional >>
OSCIL_F_BITS) & (NUM_TABLE_CELLS - 1)));
402 uint32_t phase_fractional;
403 uint32_t phase_increment_fractional;
404 const int8_t * table;