| WAVEFORM_TRIANGLE LITERAL1 | WAVEFORM_TRIANGLE LITERAL1 | ||||
| WAVEFORM_ARBITRARY LITERAL1 | WAVEFORM_ARBITRARY LITERAL1 | ||||
| WAVEFORM_PULSE LITERAL1 | WAVEFORM_PULSE LITERAL1 | ||||
| WAVEFORM_SAWTOOTH_REVERSE LITERAL1 | |||||
| WAVEFORM_SAMPLE_HOLD LITERAL1 | |||||
| AUDIO_MEMORY_23LC1024 LITERAL1 | AUDIO_MEMORY_23LC1024 LITERAL1 | ||||
| AUDIO_MEMORY_MEMORYBOARD LITERAL1 | AUDIO_MEMORY_MEMORYBOARD LITERAL1 |
| } | } | ||||
| break; | break; | ||||
| case WAVEFORM_SAWTOOTH_REVERSE: | |||||
| for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { | |||||
| *bp++ = ((short)(tone_phase>>15)*tone_amp) >> 15; | |||||
| // phase and incr are both unsigned 32-bit fractions | |||||
| tone_phase -= tone_incr; | |||||
| } | |||||
| break; | |||||
| case WAVEFORM_TRIANGLE: | case WAVEFORM_TRIANGLE: | ||||
| for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { | for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { | ||||
| if(tone_phase & 0x80000000) { | if(tone_phase & 0x80000000) { | ||||
| } | } | ||||
| break; | break; | ||||
| case WAVEFORM_SAMPLE_HOLD: | |||||
| for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { | |||||
| if(tone_phase < tone_incr) { | |||||
| sample = random(-tone_amp, tone_amp); | |||||
| } | |||||
| *bp++ = sample; | |||||
| tone_phase += tone_incr; | |||||
| } | |||||
| break; | |||||
| } | } | ||||
| if (tone_offset) { | if (tone_offset) { | ||||
| bp = block->data; | bp = block->data; |
| #define WAVEFORM_TRIANGLE 3 | #define WAVEFORM_TRIANGLE 3 | ||||
| #define WAVEFORM_ARBITRARY 4 | #define WAVEFORM_ARBITRARY 4 | ||||
| #define WAVEFORM_PULSE 5 | #define WAVEFORM_PULSE 5 | ||||
| #define WAVEFORM_SAWTOOTH_REVERSE 6 | |||||
| #define WAVEFORM_SAMPLE_HOLD 7 | |||||
| // todo: remove these... | // todo: remove these... | ||||
| #define TONE_TYPE_SINE 0 | #define TONE_TYPE_SINE 0 | ||||
| short tone_freq; | short tone_freq; | ||||
| uint32_t tone_phase; | uint32_t tone_phase; | ||||
| uint32_t tone_width; | uint32_t tone_width; | ||||
| // sample for SAMPLE_HOLD | |||||
| short sample; | |||||
| // volatile prevents the compiler optimizing out the frequency function | // volatile prevents the compiler optimizing out the frequency function | ||||
| volatile uint32_t tone_incr; | volatile uint32_t tone_incr; | ||||
| short tone_type; | short tone_type; |