20 #define SAMPLE_F_BITS 16
21 #define SAMPLE_F_BITS_AS_MULTIPLIER 65536
25 #define SAMPLE_PHMOD_BITS 16
27 enum interpolation {INTERP_NONE, INTERP_LINEAR};
47 template <
unsigned int NUM_TABLE_CELLS,
unsigned int UPDATE_RATE, uint8_t INTERP=INTERP_NONE>
94 startpos_fractional = (
unsigned long) startpos <<
SAMPLE_F_BITS;
103 phase_fractional = startpos_fractional;
133 startpos_fractional = 0;
134 endpos_fractional = (
unsigned long) NUM_TABLE_CELLS <<
SAMPLE_F_BITS;
167 if (phase_fractional>endpos_fractional){
169 phase_fractional = startpos_fractional + (phase_fractional - endpos_fractional);
175 if(INTERP==INTERP_LINEAR){
178 out = FLASH_OR_RAM_READ<
const int8_t>(table + index);
179 int8_t difference = FLASH_OR_RAM_READ<
const int8_t>((table + 1) + index) - out;
180 int8_t diff_fraction = (int8_t)(((((
unsigned int) phase_fractional)>>8)*difference)>>8);
181 out += diff_fraction;
183 out = FLASH_OR_RAM_READ<
const int8_t>(table + (phase_fractional >>
SAMPLE_F_BITS));
195 return phase_fractional<endpos_fractional;
226 phase_increment_fractional = ((((
unsigned long)NUM_TABLE_CELLS<<ADJUST_FOR_NUM_TABLE_CELLS)*frequency)/UPDATE_RATE) << (
SAMPLE_F_BITS - ADJUST_FOR_NUM_TABLE_CELLS);
254 phase_increment_fractional = (((((
unsigned long)NUM_TABLE_CELLS<<ADJUST_FOR_NUM_TABLE_CELLS)>>3)*frequency)/(UPDATE_RATE>>6))
266 return FLASH_OR_RAM_READ<
const int8_t>(table + index);
283 return (((
unsigned long)frequency * NUM_TABLE_CELLS)/UPDATE_RATE) <<
SAMPLE_F_BITS;
293 phase_increment_fractional = phaseinc_fractional;
302 static const uint8_t ADJUST_FOR_NUM_TABLE_CELLS = (
NUM_TABLE_CELLS<2048) ? 8 : 0;
308 void incrementPhase()
310 phase_fractional += phase_increment_fractional;
314 volatile unsigned long phase_fractional;
315 volatile unsigned long phase_increment_fractional;
316 const int8_t * table;
318 unsigned long startpos_fractional, endpos_fractional;