How can I do real time audio processing with sliders in a Matlab script (*.m files)?

4 views (last 30 days)
Hi! I want to perform some audio processing inside a Matlab script using sliders. I want the audio to change in real time as I move the slider across the screen. I am using as an example the AudioProcessingScript.m, but the audio changes when I release the slider rather than while I am moving it. If anyone could help me with this, I would gladly appreciate it. Thanks in advance!
The AudioProcessingScript.m script goes something like this:
%% A. Create input and output objects
fileReader = dsp.AudioFileReader( ...
'speech_dft.mp3', ...
'SamplesPerFrame',64, ...
'PlayCount',3);
deviceWriter = audioDeviceWriter( ...
'SampleRate', fileReader.SampleRate);
%% B. Create an object of a handle class
x = parameterRef;
x.name = 'gain';
x.value = 0.5;
%% C. Open the UI function for your parameter
parameterTuningUI(x,0,1)
%% D. Process audio in a loop
while ~isDone(fileReader)
audioIn = fileReader();
drawnow limitrate
audioOut = x.value*audioIn;
deviceWriter(audioOut);
end
% Release input and output objects
release(fileReader)
release(deviceWriter)

Answers (1)

Kiran Felix Robert
Kiran Felix Robert on 14 Aug 2020
Hi Ayrton,
In general, the slider callback is executed only when the slider is released. I understand that you are trying to get the values continuously as the slider is updated and not to wait for the slider to be released. I also assume that you have a working GUI and a working Audio processing callback functions. To get the slider update as it is moved ,the addlistenerfunction can be used.
The following example is to print the slider value, as it is being moved, in the command window
Ck = @(empty,ol) disp(ol.AffectedObject.Value);
f = figure();
s = uicontrol(f,'Style','slider');
addlistener(s, 'Value', 'PostSet',Ck);
The callback function can be altered to call the audio processing functions. To share data between the callbacks, refer this link.
Hope this Helps.
Kiran Felix Robert

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!