Toolbox™ is optimized for real-time audio processing.
designed for streaming multichannel audio, and they provide all necessary
parameters so that you can trade off between throughput and latency.
For information on real-time processing and tips on how to optimize your algorithm, see Audio I/O: Buffering, Latency, and Throughput.
This tutorial describes how you can implement audio stream processing in MATLAB®. It outlines the workflow for creating a development test bench and provides examples for each stage of the workflow. Begin by inspecting the anatomy of a completed audio stream processing test bench, then walk through the example for a description of each stage.
This tutorial creates a development test bench in five steps. You begin by constructing objects to input an audio signal to your test bench and output an audio signal from your test bench. You then create an audio stream loop that performs frame-based processing on your audio signal. To gain insight about your audio processing, you add scopes to visualize the input to and output from the audio stream loop. You then develop your audio processing algorithm. In the final stage, you make your processing algorithm tunable in real time.
For an overview of how audio stream processing is implemented, inspect the anatomy of the completed audio stream processing test bench. To create this test bench, walk through the example for explanations and step-by-step instructions.
Your audio stream loop can read audio directly from your device or from a file, and can write to a device or file. In this tutorial, you create an audio stream loop that reads audio frame by frame from a file, and outputs frame by frame to a device. See Quick Start Examples for alternative input/output configurations.
specify a file. To reduce latency, specify a small frame size as a
property of the
Also construct an
audioDeviceWriter sample rate if the
default of 44,100 Hz is not appropriate. If you do not modify the
sample rate between input and output to your audio stream loop, use
the sample rate of your input System
An audio stream loop refers to a programming loop that iteratively:
Reads a frame of an audio signal
Processes the audio signal frame
Writes the audio signal frame
In this tutorial, the input to the audio stream loop is read from a file. The output from the audio stream loop writes to a device.
Create Audio Stream Loop with File Input and Device Output. To read a single frame of an audio file, call your
a function without arguments. To read successive frames, call your
the audio stream loop.
To write a single frame of an audio signal to your audio device,
audioDeviceWriter like a function with
the signal frame to output as the argument. To write successive frames,
audioDeviceWriter in the audio stream loop.
objects have a
As a best practice, release your System
object after use, especially
when a System
object is communicating with a hardware device such
as your sound card.
This tutorial uses the
object to visualize the audio
Add Time Scope. To display an audio signal in the time domain, construct a
To aid visualization, specify necessary
To display the current frame of a signal, call your
a function with the signal frame to display as the argument. To display
your signal in real time, call your
the audio stream loop.
In most applications, you want to process your audio signal in the audio stream loop. The processing stage can be
An inline script in the audio stream loop
A separate function called in the audio stream loop
A System object called like a function in an audio stream loop
In this tutorial, you call the
object like a function to process
the signal in the audio stream loop.
Process Signal with
noiseGate. Construct a
object sample rate if the
default of 44,100 Hz is not appropriate. As a best practice, use the
sample rate of your input System
object. To achieve the aims of
your audio processing, specify necessary
To process the audio signal, call your
a function in the audio stream loop.
In this tutorial, you add random Gaussian noise to the audio
stream input to show a possible use case of the
MATLAB provides several options to interactively tune your algorithm with stream processing.
Add User Interface. MATLAB provides several user interfaces (UI) to inspect and interact with your code. You can use:
The built-in methods of Audio System Toolbox System objects for visualizing key characteristics of your processing algorithms. Then you can tune them in real time with MIDI controls.
A custom-built user interface. See GUI Building (MATLAB) for a tutorial.
This tutorial uses the
observe its static characteristics.
Add MIDI Controller. Many Audio System
objects include methods
that support MIDI controls. This tutorial uses the
synchronize your System
object properties to MIDI controls.
To use MIDI controls with System
objects that do not have
configureMIDI method, see Musical Instrument Digital Interface (MIDI).
To control your
with a MIDI controller, connect the MIDI device to your computer.
configureMIDI method enables you to synchronize
properties to MIDI controls using a user interface or a script. This
example synchronizes properties to a MIDI controller using a user
Before calling your audio stream loop, call the
object. When you run
your script, it does not advance until you have completed your configuration
and closed the user interface. Once the user interface opens:
Select a property to synchronize by choosing it from the drop-down menu.
Move a MIDI control.
noiseGate property in the drop-down
menu and the MIDI control you moved are now synced. Repeat these steps
for all properties you want to synchronize. Then click OK.
While your audio is stream processing, use your MIDI controller
to adjust the
noiseGate parameters in real time.
In particular, toggle the MIDI control mapped to the
to attenuate the additive Gaussian noise in the signal.
Add UDP. You can use the User Datagram Protocol (UDP) within MATLAB for connectionless transmission, or to receive or transmit datagrams outside MATLAB. Possible applications include using MATLAB to tune your audio processing algorithm while playing and visualizing your audio in a third-party environment. See Communicate Between a DAW and MATLAB Using UDP for an example application of UDP communication.