How to send envelope values to IVMeterControl

Hi, I’ll be very thankful if anyone can help me.

In my plugin, I’m calculating the envelope of the inputs. And I want the user to be able to visualize the envelope, the input, and the output of the plugin in a meter (I’m using IVMeterControl). I’ve created the input and output meters with IPeakSender, and I’m trying to create the envelope meter with IBufferSender. However, I’m having trouble writing the input parameter of ProcessBlock() for the IBufferSender.

Please tell me what I’m doing wrong or if there’s a better way to create a meter for a value that is calculated while processing the audio:

  void MyPlugin::OnIdle()
  {
    mMeterInSender.TransmitData(*this);
    mMeterOutSender.TransmitData(*this);
    mMeterEnvSender.TransmitData(*this);
  }    

void MyPlugin::ProcessBlock(sample * *inputs, sample * *outputs, int nFrames
{
  sample\*\* senv;                     //Initializing sample for the envelope data        
  for (int s = 0; s < nFrames; s++) { 
      env= XXXXXX;                     //calculate envelope
      senv[0][s] = env;                //update senv with envelope value 
       
      outputs[0][s] =XXX;              //update outputs
      outputs[1][s] = XXX;
    }
  mMeterInSender.ProcessBlock(inputs, nFrames, kMeterIn);
  mMeterEnvSender.ProcessBlock(senv, nFrames, kMeterEnv);
  mMeterOutSender.ProcessBlock(outputs, nFrames, kMeterOut);
}

And in my header file:

private:
  IPeakSender<1> mMeterInSender;
  IPeakSender<1> mMeterOutSender;
  IBufferSender<1> mMeterEnvSender;

I can tell that I’m initializing sample** senv wrong but I can’t tell how to do it right.
I’m sorry if it’s a noob question but I’ve been looking through the forums and googling a lot and I just can’t figure it out. I get kinda confused around pointers…

Thanks!

If you are going to use an IPeakSender or IBufferSender which have ProcessBlock(sample** inputs, ...) style methods, then you need to keep a “scratch buffer”, some memory that is big enough to contain nFrames worth of sample values output by the envelope generator. Here is an example of how I do that using some WDL classes, but you can also do it with, e.g std::vector.

However, you probably don’t need to send buffers of samples if you are visualizing the envelope. The UI refresh rate is only 60 times per second which is a lot slower than the sample rate. You can probably get away with sending a single value per block. I would use an ISender and just push the last value returned by the envelope, once per block,

1 Like

You can also do it without a queue, like in this example

Used this one and it worked perfectly! Thank you so much!