Bläddra i källkod

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

dds
Florian Lorétan 9 år sedan
förälder
incheckning
fbd1fe65ce
3 ändrade filer med 23 tillägg och 0 borttagningar
  1. +2
    -0
      keywords.txt
  2. +17
    -0
      synth_waveform.cpp
  3. +4
    -0
      synth_waveform.h

+ 2
- 0
keywords.txt Visa fil

@@ -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

+ 17
- 0
synth_waveform.cpp Visa fil

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

+ 4
- 0
synth_waveform.h Visa fil

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

Laddar…
Avbryt
Spara