0

I have been working on my ANC project. For this I have two microphone inputs and one loud speaker output, but initially I am using single microphone and dspStreamingPassthrough to pass microphone input to loud speaker. Here is my code

% Initialization
numIterations = 500;
% Construct sources (for all inputs)
src1 = dsp.AudioRecorder('DeviceName','Mikrofon (USB-Audiogerät)','NumChannels',1);
% Construct sinks (for all outputs)
sink1_1 = dsp.SpectrumAnalyzer('SampleRate',44100, ...
'PlotAsTwoSidedSpectrum',false, ...
'ShowLegend',true);
sink1_2 = dsp.TimeScope('BufferLength',44100, ...
'SampleRate',44100, ...
'TimeSpan',1, ...
'ShowLegend',true, ...
'ShowGrid',true, ...
'YLimits',[-0.5 0.5]);
sink1_3 =
dsp.AudioPlayer('BufferSizeSource','Property','BufferSize',1024,...
'QueueDuration',0,'OutputNumUnderrunSamples',true);
sink1_3.DeviceName = 'Lautsprecher (USB-Audiogerät)';
 % Stream processing loop
clear dspStreamingPassthrough;
for i = 1:numIterations
% Sources
in1 = step(src1);
% User Algorithm
out1 = dspStreamingPassthrough(in1);
% Sinks
step(sink1_3,out1);
step(sink1_1,out1);
step(sink1_2,out1);
nUnderrun=step(sink1_3,out1);
end
% Clean up
release(src1);
release(sink1_1);
release(sink1_2);

I am using Windows DirectSound Audio driver ( I cannot use ASIO driver as I cannot access individual audio devices names. ! ) Now I have the audio latency of 1.2 seconds i.e if I say ''hello'' in microphone now, after 1.2 seconds speaker is saying ''hello''(this is absolutely with out any audio input data processing just 'dspStreamingPassthrough'). How to reduce this incredible delay ?

For my project of 1 meter length pipe(air duct), I should be able to process the data in 1.7 msec or less !! I have tried with lowest 'BufferSize' and lowest 'QueueDuration' possible !!

What other parameters can influence to speed up this process? Is it possible with MATLAB or not ?

PS: -sorry for whole code. -I am using a cheap quality Sound card (7 euros)

Paul R
  • 208,748
  • 37
  • 389
  • 560
charansai
  • 137
  • 13
  • Even if you can reduce the latency somehow you're not going to be able to get it down to < 1.7 ms. – Paul R Oct 07 '15 at 08:22
  • So matlab is not suitable for this !? What is the solution then !? Can you suggest me something ! – charansai Oct 07 '15 at 08:40
  • It's not MATLAB - it's a more fundamental problem - 1.7 ms @ 44.1 kHz sample rate is 75 samples - the buffers in your sound card, drivers, etc are going to be larger than this. – Paul R Oct 07 '15 at 09:02
  • What is the least time in which I can process the data? I have read in wiki, with DirectSound it is 500msec. How much it will take for ASIO ? – charansai Oct 07 '15 at 09:06
  • Converting above script to MEX file going to give some results? – charansai Oct 07 '15 at 09:12
  • See: [this question/answer about WASAPI](http://stackoverflow.com/questions/10177477/windows-8-low-latency-audio) but you probably won't be able to do much better than about 50 ms. – Paul R Oct 07 '15 at 09:28
  • thank you @PaulR. Yeah it seems around 40 msec of audio latency is unavoidable even with ASIO but how to get there is still the question anyway I will try WASAPI. (y) (y) – charansai Oct 07 '15 at 10:01

1 Answers1

0

DirectSound has way higher latency than ASIO because DirectSound is not suited for low-latency apps. DSP System Toolbox does not support WASAPI yet.

The latency performance of these objects was greatly improved starting in 15a. I am not sure which version you are running but try and upgrade to 15a or higher.

As for tuning your latency, try the following: * Set the Queue Duration property to 0 seconds for both player and recorder. * For the recorder, match the SamplesPerFrame and BufferSize property. * For the player, ensure that the size of the data matches the BuferSize property.

The BufferSize property is the size at which the sound card operates.

If you get drops, increase the BufferSize value. There can be many reasons for the drops: * The algorithm you are running is not faster than BufferSize/SampleRate * The soundcard is not able to operate at this BufferSize. Some sound-cards allow you to modify this when using ASIO. * Limitation of the player/recorder objects.

Hope this helps.

Dinesh

Dinesh Iyer
  • 681
  • 3
  • 11
  • I am using MATLAB 2015b student version. With ASIO driver, without any processing just dspStreamingPassThrough, MATLAB is taking around 50msec for each 'for' loop iteration. It is far better than DirectSound, but the problem is I cant access individual device names if I use two microphones and one loud speaker with ASIO(if I use scr1.DeviceName=' then tab I can only choose ASIO4ALL v2). – charansai Oct 07 '15 at 19:21
  • I tried to use devinfo command like in the thread you mentioned but I am only getting the following output. ''>> ddevinfo=dspAudioDeviceInfo ddevinfo = name: 'ASIO4ALL v2 (ASIO)' maxInputs: 2 maxOutputs: 2'' How can I access the individual device names ?? – charansai Oct 07 '15 at 20:57
  • The device has 2 channels for inputs and 2 channels for output. So if you connect one mic to one channel and the second mic to the other channel, you can record both inputs as two channels of this device. I am not sure what you are expecting when you say "individual device names"? – Dinesh Iyer Oct 08 '15 at 01:50
  • I am sorry, probably i did not understand you properly. How to map(or connect) two different microphones with two different channels of one dsp.audioplayer object ?? I have microphones connection as shown here [link](http://www.ijehe.org/articles/2012/1/1/images/IntJEnvHealthEng_2012_1_1_24_96005_u3.jpg). PS: I tried using 'ChannelMapping' property but I can not choose two individual microphones. – charansai Oct 08 '15 at 09:44
  • When I said individual device names, I meant individual microphone names, this you can see in the code posted(line 4 and 18). The problem is if I am using ASIO I am getting devices as discussed here previously.[link](http://stackoverflow.com/questions/32842170/is-it-possible-to-process-two-microphones-input-in-real-time-using-dsp-system-to/32842500?noredirect=1#comment53815454_32842500). – charansai Oct 08 '15 at 09:44
  • @charansai: The difference is because ASIO enumerates devices differently than DirectSound and WDM. – Dinesh Iyer Oct 08 '15 at 14:09