Envelope detector and VCA with Teensy's Audio library

So I think I understand how it works, the Absolute value acts like an effect, it take the input of an audio stream and outputs the absolute value aka the envelope? So I take the output of the ABS and send that into the control input of a state variable filter?
 
Well, not exactly. After you obtain the absolute value of the signal, which is called a rectified signal, you need to low pass filter it out in order to make it a signal that evolves following the envelope of the original signal. Then you can use the signal as a control signal as you pointed out.
https://en.wikipedia.org/wiki/Envelope_detector <- this is the equivalent in the analog domain, diode rectifies and capacitor lowpassfilters.

View attachment effectAbsExample.ino
Here's the arduino sketch that you can use as a test. It uses de signal you will input in the analog input of the teensy, gets its envelope and uses it to modulate the amplitude of a sine wave. What you should listen is the volume of the sine wave to increase as the signal volume of the breathe detector increases.

Hope it helps, and get back to me for any doubts or help you need.

Salut!
 
wow, I got it working!! Now I have a sweeet envelope controlled filter, and it sounds good! I appreciate you taking the time to help me out. Now my mind is exploding with all the possibilities of envelope control...
 
Well, not exactly. After you obtain the absolute value of the signal, which is called a rectified signal, you need to low pass filter it out in order to make it a signal that evolves following the envelope of the original signal. Then you can use the signal as a control signal as you pointed out.
https://en.wikipedia.org/wiki/Envelope_detector <- this is the equivalent in the analog domain, diode rectifies and capacitor lowpassfilters.

which gives you not the envelope, but an approximation to the rms value.
Wikipedia is not completely correct!
See figure where the link is to analytic signal.
 
Glad to hear that it helped you! Which breathe sensor are you using? I've always wanted to create a trumpet-like instrument but never known of suitable sensors... You think yours can serve that purpose?
WMXZ, dunno buddy, I call that envelope an it works for me to generate the envelope of another signal... I just linked to wikipedia for a quick-dirty illustration of the concept!
 
I'm thinking you may want to add the '#include "effect_abs.h"' statement explicitly to your application code rather than putting it in Audio.h. If PRJC updates the library and creates a new Audio.h, then your modification will be lost.
 
Last edited:
Glad to hear that it helped you! Which breathe sensor are you using? I've always wanted to create a trumpet-like instrument but never known of suitable sensors... You think yours can serve that purpose?
WMXZ, dunno buddy, I call that envelope an it works for me to generate the envelope of another signal... I just linked to wikipedia for a quick-dirty illustration of the concept!

Hey! I'm using the envelope to control the bandpass frequency of the state variable filter. So it's like an auto wah. I use the effect on the synth sounds generated using the library.
 
Hey! I'm using the envelope to control the bandpass frequency of the state variable filter. So it's like an auto wah. I use the effect on the synth sounds generated using the library.

Nice! And which is the sensor you are using to detect the breathe?
 
I'm thinking you may want to add the '#include "effect_abs.h"' statement explicitly to your application code rather than putting it in Audio.h. If PRJC updates the library and creates a new Audio.h, then your modification will be lost.

Good point, it actually happened to me once, but losing the Audio.h wasn't the most annoying thing but losing the .h and .cpp of the new class code which can be erased when you update the teensyduino. Can those be placed in another folder or they need to be placed in the Audio folder in order to fetch properly the dependencies like AudioStream?
 
You can put your .cpp and .h files for your custom audio classes in a separate folder in your 'libraries' folder or in the same folder as your application .ino file. The former makes more sense as it allows you to use your custom classes in multiple applications.

Delete your custom Audio.h file. In your custom .cpp and/or .h files files, include the classes you need from the Audio library. For example:

Code:
#include "AudioStream.h"
 
Nice! And which is the sensor you are using to detect the breathe?

Hey! Not totally sure what you mean. I'm not using any sensors or any external signals. The synth sound are generated inernally by the Teensy, and I'm using that to create the envelope and then using the envelope to control the state variable filter applied to the same signal I extracted the envelope from. Hopen that makes sense!
 
Nevermind, I just thought that as long as you wanted to monitor human breath patterns you were using some sort of sensor to do so.
 
Nevermind, I just thought that as long as you wanted to monitor human breath patterns you were using some sort of sensor to do so.

I understand! There are two Sams!! You are referring to username skwelker, whose real name is Sam, who wants to monitor human breath patterns.
I am username Sam, my real name is Sam, and I want to use the envelope filter to make funky synth sounds. Now it all makes sense!!
 
