What is KVR Audio? | Submit News | Advertise | Developer Account

Options (Affects News & Product results only):

OS:
Format:
Include:
Quick Search KVR

"Quick Search" KVR Audio's Product Database, News Items, Developer Listings, Forum Topics and videos here. For advanced Product Database searching please use the full product search. For the forum you can use the phpBB forum search.

To utilize the power of Google you can use the integrated Google Site Search.

Products 0

Developers 0

News 0

Forum 0

Videos 0

Search  

Envelope implementation, help

DSP, Plug-in and Host development discussion.

Moderator: Moderators (Main)

KVRist
 
79 posts since 18 Mar, 2012

Postby bitwise; Mon Jan 14, 2013 1:22 pm

nastyfingers wrote:
I tried storing a previous sample like with filters and mixing the 2 however this just causes signal overload.

Code: Select all
    currentSamp = prevSamp + (currentSamp * (1.0f / attack));




You're accumulating more than you should. Keep track of the current adsr level, separately:

Code: Select all
...
envLevel = envLevel + increment;
...
return envLevel;


Leave currentSamp out of the ADSR class and multiply it by the value returned by the ADSR::process method.
KVRer
 
10 posts since 11 Jan, 2013, from Sheffield, UK

Postby nastyfingers; Fri Jan 18, 2013 4:27 pm

Hi guys, thank for you input. I have been busy with other projects for a few days. Unfortunately this one is still bugging me. Have things moving through the envelope ( a bit buggily) as far as sustain. Release is proving tricky.

David, does making this change simply make the code easier to read? Not sure of the reasoning I ended up using while as oppose to if, and have never really seen the difference. Does it go deeper than the obvious?

bitwise, definitely no point in sending samples when the multiplier is all we need. I made changes made and have left another question.

How do I prevent the resulting coeff becoming to large before the relevant stage ends? I know there must be some sort of exponential maths to but just cannot figure it out. I suspect the answer is in on this http://www.kvraudio.com/forum/viewtopic.php?t=161416&highlight= thread but can't see how to translate it to my code.

my current code looks like this:

Code: Select all
#include <math.h>
#include "ADSR.h"


ADSR::ADSR()
{
   //stage = 1;
   //susTimer = 0;
   prevAttCoeff = 0.0f;
   currentAttCoeff = 0.0f;
   prevDecCoeff = 0.0f;
   currentDecCoeff = 0.0f;
   prevRelCoeff = 0.0f;
   currentRelCoeff = 0.0f;
}
ADSR::~ADSR()
{
}

double ADSR::process(float attack, float decay, float sustain, float release, int* pKeyState, long* pTime)
{
   //attack
   if(*pTime <= attack)
   {
      currentAttCoeff = (1.0f /attack) + prevAttCoeff;
      prevAttCoeff = currentAttCoeff;
      (*pTime)++;
      //stage = 1;
      return currentAttCoeff;
   }
   //decay   
   if(*pTime >= attack && *pTime < (attack + decay))
   {
      currentDecCoeff = ((1 - sustain) / decay) + prevDecCoeff;
      prevDecCoeff = currentDecCoeff;
      (*pTime)++;
      //stage = 2;
      return currentDecCoeff;
   }
   //sustain
   if(*pTime >= (attack + decay) && *pKeyState == 1)
   {
      //susTimer++;
      //stage = 3;
      return sustain;
   }
   //release
   if(*pKeyState == 2 && *pTime <= (attack + decay + release))
   {
      currentDecCoeff = sustain - (sustain / release) - prevRelCoeff;
      prevDecCoeff = currentDecCoeff;
      (*pTime)++;
      //stage = 4;
      return currentRelCoeff;
   }
   return -1.f;
}

KVRer
 
10 posts since 11 Jan, 2013, from Sheffield, UK

Postby nastyfingers; Wed Jan 23, 2013 3:33 am

I replied ages ago guys but it just doesn't seem to want to appear on the thread. When I go to edit it all my text is there, just not on the thread. Can anyone see what I wrote?
Previous

Moderator: Moderators (Main)

Return to DSP and Plug-in Development