int run( const string system_filename, const CommandLineOptions & opt ) { int ticks = 0; if (opt.has("count")) { ticks = opt.value<int>("count"); if (ticks < 1) { cerr << "Invalid value for option 'count' (must be > 0)." << endl; return 1; } } ifstream system_istream(system_filename); MarSystemManager mng; MarSystem* system = mng.getMarSystem(system_istream); if (!system) { cerr << "Could not load filesystem file:" << system; return 1; } bool realtime = opt.value<bool>("realtime"); mrs_real sr = opt.value<mrs_real>("samplerate"); mrs_natural block = opt.value<mrs_natural>("block"); if (sr > 0) system->setControl("mrs_real/israte", sr); if (block > 0) system->setControl("mrs_natural/inSamples", block); system->update(); RealTime::Runner runner(system); runner.setRtPriorityEnabled(realtime); runner.start((unsigned int)ticks); runner.wait(); return 0; }
// Play a collection l of soundfiles void sfplay(vector<string> soundfiles) { MRSDIAG("sfplay.cpp - sfplay"); MarSystemManager mng; string sfName; // Output destination is either audio or soundfile MarSystem* dest; if (fileName == EMPTYSTRING) // audio output { dest = mng.create("AudioSink", "dest"); string backend = cmd_options.getStringOption("audio-backend"); if (!backend.empty()) dest->setControl("mrs_string/backend", backend); } else // filename output { dest = mng.create("SoundFileSink", "dest"); } // create playback network with source-gain-dest MarSystem* playbacknet = mng.create("Series", "playbacknet"); playbacknet->addMarSystem(mng.create("SoundFileSource", "src")); playbacknet->addMarSystem(mng.create("Gain", "gt")); playbacknet->addMarSystem(dest); // playback offset // update controls playbacknet->updControl("mrs_natural/inSamples", windowsize); playbacknet->updControl("Gain/gt/mrs_real/gain", gain); // link top-level controls playbacknet->linkControl("mrs_string/filename","SoundFileSource/src/mrs_string/filename"); playbacknet->linkControl("mrs_real/israte", "SoundFileSource/src/mrs_real/israte"); playbacknet->linkControl("mrs_natural/pos", "SoundFileSource/src/mrs_natural/pos"); playbacknet->linkControl("mrs_natural/loopPos", "SoundFileSource/src/mrs_natural/loopPos"); playbacknet->linkControl("mrs_bool/hasData", "SoundFileSource/src/mrs_bool/hasData"); if (fileName == EMPTYSTRING) // audio output playbacknet->linkControl("mrs_bool/initAudio", "AudioSink/dest/mrs_bool/initAudio"); // play each collection or soundfile vector<string>::iterator sfi; for (sfi = soundfiles.begin(); sfi != soundfiles.end(); ++sfi) { string fname = *sfi; playbacknet->updControl("mrs_string/filename", fname); mrs_natural nChannels = playbacknet->getctrl("mrs_natural/onObservations")->to<mrs_natural>(); mrs_real srate = playbacknet->getctrl("mrs_real/israte")->to<mrs_real>(); ; offset = (mrs_natural) (start * srate * nChannels); playbacknet->updControl("mrs_natural/loopPos", offset); playbacknet->updControl("mrs_natural/pos", offset); playbacknet->updControl("SoundFileSource/src/mrs_real/repetitions", repetitions); playbacknet->updControl("SoundFileSource/src/mrs_real/duration", length); if (fileName != EMPTYSTRING) // soundfile output instead of audio output playbacknet->updControl("SoundFileSink/dest/mrs_string/filename", fileName); if (fileName == EMPTYSTRING) // audio output { playbacknet->updControl("AudioSink/dest/mrs_natural/bufferSize", 256); playbacknet->updControl("AudioSink/dest/mrs_bool/initAudio", true); } MarControlPtr hasDataPtr_ = playbacknet->getctrl("mrs_bool/hasData"); while (hasDataPtr_->isTrue()) { playbacknet->tick(); } //cout << *playbacknet << endl; } // output network description to cout if ((pluginName == EMPTYSTRING) && (verboseopt)) // output to stdout { cout << (*playbacknet) << endl; } else if (pluginName != EMPTYSTRING) // output to plugin { ofstream oss(pluginName.c_str()); oss << (*playbacknet) << endl; } delete playbacknet; }