// 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 ); }
// Play soundfile given by sfName, playbacknet contains the playback // network of MarSystem objects void sftransform(mrs_real gain, string outName) { MarSystemManager mng; MarSystem* dest = mng.create("SoundFileSink", "dest"); dest->updctrl("mrs_string/filename", "sftransformOutput.au"); NetworkTCPSource* netSrc = new NetworkTCPSource("netSrc"); MarSystem* playbacknet = mng.create("Series", "playbacknet"); playbacknet->addMarSystem(netSrc); playbacknet->addMarSystem(mng.create("InvSpectrum", "ispk")); playbacknet->addMarSystem(mng.create("Gain", "gt")); playbacknet->addMarSystem(dest); // update controls if they are passed on cmd line... if ( port != 0 ) { netSrc->updctrl("mrs_natural/port", port); } playbacknet->update(); playbacknet->linkctrl("mrs_natural/nChannels", "NetworkTCPSource/netSrc/mrs_natural/nChannels"); playbacknet->linkctrl("mrs_natural/pos", "NetworkTCPSource/netSrc/mrs_natural/pos"); playbacknet->linkctrl("mrs_natural/nChannels", "SoundFileSink/dest/mrs_natural/nChannels"); playbacknet->linkctrl("mrs_bool/hasData", "NetworkTCPSource/netSrc/mrs_bool/hasData"); playbacknet->linkctrl("mrs_bool/mute", "Gain/gt/mrs_bool/mute"); // output network description to cout cout << *playbacknet << endl; // setup TCP Server and wait for connection... netSrc->refresh(); cout << "Connection Established with: " << netSrc->getClientAddr() << endl; // udpate controls //playbacknet.updctrl("mrs_natural/inSamples", MRS_DEFAULT_SLICE_NSAMPLES); playbacknet->updctrl("Gain/gt/mrs_real/gain", gain); mrs_natural wc=0; mrs_natural samplesPlayed = 0; mrs_natural onSamples = playbacknet->getctrl("mrs_natural/onSamples")->to<mrs_natural>(); // mrs_natural repeatId = 1; mrs_real* controls = 0; while (true) { try { controls = playbacknet->recvControls(); if ( controls != 0 ) { // get some reference controls, so if they have changed we update them mrs_natural inSamples = playbacknet->getctrl("mrs_natural/inSamples")->to<mrs_natural>(); mrs_natural inObservations = playbacknet->getctrl("mrs_natural/inObservations")->to<mrs_natural>(); mrs_real israte = playbacknet->getctrl("mrs_real/israte")->to<mrs_real>(); if ( (mrs_natural)controls[1] != inSamples || (mrs_natural)controls[2] != inObservations || controls[3] != israte ) { playbacknet->updctrl("mrs_natural/inSamples", (mrs_natural)controls[1]); playbacknet->updctrl("mrs_natural/inObservations", (mrs_natural)controls[2]); playbacknet->updctrl("mrs_real/israte", controls[3]); } } playbacknet->tick(); } catch( SocketException e ) { cerr << "Played " << wc << " slices of " << onSamples << " samples" << endl; exit(1); } wc ++; samplesPlayed += onSamples; } }