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

全部折叠

parameterTunerenables 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 adsp.AudioFileReaderto read in audio frame-by-frame. Create anaudioDeviceWriterto write audio to your sound card.

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

Create acrossoverFilterwith two crossovers to split the audio into three bands. Callvisualizeto plot the frequency responses of the filters. CallparameterTunerto open a UI to tune the crossover frequencies while streaming.

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

Create two压缩机objects to apply dynamic range compression on two of the subbands. Callvisualizeto plot the static characteristic of both of the compressors. CallparameterTunerto 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 anaudiopluginexample.Chorusto apply a chorus effect to one of the bands. CallparameterTunerto 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); drawnowlimitrate% Process parameterTuner callbacksend

As a best practice, release your objects once done.

release(fileReader) release(deviceWriter)

Create adsp.AudioFileReaderto read in audio frame-by-frame. Create anaudioDeviceWriterto write audio to your sound card. UseloadAudioPluginto load an equalizer plugin. If you are using a Mac, replace the.dllfile 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);

CallparameterTunerto 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); drawnowlimitrate% Process parameterTuner callbacksend

As a best practice, release your objects once done.

release(fileReader) release(deviceWriter)

Create adsp.AudioFileReaderto read in audio frame-by-frame. Create anaudioDeviceWriterto write audio to your sound card. Create anaudiopluginexample.Flangerto 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);

CallparameterTunerto 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); drawnowlimitrate% Process parameterTuner callbacksend

As a best practice, release your objects once done.

release(fileReader) release(deviceWriter)

Create adsp.AudioFileReaderto read in audio frame-by-frame. Create anaudioDeviceWriterto write audio to your sound card. Create a压缩机to process the audio data. Callvisualizeto plot the static characteristic of the压缩机.

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 atimescopeto 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)';

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

parameterTuner(dRC)

Figure Audio Parameter Tuner: compressor [dRC] contains an object of type uigridlayout.

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)); drawnowlimitrate% required to update parameterend

Figure Audio Parameter Tuner: compressor [dRC] contains an object of type uigridlayout.

As a best practice, release your objects once done.

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

Input Arguments

全部折叠

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

Output Arguments

全部折叠

Target figure, returned as aFigureobject.

Introduced in R2019a