Hey guys! I just started JUCE for a few days, I got some C++ coding experience but I am totally new to the JUCE framework. I got some questions that I can’t quite figure out!
Here is my project idea, I want to build some thing like a compressor, but not quite. I want my plugin to first look at the max volume level of my audio file. After getting the max volume level, when I play the track with this plugin on, I want the plugin to scale every sample of that track to the same volume level as the max level. So, when I play this track, no matter when, I am going to hear the same volume constantly.
So I guess this is my question:
I do not know how to read the level of a sample from an audio. Is there a function for this?
How does this VST plugin get the max level of this audio before playing through it, and use that level as the max to scale every other samples in the audio?
Maybe some suggestions on this project?
Again, I am very new to JUCE, and I am also kinda new to this audio engineering. I don’t even know if I am using the right terminologies (volume, level, etc…), so bare with me if I asked something stupid or tell me if I am not clear enough
I’d start by learning some DSP logic. starting with the principle of Time Domain vs Frequency Domain. (you’re into the time from what I understand…)
With discrete audio as you wrote you’re gettings samples. each one is like a snapshot in time. (samplerate is how much snapshots you’ve made per time - usually hertz, so for example 44.1khz is 44100samples in a seconds).
Bit Depth: is what’s your level scale (Y-axis). keep in mind a wave is going from the center to negative and positive directions… With float/double audio is usually sampled to values between -1.0 to +1.0 where 0.0 is the center (silence). also keep in mind those units ARE NOT decibels!
For your questions:
The basic very naive logic for peak-based maximum would be:
`
// this should be somewhere that won't cause it to re-set when you need to compare
// last maxPeakFound...
float maxPeakFound = 0.0f;
for (int sample = 0; sample < totalSamples; ++sample)
{
maxPeakFound = jmax(fabs(myAudio[sample]),maxPeakFound);
}
`
Getting all the audio with an audio plug-in would usually mean asking the plug-in user to play the audio material once in a detection mode. This is the most compatible way.
There’s also ARA but as you’re just starting off I’ll avoid wasting time on integrating code instead of making sure your algorithm is working.
Again, DSP understanding would be the best start. also check JUCE own DSP Examples.
Usually a VST/AU/AAX plugin work in sample blocks to get a continuous flow with the chance to optimise the algorithms. There will be situations, when the actual peak is in the neighbouring block, so you get false readings. You will have to choose a strategy to average over many blocks.
Since you are asking about how to read audio ahead, I assume you came across EBU R128 as loudness measurement unit. If not, it is the current state of the art specification. There is the implementation of @samuel, which works great. He was generous enough to show the measuring code as open source, and the plugin is available for sale. I use it, it is a real life safer.