Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Event driven audio recording

Subject: Event driven audio recording

From: Johan Carlson

Date: 11 Nov, 2008 15:02:03

Message: 1 of 6

This is what I would like to do:
1) Start a process that monitors audio input on two channels of the sound card.
2) Audio should be sampled into circular buffers of some length of my choice.
3) Once the audio signal on either channel exceeds some predefined threshold, the function should return the contents of the audio buffers.

So, why do I want this:
I'm interested in recording transient audio events. They do not occur very often and not at any predefined times. I would therefore like MATLAB to continuously record sound into two circular buffers. In this way I won't miss any part of the signal as long as the buffer lengths are set up properly.

So, any ideas? To me this sounds like a problem that someone else should have run into.

Thanks in advance,

Subject: Event driven audio recording

From: Johan Carlson

Date: 14 Nov, 2008 16:00:05

Message: 2 of 6

Hi again!

Well folks, I solved the problem myself. The solution requires the Data Acquisition Toolbox, but other than that it's fine.

I'm going to post the zip in the file exchange once I figure out how to do that.


Subject: Event driven audio recording

From: Johan Carlson

Date: 15 Nov, 2008 11:08:02

Message: 3 of 6

Hi again!

I now submitted my solution to the "File exchange". It may take a few days before it shows up, but search for "audiorec" and it should pop up.

Tested on Windows XP and MATLAB 2007b. Requires the Data Acquisition Toolbox, which has had the habit of changing a lot lately, causing old functions to stop working if you upgrade MATLAB. So, if it does not work on previous or newer MATLAB releases, let me know.


Subject: Event driven audio recording

From: Rob Purser

Date: 16 Nov, 2008 01:00:19

Message: 4 of 6

Cool application.

I wanted to follow up on one comment about the Data Acquisition Toolbox changing a lot recently. I'm the lead developer, and we try to make sure not to break people's code from one release to another. Would you be willing to tell us about a place where we did break your code? We want to learn about things that we missed in order to ensure we don't deo it in the future.

Thanks very much,
Rob Purser
Senior Team lead, Test and Measurement

Subject: Event driven audio recording

From: Johan Carlson

Date: 16 Nov, 2008 07:40:21

Message: 5 of 6


This piece of code was taken from a MATLAB 6.x version:

AI = analoginput('nidaq');

Then, using the exact same hardware, but with MATLAB 2007b, I had to do this:

hwinfo = daqhwinfo('nidaq');
dev = char(hwinfo.InstalledBoardIds);
AI = analoginput('nidaq',dev);

There's only one National Instruments card in the machine, so this shouldn't be necessary.

Then, for MATLAB 2008a it stopped working again, but unfortunately I don't have that code here. I'll check with my colleague if he managed to fix it, or I will post the error messages we got.


Subject: Event driven audio recording

From: Johan Carlson

Date: 17 Nov, 2008 16:18:01

Message: 6 of 6

OK, now my software is available at the File Exchange,


Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us