audio codec ADSR is it posible?

audio codec ADSR is it posible?

Postby dsese1234 » Fri Mar 22, 2013 12:25 am

Hi guys,

I am wondering how to code an adsr with the audio codec. i am using arduino on it. is it posible? i have an video about the adsr. here is the video. http://www.youtube.com/watch?v=XjgnchGwPtY nice sound! :)

any idea?


Regards
dsese1234
 
Posts: 2
Joined: Thu Jan 31, 2013 3:11 am

Re: audio codec ADSR is it posible?

Postby guest » Fri Mar 22, 2013 2:33 pm

it should be possible to do something like that.

the first thing to accomplish is getting some sort of triggering based on input threshold. so maybe make a simple noise gate first:

if audio_in < value -> then audio_out = 0; else audio_out = audio_in;

you can then play around with the value to see where a good trigger level is.
the next thing to accomplish is varying the amplitude with time. so set up a variable which is a counter. this will count the amount of times you have fallen through the ISR (put this in the ISR loop). you can multiply your input value by this counter to create an envelope.

here is some pseudocode

Code: Select all
at beginning

unsigned int env = 0;
byte trig = 0;
int threshold = some value;
byte decay = 0;

in ISR()

// check if doing envelope or not
if (trig = 0) {
  if (audio_in > threshold) { // if not check if trigger threshold has been reached
    trig = 1;
  }
  audio_out = 0;
}

else {
  if (decay = 0) { // if not decaying, upcount your envelope
    env++;
    if (env > 0xfffe) {
    decay = 1;
  }
  else { // otherwise downcount
    env--;
    if (env == 0) {
      decay = 0;
      trig = 0;
    }
  }
audio_out = audio_in * env; // multiply audio by envelope - be sure to use special math functions here
}


after you have something like this working, you can change how the env value gets incremented and decremented for seperate attack and decay values. be sure to look at some of the examples of doing the special math multiplies, these take way less time.
guest
Site Admin
 
Posts: 449
Joined: Thu May 20, 2010 11:58 pm

Re: audio codec ADSR is it posible?

Postby dsese1234 » Fri Mar 22, 2013 6:13 pm

Thank you so much for replying, i am analyzing your code. can you make it full code? this is nice actually but not sure yet how to apply the code on arduino. i am new about it., thanks in advance! =)
dsese1234
 
Posts: 2
Joined: Thu Jan 31, 2013 3:11 am


Return to Audio Codec Shield

Who is online

Users browsing this forum: No registered users and 1 guest


cron