Next: , Previous: Top, Up: Top


1 Playing a sound file

Problem:

You want to play an audio file using Marsyas

Solution

Put a SoundFileSoure and a AudioSink inside of a Series object.

Discussion

To do this, you just need to put a SoundFileSoure and a AudioSink inside of a Series object.

You then will set the filename of the SoundFileSource with:

        playbacknet->updctrl("SoundFileSource/src/mrs_string/filename",inAudioFileName);

And initialize the audio:

        playbacknet->updctrl("AudioSink/dest/mrs_bool/initAudio", true);

You then just tick the network until all the frames have finished playing:

     while (playbacknet->getctrl("SoundFileSource/src/mrs_bool/hasData")->isTrue())	{
       playbacknet->tick();
     }

The network will look like:

     - Series
        - SoundFileSource
        - AudioSink

The code will look like:

     MarSystem* playbacknet = mng.create("Series", "playbacknet");
     playbacknet->addMarSystem(mng.create("SoundFileSource", "src"));
     playbacknet->addMarSystem(mng.create("Gain", "gt"));
     playbacknet->addMarSystem(mng.create("AudioSink", "dest"));
     
     // Set the SoundFileName
     playbacknet->updctrl("SoundFileSource/src/mrs_string/filename",inAudioFileName);
     
     // Turn on the audio output
     playbacknet->updctrl("AudioSink/dest/mrs_bool/initAudio", true);
     
     while (playbacknet->getctrl("SoundFileSource/src/mrs_bool/hasData")->isTrue())	{
        playbacknet->tick();
     }