// 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 ); }
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 extractBpm(string filename) { cout << "BPM extractor" << endl; MarSystemManager mng; MarSystem* blackbox = mng.create("Series", "blackbox"); blackbox->addMarSystem(mng.create("SoundFileSource", "src")); /** * Linkaggio dei controlli: SoundSource */ blackbox->linkctrl("mrs_string/filename", "SoundFileSource/src/mrs_string/filename"); blackbox->linkctrl("mrs_string/labelNames", "SoundFileSource/src/mrs_string/labelNames"); blackbox->updctrl("mrs_string/filename", filename); /* * Creazione di un file di testo con alcune informazioni sul file: * fname = name of the file courrently analyzed * israte = input sample rate * osrate = output sample rate * duration = duration of the file in seconds * size = number of audio samples contained into the file * label = label for classification use */ ofstream finfo; finfo.open("durata.txt"); mrs_string fname = blackbox->getctrl("mrs_string/filename")->to<mrs_string>(); finfo << "Input file name: " << fname << endl; mrs_real israte = blackbox->getctrl("mrs_real/israte")->to<mrs_real>(); finfo << "Input samplerate: " << israte << " Hz" << endl; mrs_real osrate = blackbox->getctrl("mrs_real/osrate")->to<mrs_real>(); finfo << "Output samplerate: " << osrate << " Hz" << endl; mrs_real duration = blackbox->getctrl("SoundFileSource/src/mrs_real/duration")->to<mrs_real>(); finfo << "Duration: " << duration << " seconds" << endl; mrs_natural size = blackbox->getctrl("SoundFileSource/src/mrs_natural/size")->to<mrs_natural>(); finfo << "Number of samples of courrent file: " << size << endl; mrs_string label = blackbox->getctrl("mrs_string/labelNames")->to<mrs_string>(); finfo << "Label name: " << label << endl; finfo.close(); ofstream wavelet; wavelet.open("waveletbands.txt"); wavelet << "WAVELET BANDS VALUES" << endl; /* * Preparazione per l'estrazione dell'inviluppo del segnale audio */ //blackbox->addMarSystem(mng.create("WaveletBands", "wavelet")); //blackbox->addMarSystem(mng.create("FullWaveRectifier","rectifier")); blackbox->addMarSystem(mng.create("AutoCorrelation", "autocorrelation")); blackbox->updctrl("AutoCorrelation/autocorrelation/mrs_bool/aliasedOutput", false); blackbox->addMarSystem(mng.create("BeatHistogram", "histogram")); mrs_real val = 0.0; while (blackbox->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>()) { blackbox->tick(); const mrs_realvec& src_data = blackbox->getctrl("mrs_realvec/processedData")->to<mrs_realvec>(); val = src_data(0,0); wavelet << val << endl; } wavelet.close(); delete blackbox; cout << "done" << endl; }
// 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; } }
int process(string inName, string outName) { MarSystemManager mng; // setting up the network MarSystem* input = mng.create("Series", "input"); input->addMarSystem(mng.create("SoundFileSource","src")); input->addMarSystem(mng.create("ShiftInput", "si")); MarSystem* flowthru = mng.create("FlowThru", "flowthru"); flowthru->addMarSystem(mng.create("Hamming", "hamAna")); flowthru->addMarSystem(mng.create("LPC", "lpc")); input->addMarSystem(flowthru); input->addMarSystem(mng.create("Filter", "analysis")); MarSystem* audioSink = mng.create("SoundFileSink", "audioSink"); input->addMarSystem(mng.create("NoiseSource", "ns")); // input->addMarSystem(mng.create("Gain", "nsg1")); // input->addMarSystem(mng.create("PlotSink", "plot2")); input->addMarSystem(mng.create("Filter", "synthesis")); input->addMarSystem(mng.create("Gain", "nsg")); input->addMarSystem(mng.create("Windowing", "winSyn")); input->addMarSystem(mng.create("OverlapAdd", "ova")); input->addMarSystem(audioSink); input->updctrl("SoundFileSource/src/mrs_string/filename", inName); input->updctrl("SoundFileSource/src/mrs_natural/inSamples", hopSize); input->updctrl("ShiftInput/si/mrs_natural/winSize", windowSize); input->updctrl("Windowing/winSyn/mrs_string/type", "Hanning"); //input->updctrl("ShiftOutput/so/mrs_natural/Interpolation", hopSize); input->updctrl("FlowThru/flowthru/LPC/lpc/mrs_natural/order",lpcOrder); input->updctrl("FlowThru/flowthru/LPC/lpc/mrs_real/lambda",0.0); input->updctrl("FlowThru/flowthru/LPC/lpc/mrs_real/gamma",1.0); // input->updctrl("LPC/lpc/mrs_natural/featureMode", 0); input->linkctrl("Filter/analysis/mrs_realvec/ncoeffs", "FlowThru/flowthru/LPC/lpc/mrs_realvec/coeffs"); input->linkctrl("Filter/synthesis/mrs_realvec/dcoeffs", "FlowThru/flowthru/LPC/lpc/mrs_realvec/coeffs"); // link the power of the error with a gain input->linkctrl("Gain/nsg/mrs_real/gain", "FlowThru/flowthru/LPC/lpc/mrs_real/power"); input->updctrl("SoundFileSink/audioSink/mrs_string/filename", outName); //input->updctrl("Gain/nsg1/mrs_real/gain", .1); input->updctrl("NoiseSource/ns/mrs_string/mode", "truc"); int i = 0; while(input->getctrl("SoundFileSource/src/mrs_bool/hasData")->to<mrs_bool>()) { input->tick(); i++; // cout << input->getctrl("Filter/analysis/mrs_realvec/ncoeffs")->to<mrs_realvec>() << endl; // cout << input->getctrl("LPC/lpc/mrs_realvec/coeffs")->to<mrs_realvec>() << endl; } cout << endl << "LPC processing finished!"; delete input; return 0; }
void midiBoomChickAnnotate(mrs_natural bufferSize, mrs_natural inputSize, string backgroundopt) { /* RtMidi* rtmidi = NULL; try { rtmidi = new RtMidi(); } catch (RtError3 &error) { exit(1); } */ MarSystemManager mng; MarSystem* total = mng.create("Series", "total"); MarSystem* pnet = mng.create("Series","pnet"); MarSystem* oscbank = mng.create("Fanout", "oscbank"); oscbank->addMarSystem(mng.create("SoundFileSource", "src3")); oscbank->addMarSystem(mng.create("SoundFileSource", "src4")); pnet->addMarSystem(oscbank); pnet->addMarSystem(mng.create("Sum", "sum")); pnet->addMarSystem(mng.create("SoundFileSink", "dest")); MarSystem* bbank = mng.create("Fanout", "bbank"); bbank->addMarSystem(pnet); if (backgroundopt != EMPTYSTRING) bbank->addMarSystem(mng.create("SoundFileSource", "src5")); total->addMarSystem(bbank); total->addMarSystem(mng.create("Sum", "tsum")); total->addMarSystem(mng.create("AudioSink", "dest")); // output file pnet->updctrl("SoundFileSink/dest/mrs_string/filename", "drum.wav"); int byte2, byte3; int channel; int type; int prev_pitch; // bass drum and snare drum sounds pnet->updctrl("Fanout/oscbank/SoundFileSource/src3/mrs_string/filename", "../rawwaves/sd22k.wav"); pnet->updctrl("Fanout/oscbank/SoundFileSource/src4/mrs_string/filename", "../rawwaves/bd22k.wav"); if (backgroundopt != EMPTYSTRING) bbank->updctrl("SoundFileSource/src5/mrs_string/filename", backgroundopt); total->updctrl("AudioSink/dest/mrs_natural/bufferSize", bufferSize); total->updctrl("mrs_natural/inSamples", inputSize); pnet->linkctrl("mrs_natural/pos3", "Fanout/oscbank/SoundFileSource/src3/mrs_natural/pos"); pnet->linkctrl("mrs_natural/pos4", "Fanout/oscbank/SoundFileSource/src4/mrs_natural/pos"); /* while(1) { if (rtmidi->nextMessage() > 0) { byte3 = rtmidi->getByteThree(); byte2 = rtmidi->getByteTwo(); channel = rtmidi->getChannel(); type = rtmidi->getType(); // STC1000 NoteOn's if ((type == 144) && (byte3 != 0)) { // rewind the files if (byte2 == 44) pnet->updctrl("mrs_natural/pos3", 0); if (byte2 == 53) pnet->updctrl("mrs_natural/pos4", 0); } // Radio Drum stick 1 if ((type == 160) && (byte2 == 15)) { if ((byte3 >= 40) && (byte3 <= 100)) { pnet->updctrl("mrs_natural/pos3", 0); } else { pnet->updctrl("mrs_natural/pos4", 0); } } // Radio Drum stick 2 if ((type == 160) && (byte2 == 17)) { if ((byte3 >= 40) && (byte3 <= 100)) { pnet->updctrl("mrs_natural/pos3", 0); } else { pnet->updctrl("mrs_natural/pos4", 0); } } } total->tick(); } */ }