Hello,
as you can see it’s two questions (asks for advice) in one thread. I work on audio compressor.
- What is the best (most efficient) way to implement audio level monitor? I made it as follows, but I don’t feel it’s the best solution:
I createdMonitorClass
which is also (inherited from)Component
andTimer
. I make it visible and start timer inmyAudioProcessorEditor
. Timer period is set tomyMonitorClass.startTimer(1000 / 30);
. So it’s about 30 times per second.
InMonitorClass
I have also variablestd::atomic<float> inputLevel[NUM_OF_CHANNELS]]
which I use to set the height of theRectangle<float>
. I set it andrepaint()
in thetimerCallback
. Of course Inpaint (Graphics& g)
I fill theRectangle
and it’s my monitor actually.
And how I updateinputLevel
? I update it inmyAudioProcessor
exactly inprocessBlock
as follows:
for(int i=0; i<buffer.getNumSamples(); ++i) { for (int channel = 0; channel < totalNumInputChannels; ++channel) { auto* channelData = buffer.getWritePointer (channel); float inputSample = inputGain * buffer.getSample(channel, i); if( fabs(inputSample) > myMonitorClass.inputLevel[channel] ) myMonitorClass.inputLevel[channel] = (fabs(inpSamp)); // ... BLA ... BLA ... BLA ... } }
So it is updates only the highest level of sample. Of course in monitor timerCallback
after I set height of the Rectangle
I reset inputLevel[channel] = 0.0f;
Is it a proper manner to implement such things? It works, but maybe it could be done better?
- And my second question is about filling
Path
partly. Because I want to make my monitor on the compressor curve graph. Something like that is in Logic Pro built in compressor. There is the small circle that jumps on the compressor curve, like that:
But I want to fill the area under the curve, something like I demonstrate with red mark:
Do you understand what I mean? Please could you give me some advice how to achieve such thing?
For any help great thanks in advance.