Modulating frequency with an envelope?

Status
Not open for further replies.

soerena88

Member
Hi,

As the title says, I'm wondering how to achieve this with the Audio Library. I've tried with the AudioSynthWaveformModulated and the AudioEffectEnvelope, hooking the output of the envelop into the first input of the waveformMod. I then initiated all the waveform and envelope settings, called the "begin" method on the waveform but calling "noteOn" on the envelope does not seem to change the pitch.. it merely is stuck on the pitch it was initiated with.

Any ideas what I could be doing wrong? :)
 
The envelope needs an input signal. It's an effect, so it doesn't create anything on its own. No input means no output.

Give it a DC input if you want just the envelope for something else to use.

Like this...

env.png
 
You're the best Paul! I tried something similar with a sine synth, which gave an odd but interesting result. Didn't notice the DC object before you mentioned it. Thanks!
 
The envelope needs an input signal. It's an effect, so it doesn't create anything on its own. No input means no output.

Give it a DC input if you want just the envelope for something else to use.

Like this...

View attachment 15236


I'm not managing to change the pitch of the waveform with an envelope, can you help me?

Image1.png

Do I have to put something specific in the code?
 
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!
 
Status
Not open for further replies.
Back
Top