Next: , Previous: Reading and altering controls, Up: Example programs


9.2.3 Writing data to text files

Extract data from a network for further analysis (plotting, other programs, etc) is fairly easy to do with PlotSink.


#include "MarSystemManager.h"
using namespace std;
using namespace Marsyas;

void recognize(string sfName)
{
	MarSystemManager mng;
	MarSystem* pnet = mng.create("Series", "pnet");
// standard network
	pnet->addMarSystem(mng.create("SoundFileSource", "src"));
	pnet->updctrl("SoundFileSource/src/mrs_string/filename", sfName);
	pnet->addMarSystem(mng.create("Spectrum","spk"));

// add a PlotSink wherever we want to get data from
	pnet->addMarSystem(mng.create("PlotSink","plot"));
	pnet->updctrl("PlotSink/plot/mrs_string/filename", "out");

	while ( pnet->getctrl("SoundFileSource/src/mrs_bool/notEmpty")->to<mrs_bool>() )
	{
		pnet->tick();
	}
	delete pnet;
}

int main(int argc, const char **argv)
{
	string fileName;
	if (argc<2)
	{
		cout<<"Please enter filename."<<endl;
		exit(1);
	}
	else
	{
		fileName = argv[1];
	}
	cout << "Processing file " << fileName << endl;

	recognize(fileName);
	exit(0);
}