0

I have a project and I must play 3 different audio files through 3 different speakers. The start time of files are important (I mean they must start to play simultaneously).

My first option is using 3 networked computer, one file per computers, and a program that control these three systems (One server and two clients for example).

But I think it's really better to use a sound card with 4 channel for example. After some search I found that there are a lot of these sound cards. I want to know, is it possible to control the channel using Python or Matlab programs or any other way? Is there any library?

Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113

1 Answers1

1

The audioplayer function in MATLAB supports only 2 channels. But you can use the functionality in the DSP System Toolbox. The code snippet below can helps:

hafr1 = dsp.AudioFileReader('myfile1.wav');% Can be other formats as well
hafr2 = dsp.AudioFileReader('myfile2.wav');
hafr3 = dsp.AudioFileReader('myfile3.wav');
hap = dsp.AudioPlayer;
hap.SampleRate = hafr1.SampleRate; % Assuming that all files have same sample rate or else you have to do some clever mixing.
while ~isDone(hafr1) % assuming same size. You need to add some clever logic to adjust the number of channels if they are of different sizes
     data1 = step(hafr1);
     data2 = step(hafr2);
     data3 = step(hafr3);
     step(hap, [data1 data2 data3]);
end

This code will playback audio on the default output device. If this has three or more channels, you will hear tha audio on 3 separate channels. If not, depending on the platform, it will get mixed down into two channels.

You can refer to the doc page for info.

Dinesh

Dinesh Iyer
  • 681
  • 3
  • 11