Main Content

parameterTuner

Tune object parameters while streaming

Description

example

H = parameterTuner(obj) creates a parameter tuning UI and returns a figure handle, H.

Examples

collapse all

parameterTuner enables you to graphically tune parameters of multiple objects. In this example, you use a crossover filter to split a signal into multiple subbands and then apply different effects to the subbands.

Create a dsp.AudioFileReader to read in audio frame-by-frame. Create an audioDeviceWriter to write audio to your sound card.

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

Create a crossoverFilter with two crossovers to split the audio into three bands. Call visualize to plot the frequency responses of the filters. Call parameterTuner to open a UI to tune the crossover frequencies while streaming.

xFilt = crossoverFilter('SampleRate',fileReader.SampleRate,'NumCrossovers',2);
visualize(xFilt)
parameterTuner(xFilt)

Create two compressor objects to apply dynamic range compression on two of the subbands. Call visualize to plot the static characteristic of both of the compressors. Call parameterTuner to open UIs to tune the static characteristics.

cmpr1 = compressor('SampleRate',fileReader.SampleRate);
visualize(cmpr1)
parameterTuner(cmpr1)

cmpr2 = compressor('SampleRate',fileReader.SampleRate);
visualize(cmpr2)
parameterTuner(cmpr2)

Create an audiopluginexample.Chorus to apply a chorus effect to one of the bands. Call parameterTuner to open a UI to tune the chorus plugin parameters.

chorus = audiopluginexample.Chorus;
setSampleRate(chorus,fileReader.SampleRate);
parameterTuner(chorus)

In an audio stream loop:

  1. Read in a frame of audio from the file.

  2. Split the audio into three bands using the crossover filter.

  3. Apply dynamic range compression to the first and second bands.

  4. Apply a chorus effect to the third band.

  5. Sum the audio bands.

  6. Write the frame of audio to your audio device for listening.

while ~isDone(fileReader)
    audioIn = fileReader();
    
    [b1,b2,b3] = xFilt(audioIn);
    
    b1 = cmpr1(b1);
    b2 = cmpr2(b2);
    b3 = process(chorus,b3);
    
    audioOut = b1+b2+b3;

    deviceWriter(audioOut);
    
    drawnow limitrate % Process parameterTuner callbacks
end

As a best practice, release your objects once done.

release(fileReader)
release(deviceWriter)

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:

  1. Read in a frame of audio from the file.

  2. Apply equalization.

  3. 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)

Create a dsp.AudioFileReader to read in audio frame-by-frame. Create an audioDeviceWriter to write audio to your sound card. Create an audiopluginexample.Flanger to process the audio data and set the sample rate.

fileReader = dsp.AudioFileReader('RockGuitar-16-96-stereo-72secs.flac');
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

flanger = audiopluginexample.Flanger;
setSampleRate(flanger,fileReader.SampleRate);

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

parameterTuner(flanger)

In an audio stream loop:

  1. Read in a frame of audio from the file.

  2. Apply flanging.

  3. Write the frame of audio to your audio device for listening.

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

As a best practice, release your objects once done.

release(fileReader)
release(deviceWriter)

Create a dsp.AudioFileReader to read in audio frame-by-frame. Create an audioDeviceWriter to write audio to your sound card. Create a compressor to process the audio data. Call visualize to plot the static characteristic of the compressor.

frameLength = 1024;
fileReader = dsp.AudioFileReader('RockDrums-44p1-stereo-11secs.mp3', ...
    'SamplesPerFrame',frameLength);
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

dRC = compressor('SampleRate',fileReader.SampleRate); 
visualize(dRC)

Create a timescope to visualize the original and processed audio.

scope = timescope( ...
    'SampleRate',fileReader.SampleRate, ...
    'TimeSpanSource','property',...
    'TimeSpan',1, ...
    'BufferLength',fileReader.SampleRate*4, ...
    'YLimits',[-1,1], ...
    'TimeSpanOverrunAction','Scroll', ...
    'ShowGrid',true, ...
    'LayoutDimensions',[2,1], ...
    'NumInputPorts',2, ...
    'Title','Original vs. Compressed Audio (top) and Compressor Gain in dB (bottom)');
scope.ActiveDisplay = 2;
scope.YLimits = [-4,0];
scope.YLabel = 'Gain (dB)';

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

parameterTuner(dRC)

In an audio stream loop:

  1. Read in a frame of audio from the file.

  2. Apply dynamic range compression.

  3. Write the frame of audio to your audio device for listening.

  4. Visualize the original audio, the processed audio, and the gain applied.

While streaming, tune parameters of the dynamic range compressor and listen to the effect.

while ~isDone(fileReader)
    audioIn = fileReader();
    [audioOut,g] = dRC(audioIn);
    deviceWriter(audioOut);
    scope([audioIn(:,1),audioOut(:,1)],g(:,1));
    drawnow limitrate % required to update parameter
end

As a best practice, release your objects once done.

release(deviceWriter)
release(fileReader)
release(dRC)
release(scope)

Input Arguments

collapse all

Object to tune, specified as an object that inherits from audioPlugin or one of the following Audio Toolbox™ objects:

Output Arguments

collapse all

Target figure, returned as a Figure object.

Version History

Introduced in R2019a