void
TranscriberExtract::getAllFromAudio(const std::string audioFilename, realvec&
                                    pitchList, realvec& ampList,
                                    realvec& boundaries)
{
	MarSystem* pitchSink = mng.create("RealvecSink", "pitchSink");
	MarSystem* ampSink = mng.create("RealvecSink", "ampSink");

	MarSystem* pnet = mng.create("Series", "pnet");
	mrs_real srate = addFileSource(pnet, audioFilename);
// TODO: double the number of observations?
//	pnet->updControl("SoundFileSource/src/mrs_natural/inSamples",256);
//	pnet->addMarSystem(mng.create("ShiftInput", "shift"));
//	pnet->updControl("ShiftInput/shift/mrs_natural/winSize",512);

	MarSystem* fanout = mng.create("Fanout", "fanout");
	fanout->addMarSystem(makePitchNet(srate, 100.0, pitchSink));
	fanout->addMarSystem(makeAmplitudeNet(ampSink));
	pnet->addMarSystem(fanout);

	while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
		pnet->tick();

	pitchList = getPitchesFromRealvecSink(pitchSink, srate);
	ampList = getAmpsFromRealvecSink(ampSink);
	boundaries.create(2);
	boundaries(0) = 0;
	boundaries(1) = pitchList.getSize();
	delete pnet;
}
void newMidiInfo()
{
    /*
	  This function describes using the MidiInput object and MarControlPointers 
	  to read midi controls in a loop. The disadvantage of this approach is that
	  MidiINput will only return the last midi value between buffers. Change the 
	  buffer size you would like more precision and throughput for midi messages. 
    */
    MarSystemManager mng;
    MarSystem* series = mng.create("Series", "series");
    series->addMarSystem(mng.create("AudioSource","src"));
    series->addMarSystem(mng.create("MidiInput","midiin"));

    series->updctrl("mrs_real/israte", 44100.0);
    series->updctrl("mrs_real/osrate", 44100.0);
    // to change how often marsyas grabs messages change the buffersize
    series->updctrl("AudioSource/src/mrs_natural/bufferSize", 64);
    series->updctrl("AudioSource/src/mrs_bool/initAudio",true);
    series->updctrl("MidiInput/midiin/mrs_bool/initmidi",true);

    MarControlPtr b1 = series->getctrl("MidiInput/midiin/mrs_natural/byte1");
    MarControlPtr b2 = series->getctrl("MidiInput/midiin/mrs_natural/byte2");
    MarControlPtr b3 = series->getctrl("MidiInput/midiin/mrs_natural/byte3");

    while(1) 
    {  
        const  mrs_natural& byte1 = b1->to<mrs_natural>(); 
        const  mrs_natural& byte2 = b2->to<mrs_natural>();   
        const  mrs_natural& byte3 = b3->to<mrs_natural>(); 

        std::cout <<  "Byte 1: " << byte1 << "    Byte 2: " << byte2 << "    Byte 3: " << byte3 << endl;

        series->tick();
    }
}
realvec
TranscriberExtract::getAmpsFromAudio(const std::string audioFilename)
{
	mrs_real normalize = getNormalizingGain(audioFilename);

	MarSystem* pnet = mng.create("Series", "pnet");
	mrs_real srate;
	srate  = addFileSource(pnet, audioFilename);
	
	pnet->addMarSystem(mng.create("Gain", "normalizing"));
	pnet->updControl("Gain/normalizing/mrs_real/gain",normalize);
	MarSystem* rvSink = mng.create("RealvecSink", "rvSink");
	pnet->addMarSystem(makeAmplitudeNet(rvSink));

	while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
		pnet->tick();

	realvec rmsList = getAmpsFromRealvecSink(rvSink);
	delete pnet;

	// normalize RMS
	rmsList -= rmsList.minval();
	mrs_real maxRms = rmsList.maxval();
	if (maxRms != 0)
		rmsList /= maxRms;
	return rmsList;
}
Ejemplo n.º 4
0
// Play soundfile given by sfName, msys contains the playback
// network of MarSystem objects
void sfplayFile(MarSystem& msys, mrs_natural offset, mrs_natural duration,
                mrs_real start, mrs_real length, mrs_real gain, mrs_real repetitions, string sfName )
{
  msys.updctrl("SoundFileSource/src/mrs_string/filename", sfName);
  mrs_natural nChannels = msys.getctrl("SoundFileSource/src/mrs_natural/nChannels")->to<mrs_natural>();
  mrs_real srate = msys.getctrl("SoundFileSource/src/mrs_real/israte")->to<mrs_real>();

  // playback offset & duration
  offset = (mrs_natural) (start * srate * nChannels);
  duration = (mrs_natural) (length * srate * nChannels);

  // udpate controls
  msys.updctrl("mrs_natural/inSamples", MRS_DEFAULT_SLICE_NSAMPLES);
  msys.updctrl("Gain/gt/mrs_real/gain", gain);
  msys.updctrl("SoundFileSource/src/mrs_natural/pos", offset);

  mrs_natural wc=0;
  mrs_natural samplesPlayed = 0;
  mrs_natural onSamples = msys.getctrl("mrs_natural/onSamples")->to<mrs_natural>();
  // mrs_natural repeatId = 1;

  while (msys.getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>())
  {
    msys.tick();
    wc ++;
    samplesPlayed += onSamples;
  }
  cerr << "Played " << wc << " slices of " << onSamples << " samples" << endl;
}
Ejemplo n.º 5
0
void
toy_with_spectral_single(mrs_string sfname)
{
    MarSystemManager mng;

    MarSystem *net = mng.create("Series", "net");
    net->addMarSystem(mng.create("SoundFileSource", "src"));
    net->addMarSystem(mng.create("ShiftInput", "si"));
    net->addMarSystem(mng.create("Windowing", "win"));
    net->addMarSystem(mng.create("Spectrum", "spec"));
    net->addMarSystem(mng.create("PowerSpectrum", "pspec"));
    net->updControl("SoundFileSource/src/mrs_string/filename", sfname);
    net->updControl("mrs_natural/inSamples", 1024);
    net->updControl("ShiftInput/si/mrs_natural/winSize", 1024);
    net->updControl("Windowing/win/mrs_string/type", "Hanning");

    MarSystem *fan = mng.create("Fanout", "fan");
    net->addMarSystem(fan);
    fan->addMarSystem(mng.create("SpectralFlatnessAllBands", "sfab"));

    while ( net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>() )
    {
        net->tick();
        mrs_realvec v = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
        for (mrs_natural i = 0; i<v.getSize(); ++i)
        {
            printf("%.5g\t", v(i));
        }
        cout<<endl;
    }
    delete net;
}
Ejemplo n.º 6
0
void carfac_testing(string inAudioFileName)
{
  cout << "carfac_testing" << endl;
  cout << "inAudioFileName=" << inAudioFileName << endl;

  MarSystemManager mng;

  // Create the network
  MarSystem* net = mng.create("Series", "net");
  net->addMarSystem(mng.create("SoundFileSource", "src"));

  MarSystem* carfac = mng.create("CARFAC", "carfac");
  net->addMarSystem(carfac);

  net->addMarSystem(mng.create("Gain", "gain"));

  net->updControl("SoundFileSource/src/mrs_string/filename",inAudioFileName);
  net->updControl("mrs_natural/inSamples",512);

  // Just print the coefficients
  carfac->updControl("mrs_bool/printcoeffs",true);
  carfac->updControl("mrs_bool/printstate",false);
  cout << carfac->toString();

  // Just print the state
  carfac->updControl("mrs_bool/printcoeffs",false);
  carfac->updControl("mrs_bool/printstate",true);
  for (int i = 0; i < 5; i++) {
    net->tick();
    cout << "@@@@@@@@@@@@@@@@@@@@@@@@ "<< i + 1 << " @@@@@@@@@@@@@@@@@@@@@@@@" << endl;
    cout << carfac->toString();

  }
}
Ejemplo n.º 7
0
// please keep this at the end of all the toy_with_ functions.
// to use, copy this and paste it above, then modify as needed
void
toy_with_null(mrs_string sfname)
{
  MarSystemManager mng;

  MarSystem *net = mng.create("Series", "net");
  net->addMarSystem(mng.create("SoundFileSource", "src"));
  net->addMarSystem(mng.create("ShiftInput", "si"));
  // you probably want to add more here
  net->addMarSystem(mng.create("Spectrum", "spec"));
  net->addMarSystem(mng.create("PowerSpectrum", "pspec"));
  net->addMarSystem(mng.create("Spectrum2Chroma", "s2c"));
  net->addMarSystem(mng.create("PlotSink", "ps"));

  net->updControl("SoundFileSource/src/mrs_string/filename", sfname);
  net->updControl("mrs_natural/inSamples", 512);
  net->updControl("mrs_natural/inSamples", 1024);
  net->updControl("ShiftInput/si/mrs_natural/winSize", 512);

  while ( net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>() )
  {
    net->tick();
#if 0
    mrs_realvec v = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
    for (mrs_natural i = 0; i<v.getSize(); ++i)
    {
      printf("%.5g\t", v(i));
    }
    cout<<endl;
#endif
  }
  delete net;
}
Ejemplo n.º 8
0
void
toy_with_arff_in_out(mrs_string in_name, mrs_string out_name)
{
    MarSystemManager mng;

    MarSystem *net = mng.create("Series", "net");
    net->addMarSystem(mng.create("WekaSource", "src"));
    net->addMarSystem(mng.create("WekaSink", "dest"));

    net->updControl("WekaSource/src/mrs_string/filename", in_name);

    net->updControl("WekaSink/dest/mrs_natural/nLabels",
                    net->getControl("WekaSource/src/mrs_natural/nClasses"));
    net->updControl("WekaSink/dest/mrs_string/labelNames",
                    net->getControl("WekaSource/src/mrs_string/classNames"));
    net->updControl("WekaSink/dest/mrs_bool/regression",
                    net->getControl("WekaSource/src/mrs_bool/regression"));

    // must happen after setting the above controls
    net->updControl("WekaSink/dest/mrs_string/filename", out_name);

    while ( !net->getctrl("WekaSource/src/mrs_bool/done")->to<mrs_bool>() )
    {
        net->tick();
    }
    delete net;
}
// thread code
void* run(void * arg)
{
  
  thread_data* data = (thread_data*) arg;

  MarSystemManager mng;
  NetworkTCPSource* src = new NetworkTCPSource("src");
  
  MarSystem* featureNetwork = mng.create("Series", "featureNetwork");
  featureNetwork->addMarSystem(src);
  featureNetwork->addMarSystem(mng.create("AudioSink", "sink"));
  // featureNetwork->addMarSystem(mng.create("PlotSink", "psink"));
  
  featureNetwork->updctrl("NetworkTCPSource/src/mrs_natural/dataPort", data->dataPort);
  featureNetwork->updctrl("NetworkTCPSource/src/mrs_natural/controlsPort", data->controlsPort);

  featureNetwork->linkctrl("mrs_bool/hasData", "NetworkTCPSource/src/mrs_bool/hasData");
  
  src->refresh();
  
  mrs_natural wc = 0;
  
  mrs_real* controls = 0;
  
  mrs_natural onSamples = featureNetwork->getctrl("mrs_natural/onSamples")->to<mrs_natural>();
  
  
  // start the network 
  while ( featureNetwork->getctrl("mrs_bool/hasData")->to<mrs_bool>() ) {

	try {
		
		controls = featureNetwork->recvControls();	
      		if ( controls != 0 ) {
			
			// get some reference controls, so if they have changed we update them
			mrs_natural inSamples = featureNetwork->getctrl("mrs_natural/inSamples")->to<mrs_natural>();
			mrs_natural inObservations = featureNetwork->getctrl("mrs_natural/inObservations")->to<mrs_natural>();
			mrs_real israte = featureNetwork->getctrl("mrs_real/israte")->to<mrs_real>();
			
			if ( (mrs_natural)controls[1] != inSamples || (mrs_natural)controls[2] != inObservations 
					|| controls[3] != israte ) {
			
				featureNetwork->updctrl("mrs_natural/inSamples", (mrs_natural)controls[1]);
				featureNetwork->updctrl("mrs_natural/inObservations", (mrs_natural)controls[2]);
				featureNetwork->updctrl("mrs_real/israte", controls[3]);
			}
      		}
		
		featureNetwork->tick(); // everything happens here 
	} catch ( SocketException e ) {
  		cerr << "Played " << wc << " slices of " << onSamples << " samples" << endl;
		pthread_exit(NULL);
	}
 	wc++;
   }
  cout << "played - " << wc << " slices of " << onSamples << " samples" << endl;
 
  pthread_exit( NULL );
}
mrs_real
TranscriberExtract::getNormalizingGain(const std::string audioFilename)
{
	mrs_real maxVal = 0.0;

	MarSystem* pnet = mng.create("Series", "pnet");
	addFileSource(pnet, audioFilename);
	// forces Marsyas to write to processedData
	pnet->addMarSystem(mng.create("Gain", "null"));

	while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
	{
		pnet->tick();
	        const realvec& processedData =
                    pnet->getctrl("SoundFileSource/src/mrs_realvec/processedData")->to<mrs_realvec>();
		for (mrs_natural i=0; i< processedData.getSize(); ++i)
		{
			mrs_real val = fabs(processedData(i));
			if (val > maxVal)
				maxVal = val;
		}
	}

	delete pnet;
	return 1.0/maxVal;
}
Ejemplo n.º 11
0
// ********************** start toys **********
void
toy_with_harmonicStrength(mrs_string sfname)
{
    MarSystemManager mng;

    MarSystem *net = mng.create("Series", "net");
    net->addMarSystem(mng.create("SoundFileSource", "src"));
    net->addMarSystem(mng.create("ShiftInput", "si"));
    net->addMarSystem(mng.create("Windowing", "win"));
    net->addMarSystem(mng.create("Spectrum", "spec"));
    net->addMarSystem(mng.create("PowerSpectrum", "pspec"));
    net->addMarSystem(mng.create("HarmonicStrength", "harm"));
    net->updControl("SoundFileSource/src/mrs_string/filename", sfname);
    net->updControl("mrs_natural/inSamples", 512);
    net->updControl("ShiftInput/si/mrs_natural/winSize", 1024);
    net->updControl("Windowing/win/mrs_string/type", "Hanning");

    mrs_natural num_harmonics = 30;
    realvec harmonics(num_harmonics);
    /*
    cout<<"---------------------------"<<endl;
    cout<<"Relative harmonic strengths"<<endl;
    for (mrs_natural h = 0; h<num_harmonics; ++h)
    {
    		if (h==num_harmonics-1)
    		{
    			cout<<"0.5"<<"\t";
    			harmonics(h) = 0.5;
    		}
    		else
    	{
    		cout<<h<<"\t";
    		harmonics(h) = h+1;
    	}
    }
    cout<<endl;
    */

    //net->updControl("HarmonicStrength/harm/mrs_realvec/harmonics", harmonics);
    net->updControl("HarmonicStrength/harm/mrs_natural/harmonicsSize", num_harmonics);
    net->updControl("HarmonicStrength/harm/mrs_real/harmonicsWidth", 0.0);
    net->updControl("HarmonicStrength/harm/mrs_natural/type", 1);
    net->updControl("HarmonicStrength/harm/mrs_real/base_frequency", 200.0);
    // typical value for piano strings
    net->updControl("HarmonicStrength/harm/mrs_real/inharmonicity_B", 2e-5);

    while ( net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>() )
    {
        net->tick();
        mrs_realvec v = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
        for (mrs_natural h = 0; h<num_harmonics; ++h)
        {
            //printf("%.2f\t", v(h));
            printf("%.8g\t", v(h));
        }
        cout<<endl;
    }
    delete net;
}
Ejemplo n.º 12
0
bool MslCommandRun::execute()
{
  MarSystem* msys;

  if ( workingSet.find(name) != workingSet.end() ) {
    msys = (MarSystem *)workingSet[name];
  } else {
    cout << "Cannot find MarSystem: " << name << endl;
    return false;
  }

  mrs_natural wc=0;
  mrs_natural samplesPlayed = 0;
  mrs_natural onSamples = msys->getctrl("mrs_natural/onSamples")->to<mrs_natural>();

  mrs_real* controls = 0;

  while (true) {

    try {

      controls = msys->recvControls();

      if ( controls != 0 ) {

        // get some reference controls, so if they have changed we update them
        mrs_natural inSamples = msys->getctrl("mrs_natural/inSamples")->to<mrs_natural>();
        mrs_natural inObservations = msys->getctrl("mrs_natural/inObservations")->to<mrs_natural>();
        mrs_real israte = msys->getctrl("mrs_real/israte")->to<mrs_real>();

        if ( (mrs_natural)controls[1] != inSamples || (mrs_natural)controls[2] != inObservations
             || controls[3] != israte ) {

          msys->updctrl("mrs_natural/inSamples",(mrs_natural) controls[1]);
          msys->updctrl("mrs_natural/inObservations", (mrs_natural)controls[2]);
          msys->updctrl("mrs_real/israte", controls[3]);
        }
      }

      msys->tick();
    }
    catch( SocketException e ) {
      cout << "Played " << wc << " slices of " << onSamples << " samples" << endl;
      exit(1);
    }

    wc ++;

    if ( !msys->getctrl("mrs_bool/hasData")->isTrue() ) {
      break;
    }
    samplesPlayed += onSamples;

  } // while

  cout << "Played " << wc << " slices of " << onSamples << " samples" << endl;
  return true;
}
Ejemplo n.º 13
0
int getFileLengthForWaveform(string inFileName, int windowSize_, double& min, double& max) {

	MarSystemManager mng;

	// A series to contain everything
	MarSystem* net = mng.create("Series", "net");
	
	// The sound file
	net->addMarSystem(mng.create("SoundFileSource", "src"));
	net->addMarSystem(mng.create("Stereo2Mono", "s2m"));
	net->addMarSystem(mng.create("ShiftInput", "si"));
	net->updControl("SoundFileSource/src/mrs_string/filename", inFileName);


	mrs_real srate = net->getControl("SoundFileSource/src/mrs_real/osrate")->to<mrs_real>();
	if ((position_ == 0) && (start_ != 0.0))
		position_ = (mrs_natural) (srate * start_);
	
	if ((ticks_ == -1) && (length_ != -1.0))
		ticks_ = (mrs_natural) ((length_ * srate) / windowSize_);
	
	net->updControl("SoundFileSource/src/mrs_natural/pos", position_);
	net->updControl("SoundFileSource/src/mrs_natural/inSamples", hopSize_);
	net->updControl("ShiftInput/si/mrs_natural/winSize", windowSize_);
	
	// Compute the AbsMax of this window
	net->addMarSystem(mng.create("AbsMax","absmax"));

	realvec processedData;

	int length = 0;

	while (net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>() 
		   && (ticks_ == -1 || length < ticks_))  {
		net->tick();
		length++;

		processedData = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
		if (processedData(0) < min)
			min = processedData(0);
		if (processedData(0) > max)
			max = processedData(0);
	}


	delete net;

	if (verboseopt_) {
		cout << "length=" << length << endl;
		cout << "max=" << max << endl;
		cout << "min=" << min << endl;
	}

	return length;
}
Ejemplo n.º 14
0
void
distance_matrix()
{
  if (!wekafname_Set()) return;

  cout << "Distance matrix calculation using " << wekafname_ << endl;

  wekafname_  = inputdir_ + wekafname_;

  MarSystemManager mng;

  MarSystem* net = mng.create("Series", "net");

  MarSystem* wsrc = mng.create("WekaSource", "wsrc");
  net->addMarSystem(wsrc);
	//!!!: mode control
	net->updControl("WekaSource/wsrc/mrs_string/validationMode", "OutputInstancePair");
	net->updControl("WekaSource/wsrc/mrs_bool/normMaxMin", true);
  net->updControl("WekaSource/wsrc/mrs_string/filename", wekafname_);


	MarSystem* dmatrix = mng.create("SelfSimilarityMatrix", "dmatrix");
  dmatrix->addMarSystem(mng.create("Metric", "dmetric"));
  dmatrix->updControl("Metric/dmetric/mrs_string/metric", "euclideanDistance");
	//!!!: lmartins: normalization can only be applied when we have all feature vectors in memory...
	//... which is what we are trying to avoid here (having big realvecs in memory)...
  //dmatrix->updControl("mrs_string/normalize", "MinMax");
  net->addMarSystem(dmatrix);
	//!!!: mode control
	net->updControl("SelfSimilarityMatrix/dmatrix/mrs_natural/mode", 1); //FIXME: replace use of enum for strings?

	//link controls between WekaSource and SelfSimilarityMatrix
	net->linkControl("SelfSimilarityMatrix/dmatrix/mrs_natural/nInstances",
									 "WekaSource/wsrc/mrs_natural/nInstances");
	net->linkControl("WekaSource/wsrc/mrs_realvec/instanceIndexes",
									 "SelfSimilarityMatrix/dmatrix/mrs_realvec/instanceIndexes");

	ofstream oss;
	oss.open(distancematrix_.c_str());
	oss << "Marsyas-kea distance matrix" << endl;

	while(!net->getctrl("SelfSimilarityMatrix/dmatrix/mrs_bool/done")->to<bool>())
	{
		const mrs_realvec& idxs = net->getctrl("SelfSimilarityMatrix/dmatrix/mrs_realvec/instanceIndexes")->to<mrs_realvec>();
		oss << "(" << mrs_natural(idxs(0)) << "," << mrs_natural(idxs(1)) << ") = ";

		net->tick();

		const mrs_realvec& value = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
		oss << value(0) << endl;
	}

  oss << endl;
}
Ejemplo n.º 15
0
int
main(int argc, const char **argv)
{	
    (void) argc;  // tells the compiler that we know that we're not
    (void) argv;  // using these two variables
	MRSDIAG("helloWorld.cpp - main");

	// cout << "This is probably the simplest Marsyas example code: it simply
	// generates a sine wave with a frequency of 440Hz and send it to the audio
	// card output. Simple press CTRL+C to quit." << endl;
	
	//we usualy start by creating a MarSystem manager 
	//to help us on MarSystem creation
	MarSystemManager mng;

	//create the network, which is a simple Series network with a sine wave
	//oscilator and a audio sink object to send the ausio data for playing 
	//in the sound card
	MarSystem *network = mng.create("Series", "network");
	network->addMarSystem(mng.create("SineSource", "src"));
	network->addMarSystem(mng.create("AudioSink", "dest"));
	network->addMarSystem(mng.create("SoundFileSink", "dest2"));

	//set the window (i.e. audio frame) size (in samples). Let's say, 256 samples.
	//This is done in the outmost MarSystem (i.e. the Series/network) because flow
	//controls (as is the case of inSamples) are propagated through the network.
	//Check the Marsyas documentation for mode details.
	network->updControl("mrs_natural/inSamples", 4096);
 

	//set oscilator frequency to 440Hz
	network->updControl("SineSource/src/mrs_real/frequency", 440.0);

	// set the sampling to 44100  - a safe choice in most configurations 
	network->updControl("mrs_real/israte", 44100.0);
	network->updControl("AudioSink/dest/mrs_bool/initAudio", true);
	network->updControl("SoundFileSink/dest2/mrs_string/filename", "helloworld.wav");
	

	//now it's time for ticking the network, 
	//ad aeternum (i.e. until the user quits by CTRL+C)
	while (1) 
	{
		network->tick();
	}

	//ok, this is not really necessary because we are quiting by CTRL+C, 
	//but it's a good habit anyway ;-)
	delete network;

	return(0);
}
void
basic_negative(string infile, string outfile)
{
	MarSystem* pnet = mng.create("Series", "pnet");
	addSource( pnet, infile );
	pnet->addMarSystem(mng.create("Negative", "inv"));
	addDest( pnet, outfile);

	while (pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>())
	{
		pnet->tick();
	}
	delete pnet;
}
// TODO: move
void
basic_vibrato(string infile, string outfile)
{
	MarSystem* pnet = mng.create("Series", "pnet");
	addSource( pnet, infile );
	pnet->addMarSystem(mng.create("Vibrato", "vib"));
	addDest( pnet, outfile);

	pnet->updctrl("Vibrato/vib/mrs_real/mod_freq", 10.0);
	while (pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>())
	{
		pnet->tick();
	}
	delete pnet;
}
void
basic_windowing(string infile, string outfile)
{
	MarSystem* pnet = mng.create("Series", "pnet");
	addSource( pnet, infile );
	pnet->addMarSystem(mng.create("Windowing", "win"));
	pnet->updctrl("Windowing/win/mrs_string/type", "Hanning");
	addDest( pnet, outfile);

	while (pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>())
	{
		pnet->tick();
	}
	delete pnet;
}
void
basic_shifter(string infile, string outfile)
{
	MarSystem* pnet = mng.create("Series", "pnet");
	addSource( pnet, infile );
	pnet->addMarSystem(mng.create("Shifter", "shift"));
	pnet->updctrl("Shifter/shift/mrs_natural/shift", 16);
	addDest( pnet, outfile);

	while (pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>())
	{
		pnet->tick();
	}
	delete pnet;
}
void
basic_delay(string infile, string outfile)
{
	MarSystem* pnet = mng.create("Series", "pnet");
	addSource( pnet, infile );
	pnet->addMarSystem(mng.create("Delay", "delay"));
	pnet->updctrl("Delay/delay/mrs_natural/delaySamples", 16);
	pnet->updctrl("Delay/delay/mrs_real/feedback", (mrs_real) 0.5);
	addDest( pnet, outfile);

	while (pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>())
	{
		pnet->tick();
	}
	delete pnet;
}
Ejemplo n.º 21
0
// Variation that outputs RMS and Flux
void 
output_rmsflux(string inFileName)
{

	MarSystemManager mng;
	MarSystem* net = mng.create("Series", "net");

	net->addMarSystem(mng.create("SoundFileSource", "src"));
	net->addMarSystem(mng.create("Stereo2Mono", "s2m"));

	// A fanout that will do both RMS and Flux calculations
	MarSystem* fanout = mng.create("Fanout","fanout");
	net->addMarSystem(fanout);

	// The branch to do the RMS
	MarSystem* rms_series = mng.create("Series","rms_series");
	rms_series->addMarSystem(mng.create("Rms", "rms"));
	fanout->addMarSystem(rms_series);

	// The branch to do the Flux
	MarSystem* flux_series = mng.create("Series","flux_series");
	flux_series->addMarSystem(mng.create("ShiftInput", "si"));
	flux_series->addMarSystem(mng.create("Windowing", "win"));
	flux_series->addMarSystem(mng.create("Spectrum","spk"));
	flux_series->addMarSystem(mng.create("PowerSpectrum", "pspk"));
	flux_series->addMarSystem(mng.create("Flux", "flux")); 
	fanout->addMarSystem(flux_series);

	// Update the controls with required values
	net->updControl("SoundFileSource/src/mrs_string/filename", inFileName);

	realvec processedData;
	float time = 0;
	mrs_natural samples_per_tick = net->getControl("SoundFileSource/src/mrs_natural/onSamples")->to<mrs_natural>();
	mrs_real rate = net->getControl("SoundFileSource/src/mrs_real/osrate")->to<mrs_real>();
	mrs_real sec_per_tick = samples_per_tick / rate;
	while (net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>()) {
		net->tick();
		processedData = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
		cout << time << "," << processedData(0,0) << "," << processedData(1,0) << endl;
		time += sec_per_tick;
	}

	delete net;

}
Ejemplo n.º 22
0
int
isClose(string infile1, string infile2)
{
  MarSystemManager mng;
  MarSystem* pnet = mng.create("Series", "pnet");

  MarSystem* invnet = mng.create("Series", "invnet");
  invnet->addMarSystem(mng.create("SoundFileSource", "src2"));
  invnet->updControl("SoundFileSource/src2/mrs_string/filename", infile2);
  invnet->addMarSystem(mng.create("Negative", "neg"));

  MarSystem* fanout = mng.create("Fanout", "fanout");
  fanout->addMarSystem(mng.create("SoundFileSource", "src1"));
  fanout->updControl("SoundFileSource/src1/mrs_string/filename", infile1);
  fanout->addMarSystem(invnet);

  pnet->addMarSystem(fanout);
  pnet->addMarSystem(mng.create("Sum", "sum"));
  pnet->linkControl("mrs_bool/hasData",
                    "Fanout/fanout/SoundFileSource/src1/mrs_bool/hasData");

  mrs_natural i;
  mrs_natural samples =
    pnet->getctrl("mrs_natural/inSamples")->to<mrs_natural>();
  while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
  {
    pnet->tick();
    const realvec& processedData =
      pnet->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
    for (i=0; i<samples; ++i)
    {
      //  useful for tweaking CLOSE_ENOUGH
      //cout<<processedData(i)<<" ";
      if ( abs(processedData(i)) > CLOSE_ENOUGH )
      {
        delete pnet;
        return(1);
      }
    }
  }
  delete pnet;
  return 0;
}
realvec
TranscriberExtract::getPitchesFromAudio(const std::string audioFilename)
{
	mrs_real normalize = getNormalizingGain(audioFilename);

	MarSystem* pnet = mng.create("Series", "pnet");
	mrs_real srate = addFileSource(pnet, audioFilename);
	pnet->addMarSystem(mng.create("Gain", "normalizing"));
	pnet->updControl("Gain/normalizing/mrs_real/gain",normalize);
	MarSystem* rvSink = mng.create("RealvecSink", "rvSink");
	pnet->addMarSystem(makePitchNet(srate, 100.0, rvSink));

	while ( pnet->getctrl("mrs_bool/hasData")->to<mrs_bool>() )
		pnet->tick();

	realvec pitchList = getPitchesFromRealvecSink(rvSink, srate);
	delete pnet;
	return pitchList;
}
void record(mrs_real length, mrs_real gain, string filename) 
{
    MarSystemManager mng;

    MarSystem* recordNet = mng.create("Series", "recordNet");
    MarSystem* asrc = mng.create("AudioSource", "asrc");
    MarSystem* dest = mng.create("SoundFileSink", "dest");

    recordNet->addMarSystem(asrc);
    recordNet->addMarSystem(dest);

    recordNet->updControl("mrs_natural/inSamples", 4096);
    recordNet->updControl("mrs_real/israte", sropt);
    recordNet->updControl("AudioSource/asrc/mrs_natural/nChannels", copt);
    recordNet->updControl("AudioSource/asrc/mrs_real/gain", gain);

    // Ready to initialize audio device 
    recordNet->updControl("AudioSource/asrc/mrs_bool/initAudio", true);

    recordNet->updControl("SoundFileSink/dest/mrs_string/filename", filename);

    mrs_real srate = recordNet->getctrl("mrs_real/israte")->to<mrs_real>();
    mrs_natural nChannels = recordNet->getctrl("AudioSource/asrc/mrs_natural/nChannels")->to<mrs_natural>();
    cout << "AudioSource srate =  " << srate << endl; 
    cout << "AudioSource nChannels = " << nChannels << endl;
    mrs_natural inSamples = recordNet->getctrl("mrs_natural/inSamples")->to<mrs_natural>();


    mrs_natural iterations = (mrs_natural)((srate * length) / inSamples);

    cout << "Iterations = " << iterations << endl;


    for (mrs_natural t = 0; t < iterations; t++) 
    {
        recordNet->tick();
    }




}
Ejemplo n.º 25
0
void fftHistogram(string inFileName)
{
	double fftBins = windowSize_ / 2.0 + 1;  // N/2 + 1

	MarSystemManager mng;
	MarSystem* net = mng.create("Series", "net");
	net->addMarSystem(mng.create("SoundFileSource", "src"));
	net->addMarSystem(mng.create("Stereo2Mono", "s2m"));
	net->addMarSystem(mng.create("ShiftInput", "si"));
	net->addMarSystem(mng.create("Spectrum","spk"));
	net->addMarSystem(mng.create("PowerSpectrum","pspk"));
	net->updControl("PowerSpectrum/pspk/mrs_string/spectrumType", "decibels");
	net->updControl("SoundFileSource/src/mrs_string/filename", inFileName);
	net->updControl("SoundFileSource/src/mrs_natural/pos", position_);
	net->updControl("SoundFileSource/src/mrs_natural/inSamples", hopSize_);
	net->updControl("ShiftInput/si/mrs_natural/winSize", windowSize_);
	net->updControl("mrs_natural/inSamples", int(hopSize_));

	mrs_real frequency = net->getctrl("SoundFileSource/src/mrs_real/osrate")->to<mrs_real>();
	double pngHeight = fftBins * (highFreq_ / (frequency / 2.0));
	realvec processedData;

	// Iterate over the whole input file by ticking, outputting columns
	// of data to the .png file with each tick
	double x = 0;
	while (net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>()
		   && (ticks_ == -1 || x < ticks_))  {
		net->tick();
		processedData = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();

		for (int i = 0; i < pngHeight; ++i) {
			double data_y = i;

			double data = processedData(int(data_y),0);

			cout << "data=" << data << endl;
		}
		x++;
	}

	delete net;
}
// take advantage of MarSystemManager 
void 
tempotest_sfplay(string sfName)
{
    cout << "Playing " << sfName << endl; 

    MarSystemManager mng;

    // Create a series Composite 
    MarSystem* series = mng.create("Series", "series");
    series->addMarSystem(mng.create("SoundFileSource", "src"));
    series->addMarSystem(mng.create("AudioSink", "dest"));

    // only update controls from Composite level 
    series->updctrl("mrs_natural/inSamples", 128);
    series->updctrl("SoundFileSource/src/mrs_string/filename", sfName);

    while (series->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>())
        series->tick();

    delete series;
}
Ejemplo n.º 27
0
void
toy_with_csv_input(mrs_string sfname)
{
    MarSystemManager mng;

    MarSystem *net = mng.create("Series", "net");
    net->addMarSystem(mng.create("CsvFileSource", "src"));

    net->updControl("CsvFileSource/src/mrs_string/filename", sfname);
    net->updControl("mrs_natural/inSamples", 1);

    while ( net->getctrl("CsvFileSource/src/mrs_bool/hasData")->to<mrs_bool>() )
    {
        net->tick();
        mrs_realvec v = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
        for (mrs_natural i = 0; i<v.getSize(); ++i)
        {
            printf("%.5g\t", v(i));
        }
        cout<<endl;
    }
    delete net;
}
Ejemplo n.º 28
0
	void centroidToTxt(string sfName1) {
		cout << "Toy with centroid " << sfName1 << endl;
		MarSystemManager mng;

		MarSystem* net = mng.create("Series/net");
		net->addMarSystem(mng.create("SoundFileSource/src"));
		net->addMarSystem(mng.create("Windowing/ham"));
		net->addMarSystem(mng.create("Spectrum/spk"));
		net->addMarSystem(mng.create("PowerSpectrum/pspk"));
		net->addMarSystem(mng.create("Centroid/cntrd"));
		net->addMarSystem(mng.create("Memory/mem"));
		net->addMarSystem(mng.create("Mean/mean"));
		net->linkctrl("mrs_string/filename", "SoundFileSource/src/mrs_string/filename");
		net->updctrl("mrs_string/filename", sfName1);

		mrs_real val = 0.0;

		ofstream ofs;
		ofs.open("centroid.mpl");
		ofs << *net << endl;
		ofs.close();

		ofstream text;
		text.open("centroid.txt");


		while (net->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>())
		{
			net->tick();
			const mrs_realvec& src_data =
			net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
			val = src_data(0,0);
			text << val << endl;
			//cout << val << endl;
		}
		text.close();
	}
