2 Sounds Cards and 5.1 speakers

Hello, I want to manage two sound cards through Matlab. One that sends sound: it is connected to an amplifier by an optical socket and is supposed to handle 5 speakers. One that receives sound output from two microphones (right/left) by BNC cable. I don’t know how in Matlab, handled these sound cards. that is, I don’t know how to tell Matlab to select this card to do this action and this card to do this action. How to select the speakers that send the sounds? And the analysis of either output ?
I know the function AudioDeviceWritter, AudioDeviceReader but only for the use of devices defaulted manually in computer-specific settings.
thanks for your help.

Answers (1)

The audioDeviceReader and audioDeviceWriter objects have "Driver" and "Device" properties. For example, if the output device supports 5.1 (6 channels), you could play this:
adw = audioDeviceWriter(48000,"Device","5.1 audio device");
% Play 6 channels of random noise (number of columns when calling adw)
for ii = 1:20
adw(randn(1024,6)/20);
end
Note that pressing tab after "Device"," will bring up a list of devices in your system.
Same with the reader, except you specify the number of channels when creating it:
adr = audioDeviceReader(48e3,adw.BufferSize,"Device","Dual Microphone Device","NumChannels",2);
Calling adr() will return a buffer-long matrix with 2 columns.
Note that two different devices will have independant sampling clocks that differ ever so slightly (one slightly faster than the other), so if you use the writer and reader with different devices in a loop for a very long time without taking this into account, one device might underrun every once in a while (maybe after several minutes).

6 Comments

Chloooo
Chloooo on 17 Oct 2019
Edited: Chloooo on 17 Oct 2019
Thank you very much for your relevant answer for solve my recorder problem !
I think i must use AudioDeviceWriter to send audio on speakers but this function don't have any properties "NumChannels" so I can't defined my maximum number channels at 5 as simply. I want to manage the speakers in a manner to selected on speaker for one of the 6 channels of the audio which i want send. I continue to try..
Best Regards,
Only AudioDeviceReader needs a NumChannels property so that it knows how many columns to return. For AudioDeviceWriter, the number of channels is defined when you call the object.
This will play six channels (5.1) if supported by the device, because the frame has six columns:
adw(randn(1024,6)/20);
This would only play two channels:
adw(randn(1024,2)/20);
By the way, the default mapping for 5.1 is: Front Left, Front Right, Center, Low-Frequency Effects (LFE), Surround Left, Surround Right. There is a ChannelMapping property if you need to change that.
OK, I understand. Thank you very much; But a last question : How I can play the 6 channel audio through speakers? Because audioDeviceWriter don't have the play function automatically, no ?
You have to loop through every frame. Please have a look at the example (help audioDeviceWriter). Also, you might be interested by audioplayer or sound depending on what you are trying to acheive.
I seem to recall that sound and audioplayer can only handle 2 channels on Windows because they use OS interface routines that only support 2 channels??
Walter is correct, the OP asked for multichannel so that will limit us to audioDeviceWriter.

Sign in to comment.

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Products

Release

R2019b

Asked:

on 11 Oct 2019

Commented:

on 18 Oct 2019

Community Treasure Hunt

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

Start Hunting!