예제 #1
0
TimeLine Fragment::getStopTimes(size_t stopIndex) const {
    if (stopIndex >= stopCount_) {
        throw std::out_of_range{"stop index out of range in schedule"};
    }

    TimeLine    rv;
    for (size_t i = 0; i < timeLinesCount_; ++i) {
        rv.push_back(timeTable_[i * stopCount_ + stopIndex]);
    }
    return rv;
}
int
main(int argc, const char **argv)
{
	MRSDIAG("sfplay.cpp - main");

	string progName = argv[0];  
	progName = progName.erase(0,3);

	initOptions();
	cmd_options.readOptions(argc, argv);
	loadOptions();

	vector<string> soundfiles = cmd_options.getRemaining();
	vector<string>::iterator sfi;

	if (argc == 1)
		printUsage(progName);

	if (helpopt) 
		printHelp(progName);

	if (usageopt)
		printUsage(progName);

	int i = 0;
	Collection l;
	string sfName;

	for (sfi = soundfiles.begin(); sfi != soundfiles.end(); ++sfi) 
	{
		sfName = *sfi;
		i++;
	}

	string extractorStr = extractorName;
	TimeLine tline;

	if (tlineName == EMPTYSTRING)
	{
		tline.load(tlineName);
		cout << tline;
	}

	if (extractorStr.substr(0,2) == "SV") 
	{
		textract_trainAccumulator(sfName, offset, duration, start, length, gain,i, pluginName, wekafname, memSize, extractorName.substr(2, extractorName.length()), tline);
	}

	exit(0);
}
예제 #3
0
파일: lines.cpp 프로젝트: gonmator/busplan
TimeLine Lines::getStopTimes(Day day, const Stop& stop) const {
    TimeLine    rv;
    for (const auto& linep: lines_) {
        auto    tl = linep.second.getStopTimes(day, stop);
        rv.insert(rv.end(), tl.cbegin(), tl.cend());
    }

    std::stable_sort(rv.begin(), rv.end());
    rv.erase(std::unique(rv.begin(), rv.end()), rv.end());

    return rv;
}
예제 #4
0
void MainWindow2::writeSettings()
{
    QSettings settings("Pencil", "Pencil");
    settings.setValue("editorPosition", pos());
    settings.setValue("editorSize", size());

    Palette* colourPalette = m_colorPalette;
    if (colourPalette != NULL)
    {
        settings.setValue("colourPalettePosition", colourPalette->pos());
        settings.setValue("colourPaletteSize", colourPalette->size());
        settings.setValue("colourPaletteFloating", colourPalette->isFloating());
    }

    TimeLine* timelinePalette = editor->getTimeLine();
    if (timelinePalette != NULL)
    {
        settings.setValue("timelinePalettePosition", timelinePalette->pos());
        settings.setValue("timelinePaletteSize", timelinePalette->size());
        settings.setValue("timelinePaletteFloating", timelinePalette->isFloating());
    }

    QDockWidget* toolWidget = editor->toolSet;
    if (toolWidget != NULL)
    {
        settings.setValue("drawPalettePosition", toolWidget->pos());
        settings.setValue("drawPaletteSize", toolWidget->size());
        settings.setValue("drawPaletteFloating", toolWidget->isFloating());
    }

    QDockWidget* optionPalette = m_toolOptionWidget;
    if (optionPalette != NULL)
    {
        settings.setValue("optionPalettePosition", optionPalette->pos());
        settings.setValue("optionPaletteSize", optionPalette->size());
        settings.setValue("optionPaletteFloating", optionPalette->isFloating());
    }

    QDockWidget* displayPalette = m_displayOptionWidget;
    if (displayPalette != NULL)
    {
        settings.setValue("displayPalettePosition", displayPalette->pos());
        settings.setValue("displayPaletteSize", displayPalette->size());
        settings.setValue("displayPaletteFloating", displayPalette->isFloating());
    }

}
예제 #5
0
파일: Talk.cpp 프로젝트: Amos-zq/marsyas
void
Talk::process(char *message)
{
  printf("Talk process called\n");
  cerr << "Message = " << message << endl;
  char *word;
  char *filename;
  mrs_string fname;
  unsigned int lineSize;
  int start, end, win_size;
  word = strtok(message, SEPCHARS);
  if (!strcmp(word,"load"))
  {
#ifdef MARSYAS_WIN32
    filename = _strdup(strtok(NULL,SEPCHARS));
#else
    filename = strdup(strtok(NULL,SEPCHARS));
#endif
    lineSize = atoi(strtok(NULL, SEPCHARS));
    fname = filename;
    cerr << "load command: Filename = " << filename <<  endl;
    cerr << "load command: LineSize = " << lineSize << endl;
    communicator_->send_message("From Server: Load command received. Preparing plot\n");
    cmd_load(fname, lineSize);



  }
  else if (!strcmp(word,"play"))
  {
    start = atoi(strtok(NULL, SEPCHARS));
    end   = atoi(strtok(NULL, SEPCHARS));
    lineSize = atoi(strtok(NULL, SEPCHARS));
    cerr << "play command. start = " << start << " end = " << end << endl;
    cmd_play(start, end, lineSize);
  }
  else if (!strcmp(word,"merge"))
  {
    mrs_string systemName = strtok(NULL, SEPCHARS);
    unsigned int pstart = atoi(strtok(NULL, SEPCHARS));
    unsigned int pend = atoi(strtok(NULL, SEPCHARS));
    unsigned int start = atoi(strtok(NULL, SEPCHARS));
    unsigned int end = atoi(strtok(NULL, SEPCHARS));
    unsigned int win_size = atoi(strtok(NULL, SEPCHARS));
    cerr << "Merge command " << endl;
    cerr << "System = " << systemName << " pstart = " << pstart <<
         " pend = " << pend << " start = " << start << " end = " << end
         << " win_size = " << win_size << endl;
    communicator_->send_message("From Server; merge command received\n");
    cmd_merge(systemName, pstart, pend, start, end, win_size);
  }


  else if (!strcmp(word,"classify"))
  {
    /* mrs_string systemName = strtok(NULL, SEPCHARS);
    mrs_string classifierName = MARSYAS_MFDIR;
    classifierName += "/classifiers/";
    classifierName += strtok(NULL, SEPCHARS);
    classifierName += systemName;
    classifierName += ".mcf";
    start = atoi(strtok(NULL, SEPCHARS));
    end   = atoi(strtok(NULL, SEPCHARS));
    win_size = atoi(strtok(NULL, SEPCHARS));
    cerr << "Classify command. " << endl;
    cerr << "System = " << systemName << " Classifier = " << classifierName << " start = " << start << " end = " << end << endl;
    communicator_->send_message("From Server: classify command received\n");
    cmd_classify(systemName, classifierName, start, end, win_size);
    */
  }
  else if (!strcmp(word,"fft"))
  {
    int start = atoi(strtok(NULL, SEPCHARS));
    int winSize  = atoi(strtok(NULL, SEPCHARS));
    communicator_->send_message("From Server: fft command received\n");
    cmd_fft(start, winSize);
  }
  else if (!strcmp(word, "fullfft"))
  {
    int winSize = atoi(strtok(NULL, SEPCHARS));
    communicator_->send_message("From Server: fullfft command received\n");
    cmd_fullfft(winSize);
  }
  else if (!strcmp(word,"segment"))
  {
    int mask_size = 11;
    int winSize;

    realvec mask(mask_size);
    for (int i=0; i<mask_size; ++i)
      mask(i) = (mrs_real)atof(strtok(NULL, SEPCHARS));
    cerr << "Segment command." << endl;
    mrs_string systemName = strtok(NULL, SEPCHARS);
    int memSize = atoi(strtok(NULL, SEPCHARS));
    int numPeaks = atoi(strtok(NULL, SEPCHARS));
    int peakSpacing  = atoi(strtok(NULL, SEPCHARS));
    start = atoi(strtok(NULL, SEPCHARS));
    end   = atoi(strtok(NULL, SEPCHARS));
    winSize = atoi(strtok(NULL, SEPCHARS));
    communicator_->send_message("From Server: segment command received\n");
    cmd_segment(systemName, memSize, numPeaks, peakSpacing, start, end, winSize);
  }
  else if (!strcmp(word,"extract"))
  {
    cerr << "Extract command." << endl;
    mrs_string systemName = strtok(NULL, SEPCHARS);
    mrs_string fileName = strtok(NULL, SEPCHARS);
    TimeLine tline;
    tline.receive(communicator_);

    communicator_->send_message("From Server: extract command received\n");

    cmd_extract(systemName, fileName, tline);
  }

  else if (!strcmp(word,"snoop"))
  {
    cerr << "Snoop command." << endl;
    //  these aren't used?  -gp
    //int feat_num;
    //feat_num = atoi(strtok(NULL, SEPCHARS));
    communicator_->send_message("Howdy. You just send a snoop command\n");
  }
  else if (!strcmp(word,"colorgram"))
  {
    cerr << "Colorgram command." << endl;
    mrs_string collection = strtok(NULL, SEPCHARS);
    mrs_string system = strtok(NULL, SEPCHARS);
    start = atoi(strtok(NULL, SEPCHARS));
    end   = atoi(strtok(NULL, SEPCHARS));
    win_size = atoi(strtok(NULL, SEPCHARS));
    communicator_->send_message("From server: colorgram command received.\n");
    cmd_colorgram(collection, system, start, end, win_size);
  }
  else
    communicator_->send_message("Howdy. Unknown command\n");
  cerr << "Talk::Process is done" << endl;
}
예제 #6
0
파일: Talk.cpp 프로젝트: Amos-zq/marsyas
void
Talk::cmd_segment(mrs_string systemName, unsigned int memSize, unsigned int numPeaks, unsigned int peakSpacing, unsigned int start, unsigned int end, unsigned int winSize)
{
  // FIXME Unused parameters
  (void) memSize;
  (void) numPeaks;
  (void) peakSpacing;
  (void) start;
  (void) end;
  (void) winSize;

  TimeLine tline;

  mrs_natural hops = src_->getctrl("mrs_natural/size")->to<mrs_natural>() * src_->getctrl("mrs_natural/nChannels")->to<mrs_natural>() / src_->getctrl("mrs_natural/inSamples")->to<mrs_natural>() + 1;

  if(!strcmp(systemName.c_str(), "REG"))
    tline.regular(100, hops);

  realvec peaks(hops);


  tline.send(communicator_);
  peaks.send(communicator_);


//   tline.print(stdout);

//   cerr << "cmd_segment::systemName " << systemName << endl;
//   cerr << "cmd_segment::memSize " << memSize << endl;
//   cerr << "cmd_segment::numPeaks " << numPeaks << endl;
//   cerr << "cmd_segment::peakSpacing " << peakSpacing << endl;
//   cerr << "cmd_segment::start " << start << endl;
//   cerr << "cmd_segment::end " << end << endl;
//   cerr << "cmd_segment::winSize " << winSize << endl;






//   mrs_string extractorstr = systemName;
//   mrs_string rextractorstr = systemName;
//   if (!strcmp(rextractorstr.c_str(), "REG"))
//       extractorstr = "FFT_SEGM";

//   if (winSize != DEFAULT_WIN_SIZE)
//     {
//       start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE));
//       end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE));
//       winSize = DEFAULT_WIN_SIZE;
//     }
//   src_->initWindow(winSize);
//   cerr << "Src winSize = " << src_->winSize() << endl;


//   Spectral spectral(src_);
//   SpectralSegm spectralsegm(src_,10);
//   MemMFCC mfcc(src_);

//   FeatExtractor mfccExtractor(src_, &mfcc);
//   FeatExtractor spectralExtractor(src_, &spectral);
//   FeatExtractor segmExtractor(src_, &spectralsegm);
//   SfxExtractor sfxExtractor(src_);

//   FeatMatrix mfccRes(src_->iterations(), mfcc.outSize());
//   FeatMatrix spectralRes(src_->iterations(), spectral.outSize());
//   FeatMatrix spectralSegmRes(src_->iterations(), spectralsegm.outSize());
//   FeatMatrix sfxRes(1, 2);


//   map<const char *, FeatMatrix *, ltstr> results;
//   results["FFT"] = &spectralRes;
//   results["FFT_SEGM"] = &spectralSegmRes;
//   results["MFCC"] = &mfccRes;
//   results["SFX"] = &sfxRes;


//   map<const char *, Extractor *, ltstr> extractors;
//   extractors["FFT"] = &spectralExtractor;
//   extractors["FFT_SEGM"] = &segmExtractor;
//   extractors["MFCC"] = &mfccExtractor;
//   extractors["SFX"] = &sfxExtractor;


//   map<const char *, Extractor *, ltstr>::iterator cur;
//   const char *ch = extractorstr.c_str();
//   cur = extractors.find(ch);

//   if (cur == extractors.end())
//     {
//       cerr << "Extractor " << extractorstr << " is not supported\n" << endl;
//       return;
//     }
//   else
//     {
//       extractors[extractorstr.c_str()]->extract(*(results[extractorstr.c_str()]));
//     }
//   TimeLine tline;
//   SegmentorSortedPeaks segmentor;
//   segmentor.init(numPeaks, peakSpacing);
//   fvec res((*(results[extractorstr.c_str()])).rows());
//   fvec peaks((*(results[extractorstr.c_str()])).rows());
//   segmentor.segment(*(results[extractorstr.c_str()]), res);
//   segmentor.peaks(*(results[extractorstr.c_str()]), peaks);


}
void textract_trainAccumulator(string sfName, mrs_natural offset, mrs_natural duration, mrs_real start, mrs_real length, mrs_real gain, mrs_natural label, string pluginName, string wekafname, mrs_natural memSize, string extractorStr, TimeLine& tline)
{
	MarSystemManager mng;

	MRSDIAG("sfplay.cpp - sfplay");

	// default 
	if (extractorStr == EMPTYSTRING) 
		extractorStr = "STFT";

	// Find proper soundfile format and create SignalSource 
	MarSystem *src = mng.create("SoundFileSource", "src");

	src->updctrl("mrs_string/filename", sfName);
	src->updctrl("mrs_natural/inSamples", MRS_DEFAULT_SLICE_NSAMPLES);

	if (tlineName == EMPTYSTRING)
	{
		mrs_natural hops = src->getctrl("mrs_natural/size")->to<mrs_natural>() * src->getctrl("mrs_natural/nChannels")->to<mrs_natural>() / 2048 + 1;
		tline.regular(100, hops);
	}

	MarSystem *dest_;
	dest_ = mng.create("AudioSink", "dest");

	MarSystem *series = mng.create("Series", "playbacknet");
	series->addMarSystem(src);
	series->addMarSystem(dest_);

	series->updctrl("AudioSink/dest/mrs_natural/nChannels", 
		series->getctrl("SoundFileSource/src/mrs_natural/nChannels")->to<mrs_natural>());  

	// Calculate duration, offset parameters if necessary 
	if (start > 0.0f) 
		offset = (mrs_natural) (start 
		* src->getctrl("mrs_real/israte")->to<mrs_real>() 
		* src->getctrl("mrs_natural/nChannels")->to<mrs_natural>());
	if (length != 30.0f) 
		duration = (mrs_natural) (length 
		* src->getctrl("mrs_real/israte")->to<mrs_real>() 
		* src->getctrl("mrs_natural/nChannels")->to<mrs_natural>());

	// accumulate feature vectors over 30 seconds 
	MarSystem* acc = mng.create("Accumulator", "acc");

	acc->updctrl("mrs_natural/nTimes", 100);

	// Calculate windowed power spectrum and then 
	// calculate specific feature sets 
	MarSystem* spectralShape = mng.create("Series", "spectralShape");
	spectralShape->addMarSystem(mng.create("Windowing", "hamming"));
	spectralShape->addMarSystem(mng.create("Spectrum","spk"));
	spectralShape->addMarSystem(mng.create("PowerSpectrum", "pspk"));
	spectralShape->updctrl("PowerSpectrum/pspk/mrs_string/spectrumType","power");  

	// Spectrum Shape descriptors
	MarSystem* spectrumFeatures = mng.create("Fanout", "spectrumFeatures");

	if (extractorStr == "STFT") 
	{
		spectrumFeatures->addMarSystem(mng.create("Centroid", "cntrd"));
		spectrumFeatures->addMarSystem(mng.create("Rolloff", "rlf"));      
		spectrumFeatures->addMarSystem(mng.create("Flux", "flux"));
	}
	else if (extractorStr == "STFTMFCC")
	{
		spectrumFeatures->addMarSystem(mng.create("Centroid", "cntrd"));
		spectrumFeatures->addMarSystem(mng.create("Rolloff", "rlf"));      
		spectrumFeatures->addMarSystem(mng.create("Flux", "flux"));
		spectrumFeatures->addMarSystem(mng.create("MFCC", "mfcc"));
	}
	else if (extractorStr == "MFCC")
		spectrumFeatures->addMarSystem(mng.create("MFCC", "mfcc"));
	else if (extractorStr == "SCF")
		spectrumFeatures->addMarSystem(mng.create("SCF", "scf"));
	else if (extractorStr == "SFM") 
		spectrumFeatures->addMarSystem(mng.create("SFM", "sfm"));

	mng.registerPrototype("SpectrumFeatures", spectrumFeatures->clone());
	spectralShape->addMarSystem(mng.create("SpectrumFeatures", "spectrumFeatures"));
	mng.registerPrototype("SpectralShape", spectralShape->clone());

	//  add time-domain zerocrossings
	MarSystem* features = mng.create("Fanout", "features");
	features->addMarSystem(mng.create("SpectralShape", "SpectralShape"));
	if (extractorStr == "STFT")
		features->addMarSystem(mng.create("ZeroCrossings", "zcrs"));      
	mng.registerPrototype("Features", features->clone());

	// Means and standard deviation (statistics) for texture analysis 
	MarSystem* statistics = mng.create("Fanout","statistics");
	statistics->addMarSystem(mng.create("Mean", "mn"));
	statistics->addMarSystem(mng.create("StandardDeviation", "std"));
	mng.registerPrototype("Statistics", statistics->clone());

	// weka output 
	MarSystem *wsink = mng.create("WekaSink","wsink");

	// Build the overall feature calculation network 
	MarSystem* featureNetwork = mng.create("Series", "featureNetwork");

	featureNetwork->addMarSystem(src->clone());
	featureNetwork->addMarSystem(mng.create("Features", "features"));
	featureNetwork->addMarSystem(mng.create("Memory", "memory"));
	featureNetwork->updctrl("Memory/memory/mrs_natural/memSize", memSize);
	featureNetwork->addMarSystem(mng.create("Statistics", "statistics"));  

	// add network to accumulator
	acc->addMarSystem(featureNetwork->clone());

	// Final network compute 30-second statistics 
	MarSystem* total = mng.create("Series", "total");
	total->addMarSystem(acc->clone());
	total->addMarSystem(mng.create("Statistics", "statistics2"));
	// total->addMarSystem(mng.create("Mean", "mn2"));
	total->addMarSystem(wsink->clone());

	// update controls 
	total->updctrl("mrs_natural/inSamples", MRS_DEFAULT_SLICE_NSAMPLES);
	total->updctrl("Accumulator/acc/Series/featureNetwork/" + src->getType() + "/src/mrs_natural/pos", offset);      

	mrs_natural wc = 0;
	mrs_natural samplesPlayed =0;

	// main loop for extracting the features 
	string className = "";

	total->updctrl("Accumulator/acc/Series/featureNetwork/SoundFileSource/src/mrs_string/filename", sfName);
	wc = 0;  	  
	samplesPlayed = 0;

	total->updctrl("WekaSink/wsink/mrs_natural/nLabels", (mrs_natural)3);
	if (wekafname == EMPTYSTRING) 
		total->updctrl("WekaSink/wsink/mrs_string/filename", "weka2.arff");
	else 
		total->updctrl("WekaSink/wsink/mrs_string/filename", wekafname);  

	// total->tick();

	for (int r = 0; r < tline.numRegions(); r++)
	{
		cout << "start = " << tline.regionStart(r) << endl;
		cout << "end = " << tline.regionEnd(r) << endl;

		total->updctrl("Accumulator/acc/Series/featureNetwork/SoundFileSource/src/mrs_natural/pos", (mrs_natural)tline.regionStart(r) * tline.lineSize());
		total->updctrl("mrs_natural/inSamples", tline.lineSize());
		if (tlineName == EMPTYSTRING)
		{
			if ((tline.regionClass(r) > 0) && (tline.regionClass(r) != 4))//[?]
			{
				total->updctrl("WekaSink/wsink/mrs_natural/label", tline.regionClass(r)-1);
			}
		}
		else
			total->tick();
	}

	if (pluginName == EMPTYSTRING) // output to stdout 
		cout << (*total) << endl;      
	else 
	{
		ofstream oss(pluginName.c_str());
		oss << (*total) << endl;
	}
}
예제 #8
0
std::vector< std::vector< std::vector<double> > >
CorrelatedRockSamples::CreateSamplesExtended(int                                      i_max,
                                             TimeLine                               & time_line,
                                             const std::vector<DistributionsRock*>  & dist_rock)
{
  std::list<int> time;
  time_line.GetAllTimes(time);
  int k_max = static_cast<int>(dist_rock.size());

  // Set up time vectors, the same for all sets of correlated samples.
  time_line.ReSet();
  int et_dummy, edi_dummy;
  double dt_year;
  std::vector< std::vector<double> > delta_time(k_max);
  for (int k = 0; k < k_max; ++k){
    time_line.GetNextEvent(et_dummy, edi_dummy, dt_year);
    for (int l = k; l < k_max; ++l)
      delta_time[l].push_back(dt_year);
  }

  int nReservoirVariables =  dist_rock[0]->GetNumberOfReservoirVariables();

  // Set up data structures.
  // The order of indices is chosen to make extraction of all samples for a given time instance easy.
  std::vector< std::vector< std::vector<double> > > m(k_max);
  std::vector< std::vector< Rock * > > rock(k_max);
  for (int k = 0; k < k_max; ++k){
    m[k].resize(i_max);
    rock[k].resize(i_max);
    for (int i = 0; i < i_max; ++i)
      m[k][i].resize(3+nReservoirVariables);
  }

  const std::vector<double> trend_params_dummy(2,0);
  std::vector<double>reservoirVariables(nReservoirVariables,0);
  // Finding the sets of correlated samples.
  // Each set of samples for a specific i are correlated in time.
  dist_rock[0]->SetResamplingLevel(DistributionWithTrend::Full);
  for (int i = 0; i < i_max; ++i){
    rock[0][i] = dist_rock[0]->GenerateSampleAndReservoirVariables(trend_params_dummy,reservoirVariables);
    rock[0][i]->GetSeismicParams(m[0][i][0], m[0][i][1], m[0][i][2]);
    m[0][i][0]=std::log(m[0][i][0]);
    m[0][i][1]=std::log(m[0][i][1]);
    m[0][i][2]=std::log(m[0][i][2]);
    for(int l =0;l< nReservoirVariables;l++)
        m[0][i][l+3]=reservoirVariables[l];

    std::vector< Rock * > rock_seen(1, rock[0][i]);
    for (int k = 1; k < k_max; ++k){
      dist_rock[k]->SetResamplingLevel(DistributionWithTrend::Full);
      rock[k][i] = dist_rock[k]->EvolveSampleAndReservoirVaribles(delta_time[k][k], *(rock[k-1][i]),reservoirVariables); // delta_time info also for the rock to be found.
      rock[k][i]->GetSeismicParams(m[k][i][0], m[k][i][1], m[k][i][2]);
      m[k][i][0]=std::log(m[k][i][0]);
      m[k][i][1]=std::log(m[k][i][1]);
      m[k][i][2]=std::log(m[k][i][2]);
      for(int l =0;l< nReservoirVariables;l++)
        m[k][i][l+3]=reservoirVariables[l];
      rock_seen.push_back(rock[k][i]);
    }
  }

  // Must delete memory allocated by classes DistributionsRock and Rock.
  for (int k = 0; k < k_max; ++k){
    for (int i = 0; i < i_max; ++i){
      if (rock[k][i] != NULL)
        delete rock[k][i];
    }
  }

  return m;
}