void
peakClusteringEval(realvec &peakSet, string sfName, string outsfname, string noiseName, string mixName, string intervalFrequency, string panningInfo, mrs_real noiseDelay, string T, mrs_natural N, mrs_natural Nw, 
				   mrs_natural D, mrs_natural S, mrs_natural C,
				   mrs_natural accSize, mrs_natural synthetize, mrs_real *snr0)
{
	//FIXME: D is the same as hopSize_ -> fix to avoid confusion!

	MATLAB_EVAL("clear");

	MarSystemManager mng;

	cout << "Extracting Peaks and Computing Clusters..." << endl;
	
	//**************************************************
	// create the peakClusteringEval network
	//**************************************************
	MarSystem* mainNet = mng.create("Series", "mainNet");

	//**************************************************************************
	//create accumulator for the texture window and add it to the main network
	//**************************************************************************
	MarSystem* textWinNet = mng.create("Accumulator", "textWinNet");
	mainNet->addMarSystem(textWinNet);

	//************************************************************************
	//create Analysis Network and add it to the texture window accumulator
	//************************************************************************
	MarSystem* analysisNet = mng.create("Series", "analysisNet");
	textWinNet->addMarSystem(analysisNet);

	//************************************************************************
	//create FanInOut for mixing with a noise source and add to Analysis Net
	//************************************************************************
	MarSystem* mixer = mng.create("FanOutIn", "mixer");
	//---- create original series and add it to mixer
	MarSystem* oriNet = mng.create("Series", "oriNet");
	if (microphone_) 
		oriNet->addMarSystem(mng.create("AudioSource", "src"));
	else
	{
		//oriNet->addMarSystem(mng.create("SoundFileSource", "src"));
		oriNet->addMarSystem(mng.create("MidiFileSynthSource", "src")); //[!]
	}
	oriNet->addMarSystem(mng.create("Gain", "oriGain"));
	mixer->addMarSystem(oriNet);
	//---- create a series for the noiseSource
	if(noiseName != EMPTYSTRING)
	{
		MarSystem* mixseries = mng.create("Series", "mixseries");
		if(noiseName == "white")
			mixseries->addMarSystem(mng.create("NoiseSource", "noise"));
		else
			mixseries->addMarSystem(mng.create("SoundFileSource", "noise"));

		mixseries->addMarSystem(mng.create("Delay", "noiseDelay"));
		MarSystem* noiseGain = mng.create("Gain", "noiseGain");
		mixseries->addMarSystem(noiseGain);
		// add this series in the fanout
		mixer->addMarSystem(mixseries);
	}
	//add Mixer to analysis network
	analysisNet->addMarSystem(mixer);

	//********************************************************
	// create SoundFileSink and add it to the analysis net
	//********************************************************
	if(noiseName != EMPTYSTRING)
		analysisNet->addMarSystem(mng.create("SoundFileSink", "mixSink"));

	
	//***********************************************************
	// create peakExtract network and add it to the analysis net
	//***********************************************************
	MarSystem* peakExtract = mng.create("Series","peakExtract");
	peakExtract->addMarSystem(mng.create("ShiftInput", "si")); //[?]

	MarSystem* stereoFo = mng.create("Fanout","stereoFo");
	// create Spectrum Network and add it to the analysis net
	MarSystem* spectrumNet = mng.create("Series", "spectrumNet");
	spectrumNet->addMarSystem(mng.create("Stereo2Mono","s2m"));

	//onset detector
	MarSystem* onsetdetector = mng.create("FlowThru", "onsetdetector");
	//onsetdetector->addMarSystem(mng.create("ShiftInput", "si"));
	onsetdetector->addMarSystem(mng.create("Windowing", "win")); 
	onsetdetector->addMarSystem(mng.create("Spectrum","spk"));
	onsetdetector->addMarSystem(mng.create("PowerSpectrum", "pspk"));
	onsetdetector->addMarSystem(mng.create("Flux", "flux")); 
	onsetdetector->addMarSystem(mng.create("ShiftInput","sif"));
	onsetdetector->addMarSystem(mng.create("Filter","filt1"));
	onsetdetector->addMarSystem(mng.create("Reverse","rev1"));
	onsetdetector->addMarSystem(mng.create("Filter","filt2"));
	onsetdetector->addMarSystem(mng.create("Reverse","rev2"));
	onsetdetector->addMarSystem(mng.create("PeakerOnset","peaker")); 
	spectrumNet->addMarSystem(onsetdetector);
		
	spectrumNet->addMarSystem(mng.create("Shifter", "sh"));
	spectrumNet->addMarSystem(mng.create("Windowing", "wi"));
	MarSystem* parallel = mng.create("Parallel", "par");
	parallel->addMarSystem(mng.create("Spectrum", "spk1"));
	parallel->addMarSystem(mng.create("Spectrum", "spk2"));
	spectrumNet->addMarSystem(parallel);
	// add spectrumNet to stereo fanout
	stereoFo->addMarSystem(spectrumNet);
	//
	//create stereo spectrum net
	MarSystem* stereoSpkNet = mng.create("Series","stereoSpkNet");
	MarSystem* LRnet = mng.create("Parallel","LRnet");
	//
	MarSystem* spkL = mng.create("Series","spkL");
	spkL->addMarSystem(mng.create("Windowing","win"));
	spkL->addMarSystem(mng.create("Spectrum","spk"));
	LRnet->addMarSystem(spkL);
	//
	MarSystem* spkR = mng.create("Series","spkR");
	spkR->addMarSystem(mng.create("Windowing","win"));
	spkR->addMarSystem(mng.create("Spectrum","spk"));
	LRnet->addMarSystem(spkR);
	//
	//add it to the stereo spectrum net series
	stereoSpkNet->addMarSystem(LRnet);
	//
	//add stereo spectrum object to stereo spectrum net
	//stereoSpkNet->addMarSystem(mng.create("StereoSpectrum","stereoSpk")); //AVENDANO
	stereoSpkNet->addMarSystem(mng.create("EnhADRess","ADRess"));//enhADRess_1
	stereoSpkNet->addMarSystem(mng.create("EnhADRessStereoSpectrum","stereoSpk")); //enhADRess_2
	//
	// add the stereo Spectrum net to the Fanout
	stereoFo->addMarSystem(stereoSpkNet);
	//
	// add the fanout to the peakExtract net
	peakExtract->addMarSystem(stereoFo);
	//
	//add peakExtract net to analysis net 
	analysisNet->addMarSystem(peakExtract);

	//***************************************************************
	//add PeakConvert to main SERIES for processing texture windows
	//***************************************************************
	mainNet->addMarSystem(mng.create("PeakConvert", "conv"));
	mainNet->linkControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_natural/winSize",
						 "Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/ShiftInput/si/mrs_natural/winSize");

	//***************************************************************
	//create a FlowThru for the Clustering Network and add to main net
	//***************************************************************
	MarSystem* clustNet = mng.create("FlowThru", "clustNet");
	mainNet->addMarSystem(clustNet);

	//***************************************************************
	// create Similarities Network and add it to ClustNet
	//***************************************************************
	MarSystem* simNet = mng.create("FanOutIn", "simNet");
	simNet->updControl("mrs_string/combinator", "*");
	//
	//create Frequency similarity net and add it to simNet
	//
	MarSystem* freqSim = mng.create("Series","freqSim");
	//--------
	freqSim->addMarSystem(mng.create("PeakFeatureSelect","FREQfeatSelect"));
	freqSim->updControl("PeakFeatureSelect/FREQfeatSelect/mrs_natural/selectedFeatures",
					 PeakFeatureSelect::pkFrequency | PeakFeatureSelect::barkPkFreq);
	//--------
	MarSystem* fsimMat = mng.create("SelfSimilarityMatrix","FREQsimMat");
	fsimMat->addMarSystem(mng.create("Metric","FreqL2Norm"));
	fsimMat->updControl("Metric/FreqL2Norm/mrs_string/metric","euclideanDistance");
	fsimMat->updControl("mrs_natural/calcCovMatrix", SelfSimilarityMatrix::diagCovMatrix);
	//fsimMat->updControl("mrs_string/normalize", "MinMax");
	//fsimMat->linkControl("mrs_realvec/covMatrix", "Metric/FreqL2Norm/mrs_realvec/covMatrix");
	freqSim->addMarSystem(fsimMat);	
	//--------
	freqSim->addMarSystem(mng.create("RBF","FREQrbf"));
	freqSim->updControl("RBF/FREQrbf/mrs_string/RBFtype","Gaussian");
	freqSim->updControl("RBF/FREQrbf/mrs_bool/symmetricIn",true);
	//--------
	simNet->addMarSystem(freqSim);
	//
	//create Amplitude similarity net and add it to simNet
	//
	MarSystem* ampSim = mng.create("Series","ampSim");
	//--------
	ampSim->addMarSystem(mng.create("PeakFeatureSelect","AMPfeatSelect"));
	ampSim->updControl("PeakFeatureSelect/AMPfeatSelect/mrs_natural/selectedFeatures",
					PeakFeatureSelect::pkAmplitude | PeakFeatureSelect::dBPkAmp);
	//--------
	MarSystem* asimMat = mng.create("SelfSimilarityMatrix","AMPsimMat");
	asimMat->addMarSystem(mng.create("Metric","AmpL2Norm"));
	asimMat->updControl("Metric/AmpL2Norm/mrs_string/metric","euclideanDistance");
	asimMat->updControl("mrs_natural/calcCovMatrix", SelfSimilarityMatrix::diagCovMatrix);
	//asimMat->updControl("mrs_string/normalize", "MinMax");
	//asimMat->linkControl("mrs_realvec/covMatrix", "Metric/AmpL2Norm/mrs_realvec/covMatrix");
	ampSim->addMarSystem(asimMat);	
	//--------
	ampSim->addMarSystem(mng.create("RBF","AMPrbf"));
	ampSim->updControl("RBF/AMPrbf/mrs_string/RBFtype","Gaussian");
	ampSim->updControl("RBF/AMPrbf/mrs_bool/symmetricIn",true);
	//--------
	simNet->addMarSystem(ampSim);
	//
	//create HWPS similarity net and add it to simNet
	//
	MarSystem* HWPSim = mng.create("Series","HWPSim");
	//--------
	HWPSim->addMarSystem(mng.create("PeakFeatureSelect","HWPSfeatSelect"));
	HWPSim->updControl("PeakFeatureSelect/HWPSfeatSelect/mrs_natural/selectedFeatures",
					PeakFeatureSelect::pkFrequency | PeakFeatureSelect::pkSetFrequencies | PeakFeatureSelect::pkSetAmplitudes);
	//--------
	MarSystem* HWPSsimMat = mng.create("SelfSimilarityMatrix","HWPSsimMat");
	HWPSsimMat->addMarSystem(mng.create("HWPS","hwps"));
	HWPSsimMat->updControl("HWPS/hwps/mrs_bool/calcDistance", true);
	HWPSim->addMarSystem(HWPSsimMat);	
	//--------
	HWPSim->addMarSystem(mng.create("RBF","HWPSrbf"));
	HWPSim->updControl("RBF/HWPSrbf/mrs_string/RBFtype","Gaussian");
	HWPSim->updControl("RBF/HWPSrbf/mrs_bool/symmetricIn",true);
	//--------
	simNet->addMarSystem(HWPSim);
	//
	//create Panning similarity net and add it to simNet
	//
	MarSystem* panSim = mng.create("Series","panSim");
	//--------
	panSim->addMarSystem(mng.create("PeakFeatureSelect","PANfeatSelect"));
	panSim->updControl("PeakFeatureSelect/PANfeatSelect/mrs_natural/selectedFeatures",
					PeakFeatureSelect::pkPan);
	//--------
	MarSystem* psimMat = mng.create("SelfSimilarityMatrix","PANsimMat");
	psimMat->addMarSystem(mng.create("Metric","PanL2Norm"));
	psimMat->updControl("Metric/PanL2Norm/mrs_string/metric","euclideanDistance");
	psimMat->updControl("mrs_natural/calcCovMatrix", SelfSimilarityMatrix::diagCovMatrix);
	//psimMat->updControl("mrs_string/normalize", "MinMax");
	//psimMat->linkControl("mrs_realvec/covMatrix", "Metric/PanL2Norm/mrs_realvec/covMatrix");
	panSim->addMarSystem(psimMat);	
	//--------
	panSim->addMarSystem(mng.create("RBF","PANrbf"));
	panSim->updControl("RBF/PANrbf/mrs_string/RBFtype","Gaussian");
	panSim->updControl("RBF/PANrbf/mrs_bool/symmetricIn",true);
	//--------
	simNet->addMarSystem(panSim);
	//
	// LINK controls of PeakFeatureSelects in each similarity branch
	//
	simNet->linkControl("Series/ampSim/PeakFeatureSelect/AMPfeatSelect/mrs_natural/totalNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/totalNumPeaks");
	simNet->linkControl("Series/HWPSim/PeakFeatureSelect/HWPSfeatSelect/mrs_natural/totalNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/totalNumPeaks");
	simNet->linkControl("Series/panSim/PeakFeatureSelect/PANfeatSelect/mrs_natural/totalNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/totalNumPeaks");
	//------
	simNet->linkControl("Series/ampSim/PeakFeatureSelect/AMPfeatSelect/mrs_natural/frameMaxNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/frameMaxNumPeaks");
	simNet->linkControl("Series/HWPSim/PeakFeatureSelect/HWPSfeatSelect/mrs_natural/frameMaxNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/frameMaxNumPeaks");
	simNet->linkControl("Series/panSim/PeakFeatureSelect/PANfeatSelect/mrs_natural/frameMaxNumPeaks",
					 "Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/frameMaxNumPeaks");
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//add simNet to clustNet
	clustNet->addMarSystem(simNet);
	//
	// LINK controls related to variable number of peak from PeakConvert to simNet
	//
	mainNet->linkControl("FlowThru/clustNet/FanOutIn/simNet/Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/totalNumPeaks",
					  "PeakConvert/conv/mrs_natural/totalNumPeaks");
	mainNet->linkControl("FlowThru/clustNet/FanOutIn/simNet/Series/freqSim/PeakFeatureSelect/FREQfeatSelect/mrs_natural/frameMaxNumPeaks",
					  "PeakConvert/conv/mrs_natural/frameMaxNumPeaks");

	//***************************************************************
	// create NCutNet MarSystem and add it to clustNet
	//***************************************************************
