Next: , Previous: Playing a sound file, Up: Top


2 Read in and write out a soundfile

Problem

You want to read in a sound file and write out the same sound file.

Solution

Use a SoundFileSource to read in the audio file, and put it into a Series, then add a SoundFileSink to the Series.

Discussion

This recipe is similar to the one given above, where you want to read in an audiofile and play it on your speakers, but in this case you want to output it to another audio file. This is the basic building block of a number of different audio processing applications, you would just put your processing code in between the SoundFileSource and SoundFileSink:

       MarSystemManager mng;
     
       // create playback network with source-gain-dest
       MarSystem* playbacknet = mng.create("Series", "playbacknet");
       playbacknet->addMarSystem(mng.create("SoundFileSource", "src"));
       playbacknet->addMarSystem(mng.create("SoundFileSink", "dest"));
     
       playbacknet->updctrl("SoundFileSource/src/mrs_string/filename",inAudioFileName);
       playbacknet->updctrl("SoundFileSink/dest/mrs_string/filename",outAudioFileName);
     
       while (playbacknet->getctrl("SoundFileSource/src/mrs_bool/hasData")->isTrue()) {
       	playbacknet->tick();
       }