Browse Source

Add variable triangle waveform

dds
PaulStoffregen 6 years ago
parent
commit
4cd3436bd7
6 changed files with 35 additions and 9 deletions
  1. +4
    -0
      examples/Synthesis/Waveforms/Waveforms.ino
  2. BIN
      gui/img/waveforms.png
  3. +1
    -0
      gui/index.html
  4. +1
    -0
      keywords.txt
  5. +20
    -0
      synth_waveform.cpp
  6. +9
    -9
      synth_waveform.h

+ 4
- 0
examples/Synthesis/Waveforms/Waveforms.ino View File

Serial.println("Triangle"); Serial.println("Triangle");
break; break;
case WAVEFORM_TRIANGLE: case WAVEFORM_TRIANGLE:
current_waveform = WAVEFORM_TRIANGLE_VARIABLE;
Serial.println("Variable Triangle");
break;
case WAVEFORM_TRIANGLE_VARIABLE:
current_waveform = WAVEFORM_ARBITRARY; current_waveform = WAVEFORM_ARBITRARY;
Serial.println("Arbitary Waveform"); Serial.println("Arbitary Waveform");
break; break;

BIN
gui/img/waveforms.png View File

Before After
Width: 240  |  Height: 362  |  Size: 33KB Width: 240  |  Height: 408  |  Size: 38KB

+ 1
- 0
gui/index.html View File

<li><span class=literal>WAVEFORM_SAWTOOTH_REVERSE</span></li> <li><span class=literal>WAVEFORM_SAWTOOTH_REVERSE</span></li>
<li><span class=literal>WAVEFORM_SQUARE</span></li> <li><span class=literal>WAVEFORM_SQUARE</span></li>
<li><span class=literal>WAVEFORM_TRIANGLE</span></li> <li><span class=literal>WAVEFORM_TRIANGLE</span></li>
<li><span class=literal>WAVEFORM_TRIANGLE_VARIABLE</span></li>
<li><span class=literal>WAVEFORM_ARBITRARY</span></li> <li><span class=literal>WAVEFORM_ARBITRARY</span></li>
<li><span class=literal>WAVEFORM_PULSE</span></li> <li><span class=literal>WAVEFORM_PULSE</span></li>
<li><span class=literal>WAVEFORM_SAMPLE_HOLD</span></li> <li><span class=literal>WAVEFORM_SAMPLE_HOLD</span></li>

+ 1
- 0
keywords.txt View File

WAVEFORM_PULSE LITERAL1 WAVEFORM_PULSE LITERAL1
WAVEFORM_SAWTOOTH_REVERSE LITERAL1 WAVEFORM_SAWTOOTH_REVERSE LITERAL1
WAVEFORM_SAMPLE_HOLD LITERAL1 WAVEFORM_SAMPLE_HOLD LITERAL1
WAVEFORM_TRIANGLE_VARIABLE LITERAL1


AUDIO_MEMORY_23LC1024 LITERAL1 AUDIO_MEMORY_23LC1024 LITERAL1
AUDIO_MEMORY_MEMORYBOARD LITERAL1 AUDIO_MEMORY_MEMORYBOARD LITERAL1

+ 20
- 0
synth_waveform.cpp View File

} }
break; break;


case WAVEFORM_TRIANGLE_VARIABLE:
do {
uint32_t rise = 0xFFFFFFFF / (pulse_width >> 16);
uint32_t fall = 0xFFFFFFFF / (0xFFFF - (pulse_width >> 16));
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
if (ph < pulse_width/2) {
uint32_t n = (ph >> 16) * rise;
*bp++ = ((n >> 16) * magnitude) >> 16;
} else if (ph < 0xFFFFFFFF - pulse_width/2) {
uint32_t n = 0x7FFFFFFF - (((ph - pulse_width/2) >> 16) * fall);
*bp++ = ((n >> 16) * magnitude) >> 16;
} else {
uint32_t n = ((ph + pulse_width/2) >> 16) * rise + 0x80000000;
*bp++ = ((n >> 16) * magnitude) >> 16;
}
ph += inc;
}
} while (0);
break;

case WAVEFORM_PULSE: case WAVEFORM_PULSE:
magnitude15 = signed_saturate_rshift(magnitude, 16, 1); magnitude15 = signed_saturate_rshift(magnitude, 16, 1);
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) { for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {

+ 9
- 9
synth_waveform.h View File

} }




#define WAVEFORM_SINE 0
#define WAVEFORM_SAWTOOTH 1
#define WAVEFORM_SQUARE 2
#define WAVEFORM_TRIANGLE 3
#define WAVEFORM_ARBITRARY 4
#define WAVEFORM_PULSE 5
#define WAVEFORM_SAWTOOTH_REVERSE 6
#define WAVEFORM_SAMPLE_HOLD 7
#define WAVEFORM_SINE 0
#define WAVEFORM_SAWTOOTH 1
#define WAVEFORM_SQUARE 2
#define WAVEFORM_TRIANGLE 3
#define WAVEFORM_ARBITRARY 4
#define WAVEFORM_PULSE 5
#define WAVEFORM_SAWTOOTH_REVERSE 6
#define WAVEFORM_SAMPLE_HOLD 7
#define WAVEFORM_TRIANGLE_VARIABLE 8


class AudioSynthWaveform : public AudioStream class AudioSynthWaveform : public AudioStream
{ {

Loading…
Cancel
Save