As I can't get the envelope to work in my project which is a bit complex, I made a very simple example to ask here. I'm not working with the audio shield, but it should be easy to replace to test or explain.
If I click on my momentary switch and let go, nothing happens in the way an ADSR works when changing the parameters. No matter which parameter I change that I need (decay or release). So there's something I'm missing.
Attack works. Hold works (?). But these are not the parameters needed cause I need an envelope.
Sustain acts like opening a VCA. The sound remains open as soon as the value is more than 0. This is strange.
It is not doing what I'm expecting from an ADSR: attack, then decay, then sustain, then comes the release phase, then the sound stops.
Here it's just sustaining forever when the sustain value is 1.
And when the sustain value is at 0, the sound stops (after the hold time-- not really sure), no matter what I have in decay or release.
I'd like to know how this envelope is suposed to work. I look at the Teensy Audio Tutorial & Workshop video tutorial, but it's not clear to me.
Here a longer code where I set pots to change each param. Easier to see what happens, then changing the value in the code and compile each time.
Same result. Does not look like ADSR***
In this example the attack is OK. Acts like it should.
Hold?
Decay?
Sustain: as explained earlier.
Release: nothing.
Very strange!
***with an ADSR, I'd be able to make a drum/percussive sound when clicking on a button (or triggering via an external signal), like a drum sound from a AudioSynthSimpleDrum for instance.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioSynthWaveformSine sine1; //xy=1141,940
AudioEffectEnvelope envelope1; //xy=1290,942
AudioMixer4 mixer1; //xy=1501.6666666666665,946.6666666666665
AudioOutputAnalog dac1; //xy=1751,1062
AudioConnection patchCord1(sine1, envelope1);
AudioConnection patchCord2(envelope1, 0, mixer1, 0);
AudioConnection patchCord3(mixer1, dac1);
// Switch select
#define trigSwitch_PIN 3
// bounce pour Select switch
Bounce trigSwitch = Bounce(trigSwitch_PIN, 15);
void setup() {
Serial.begin(115200);
AudioMemory(15);
pinMode(trigSwitch_PIN, INPUT_PULLUP);
envelope1.attack(10);
envelope1.hold(100);
envelope1.decay(250);
envelope1.sustain(0);
envelope1.release(10);
sine1.frequency(1000);
sine1.amplitude(1.0);
AudioInterrupts();
}
void loop() {
trigSwitch.update(); // listen to Select switch
if (trigSwitch.fallingEdge()) {
envelope1.noteOn();
}
// if (trigSwitch.risingEdge()) {
// envelope1.noteOff();
// }
}
Attack works. Hold works (?). But these are not the parameters needed cause I need an envelope.
Sustain acts like opening a VCA. The sound remains open as soon as the value is more than 0. This is strange.
It is not doing what I'm expecting from an ADSR: attack, then decay, then sustain, then comes the release phase, then the sound stops.
Here it's just sustaining forever when the sustain value is 1.
And when the sustain value is at 0, the sound stops (after the hold time-- not really sure), no matter what I have in decay or release.
I'd like to know how this envelope is suposed to work. I look at the Teensy Audio Tutorial & Workshop video tutorial, but it's not clear to me.
Here a longer code where I set pots to change each param. Easier to see what happens, then changing the value in the code and compile each time.
Same result. Does not look like ADSR***
In this example the attack is OK. Acts like it should.
Hold?
Decay?
Sustain: as explained earlier.
Release: nothing.
Very strange!
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>
AudioSynthWaveformSine sine1; //xy=1141,940
AudioEffectEnvelope envelope1; //xy=1290,942
AudioMixer4 mixer1; //xy=1501.6666666666665,946.6666666666665
AudioOutputAnalog dac1; //xy=1751,1062
AudioConnection patchCord1(sine1, envelope1);
AudioConnection patchCord2(envelope1, 0, mixer1, 0);
AudioConnection patchCord3(mixer1, dac1);
// Switch select
#define trigSwitch_PIN 3
#define attackPot 10
#define holdPot 7
#define decayPot 6
#define sustainPot 5
#define releasePot 11
// store pot readings into ADSR parameter settings
int attackParam;
int decayParam;
float sustainParam;
int releaseParam;
// limit maximum timing for parameters set by pots
#define attackMax 2000
#define decayMax 2000
#define releaseMax 2000
// bounce pour Select switch
Bounce trigSwitch = Bounce(trigSwitch_PIN, 15);
void setup() {
Serial.begin(115200);
AudioMemory(15);
pinMode(trigSwitch_PIN, INPUT_PULLUP);
// attackParam = 50;
// decayParam = 50;
// sustainParam = 0.5;
// releaseParam = 250;
// assign envelope parameters
envelope1.delay(0);
envelope1.attack(attackParam); // max 11880 mS
envelope1.hold(0); // max 11880 mS
envelope1.decay(decayParam); // max 11880 mS
envelope1.sustain(sustainParam); // gain level from 0 to 1.0
envelope1.release(releaseParam); // max 11880 mS
sine1.frequency(500);
sine1.amplitude(1.0);
AudioInterrupts();
}
void loop() {
trigSwitch.update(); // listen to Select switch
if (trigSwitch.fallingEdge()) {
envelope1.noteOn();
}
// if (trigSwitch.risingEdge()) {
// envelope1.noteOff();
// }
// read in pots and adjust ADSR parameters
attackParam = map(analogRead(attackPot), 0, 1023, 0, attackMax);
decayParam = map(analogRead(decayPot), 0, 1023, 0, decayMax);
sustainParam = map(analogRead(sustainPot), 0, 1023, 0, 1.0);
releaseParam = map(analogRead(releasePot), 0, 1023, 0, releaseMax);
// debug serial output
Serial.print("Attack: ");
Serial.print(attackParam);
Serial.print(" Decay: ");
Serial.print(decayParam);
Serial.print(" Sustain: ");
Serial.print(sustainParam);
Serial.print(" Release: ");
Serial.println(releaseParam);
// apply ADSR parameters to sound generators
envelope1.attack(attackParam); // max 11880 mS
envelope1.decay(decayParam); // max 11880 mS
envelope1.sustain(sustainParam); // gain level from 0 to 1.0
envelope1.release(releaseParam); // max 11880 mS
}
***with an ADSR, I'd be able to make a drum/percussive sound when clicking on a button (or triggering via an external signal), like a drum sound from a AudioSynthSimpleDrum for instance.