%% Tune Hosted Audio Plugin Parameters
% Create a dsp.AudioFileReader to read in audio frame-by-frame. Create an audioDeviceWriter to write audio to your sound card. Use loadAudioPlugin to load an equalizer plugin. If you are using a Mac, replace the .dll file extension with .vst.

fileReader = dsp.AudioFileReader('FunkyDrums-48-stereo-25secs.mp3');
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

pluginPath = fullfile(matlabroot,'toolbox/audio/samples/ParametricEqualizer.dll');
eq = loadAudioPlugin(pluginPath);
setSampleRate(eq,fileReader.SampleRate);

%
% Call parameterTuner to open a UI to tune parameters of the equalizer while streaming.

parameterTuner(eq)

%
%
% In an audio stream loop:
% Read in a frame of audio from the file.
% Apply equalization.
% Write the frame of audio to your audio device for listening.

while ~isDone(fileReader)
    audioIn = fileReader();
    audioOut = process(eq,audioIn);
    deviceWriter(audioOut);
    
    drawnow limitrate % Process parameterTuner callbacks
end

%
% As a best practice, release your objects once done.

release(fileReader)
release(deviceWriter)

%
% Copyright 2018 The MathWorks, Inc.