Code covered by the MathWorks Limited License

Highlights from
Real-Time Audio Processor


5.0 | 1 rating Rate this file 75 Downloads (last 30 days) File Size: 48.5 KB File ID: #37770
image thumbnail

Real-Time Audio Processor



Simplifies streaming or generating audio in real time.

| Watch this File

File Information

The RealTimeAudioProcessor makes it easy to stream or generate audio in real time in MATLAB.

It includes examples for generating sound from a qwerty keyboard, generating sound from a MIDI keyboard (with included MIDI interface for acquiring MIDI inputs), and using any old algorithm you have lying around as real-time processor.

For a smooth experience, please start with the included documentation. There are a few things to do for the best performance.

* Windows
* MATLAB r2012a or greater
* Signal Processing Toolbox
* DSP System Toolbox
* Soundcard with ASIO driver (recommended)
* MIDI input device (recommended only for MidiDemo)

Early beta.

Required Products DSP System Toolbox
Signal Processing Toolbox
MATLAB release MATLAB 7.14 (R2012a)
Other requirements * Windows XP, Vista, or 7 * Soundcard with ASIO driver (recommended) * MIDI input device (recommended only for MidiDemo)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
24 Mar 2014 Nakarin  
31 Jan 2014 Tucker McClure

Hi Fer,

This should be pretty easy. Here's where to get started.

1. Usually, one calls MATLAB's 'filter' function when all of the data is present, but if we want to use it on a real-time stream, then we'll need to call it many times on little chunks of audio as they come in. Of course, filters have state, so we can't just call the filter "fresh" on each little chunk; we'll have pass in the last filter state to get it started where it left off last time. MATLAB has this built in:

[out, state_out] = filter(b, a, in, state_in);

2. Now we need to wrap this up in a usable function with our coefficients. Something like this:

[out, state] = my_filter(t, in, state)

b = [...];
a = [...];
[out, state] = filter(a, b, in, state);


(See sine_of_the_times.m for an example.)

3. Now we tell the Real-Time Audio Process to use this function on all incoming audio. We can easily do this with a "HandlePlayer", something like this:

rtap = HandlePlayer(@my_filter, ...);

(See handle_driver.m for an example; note that the example is stereo in/out.)

Please also see the "Real Time Audio Processor.docx" file for much more discussion.

31 Jan 2014 Fer

Hi Tucker,
i want to process a signal in real time. But i dont understand how its works...

Usually i use the function filter() in matlab with some coefficient thay i desing.

Which of these code i have to use for real time aplication?
Muchas Gracias!

26 Aug 2013 Stephen

Hi Tucker,
Thanks for uploading this! I've been looking for some real time audio processing power for matlab. I have a question. I've been trying to get my fm synthesis function to work within your code but I find my modifications aren't working. I have used the QwertyDemo.m file as a jumping point and was wondering: How can I modify it to create a variable (based on accelerometer data) drone. I have no problem getting accelerometer data in Matlab

06 Nov 2012 Tucker McClure

Hi Bert,

Your question prompts a few things.

1. The MEX files for midi_interface.cpp are included, so you shouldn't need to build them. That script is only included in case someone *wants* to rebuild it for whatever reason. You should be able to just call midi_interface('open') from the command line to get going.

2. If for whatever reason you *do* want to rebuild it, it requires that you have the Windows SDK and edit midi_interface_builder.m to reflect the right path for its include and binary directories. This isn't documented because it's not intended for the user to do this.

3. The error is actually about a loss of precision in a cast. This is usually a warning instead of an error. Somewhere in your compiler, there's a setting for whether loss of precision should be considered an error or a warning. If you set it to warning, it will probably move on.

There's some included documentation about setting everything up. Have you read through this? Have you tried running any of the examples yet?

Hope that helps,

- Tucker

05 Nov 2012 Bert

I tried to run the midi_interface_builder but got his error:

>> midi_interface_builder
Building MEX file... midi_interface.cpp: In function 'bool OpenMidiInputDevice(unsigned int)':
midi_interface.cpp:111:64: error: cast from 'void (*)(HMIDIIN, UINT, DWORD, DWORD, DWORD) {aka void (*)(HMIDIIN__*, unsigned int, long unsigned int, long unsigned int, long unsigned int)}' to 'DWORD {aka long unsigned int}' loses precision [-fpermissive]

C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'midi_interface.cpp' failed.

Error using mex (line 206)
Unable to complete successfully.
Error in midi_interface_builder (line 18)
mex(['-I' sdk_path include_sub], ...
206 throw(exception);

04 Sep 2012

Updated copyright info.

Contact us