Browse Source

#144: Add the reverse sawtooth and sample-and-hold waveforms.

dds
Florian Lorétan 9 years ago
parent
commit
fbd1fe65ce
3 changed files with 23 additions and 0 deletions
  1. +2
    -0
      keywords.txt
  2. +17
    -0
      synth_waveform.cpp
  3. +4
    -0
      synth_waveform.h

+ 2
- 0
keywords.txt View File

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

+ 17
- 0
synth_waveform.cpp View File

} }
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;

+ 4
- 0
synth_waveform.h View File

#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;

Loading…
Cancel
Save