
Originally Posted by
Angel
Do I have to put something specific in the code?
Yes, you need to configure the modulated waveform to make sound and to respond in the way you want to its input, and you need to cause the other stuff to create that modulated input.
Here's a quick test program I wrote just now, for the diagram I showed in msg #2. When you run this, you can easily hear it working!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioSynthWaveformDc dc1; //xy=131,185
AudioEffectEnvelope envelope1; //xy=283,155
AudioSynthWaveformModulated waveformMod1; //xy=385,239
AudioOutputI2S i2s1; //xy=582,240
AudioConnection patchCord1(dc1, envelope1);
AudioConnection patchCord2(envelope1, 0, waveformMod1, 0);
AudioConnection patchCord3(waveformMod1, 0, i2s1, 0);
AudioConnection patchCord4(waveformMod1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=482,303
// GUItool: end automatically generated code
void setup() {
AudioMemory(20);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
dc1.amplitude(0.95);
envelope1.delay(0);
envelope1.attack(200);
envelope1.hold(200);
envelope1.decay(200);
envelope1.sustain(0.4);
envelope1.release(1500);
waveformMod1.begin(WAVEFORM_SAWTOOTH);
waveformMod1.amplitude(0.8);
waveformMod1.frequency(120);
waveformMod1.frequencyModulation(4); // 1.0 input increases 3 octaves
}
void loop() {
delay(2000);
envelope1.noteOn();
delay(1000);
envelope1.noteOff();
delay(2000);
}
The idea is this oscillator runs at a constant 120 Hz, but quick ramps up by 4 octaves during the attack-hold-decay portion of the envelope. During the sustain phase (before noteOff is called) it remains at 1.6 octaves higher than normal 120 Hz, because the sustain level is has a gain of 0.4, and the DC input is 1.0, and the modulation is 4 octaves for 1.0. When noteOff is called, the release phase happens over 1.5 seconds, so you can hear it gradually return back down to the lower 120 Hz buzzing sound. The process repeats every 5 seconds, which gets a bit old after a few cycles of constant amplitude sawtooth buzzing sound.... but hopefully as you hear the transitions you can see hear how this code is working. Obviously for musically pleasing sounds you'd want something much more dynamic than a constant amplitude waveform!