Well, not exactly. After you obtain the absolute value of the signal, which is called a rectified signal, you need to low pass filter it out in order to make it a signal that evolves following the envelope of the original signal. Then you can use the signal as a control signal as you pointed out.
https://en.wikipedia.org/wiki/Envelope_detector <- this is the equivalent in the analog domain, diode rectifies and capacitor lowpassfilters.

View attachment 10313
Here's the arduino sketch that you can use as a test. It uses de signal you will input in the analog input of the teensy, gets its envelope and uses it to modulate the amplitude of a sine wave. What you should listen is the volume of the sine wave to increase as the signal volume of the breathe detector increases.

Hope it helps, and get back to me for any doubts or help you need.

Salut!

RTPNaskers can you help me use your Envelope with midi cc? I thinking do it in steps like that: adc1(A2) go to abs go to filter1 go to usbMIDI CC1. But I'm not sure how to get output from filter, and use it to generating CC, and what I need else to connect to the input 1 filter? can I connect real potentiometer to the input 1 for setting freq filter?
 
Hi Kirazvora!

I think that what you want to do is definitely possible. Your guess is right: you need to get the envelope with the abs and then the filter and then output this from the audio system to the sketch so you can put these values into a variable that is sent with usbMDI CC1. To do so input and output data from the sketch to the audio system and back again to the sketch I'm pretty sure you need to use AudioPlayQueue and AudioRecordQueue respectively. I haven't done so yet and it looks you have to deal with buffers and other stuff that might be tricky but I think that's the way to go. If needed I can try to implement and sketch with these so I learn myself how to use them!

Salut!
 
Hi Kirazvora!

I think that what you want to do is definitely possible. Your guess is right: you need to get the envelope with the abs and then the filter and then output this from the audio system to the sketch so you can put these values into a variable that is sent with usbMDI CC1. To do so input and output data from the sketch to the audio system and back again to the sketch I'm pretty sure you need to use AudioPlayQueue and AudioRecordQueue respectively. I haven't done so yet and it looks you have to deal with buffers and other stuff that might be tricky but I think that's the way to go. If needed I can try to implement and sketch with these so I learn myself how to use them!

Salut!

Yeah it’s possible, I downloaded abs and I will try it. Abs in the working, is similarly to RMS object from Audio library? I guess that is. Will be great to see examples from you if you can. I trying get envelope follower with RMS object and I get some success, close to my needs. Still have some minor problems, when finishing up, I put my code on forum.
 
Take in account that abs by itself won't do the envelope following, actually by itself does some sort of double-pitching to the signal as it rectifies it: kinda funny, but not what you're looking for. It has to work along with an LPF with a low cutoff frequency around 15Hz or less. I'm attaching the same example I uploaded for you to test the envelope following. When I get a little more of free time I'll try to do an example that can output the envelope from the audio system to the sketch.
 

Attachments

  • effectAbsExample.ino
    825 bytes · Views: 93
Hey guys!
This thread made me understand how an Auto-Wah works. Using the waveform envelope asynchronously with a peak function, it trigs the effect and adjust the bandpass filter accordingly. Here is my first test that gives a nice render.
About the theory of a wah pedal, here is the electrosmash explanation: https://www.electrosmash.com/vox-v847-analysis
BTW, this is my first post in the forum. It's very interesting stuff for a coder musician! :)
 

Attachments

  • Pedal_Wah.ino
    2.7 KB · Views: 12
Trying to use this ABS effect to control filter cutoff with a guitar. It’s working but sounds pretty distorted, is that normal? Maybe i’ve got it plumbed in wrong? amp1 is a stand in for abs1, changes have been made to the sketch

Screenshot 2024-03-01 at 12.29.51.png


Code:
#include "effect_abs.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputI2S            i2s1;           //xy=89.88888931274414,110.66666793823242
AudioEffectAbs           abs1;           //xy=210,35.555556297302246
AudioFilterStateVariable filter1;        //xy=350.00002670288086,38.88889026641846
AudioFilterStateVariable filter2;        //xy=354.44444274902344,110.00000381469727
AudioOutputI2S           i2s2;           //xy=528.2222518920898,57.33333969116211
AudioConnection          patchCord1(i2s1, 0, abs1, 0);
AudioConnection          patchCord2(i2s1, 0, filter2, 0);
AudioConnection          patchCord3(abs1, 0, filter1, 0);
AudioConnection          patchCord4(filter1, 0, filter2, 1);
AudioConnection          patchCord5(filter2, 1, i2s2, 0);
AudioControlSGTL5000     sgtl5000_1;     //xy=716.5555725097656,208.22222709655762
// GUItool: end automatically generated code


void setup() {
  AudioMemory(60);

  filter1.frequency(1.0);

  filter2.frequency(600);
  filter2.resonance(5);
  filter2.octaveControl(7);
}

void loop() {
}
 
Back
Top