// 	MarSystem* NCutNet = mng.create("Series","NCutNet");
// 	clustNet->addMarSystem(NCutNet);
// 	//---add NCutNet components
// 	// add a stack to stack the 
// 	MarSystem* stack = mng.create("Fanout","stack");
// 	NCutNet->addMarSystem(stack);
// 	stack->addMarSystem(mng.create("NormCut","NCut"));
// 	stack->addMarSystem(mng.create("Gain", "ID"));
// 	// add the cluster selection module
// 	NCutNet->addMarSystem(mng.create("PeakClusterSelect","clusterSelect"));
	
	// Do not select most prominent clusters anymore
	clustNet->addMarSystem(mng.create("NormCut","NCut")); //[!]

	//***************************************************************
	// create PeakLabeler MarSystem and add it to mainNet
	//***************************************************************
	MarSystem* labeler = mng.create("PeakLabeler","labeler");
	mainNet->addMarSystem(labeler);
	//---- link labeler label control to the NCut output control
	mainNet->linkControl("PeakLabeler/labeler/mrs_realvec/peakLabels", "FlowThru/clustNet/mrs_realvec/innerOut");

	//***************************************************************
	// create PeakViewSink MarSystem and add it to mainNet
	//***************************************************************
	if(peakStore_)
	{
		mainNet->addMarSystem(mng.create("PeakViewSink", "peSink"));
		mainNet->updControl("PeakViewSink/peSink/mrs_string/filename", filePeakName);
	}

	//****************************************************************
	// Create Synthesis Network
	//****************************************************************
	MarSystem* postNet = mng.create("Series", "postNet");

	// Create Peak Synth ////////////////////////////////////
	MarSystem* peakSynth = mng.create("Series", "peakSynth");
	peakSynth->addMarSystem(mng.create("PeakSynthOsc", "pso"));
	peakSynth->addMarSystem(mng.create("Windowing", "wiSyn"));
	peakSynth->addMarSystem(mng.create("OverlapAdd", "ov"));
	peakSynth->addMarSystem(mng.create("Gain", "outGain"));
