Can anyone help with how could I add ADSR to an Arduino Uno synth?
Originally i thought the envelope table would do that, but that seems to be for the wave shape envelope instead?

even without potentiometers, if i want to set only 1 Adsr envelope to a sine wave.. Is it possible with some optimised code or something?

Reading a few tutorials I found on google but i can't quite understand it yet

You can do it through the wave table.

The alternitave is multiplying every sample by a floating point value and that is going to screw your waveform's sample rate.What processor are you running ?

Ah yes, it’s a ATmega328P at 16Mhz. Is the alternative method going to slow that down a lot? It seems so… but

With the wave table, would one way to be writing each wave table for attack, decay, sustain, and releaseand then some how multiplying that in a function to the output, or after the output?

With some smaller code however I wonder if its possible in a way like this:
For example

``````/******** Sine wave parameters ********/
#define PI2     6.283185 // 2 * PI - saves calculating it later
#define AMP     127      // Multiplication factor for the sine wave
#define OFFSET  128      // Offset shifts wave to just positive values

/******** Lookup table ********/
#define LENGTH  256  // The length of the waveform lookup table
byte wave[LENGTH];   // Storage for the waveform

for (int i=0; i<LENGTH; i++) {
float v = (AMP*sin((PI2/LENGTH)*i));  // Calculate current entry
wave[i] = int(v+OFFSET);              // Store value as integer
}
``````

makes a look up table for the sine, but could you make a loop that a loop that makes a sort of exponential table for Adsr? However I only really have one ADSR setting I want to use and that is a long attack and long release, so a wave table would be fine. I’m just wondering how to implement it, would it be a case of multiplying an Adsr function for the output or after the output? I’m using “the_synth” library which seems to be capable of adding this in synth.h and adding extra tables in table.h The_Synth
Sorry, obviously i have never done this before… thanks for your help

Is the alternative method going to slow that down a lot?

I think so, but try it and see if it does for your application.

With the wave table, would one way to be writing each wave table for attack, decay, sustain, and release

Is that not what it is already?

and then some how multiplying that in a function to the output, or after the output?

No once you have identified the points in the wave tables, you can control the speed that the wave tables advance, or you can hold the waveform at that point for a specific time for the sustain.

That synth looks quite over simplified for what you are trying to do.

Ah yes, it's a ATmega328P at 16Mhz