Hi everyone - getting into the Teensy Audio Library is super fun, but I find the synthesis aspects a little opaque at times
Can someone tell me why this code doesn't fade away nicely, but instead clips at the end of the bell-tone? I've been trying to get the bell to fade away and can't understand what's wrong...
I'm working with the DAC not the audioshield, so you'll have to change a bit of code if you want to use the shield...
Thanks for giving me such nice tools to learn with!
Erin
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
int ringabell = 0;
int testLed = 13;
boolean noteGo;
boolean noteStop;
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=283,52
AudioSynthWaveform waveform2; //xy=299,262
AudioEffectEnvelope envelope1; //xy=429,51
AudioSynthWaveformSineModulated sine_fm1; //xy=435,126
AudioSynthWaveformSineModulated sine_fm2; //xy=451,266
AudioEffectEnvelope envelope3; //xy=511,360
AudioEffectEnvelope envelope2; //xy=529,192
AudioMixer4 mixer1; //xy=690,230
AudioOutputAnalog dac1; //xy=861,250
AudioConnection patchCord1(waveform1, envelope1);
AudioConnection patchCord2(waveform2, sine_fm2);
AudioConnection patchCord3(envelope1, sine_fm1);
AudioConnection patchCord4(sine_fm1, envelope2);
AudioConnection patchCord5(sine_fm2, envelope3);
AudioConnection patchCord6(envelope3, 0, mixer1, 1);
AudioConnection patchCord7(envelope2, 0, mixer1, 0);
AudioConnection patchCord8(mixer1, dac1);
// GUItool: end automatically generated code
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
AudioMemory(8);
waveform1.begin(0.25, 400, WAVEFORM_SINE);
waveform2.begin(0.25, 400, WAVEFORM_SINE);
sine_fm1.frequency(200);
sine_fm1.amplitude(0.5);
sine_fm2.frequency(200);
sine_fm2.amplitude(0.5);
mixer1.gain(0, 0);
//mixer1.gain(1, 0);
envelope1.attack(2);
envelope1.hold(1);
envelope1.decay(3000);
envelope1.sustain(0);
envelope1.release(0.0);
envelope2.attack(2);
envelope2.hold(1);
envelope2.decay(3000);
envelope2.sustain(0);
envelope2.release(0.0);
envelope3.attack(2);
envelope3.hold(1);
envelope3.decay(200);
envelope3.sustain(0.1);
envelope3.release(500);
pinMode(testLed, OUTPUT);
}
elapsedMillis every1; //note that this occurs outside the setup
void loop() {
// put your main code here, to run repeatedly:
if(every1 >= 1) {
ringabell = ringabell+1;
if(ringabell == 2) {
sine_fm2.amplitude(0.5);
envelope3.noteOn();
digitalWrite(testLed, HIGH);
}
if(ringabell == 1200) {
sine_fm2.amplitude(0.0);
noteStop=1;
digitalWrite(testLed, LOW);
}
if(ringabell >= 3000) ringabell = 0;
every1 = every1-1;
}
if(noteStop==1) {
envelope3.noteOff();
noteStop=0;
}
}
Can someone tell me why this code doesn't fade away nicely, but instead clips at the end of the bell-tone? I've been trying to get the bell to fade away and can't understand what's wrong...
I'm working with the DAC not the audioshield, so you'll have to change a bit of code if you want to use the shield...
Thanks for giving me such nice tools to learn with!
Erin
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
int ringabell = 0;
int testLed = 13;
boolean noteGo;
boolean noteStop;
// GUItool: begin automatically generated code
AudioSynthWaveform waveform1; //xy=283,52
AudioSynthWaveform waveform2; //xy=299,262
AudioEffectEnvelope envelope1; //xy=429,51
AudioSynthWaveformSineModulated sine_fm1; //xy=435,126
AudioSynthWaveformSineModulated sine_fm2; //xy=451,266
AudioEffectEnvelope envelope3; //xy=511,360
AudioEffectEnvelope envelope2; //xy=529,192
AudioMixer4 mixer1; //xy=690,230
AudioOutputAnalog dac1; //xy=861,250
AudioConnection patchCord1(waveform1, envelope1);
AudioConnection patchCord2(waveform2, sine_fm2);
AudioConnection patchCord3(envelope1, sine_fm1);
AudioConnection patchCord4(sine_fm1, envelope2);
AudioConnection patchCord5(sine_fm2, envelope3);
AudioConnection patchCord6(envelope3, 0, mixer1, 1);
AudioConnection patchCord7(envelope2, 0, mixer1, 0);
AudioConnection patchCord8(mixer1, dac1);
// GUItool: end automatically generated code
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
AudioMemory(8);
waveform1.begin(0.25, 400, WAVEFORM_SINE);
waveform2.begin(0.25, 400, WAVEFORM_SINE);
sine_fm1.frequency(200);
sine_fm1.amplitude(0.5);
sine_fm2.frequency(200);
sine_fm2.amplitude(0.5);
mixer1.gain(0, 0);
//mixer1.gain(1, 0);
envelope1.attack(2);
envelope1.hold(1);
envelope1.decay(3000);
envelope1.sustain(0);
envelope1.release(0.0);
envelope2.attack(2);
envelope2.hold(1);
envelope2.decay(3000);
envelope2.sustain(0);
envelope2.release(0.0);
envelope3.attack(2);
envelope3.hold(1);
envelope3.decay(200);
envelope3.sustain(0.1);
envelope3.release(500);
pinMode(testLed, OUTPUT);
}
elapsedMillis every1; //note that this occurs outside the setup
void loop() {
// put your main code here, to run repeatedly:
if(every1 >= 1) {
ringabell = ringabell+1;
if(ringabell == 2) {
sine_fm2.amplitude(0.5);
envelope3.noteOn();
digitalWrite(testLed, HIGH);
}
if(ringabell == 1200) {
sine_fm2.amplitude(0.0);
noteStop=1;
digitalWrite(testLed, LOW);
}
if(ringabell >= 3000) ringabell = 0;
every1 = every1-1;
}
if(noteStop==1) {
envelope3.noteOff();
noteStop=0;
}
}