Next: , Previous: Read in and write out a soundfile, Up: Top

3 Playing multiple sound files at once


You want to output multiple sound files to the audio device on your system all at the same time.


Make a network with SoundFileSources and put all these SoundFileSources inside a Fanout.


To do this, you need a network with SoundFileSources for each of the input sources. You then put all these SoundFileSources inside a Fanout, this will play all the sound files simultaneously.

The output of the Fanout is a stacked array of all the data from the audio files, you need to combine these together using a Sum object.

Finally, you output all of them to an AudioSink

The network will look like:

     - Series
       - Fanout
         - SoundFileSource
         - SoundFileSource
         - SoundFileSource
       - Sum
       - AudioSink

The code will look like:

     MarSystemManager mng;
     MarSystem* playbacknet = mng.create("Series", "playbacknet");
     MarSystem* fanout = mng.create("Fanout", "fanout");
     // Create the SoundFileSources
     fanout->addMarSystem(mng.create("SoundFileSource", "src1"));
     fanout->addMarSystem(mng.create("SoundFileSource", "src2"));
     fanout->addMarSystem(mng.create("SoundFileSource", "src3"));
     // Assign filenames to the SoundFileSources
     // Add the fanout to the main network
     // Sum up all of the fanouts
     playbacknet->addMarSystem(mng.create("Sum", "sum"));
     // Create the output file which is a SoundFileSink
     playbacknet->addMarSystem(mng.create("AudioSink", "dest"));
     playbacknet->updctrl("AudioSink/dest/mrs_bool/initAudio", true);
     while (!done) {