I want to record simultaneously using 5 usb microphones. My solution almost works, but there is a delay in the signals caused by the recording which will mess up my entire project.

22 views (last 30 days)
Suresh Yhap
Suresh Yhap on 2 Nov 2015
Answered: Walter Roberson on 2 Nov 2015
if true
close all;
clear all;
clc;
fs = 44.1e3; % Standard sampling frequency 44.1kHz
% The last argument is set up to correspond to mics 1-5
recObj1 = audiorecorder(fs, 8, 1, 4);
recObj2 = audiorecorder(fs, 8, 1, 5);
recObj3 = audiorecorder(fs, 8, 1, 2);
recObj4 = audiorecorder(fs, 8, 1, 6);
recObj5 = audiorecorder(fs, 8, 1, 1);
% This method of recording causes time delay in the signals,
% throwing off the results. But I couldn't find another way
% to record with all the mics simultaneously
record(recObj1);
record(recObj2);
record(recObj3);
record(recObj4);
record(recObj5);
pause(2); % Make a sound like a clap for instance
stop(recObj1);
stop(recObj2);
stop(recObj3);
stop(recObj4);
stop(recObj5);
out1 = getaudiodata(recObj1);
out2 = getaudiodata(recObj2);
out3 = getaudiodata(recObj3);
out4 = getaudiodata(recObj4);
out5 = getaudiodata(recObj5);
% http://www.mathworks.com/help/signal/ref/xcorr.html
t1 = (0:length(out1)-1)/fs;
t2 = (0:length(out2)-1)/fs;
t3 = (0:length(out3)-1)/fs;
t4 = (0:length(out4)-1)/fs;
t5 = (0:length(out5)-1)/fs;
figure;
plot(t1,out1);
figure;
plot(t2,out2);
figure;
plot(t3,out3);
figure;
plot(t4,out4);
figure;
plot(t5,out5);
end
  5 Comments
Geoff Hayes
Geoff Hayes on 2 Nov 2015
Can't you compensate since you know (roughly) the delay? i.e. drop some of the initial samples from the first four recorder objects.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2015
You have the wrong setup to achieve the precision that you want.
USB is a polled serial bus, shared by multiple devices. The controller sends out a command with a destination device address, and that device replies. Then the controller goes on to the next device it knows about, and it replies. There is a cycle of that. Each device that has a bunch of data to send will reply saying so (unless the data is relatively small, then it will be sent immediately). Then the controller goes around to each of those devices in turn saying "Okay, it's your turn to send something" and the device that was addressed does so. Then it is the turn of the next device to transmit a bunch of data, and so on through the "work list" for the cycle. Then it all starts over again.
This is not the right architecture for devices that need low latency!
audiorecorder() is not designed for use with multiple devices that need to be synchronized, and it is not designed for low-latency operation even within a single device.
At the very least you should switch to using ASIO with PortAudio or equivalent libraries; see http://www.mathworks.com/matlabcentral/answers/242143-asio-audio-device-access
You should be considering switching to a Data Acquisition setup, treating the sound like scientific data to be processed through tools and devices designed for that purpose. The devices available for those purposes often support sync triggers to start data acquisition, and support multi-channel acquisition. You can also get setups in which the data samples are time-stamped, which would allow you to better synchronize the data.
The more I read about USB, the less than impressed I am with using it for serious scientific measurements. Even with USB 3.0. Possible exception: for work that is not real-time, where recording is the important factor rather than fast response, then USB 3.0 is decent for bulk data transfer with devices that do not cost a fortune.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!