@@ -162,6 +162,8 @@ WAVEFORM_SQUARE LITERAL1 | |||
WAVEFORM_TRIANGLE LITERAL1 | |||
WAVEFORM_ARBITRARY LITERAL1 | |||
WAVEFORM_PULSE LITERAL1 | |||
WAVEFORM_SAWTOOTH_REVERSE LITERAL1 | |||
WAVEFORM_SAMPLE_HOLD LITERAL1 | |||
AUDIO_MEMORY_23LC1024 LITERAL1 | |||
AUDIO_MEMORY_MEMORYBOARD LITERAL1 |
@@ -108,6 +108,14 @@ void AudioSynthWaveform::update(void) | |||
} | |||
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: | |||
for(int i = 0;i < AUDIO_BLOCK_SAMPLES;i++) { | |||
if(tone_phase & 0x80000000) { | |||
@@ -137,6 +145,15 @@ void AudioSynthWaveform::update(void) | |||
} | |||
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) { | |||
bp = block->data; |
@@ -45,6 +45,8 @@ extern const int16_t AudioWaveformSine[257]; | |||
#define WAVEFORM_TRIANGLE 3 | |||
#define WAVEFORM_ARBITRARY 4 | |||
#define WAVEFORM_PULSE 5 | |||
#define WAVEFORM_SAWTOOTH_REVERSE 6 | |||
#define WAVEFORM_SAMPLE_HOLD 7 | |||
// todo: remove these... | |||
#define TONE_TYPE_SINE 0 | |||
@@ -117,6 +119,8 @@ private: | |||
short tone_freq; | |||
uint32_t tone_phase; | |||
uint32_t tone_width; | |||
// sample for SAMPLE_HOLD | |||
short sample; | |||
// volatile prevents the compiler optimizing out the frequency function | |||
volatile uint32_t tone_incr; | |||
short tone_type; |