Browse Source

Merge pull request #65 from Nantonos/master

width -> pulseWidth
dds
Paul Stoffregen 10 years ago
parent
commit
041e5ef0ae
4 changed files with 12 additions and 7 deletions
  1. +3
    -3
      examples/Synthesis/pulseWidth/pulseWidth.ino
  2. +4
    -1
      gui/list.html
  3. +3
    -1
      keywords.txt
  4. +2
    -2
      synth_waveform.h

examples/Synthesis/pulse/pulse.ino → examples/Synthesis/pulseWidth/pulseWidth.ino View File

// demonstrate pulse with slow changes in width
// demonstrate pulse with slow changes in pulse width


#include <Audio.h> #include <Audio.h>
#include <Wire.h> #include <Wire.h>
audioShield.enable(); audioShield.enable();
audioShield.volume(0.45); audioShield.volume(0.45);


waveform1.width(0.5);
waveform1.pulseWidth(0.5);
waveform1.begin(0.4, 220, WAVEFORM_PULSE); waveform1.begin(0.4, 220, WAVEFORM_PULSE);


envelope1.attack(50); envelope1.attack(50);
float w; float w;
for (uint32_t i =1; i<20; i++) { for (uint32_t i =1; i<20; i++) {
w = i / 20.0; w = i / 20.0;
waveform1.width(w);
waveform1.pulseWidth(w);
envelope1.noteOn(); envelope1.noteOn();
delay(800); delay(800);
envelope1.noteOff(); envelope1.noteOff();

+ 4
- 1
gui/list.html View File

</script> </script>
<script type="text/x-red" data-help-name="AudioSynthWaveform"> <script type="text/x-red" data-help-name="AudioSynthWaveform">
<h3>Summary</h3> <h3>Summary</h3>
<p>Create a waveform: sine, sawtooth, square, or triangle</p>
<p>Create a waveform: sine, sawtooth, square, triangle, pulse or arbitrary.</p>
<h3>Audio Connections</h3> <h3>Audio Connections</h3>
<table class=doc align=center cellpadding=3> <table class=doc align=center cellpadding=3>
<tr class=top><th>Port</th><th>Purpose</th></tr> <tr class=top><th>Port</th><th>Purpose</th></tr>
<a href="http://www.pjrc.com/teensy/td_libs_AudioProcessorUsage.html" target="_blank">AudioNoInterrupts()</a> <a href="http://www.pjrc.com/teensy/td_libs_AudioProcessorUsage.html" target="_blank">AudioNoInterrupts()</a>
should be used to guarantee all new settings take effect together. should be used to guarantee all new settings take effect together.
</p> </p>
<p class=func><span class=keyword>pulseWidth</span>(amount);</p>
<p class=desc>Change the width (duty cycle) of the pulse.</p>
<p class=func><span class=keyword>arbitraryWaveform</span>(array, maxFreq);</p> <p class=func><span class=keyword>arbitraryWaveform</span>(array, maxFreq);</p>
<p class=desc> <p class=desc>
Configure the waveform to be used with WAVEFORM_ARBITRARY. Array Configure the waveform to be used with WAVEFORM_ARBITRARY. Array
<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_ARBITRARY</span></li> <li><span class=literal>WAVEFORM_ARBITRARY</span></li>
<li><span class=literal>WAVEFORM_PULSE</span></li>
</ul> </ul>
</p> </p>
</script> </script>

+ 3
- 1
keywords.txt View File

Audio KEYWORD2
Audio KEYWORD2
AudioConnection KEYWORD2 AudioConnection KEYWORD2
AudioInputI2S KEYWORD2 AudioInputI2S KEYWORD2
AudioOutputI2S KEYWORD2 AudioOutputI2S KEYWORD2
phase KEYWORD2 phase KEYWORD2
amplitude KEYWORD2 amplitude KEYWORD2
offset KEYWORD2 offset KEYWORD2
pulseWidth KEYWORD2
resonance KEYWORD2 resonance KEYWORD2
octaveControl KEYWORD2 octaveControl KEYWORD2
averageTogether KEYWORD2 averageTogether KEYWORD2
WAVEFORM_SQUARE LITERAL1 WAVEFORM_SQUARE LITERAL1
WAVEFORM_TRIANGLE LITERAL1 WAVEFORM_TRIANGLE LITERAL1
WAVEFORM_ARBITRARY LITERAL1 WAVEFORM_ARBITRARY LITERAL1
WAVEFORM_PULSE LITERAL1



+ 2
- 2
synth_waveform.h View File

else if (n > 1.0) n = 1.0; else if (n > 1.0) n = 1.0;
tone_offset = n * 32767.0; tone_offset = n * 32767.0;
} }
void width(float n) { // 0.0 to 1.0
void pulseWidth(float n) { // 0.0 to 1.0
if (n < 0) n = 0; if (n < 0) n = 0;
else if (n > 1.0) n = 1.0; else if (n > 1.0) n = 1.0;
tone_width = n * 0x7fffffffLL; tone_width = n * 0x7fffffffLL;
// width is stored as the equivalent phase
// pulse width is stored as the equivalent phase
} }
void begin(short t_type) { void begin(short t_type) {
tone_phase = 0; tone_phase = 0;

Loading…
Cancel
Save