Change slider according to audio input?

Hi guys, noobie here.

Making an audio plug-in, I want to change the slider value based on values that come up from the audio buffer. Let’s say for example I want to move the slider in each sample to the value corresponding to the sample value or something like that. I naively tried: preSlider.setValue(cur_sample_value);

within the processing block but I don’t have access to the slider from there. My C++ is pretty dusty. I can post code if needed. An example would be highly appreciated.

Unfortunately it is not only the C++ knowledge, that is in your way, but a basic understanding of audio processing in general.
In one seconds you have normally 44100 or 48000 samples. That means you want to change the slider 48000 times per seconds. Even if you do a highly optimised drawing lets say of 60 frames per seconds, your slider had 800 different values per frame. This shows, that your slider position would end up at random positions. Needless to say, that an interaction with that Slider would be impossible.

Parameters a user can handle should not need an interaction of more than 30 changes per second, maybe even less.

Now the C++ side:
Your parameter needs to be in the Processor. The GUI should only read the value, the processor should not push a value to the GUI, since it is not necessarily present. At least it should not rely on beeing successful doing so.

Also any interaction with the message thread (GUI) should be done with caution, since the message thread does not guarantee to finish in a determined time, which is crucial for the audio thread.

Hope that gets you further, maybe have a thought, what you actually want to control with the slider…

The way I’d do it would be to have a getCurrentSample() method in my processor to return the current amplitude of the audio. Then in the editor have a timer to call the get method maybe 60 times a second and update the slider’s value.

@daniel has already mentioned it a bit but if you just set your slider value to raw samples it’s going to look a bit… crap. You’d be better off implementing some sort of envelope to smooth your audio signal before sending those values to your slider.

Thanks guys for your response

I do understand the sample rate thing and that it doesn’t make sense to update a slider that often.
What I ask is rather an implementation thing:
How I can affect the slider value from the process block.

The single sample update is just a naive example I used, what I have in mind is pretty much like learning auto-attack and auto-release from the signal, adjusting let’s say in every sample or every buffer until some time and then to be able to change these learnt times using a slider.

It sounds like the timer approach might work, I’ll need to check it out. Any other ideas are also welcome.

The Timer approach is the most commonly used one.
If the update happens only every couple of seconds or even longer, you can use the AsyncUpdater to overcome the thread boundaries and use AudioProcessor::getActiveEditor() to trigger something in the editor (if it exists).

Basically have a read in this thread, it covers exactly your problem:

1 Like