Tune object parameters while streaming
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 adsp.AudioFileReader
to read in audio frame-by-frame. Create anaudioDeviceWriter
to write audio to your sound card.
fileReader = dsp.AudioFileReader('FunkyDrums-48-stereo-25secs.mp3',...'PlayCount',2); deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);
Create acrossoverFilter
with two crossovers to split the audio into three bands. Callvisualize
to plot the frequency responses of the filters. CallparameterTuner
to 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. Callvisualize
to plot the static characteristic of both of the compressors. CallparameterTuner
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 anaudiopluginexample.Chorus
to apply a chorus effect to one of the bands. CallparameterTuner
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); drawnowlimitrate% Process parameterTuner callbacksend
As a best practice, release your objects once done.
release(fileReader) release(deviceWriter)
Create adsp.AudioFileReader
to read in audio frame-by-frame. Create anaudioDeviceWriter
to write audio to your sound card. UseloadAudioPlugin
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);
CallparameterTuner
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); drawnowlimitrate% Process parameterTuner callbacksend
As a best practice, release your objects once done.
release(fileReader) release(deviceWriter)
Create adsp.AudioFileReader
to read in audio frame-by-frame. Create anaudioDeviceWriter
to write audio to your sound card. Create anaudiopluginexample.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);
CallparameterTuner
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); drawnowlimitrate% Process parameterTuner callbacksend
As a best practice, release your objects once done.
release(fileReader) release(deviceWriter)
Create adsp.AudioFileReader
to read in audio frame-by-frame. Create anaudioDeviceWriter
to write audio to your sound card. Create a压缩机
to process the audio data. Callvisualize
to 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 atimescope
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)';
CallparameterTuner
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)); drawnowlimitrate% required to update parameterend
As a best practice, release your objects once done.
release(deviceWriter) release(fileReader) release(dRC) release(scope)
obj
—Object to tuneaudioPlugin
object|压缩机
|expander
|limiter
|noiseGate
|octaveFilter
|crossoverFilter
|multibandParametericEQ
|graphicEQ
|audioOscillator
|wavetableSynthesizer
|reverberator
Object to tune, specified as an object that inherits fromaudioPlugin
or one of the following Audio Toolbox™ objects:
H
— Target figureFigure
objectTarget figure, returned as aFigure
object.
You have a modified version of this example. Do you want to open this example with your edits?
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.
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:.
Selectweb siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.