// 		MarSystem *dest;
// 		dest = new SoundFileSink("dest");
// 		//dest->updControl("mrs_string/filename", outsfname);
// 		peakSynth->addMarSystem(dest);
	mng.registerPrototype("PeakSynth", peakSynth);

	// Create Bank of Synths ////////////////////////////////////////////////
	MarSystem* synthBank = mng.create("Fanout","synthBank");
	mrs_natural numSynths = 10; // HARDCODED FOR NOW [!]
	synthBank->addMarSystem(mng.create("PeakSynth", "synthCluster_0"));
	synthBank->updControl("PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_natural/peakGroup2Synth", 0);
	for(mrs_natural s=1; s < numSynths; ++s)
	{
		ostringstream oss;
		oss << "synthCluster_" << s;
		synthBank->addMarSystem(mng.create("PeakSynth", oss.str()));
		//link controls between branches
		synthBank->linkControl("PeakSynth/"+oss.str()+"/PeakSynthOsc/pso/mrs_real/samplingFreq",
							   "PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_real/samplingFreq");
		synthBank->linkControl("PeakSynth/"+oss.str()+"/PeakSynthOsc/pso/mrs_natural/delay",
							   "PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_natural/delay");
		synthBank->linkControl("PeakSynth/"+oss.str()+"/PeakSynthOsc/pso/mrs_natural/synSize",
							   "PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_natural/synSize");
		synthBank->linkControl("PeakSynth/"+oss.str()+"/Windowing/wiSyn/mrs_string/type",
							   "PeakSynth/synthCluster_0/Windowing/wiSyn/mrs_string/type");

		synthBank->updControl("PeakSynth/"+oss.str()+"/PeakSynthOsc/pso/mrs_natural/peakGroup2Synth", s);
	}

	postNet->addMarSystem(synthBank);
	
	// SHREDDER /////////////////////////////////////////////////
	MarSystem* synthNet = mng.create("Shredder", "synthNet");
	synthNet->addMarSystem(postNet);
	synthNet->updControl("mrs_bool/accumulate", true); //accumulate output
	mainNet->addMarSystem(synthNet);
	//link Shredder nTimes to Accumulator nTimes
	mainNet->linkControl("Shredder/synthNet/mrs_natural/nTimes",
					  "Accumulator/textWinNet/mrs_natural/nTimes");

	// add a MATLAB sink at the very end of the network!
	mainNet->addMarSystem(mng.create("PlotSink", "send2MATLAB"));
	mainNet->updControl("PlotSink/send2MATLAB/mrs_bool/sequence", false);
	mainNet->updControl("PlotSink/send2MATLAB/mrs_bool/messages", false);
	mainNet->updControl("PlotSink/send2MATLAB/mrs_bool/matlab", true);
	mainNet->updControl("PlotSink/send2MATLAB/mrs_string/matlabCommand",
					 "evaluateTextWin;");
	
	//****************************************************************
	
	////////////////////////////////////////////////////////////////
	// update the controls
	////////////////////////////////////////////////////////////////
	//mainNet->updControl("Accumulator/textWinNet/mrs_natural/nTimes", accSize);

	if (microphone_) 
	{
		mainNet->updControl("mrs_natural/inSamples", D);
		mainNet->updControl("mrs_natural/inObservations", 1);
	}
	else
	{
		cout << ">> Loading MIDI file and synthetizing audio data..." << endl;
		mainNet->updControl("mrs_natural/inSamples", D);
		mainNet->updControl("mrs_real/israte", samplingFrequency_);
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_real/start", 10.0);
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_real/end", 20.0);
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_string/filename", sfName);
		//mainNet->updControl("mrs_natural/inObservations", 1);
		//samplingFrequency_ = mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_real/osrate")->to<mrs_real>();
	}

	if(noiseName != EMPTYSTRING)
	{
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/mixseries/SoundFileSource/noise/mrs_string/filename", noiseName);
		mainNet->updControl("mrs_natural/inSamples", D);
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/mixseries/NoiseSource/noise/mrs_string/mode", "rand");
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Seriesmixseries/Delay/noiseDelay/mrs_real/delaySeconds",  noiseDelay);
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/mixseries/Gain/noiseGain/mrs_real/gain", noiseGain_);
	}

	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/ShiftInput/si/mrs_natural/winSize", Nw+1);

	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/Shifter/sh/mrs_natural/shift", 1);

	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/Windowing/wi/mrs_natural/size", N);
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/Windowing/wi/mrs_string/type", "Hanning");
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/Windowing/wi/mrs_bool/zeroPhasing", true);

	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkL/Windowing/win/mrs_natural/size", N);
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkL/Windowing/win/mrs_string/type", "Hanning");
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkL/Windowing/win/mrs_bool/zeroPhasing", true);
	//
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkR/Windowing/win/mrs_natural/size", N);
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkR/Windowing/win/mrs_string/type", "Hanning");
	mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/stereoSpkNet/Parallel/LRnet/Series/spkR/Windowing/win/mrs_bool/zeroPhasing", true);

	if(unprecise_)
		mainNet->updControl("PeakConvert/conv/mrs_bool/improvedPrecision", false);      
	else
		mainNet->updControl("PeakConvert/conv/mrs_bool/improvedPrecision", true);  
	
	if(noPeakPicking_)
		mainNet->updControl("PeakConvert/conv/mrs_bool/picking", false);      
	
	mainNet->updControl("PeakConvert/conv/mrs_natural/frameMaxNumPeaks", S); 
	mainNet->updControl("PeakConvert/conv/mrs_string/frequencyInterval", intervalFrequency);  
	mainNet->updControl("PeakConvert/conv/mrs_natural/nbFramesSkipped", 0);//(N/D));  

	//mainNet->updControl("FlowThru/clustNet/Series/NCutNet/Fanout/stack/NormCut/NCut/mrs_natural/numClusters", C); [!]
	//mainNet->updControl("FlowThru/clustNet/Series/NCutNet/PeakClusterSelect/clusterSelect/mrs_natural/numClustersToKeep", nbSelectedClusters_);//[!]
	//
	if(C > 0) //use fixed and manually set number of clusters
	{
		cout << ">> Using fixed number of clusters: " << C << " clusters." << endl;
		mainNet->updControl("FlowThru/clustNet/NormCut/NCut/mrs_natural/numClusters", C); //[!]
	}
	else if(C==0) //use GT number of clusters
	{
		cout << "** Using GT number of clusters." << endl;
		mainNet->linkControl("FlowThru/clustNet/NormCut/NCut/mrs_natural/numClusters",
							 "Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_natural/numActiveNotes");
	}
	else if(C==-1) //automatically estimate number of clusters
	{
		cout << "Automatic Estimation of number of clusters: NOT YET IMPLEMENTED! Exiting...";
		exit(0);
	}

	// 	//[TODO]
	// 	mainNet->setctrl("PeClust/peClust/mrs_natural/selectedClusters", nbSelectedClusters_); 
	// 	mainNet->setctrl("PeClust/peClust/mrs_natural/hopSize", D); 
	// 	mainNet->setctrl("PeClust/peClust/mrs_natural/storePeaks", (mrs_natural) peakStore_); 
	// 	mainNet->updControl("PeClust/peClust/mrs_string/similarityType", T); 
	//
	// 	similarityWeight_.stretch(3);
	// 	similarityWeight_(0) = 1;
	// 	similarityWeight_(1) = 10;  //[WTF]
	// 	similarityWeight_(2) = 1;
	// 	mainNet->updControl("PeClust/peClust/mrs_realvec/similarityWeight", similarityWeight_); 

	if(noiseName != EMPTYSTRING)
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/SoundFileSink/mixSink/mrs_string/filename", mixName);

	mainNet->update();

	//check if input is a stereo signal
	if(mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/mrs_natural/onObservations")->to<mrs_natural>() == 1)
	{
		//if a not a stereo signal, we must set the Stereo2Mono weight to 1.0 (i.e. do no mixing)!
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/Stereo2Mono/s2m/mrs_real/weight", 1.0);
	}

	//------------------------------------------------------------------------
	//check which similarity computations should be disabled (if any)
	//------------------------------------------------------------------------
	// Frequency Similarity
	if(ignoreFrequency)
	{
		cout << "** Frequency Similarity Computation disabled!" << endl;
		mainNet->updControl("FlowThru/clustNet/FanOutIn/simNet/mrs_string/disableChild",
						 "Series/freqSim");
	}
	else
		cout << "** Frequency Similarity Computation enabled!" << endl;
	// amplitude similarity
	if(ignoreAmplitude)
	{
		cout << "** Amplitude Similarity Computation disabled!" << endl;
		mainNet->updControl("FlowThru/clustNet/FanOutIn/simNet/mrs_string/disableChild",
						 "Series/ampSim");
	}
	else
		cout << "** Amplitude Similarity Computation enabled!" << endl;
	// HWPS similarity
	if(ignoreHWPS)
	{
		cout << "** HWPS (harmonicity) Similarity Computation disabled!" << endl;
		mainNet->updControl("FlowThru/clustNet/FanOutIn/simNet/mrs_string/disableChild",
						 "Series/HWPSim");
	}
	else
		cout << "** HWPS (harmonicity) Similarity Computation enabled!" << endl;
	//
	//Panning Similarity
	if(mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/mrs_natural/onObservations")->to<mrs_natural>() == 2 &&
	   !ignorePan)
	{
		cout << "** Panning Similarity Computation enabled!" << endl;
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/mrs_string/enableChild",
						 "Series/stereoSpkNet");
		mainNet->updControl("FlowThru/clustNet/FanOutIn/simNet/mrs_string/enableChild",
						 "Series/panSim");
	}
	else //if not stereo or if stereo to be ignored, disable some branches 
	{
		cout << "** Panning Similarity Computation disabled!" << endl;
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/Series/peakExtract/Fanout/stereoFo/mrs_string/disableChild",
						 "Series/stereoSpkNet");
		mainNet->updControl("FlowThru/clustNet/FanOutIn/simNet/mrs_string/disableChild",
						 "Series/panSim");
	}
	//
	mainNet->update(); //probably not necessary... [!]
	//------------------------------------------------------------------------

	if(noiseDuration_) //[WTF]
	{
		ostringstream ossi;
		ossi << ((noiseDelay_+noiseDuration_)) << "s";
		cout << ossi.str() << endl;
		// touch the gain directly
		//	noiseGain->updControl("0.1s", Repeat("0.1s", 1), new EvValUpd(noiseGain,"mrs_real/gain", 0.0));
	}

	//ONSET DETECTION CONFIGURATION (if enabled)
	if(useOnsets)
	{
		cout << "** Onset detector enabled -> using dynamically adjusted texture windows!" << endl;
		cout << "WinSize = " << winSize_ << endl;
		cout << "N = " << N << endl;
		cout << "Nw = " << Nw << endl;
		cout << "hopSize = " << hopSize_ << endl;
		cout << "D = " << D << endl;
		cout << "fs = " << samplingFrequency_ << endl;

		//link controls for onset detector
		onsetdetector->linkControl("Filter/filt2/mrs_realvec/ncoeffs",
								"Filter/filt1/mrs_realvec/ncoeffs");
		onsetdetector->linkControl("Filter/filt2/mrs_realvec/dcoeffs",
								"Filter/filt1/mrs_realvec/dcoeffs");
		//link onset detector to accumulator and if onsets enabled, set "explicitFlush" mode
		textWinNet->linkControl("mrs_bool/flush",
								"Series/analysisNet/Series/peakExtract/Fanout/stereoFo/Series/spectrumNet/FlowThru/onsetdetector/PeakerOnset/peaker/mrs_bool/onsetDetected");

		//update onset detector controls
		onsetdetector->updControl("PowerSpectrum/pspk/mrs_string/spectrumType", "wrongdBonsets");
		onsetdetector->updControl("Flux/flux/mrs_string/mode", "DixonDAFX06");
		realvec bcoeffs(1,3);//configure zero-phase Butterworth filter of Flux time series -> butter(2, 0.28)
		bcoeffs(0) = 0.1174;
		bcoeffs(1) = 0.2347;
		bcoeffs(2) = 0.1174;
		realvec acoeffs(1,3);
		acoeffs(0) = 1.0;
		acoeffs(1) = -0.8252;
		acoeffs(2) = 0.2946;
		onsetdetector->updControl("Filter/filt1/mrs_realvec/ncoeffs", bcoeffs);
		onsetdetector->updControl("Filter/filt1/mrs_realvec/dcoeffs", acoeffs);
		mrs_natural lookAheadSamples = 6;
		onsetdetector->updControl("PeakerOnset/peaker/mrs_natural/lookAheadSamples", lookAheadSamples); //!!
		onsetdetector->updControl("PeakerOnset/peaker/mrs_real/threshold", 1.5); //!!!
		onsetdetector->updControl("ShiftInput/sif/mrs_natural/winSize", 4*lookAheadSamples+1);

		//set Accumulator controls for explicit flush mode
		mrs_natural winds = 1+lookAheadSamples+mrs_natural(ceil(mrs_real(winSize_)/hopSize_/2.0));
		cout << "Accumulator/textWinNet timesToKeep = " << winds << endl;
		mrs_real textureWinMinLen = 0.050; //secs
		mrs_real textureWinMaxLen = 1.0; //secs
		mrs_natural minTimes = (mrs_natural)(textureWinMinLen*samplingFrequency_/hopSize_); 
		mrs_natural maxTimes = (mrs_natural)(textureWinMaxLen*samplingFrequency_/hopSize_); 
		cout << "Accumulator/textWinNet MinTimes = " << minTimes << " (i.e. " << textureWinMinLen << " secs)" << endl;
		cout << "Accumulator/textWinNet MaxTimes = " << maxTimes << " (i.e. " << textureWinMaxLen << " secs)" <<endl;
		textWinNet->updControl("mrs_string/mode", "explicitFlush");
		textWinNet->updControl("mrs_natural/timesToKeep", winds);
		//textWinNet->updControl("mrs_string/mode","explicitFlush");
		textWinNet->updControl("mrs_natural/maxTimes", maxTimes); 
		textWinNet->updControl("mrs_natural/minTimes", minTimes);

		//set MidiFileSynthSource to receive a signal for each texture window
		mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/sigNewTextWin", false);
		mainNet->linkControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/newTextWin",
							 "Accumulator/textWinNet/mrs_bool/flush");
	}
	else
	{
		cout << "** Onset detector disabled ->";
		if(accSize_>0)//manually set texture window length
		{
			cout << " using fixed length texture windows" << endl;
			cout << "Accumulator/textWinNet nTimes = " << accSize << " (i.e. " << accSize*hopSize_/samplingFrequency_ << " secs)" << endl;
			mainNet->updControl("Accumulator/textWinNet/mrs_natural/nTimes", accSize);
			
			//set MidiFileSynthSource to receive a signal for each texture window
			mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/sigNewTextWin", false);
			mainNet->linkControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/newTextWin",
								 "Accumulator/textWinNet/mrs_bool/flush");

		}
		else //use GT for texture window length
		{
			cout << " using GT length texture windows" << endl;

			//set texture window
			mainNet->updControl("Accumulator/textWinNet/mrs_string/mode", "explicitFlush");
			mrs_real textureWinMinLen = 0.0; //secs - let GT take care of this...
			mrs_real textureWinMaxLen = 15.0; //secs - just a majorant...
			mrs_natural minTimes = (mrs_natural)(textureWinMinLen*samplingFrequency_/hopSize_); 
			mrs_natural maxTimes = (mrs_natural)(textureWinMaxLen*samplingFrequency_/hopSize_); 
			cout << "Accumulator/textWinNet MinTimes = " << minTimes << " (i.e. " << textureWinMinLen << " secs)" << endl;
			cout << "Accumulator/textWinNet MaxTimes = " << maxTimes << " (i.e. " << textureWinMaxLen << " secs)" <<endl;
			mainNet->updControl("Accumulator/textWinNet/mrs_natural/maxTimes", maxTimes); 
			mainNet->updControl("Accumulator/textWinNet/mrs_natural/minTimes", minTimes);

			//set MidiFileSynthSource to send a signal for each texture window
			mainNet->updControl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/sigNewTextWin", true);
			mainNet->linkControl("Accumulator/textWinNet/mrs_bool/flush",
								 "Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/newTextWin");
		}
	}

	mrs_natural delay = -(winSize_/2 - hopSize_); 
	mainNet->updControl("Shredder/synthNet/Series/postNet/Fanout/synthBank/PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_real/samplingFreq", samplingFrequency_);
	mainNet->updControl("Shredder/synthNet/Series/postNet/Fanout/synthBank/PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_natural/delay", delay); // Nw/2+1 
	mainNet->updControl("Shredder/synthNet/Series/postNet/Fanout/synthBank/PeakSynth/synthCluster_0/PeakSynthOsc/pso/mrs_natural/synSize", hopSize_*2);
	mainNet->updControl("Shredder/synthNet/Series/postNet/Fanout/synthBank/PeakSynth/synthCluster_0/Windowing/wiSyn/mrs_string/type", "Hanning");
		
	//[!]
	//if (outsfname == "MARSYAS_EMPTY") 
	//	mainNet->updControl("Shredder/synthNet/Series/postNet/AudioSink/dest/mrs_natural/bufferSize", bopt_);
	// else
	//	mainNet->updControl("Shredder/synthNet/Series/postNet/SoundFileSink/dest/mrs_string/filename", outsfname);//[!]
	

	//***************************************************************************************************************
	//									MAIN TICKING LOOP
	//***************************************************************************************************************
	cout <<">> Start processing..." << endl;
	//ofstream cfile("density.txt", ios::app); //[WTF] [TODO]
	mrs_real globalSnr = 0;
	mrs_natural frameCount = 0;
	//	mrs_real time=0;

	mrs_natural numTextWinds = 0;
	while(analysisNet->getctrl("FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/hasData")->to<mrs_bool>())//(1)
	{	
		mainNet->tick();
		numTextWinds++;

		//if(numTextWinds == 63)
		//{
		//	cout << "!!!!" << endl;
		//}


		if (!microphone_)
		{
			//bool temp = mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/hasData")->to<mrs_bool>();
			//bool temp1 = textWinNet->getctrl("Series/analysisNet/FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/hasData")->to<mrs_bool>();
			//bool temp2 = analysisNet->getctrl("FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_bool/hasData")->to<mrs_bool>();

			mrs_real timeRead =  analysisNet->getctrl("FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_natural/pos")->to<mrs_natural>()/samplingFrequency_;
			mrs_real timeLeft;
			//if(!stopAnalyse_)
			timeLeft =  analysisNet->getctrl("FanOutIn/mixer/Series/oriNet/MidiFileSynthSource/src/mrs_natural/size")->to<mrs_natural>()/samplingFrequency_;
			//else
			//	timeLeft = stopAnalyse_;
			
			// string fname = mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/FanOutIn/mixer/Series/oriNet/SoundFileSource/src/mrs_string/filename")->to<mrs_string>();

			printf("Processed texture window %d : %.2f / %.2f \r", (int)numTextWinds, timeRead, timeLeft);
			fflush(stdout);

			//cout << fixed << setprecision(2) << timeRead << "/" <<  setprecision(2) << timeLeft;
			///*bool*/ temp = mainNet->getctrl("Accumulator/textWinNet/Series/analysisNet/SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>();

			//[TODO]
			// 			mrs_real density = mainNet->getctrl("PeClust/peClust/mrs_real/clusterDensity")->to<mrs_real>();
			// 			cfile << density << " " << oriGain << endl;
			// 			//cout << oriGain << endl;

			//if (temp2 == false || (stopAnalyse_ !=0 && stopAnalyse_<timeRead))
			//	break;
		}
	}
	if(synthetize_ > -1 && residual_ && frameCount != 0)
	{
		cout << "Global SNR : " << globalSnr/frameCount << endl;
		*snr0 = globalSnr/frameCount;
	}

	if(peakStore_)
	{
// 		mainNet->updControl("PeakViewSink/peSink/mrs_real/fs", samplingFrequency_);
// 		mainNet->updControl("PeakViewSink/peSink/mrs_natural/frameSize", D);
// 		mainNet->updControl("PeakViewSink/peSink/mrs_string/filename", filePeakName); 
// 		mainNet->updControl("PeakViewSink/peSink/mrs_bool/done", true);
	}

	//cout << ">> Saving .mat file with results so they can be opened in MATLAB in: " << fileMatName << endl;
	//MATLAB_EVAL("save " + fileMatName);

	if(numTextWinds > 0)
	{
		cout << ">> Saving SDR results to SDR.mat" << endl;
		MATLAB_EVAL("saveSDRresults");
	}

	cout << endl << ">> End of processing. Bye!" << endl;

	//cfile.close(); [TODO]
}
Ejemplo n.º 30
0
void
distance_matrix_MIREX()
{
  if (!wekafname_Set()) return;

  cout << "Distance matrix calculation using " << wekafname_ << endl;

  wekafname_  = inputdir_ + wekafname_;

  MarSystemManager mng;

  MarSystem* net = mng.create("Series", "net");
  MarSystem* accum = mng.create("Accumulator", "accum");
  MarSystem* wsrc = mng.create("WekaSource", "wsrc");
  accum->addMarSystem(wsrc);
  accum->updControl("WekaSource/wsrc/mrs_bool/normMaxMin", true);
  accum->updControl("WekaSource/wsrc/mrs_string/filename", wekafname_);
  mrs_natural nInstances =
    accum->getctrl("WekaSource/wsrc/mrs_natural/nInstances")->to<mrs_natural>();
  accum->updControl("mrs_natural/nTimes", nInstances);



  MarSystem* dmatrix = mng.create("SelfSimilarityMatrix", "dmatrix");
  dmatrix->addMarSystem(mng.create("Metric", "dmetric"));
  dmatrix->updControl("Metric/dmetric/mrs_string/metric", "euclideanDistance");

  net->addMarSystem(accum);
  net->addMarSystem(dmatrix);

  net->tick();

  ofstream oss;
  oss.open(distancematrix_.c_str());

  oss << "Marsyas-kea distance matrix for MIREX 2007 Audio Similarity Exchange " << endl;


  // collection simply for naming the entries
  Collection l;
  l.read(inputdir_ + predictcollectionfname_);
  for (size_t i=1; i <= l.size(); ++i)
	{
		oss << i << "\t" << l.entry(i-1) << endl;
	}


  oss << "Q/R";
  const mrs_realvec& dmx = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();

  for (int i=1; i <= nInstances; ++i)
	{
		oss << "\t" << i;
	}
  oss << endl;

  for (int i=1; i <= nInstances; ++i)
	{
		oss << i;
		for (int j=0; j < nInstances; j++)
			oss <<"\t" << dmx(i-1, j);
		oss << endl;
	}

  oss << endl;
}