COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 03-26-2013, 01:38 AM   #1
cisdsp
Human being with feelings
 
cisdsp's Avatar
 
Join Date: Mar 2013
Posts: 75
Default Something wrong with envelope calculations

Hi

I need some help on following code.
Doing some metering stuff with a own envelope follower code doesn't work correctly.

Getting my values like this:

Code:
//--processReplacing
    //--MAX PEAKS CALC METER
    
    peakL = MAX(peakL, fabs(*in1));
    peakR = MAX(peakR, fabs(*in2));
    
    //--PHASE CORRELATION METER
    CorrLR = outputCorr;

Then I have my envelopes and the calculations for the metering:

Code:
  double atCorr = exp(log(0.01)/( 10.0 * SR * 0.001));
  double relCorr = exp(log(0.01)/( 50 * SR * 0.001));
  
  double at2 = exp(log(0.01)/( 0.1 * SR * 0.001));
  double rel2 = exp(log(0.01)/( 50 * SR * 0.001));
  
  double envelope = 0.0;
  double envelope1 = 0.0;
  double envelope2 = 0.0;
  
  //--CORR ENVELOPE
  double tmpCorr = fabs(CorrLR);
  if(tmpCorr > envelope){
    envelope = atCorr * (envelope - tmpCorr) + tmpCorr;
  } else {
    envelope = relCorr * (envelope - tmpCorr) + tmpCorr;
  }
  
  //--LEFT ENVELOPE
  double tmpLeft = fabs(peakL);
  if(tmpLeft > envelope1){
    envelope1 = at2 * (envelope1 - tmpLeft) + tmpLeft;
  } else {
    envelope1 = rel2 * (envelope1 - tmpLeft) + tmpLeft;
  }
  
  //--LEFT ENVELOPE
  double tmpRight = fabs(peakR);
  if(tmpRight > envelope2){
    envelope2 = at2 * (envelope2 - tmpRight) + tmpRight;
  } else {
    envelope2 = rel2 * (envelope2 - tmpRight) + tmpRight;
  }
  
  CorrLR = CorrLR * envelope + mPrevCorr * (1.0 - envelope);
  peakL = peakL * envelope1 + mPrevL * (1.0 - envelope1);
  peakR = peakR * envelope2 + mPrevR * (1.0 - envelope2);



  mPrevL = peakL;
  mPrevR = peakR;
  mPrevCorr = CorrLR;
  
  if (GetGUI())
  {
    GetGUI()->SetControlFromPlug(mMeterIdx_L, peakL);
    GetGUI()->SetControlFromPlug(mMeterIdx_R, peakR);
    GetGUI()->SetControlFromPlug(mCorrIdx, CorrLR);

  }

So the thing is, that the metering for Correlation works perfectly.
The meters for Left and Right stock in last position when I stop the playback.

What's wrong in the LEFT & RIGHT envelopes?
Any help would be fine

Thanks!
__________________
Website: CIS DSP Factory
cisdsp is offline   Reply With Quote
Old 03-26-2013, 06:21 AM   #2
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

The problem seems to be that the peakL and peakR values never get any smaller because of MAX(). However, I don't really understand your code, so I can't tell what to do about it.
Tale is offline   Reply With Quote
Old 03-26-2013, 06:35 AM   #3
random_id
Human being with feelings
 
random_id's Avatar
 
Join Date: May 2012
Location: PA, USA
Posts: 356
Default

If you have an envelope follower setup, I don't think you need to do this:
Code:
     
peakL = MAX(peakL, fabs(*in1));
peakR = MAX(peakR, fabs(*in2));
The envelope follower already handles the changes in volume. I think you just need the fabs(*in).

Do you have the envelope follower code within ProcessReplacing, or is it somewhere else? The reason I ask is because I struggled in getting my own code to work until I realized that the host controls how many frames are sent to ProcessReplacing. If the envelope attack and decay are longer than the frames in samples, they will get constantly created/destroyed after all of the frames are processed.
__________________
Website: LVC-Audio
random_id is offline   Reply With Quote
Old 04-19-2013, 07:48 AM   #4
cisdsp
Human being with feelings
 
cisdsp's Avatar
 
Join Date: Mar 2013
Posts: 75
Default

Quote:
Originally Posted by random_id View Post
If you have an envelope follower setup, I don't think you need to do this:
Code:
     
peakL = MAX(peakL, fabs(*in1));
peakR = MAX(peakR, fabs(*in2));
The envelope follower already handles the changes in volume. I think you just need the fabs(*in).

Do you have the envelope follower code within ProcessReplacing, or is it somewhere else? The reason I ask is because I struggled in getting my own code to work until I realized that the host controls how many frames are sent to ProcessReplacing. If the envelope attack and decay are longer than the frames in samples, they will get constantly created/destroyed after all of the frames are processed.

If I can ask for your advice, where did you placed your envelopes?
__________________
Website: CIS DSP Factory
cisdsp is offline   Reply With Quote
Old 04-19-2013, 09:31 AM   #5
random_id
Human being with feelings
 
random_id's Avatar
 
Join Date: May 2012
Location: PA, USA
Posts: 356
Default

I have a separate class for each of my VUs that handle the attack/decay. I then declare the class in the header file of my plugin.

In the constructor of the VU envelope class, I have the attack and decay values calculated. I also have a ChangeSettings() method for sending new attack and decay settings.

Within the ProcessDoubleReplacing() frame loop of my plugin, I send the values to the VU envelope control (e.g., SetVal()). The control determines if it is attack or decay, and holds onto the current peak value as a private member of the VU envelope class. Outside of the frame loop, I use a GetCurrentPeak() method to retrieve the current value of the VU envelope. I use this to send to the graphical VU control (e.g., inLPeak->SetValueFromPlug(in_vu_Pl.GetCurrentPeak()); // the inLPeak is my GUI control for drawing the VU, the in_vu_Pl is my VU envelope control).

So, for my setup you need:
- to have a method for changing the attack or decay. This could be one method, or separate for attack and decay.
- to have a method for sending the current level from ProcessDoubleReplacing(), and the VU envelope class does the attack/decay calculation and stores it in a private member of the VU class
- to have a GetCurrentPeak() method to retrieve the current value from the class.

I also have some other things that I added, like a reset method, a way to calculate RMS, and a way to return a peak that is BOUNDED versus UNBOUNDED; however, those things aren't critical.
__________________
Website: LVC-Audio
random_id is offline   Reply With Quote
Old 04-20-2013, 04:39 AM   #6
cisdsp
Human being with feelings
 
cisdsp's Avatar
 
Join Date: Mar 2013
Posts: 75
Default

Thanks, I'll try that
__________________
Website: CIS DSP Factory
cisdsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 07:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.