parameterTuner
Tune object parameters while streaming
Description
Examples
Tune Parameters of Multiple Objects
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:
Read in a frame of audio from the file.
Split the audio into three bands using the crossover filter.
Apply dynamic range compression to the first and second bands.
Apply a chorus effect to the third band.
Sum the audio bands.
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)
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)
Tune MATLAB Audio Plugin Parameters
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:
Read in a frame of audio from the file.
Apply flanging.
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)
Tune Compressor Parameters
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:
Read in a frame of audio from the file.
Apply dynamic range compression.
Write the frame of audio to your audio device for listening.
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)
Tune Octave Spectrum Estimator Properties
Create a dsp.AudioFileReader
to stream an audio file for processing. Create an audioDeviceWriter
to play the audio as you stream it.
reader = dsp.AudioFileReader("FunkyDrums-44p1-stereo-25secs.mp3");
player = audioDeviceWriter(SampleRate=reader.SampleRate);
Create an octaveSpectrumEstimator
object with the same sample rate as the file reader and set the Bandwidth
to 1 octave.
o = octaveSpectrumEstimator(reader.SampleRate,Bandwidth="1 octave");
Call visualize
on the object to open a visualizer to display the spectrum.
visualize(o)
Call parameterTuner
to open a UI to tune parameters of the octaveSpectrumEstimator
while streaming.
parameterTuner(o)
In a streaming loop:
Read in a frame of audio data.
Compute the octave-band spectrum
Play the audio with the device writer.
Adjust the properties in the parameterTuner
UI while streaming.
while ~isDone(reader) audioIn = reader(); p = o(audioIn); player(audioIn); end
Input Arguments
obj
— Object to tune
audioPlugin
object | compressor
| expander
| limiter
| noiseGate
| octaveFilter
| crossoverFilter
| multibandParametericEQ
| graphicEQ
| audioOscillator
| wavetableSynthesizer
| reverberator
| shelvingFilter
| octaveSpectrumEstimator
Object to tune, specified as an object that inherits from audioPlugin
or one of the following Audio Toolbox™ objects:
Output Arguments
H
— Target figure
Figure
object
Target figure, returned as a Figure
object.
Calling parameterTuner
on an octaveSpectrumEstimator
object does not return a figure handle.
Version History
Introduced in R2019a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)