Clicking envelope with Audio Library?

Paul, maybe this could be a good (?) practical example for using the Envelope object.

I'd love to include a couple examples with the library, if you'd like to contribute a complete program.

Generally, examples fall into 2 different categories. Most are designed to be simple and have minimal dependency on other stuff. For those "less is more", where simplicity and quickly achieving a known-good result (without dependency on other devices) is the best way to help people learn the particular feature.

The other type of examples are more complex, but fulfill a commonly needed function. Maybe this MIDI controlled sketch could be one of those. Typically, complex examples need more explanation or documentation, so someone unfamiliar with the application can use them effectively.

Examples should also state they're public domain, usually with a simple 1-line message (many currently do not, but should). See Arduino's builtin File > Examples > 01.Basics examples for the ideal way.

If you're willing to contribute example code, please try to design it along one of these 2 paths. Github pull requests are the best way to send the code, but posting here is ok too.
 
>>>If you're willing to contribute example code, please try to design it along one of these 2 paths. Github pull requests are the best way to send the code, but posting here is ok too.

Paul,
I think this is a great idea and I will give it a shot next weekend.

In the meantime, here is what I was able to concoct up to now:
https://www.youtube.com/watch?v=0TwvVEKTPfU

This is my second synth designed to produce these special (morphing) waveforms.
The first version of this synth was "variable rate conversion": I designed a way to read the wavetable at a different speed (according to the pitch), I used a DS1077 for that. The waveforms were stored in an external EEPROM (https://www.youtube.com/watch?v=uTbrVGvP8gg). The drawback of this design is that - unless I feed the sound back to the teensy from the audio board - I need a lot of external components for 1) ADSR, 2) VCF, etc.

The new version is more compact, the Audio library gives us support to perform a lot of operations in the digital domain ( I really, really dig the FFT, especially since I figured out how to use the queue..., the mic example was great!).
However, using a phase increment to vary the pitch introduces aliasing.
As we discussed, the way to fix this is to band limit the wavetable for the higher notes, the drawback is that I need to manage more wavetables for the same waveform.
I am experimenting with Matlab (I may buy a home version) to accomplish this reliably and accurately.
Of course, I will keep you posted.

Thank you Paul and all for your continued support.
 
Does the default Audio library include these click-reducing improvements yet? i.e those mentioned earlier in this post?
It looks like the improvements would eliminate the noteOff() before SUSTAIN-phase click issue.

I expect I still need to handle the noteON() before end-of-DECAY clicking possibility.
It would help to have a method, such as envelope.Phase(), which would return the current envelop phase, and allow waiting for an appropriate phase for pitch changes.
 
Last edited:
I've finally fixed the envelope object numerical limitation.

I also tried to fix this click issue. Could really use some feedback on the effectiveness of this fix, if anyone is willing to try the latest from github...
 
I have the same click of ever :(

Are you running the latest code? Please, do 2 things to check.

1: Click Help > About (or Arduino > About on macintosh) to check the Teensyduino version.

2: The add any error to your code and click Verify. When compile fails, Arduino prints info about any duplicate libraries. You may have an old copy in some location like Documents/Arduino/libraries/Audio which is overriding the one from Teensyduino in hardware/teensy/avr/libraries/Audio.
 
Are you running the latest code? Please, do 2 things to check.

1: Click Help > About (or Arduino > About on macintosh) to check the Teensyduino version.

2: The add any error to your code and click Verify. When compile fails, Arduino prints info about any duplicate libraries. You may have an old copy in some location like Documents/Arduino/libraries/Audio which is overriding the one from Teensyduino in hardware/teensy/avr/libraries/Audio.

Thank you Paul for your reply ..


Arduino 1.8.3 Teensyduino 1.37

I have a duplicate library "SD" but it's unused in my code .. (solved now thank you).

So i'm using audio library with SGTL500 and 64 audio blocks samples (AudioStream.h).

Example of my code than generate click when the note are
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=475,173
AudioEffectEnvelope      envelope1;      //xy=723,239
AudioOutputI2S           i2s2;           //xy=1035,61
AudioConnection          patchCord1(sine1, envelope1);
AudioConnection          patchCord2(envelope1, 0, i2s2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=94,31
// GUItool: end automatically generated code

elapsedMillis tempo;

void setup() {

/////////////////////////   SETUP AUDIO    ////////////////////////////////////

sgtl5000_1.enable();
AudioMemory(30);
sgtl5000_1.lineOutLevel(13);
sgtl5000_1.lineInLevel(0);
sgtl5000_1.adcHighPassFilterDisable();
sgtl5000_1.muteHeadphone();
sine1.amplitude(1);
sine1.frequency(400);
envelope1.attack(30);
envelope1.decay(200);
envelope1.sustain(1);
envelope1.release(200);

}
void loop() {if (tempo > 1000) {envelope1.noteOff(); envelope1.noteOn(); tempo=0;}
}


Waves when there is the clip:

Schermata 2017-07-14 alle 11.40.06.png

Audio of the clip:

https://www.dropbox.com/s/21lv1wtozqhmves/click.mp3?dl=0
 
You're turning the note off, and then immediately back on again. There simply isn't any time allowed for the release phase. What do you expect the envelope to do?
 
You're turning the note off, and then immediately back on again. There simply isn't any time allowed for the release phase. What do you expect the envelope to do?

Mhhh i expect that it works like all the synthesizer with only one voice so i can play note imediately after a previous note without attend that the first envelope is finished... The musician plays the keyboard isn't a electronic technician, he must to be able to play the note when he want :)

This is the same problem of the previous version of library, but now the click position is changed in fase...
 
Mhhh i expect that it works like all the synthesizer with only one voice so i can play note imediately after a previous note without attend that the first envelope is finished... The musician plays the keyboard isn't a electronic technician, he must to be able to play the note when he want :)

This is the same problem of the previous version of library, but now the click position is changed in fase...
OK, how should it look like to avoid that ?

I guess, a simple solution is to use more than one voice : let the first release and start the second in parallel. Of course you need a more advanced sketch which is able to to do this.
 
I know that i must to use more voice but for a drums machines for example it's impossible... should be use 100 voices for good user experience... it's a problem and I hope that it's possible to be solved...
 
No, you're stopping the voice. The Teensy does what you tell him..
And you don't need 100 voices. maybe 10 (max).
 
No Frank, sorry but it's my work... for a drums machine like tr909 we need 20/25 voices for a working sound (able to fast repeat) without click and it's nosense if you think that it's a workaround of a problem 😅

I hope in a solution because audio library have a grate sound quality and it's a real revolution, for me it's the way for the future of music ❤️
 
If you add efx, filters, other sounds and features... all it's a problem if you need a workaround for a click 😅
 
Well, i see two ways:
a) use a second voice and let the first play until it is done (my suggestion)
b) wait until the first hits "zero" - this adds a unpredictable lag and does NOT stop the voice immediately. In addition, if you want to use this for drums, it will not sound good - a hi-hat for example will stop way too fast, and you'll hear this.

I don't see an other way. Do you know a better way ? You're the pro, and I'm willing to learn....

Edit:
I'm not sure if b) avoids a click in every case...
a) should be easy to solve with a queue (linked list?) or array.
 
Last edited:
For synth I have an idea.... but I must to try it..
If you add a flag for the prev note status (noteon or noteoff) when you need the second note over the previous and the flag say that the envelope is on you can change only the freq without use the envelope note...

What do you think?

The freq modification don't makes a click...
 
I'm a musician not a bulder of commercial synth... I don't know.. 😅

Some synth are analog, some have the samples, I think that teensy is the new way but we must to solve all the problems :)
 
You're saying you need drum sounds, but you're testing with a sine wave using 1.0 sustain. That's nothing like a drum sound at all.

So again, I will repeat Frank's question. What do you expect the envelope gain to do when you are in the sustain phase and you immediately end the note and begin another? Your answer to this question must be in terms of how the envelope object changes its gain over time, not some story about a drum machine. We're talking about the math of the envelope object.
 
Paul, please... record a good piano melodie by a OSC with this click... please try and after we can speak about this problem... :)

There is a problem but you don't want to see it and a can't understand why!

Try... MP3 is good for me... ;)
 
Paul, please... record a good piano melodie by a OSC with this click...

How am I supposed to perform this test? Do I need to fully write the code to play a piano melody, somehow using the envelope object? What code do I use? The only code I see posted is on message #32, which is only a single sine wave.
 
all the codes have a click if you play 2 note closer! This is the problem and I think that you know this!

you can fix my code #32, how can I have a sound without click? I must to tell to musician that he must to wait the envelope time before next note? 🙊

Please... the only way is using more voices but it's a workaround not a solution and if you have a fast finger musician we need 20 voices for instrument 🙈
 
Back
Top