• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ mrs_string类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中mrs_string的典型用法代码示例。如果您正苦于以下问题:C++ mrs_string类的具体用法?C++ mrs_string怎么用?C++ mrs_string使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了mrs_string类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: is

void 
Collection::read(mrs_string filename)
{
    ifstream is(filename.c_str());
    name_ = filename.substr(0, filename.rfind(".", filename.length()));

    is >> (*this);
}
开发者ID:GanAlps,项目名称:Extracting-Features-from-audio,代码行数:8,代码来源:Collection.cpp


示例2: mxCreateString

void
MATLABengine::putVariable(const mrs_string value, mrs_string MATLABname)
{
  //-----------------------------------
  //send C/C++ string to MATLAB string
  //-----------------------------------

  mxArray *mxVector = mxCreateString(value.c_str());
  engPutVariable(engine_, MATLABname.c_str(), mxVector);

  mxDestroyArray(mxVector);
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:12,代码来源:MATLABengine.cpp


示例3: while

void
Marsyas::string2parameters(mrs_string s, realvec &v, char d)
{
  mrs_natural i =0, pos=0, newPos=0;
  mrs_string tmp;
  while(newPos != -1 )
  {
    newPos = (mrs_natural) s.find_first_of(&d, pos, 1);
    tmp = s.substr(pos, newPos);
    v(i++) = atof(tmp.c_str());
    pos = newPos+1;
  }
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:13,代码来源:Conversions.cpp


示例4: fopen

void
MP3FileSink::putHeader(mrs_string filename)
{
#ifdef MARSYAS_LAME
    sfp_ = fopen(filename.c_str(), "wb");
#endif
}
开发者ID:typec4st,项目名称:Extracting-Features-from-audio,代码行数:7,代码来源:MP3FileSink.cpp


示例5: strlen

void
AuFileSink::putHeader(mrs_string filename)
{
    mrs_natural nChannels = (mrs_natural)getctrl("mrs_natural/inObservations")->to<mrs_natural>();

    written_ = 0;
    const char *comment = "MARSYAS 2001, George Tzanetakis.\n";
    mrs_natural commentSize = strlen(comment);
    sfp_ = fopen(filename.c_str(), "wb");
    hdr_->pref[0] = '.';
    hdr_->pref[1] = 's';
    hdr_->pref[2] = 'n';
    hdr_->pref[3] = 'd';

#if defined(MARSYAS_BIGENDIAN)
    hdr_->hdrLength = 24 + commentSize;
    hdr_->fileLength = 0;
    hdr_->mode = SND_FORMAT_LINEAR_16;
    hdr_->srate = (mrs_natural)getctrl("mrs_real/israte")->to<mrs_real>();
    hdr_->channels = nChannels;
#else
    hdr_->hdrLength = ByteSwapLong(24 + (unsigned long)commentSize);
    hdr_->fileLength = ByteSwapLong(0);
    hdr_->mode = ByteSwapLong(SND_FORMAT_LINEAR_16);
    hdr_->srate = ByteSwapLong((mrs_natural)getctrl("mrs_real/israte")->to<mrs_real>());
    hdr_->channels = ByteSwapLong(nChannels);
#endif

    fwrite(hdr_, 24, 1, sfp_);
    // Write comment part of header
    fwrite(comment, commentSize, 1, sfp_);
    sfp_begin_ = ftell(sfp_);
}
开发者ID:typec4st,项目名称:Extracting-Features-from-audio,代码行数:33,代码来源:AuFileSink.cpp


示例6: Dump

//debug helper funtion to dump table to an ascii file
void WekaData::Dump(const mrs_string& filename, const vector<mrs_string>& classNames) const
{
  char buffer[32];

  ofstream *mis = new ofstream;

  mis->open(filename.c_str(), ios_base::out | ios_base::trunc );
  MRSASSERT( mis->is_open() );

  for(vector<vector<mrs_real>*>::const_iterator citer = this->begin(); citer!=this->end(); citer++)
  {
    bool first = true;
    const vector<mrs_real> *row = (*citer);
    int ii;
    for(ii=0; ii<(int)row->size()-1; ++ii)
    {
      if(!first)
        mis->write(", ", 2);
      first = false;

      sprintf(buffer, "%09.4f", row->at(ii));
      mis->write(buffer, strlen(buffer));
    }
    mis->write(", ", 2);
    mrs_natural classIndex = (mrs_natural)row->at(ii);
    mis->write(classNames[classIndex].c_str(), strlen(classNames[classIndex].c_str()));
    mis->write("\n", 1);
  }

  mis->close();
  delete mis;
}//Dump
开发者ID:Amos-zq,项目名称:marsyas,代码行数:33,代码来源:WekaData.cpp


示例7: from

bool
realvec::read(mrs_string filename)
{
  ifstream from(filename.c_str());
  if (from.is_open())
  {
    from >> (*this);
    return true;
  }
开发者ID:BitMax,项目名称:marsyas,代码行数:9,代码来源:realvec.cpp


示例8: if

/* convert a string representing time to number of samples base on the
given sample rate. Format "123.456#" where # is the time division.
Valid time divisions: { h, m, s, ms, us }.
On a format error,
Errors: -1 is returned. ie more than 1 decimal point, invalid time
division.
*/
mrs_natural
Marsyas::time2samples(mrs_string time, mrs_real srate) {
  //example times: { "10us", "10ms", "10s", "10m", "10h" }
  if (time=="") { return 0; }
  // calculate time value
  mrs_real samples=0;
  int i=0;
  int len=(int)time.length();
  bool decimal_point=false;
  mrs_real divisor = 10.0;
  for (i=0; i<len && (time[i]=='.' || (time[i]>='0' && time[i]<='9')); ++i) {
    if (decimal_point) {
      if (time[i]=='.') { return -1; }
      samples = samples + ((mrs_real)(time[i]-'0'))/divisor;
      divisor = divisor * 10.0;
    } else if (time[i]=='.') {
      decimal_point=true;
    } else {
      samples = samples * 10.0 + (time[i]-'0');
    }
  }
  //
  if (i<len) {
    char a=time[++i];
    if (i>=len) {
      if (a=='h') { // hours
        samples= 120.0*samples*srate;
      } else if (a=='m') { // minutes
        samples=  60.0*samples*srate;
      } else if (a=='s') { // seconds
        samples=       samples*srate;
      } else {
        return -1;
      }
    } else {
      char b=time[i];
      if ((i+1)>=len) {
        if (a=='u' && b=='s') { // micro-seconds
          samples= samples/1000000.0*srate;
        } else if (a=='m' && b=='s') { // milli-seconds
          samples= samples/1000.0*srate;
        } else {
          return -1;
        }
      }
    }
  }
  return (mrs_natural)samples;
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:56,代码来源:Conversions.cpp


示例9: mxCreateNumericArray

void
MATLABengine::putVariable(const double *const value, unsigned int size, mrs_string MATLABname)
{
  //-----------------------------------
  //send C/C++ vector to MATLAB vector
  //-----------------------------------
  mwSize dims[2];
  dims[0] = 1; //row vector
  dims[1] = size;

  mxArray *mxVector = mxCreateNumericArray(2, dims, mxDOUBLE_CLASS, mxREAL);
  memcpy(mxGetData(mxVector), (void *)value, size*mxGetElementSize(mxVector));
  engPutVariable(engine_, MATLABname.c_str(), mxVector);

  mxDestroyArray(mxVector);
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:16,代码来源:MATLABengine.cpp


示例10: fopen

void 
ViconFileSource::getHeader(mrs_string filename)
{
	// Need to read Vicon File Header to get number and name of markers
	vfp_ = fopen(filename.c_str(), "r");
	if (vfp_)
    {
		// read first line from file
		char buffer[4096];
		fgets(buffer, 4096, vfp_);
		stringstream line(buffer);
		char entry[256];
		fileObs_ = 0;
		while (line.getline(entry, 256, ','))
		{
	  
			fileObs_++;
		}
		setctrl("mrs_natural/onObservations", fileObs_);
		setctrl("mrs_string/markers", buffer);
    }
} 
开发者ID:GanAlps,项目名称:Extracting-Features-from-audio,代码行数:22,代码来源:ViconFileSource.cpp


示例11: main

int
main(int argc, const char **argv)
{
  MRSDIAG("pitchextract.cpp - main");

  string progName = argv[0];

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

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

  if (helpopt)
    printHelp(progName);

  if (usageopt)
    printUsage(progName);

  // If the user didn't specify the filename to extract, show the
  // usage information.
  if (argc < 2)
    printUsage(progName);

  // cout << "PitchExtract windowSize = " << wopt << endl;
  // cout << "PitchExtract hopSize = " << hopt << endl;
  // cout << "PitchExtract lowerPitch = " << lpopt << endl;
  // cout << "PitchExtract upperPitch = " << upopt << endl;
  // cout << "PitchExtract threshold  = " << topt << endl;
  // cout << "PitchExtract playback   = " << plopt << endl;

  vector<string>::iterator sfi;
  for (sfi = soundfiles.begin(); sfi != soundfiles.end(); ++sfi)
  {
    string sfname = *sfi;
    cout << "Processing: " << sfname << endl;

    FileName fn(sfname);
    if (fn.ext() != "mf")
    {
      if (mode == "sacf" || mode == "praat") {
        pitchextract(sfname, wopt, hopt, lpopt, upopt, topt, plopt != 0, ofnameopt);
      } else if (mode == "yin") {
        yinpitchextract(sfname, wopt, hopt, plopt != 0, ofnameopt);
      }
      else if (mode == "caricature")
      {
        pitchextract_caricature(sfname, wopt, hopt, lpopt, upopt, topt, plopt != 0, ofnameopt);
      }

      else if (mode == "key")
      {
        ofstream ofs;
        ofs.open(output_fname.c_str());

        int prediction = pitchextract_key(sfname, wopt, hopt, lpopt, upopt, topt, plopt != 0, ofnameopt);
        vector<string> key_names;
        key_names.push_back("A");
        key_names.push_back("Bb");
        key_names.push_back("B");
        key_names.push_back("C");
        key_names.push_back("C#");
        key_names.push_back("D");
        key_names.push_back("Eb");
        key_names.push_back("E");
        key_names.push_back("F");
        key_names.push_back("F#");
        key_names.push_back("G");
        key_names.push_back("G#");
        if (prediction < 12)
        {
          cout << key_names[prediction] << "\t" << "major" <<  endl;
          ofs << key_names[prediction] << "\t" << "major" <<  endl;
        }
        else
        {
          cout << key_names[prediction-12] << "\t" << "minor" << endl;
          ofs << key_names[prediction-12] << "\t" << "minor" << endl;
        }

      }
      else {
        cout << "Unsupported pitch extraction mode (" << mode << ")" << endl;
        printUsage(progName);
      }
    }
    else
    {
      Collection l;
      l.read(sfname);

      int correct_predictions = 0;
      int predictions = 0;

      for (unsigned int i=0; i < l.size(); i++)
      {
        FileName fn(l.entry(i));
        sfname = l.entry(i);
        mrs_string ofname = fn.nameNoExt() + ".txt";
        cout << ofname << endl;
//.........这里部分代码省略.........
开发者ID:sanyaade-teachings,项目名称:marsyas,代码行数:101,代码来源:pitchextract.cpp


示例12: remove

void
WekaSink::putHeader(mrs_string inObsNames)
{
  //updctrl(ctrl_putHeader_, false);
  ctrl_putHeader_->setValue(true);

  // Only write the header when we are dealing with a new file, i.e. when
  // the filename setting differs from the filename we were (previously)
  // writing to.
  if ((filename_ != ctrl_filename_->to<mrs_string>()))
  {
    // Close the previously used output file if needed and cleanup.
    if (mos_ != NULL)
    {
      mos_->close();
      delete mos_;
      // TODO: do something about this ugly hack.
      if (filename_ == "weka.arff")
      {
        remove(filename_.c_str());
      }
    }

    // Set the current filename to the new value.
    filename_ = ctrl_filename_->to<mrs_string>();

    // Open a new output stream.
    mos_ = new ofstream;
    mos_->open(filename_.c_str());

    // General header stuff.
    (*mos_) << "% Created by Marsyas" << endl;
    (*mos_) << "@relation " << filename_ << endl;

    // The number of attributes is one less than the number of input
    // observations because we assume the last observation is for the label?
    // TODO: why this assumption? What if a use case requires two labels per
    // feature vector or no labels?
    // There is no such assumption is the WEKA ARFF format anyway.
    mrs_natural nAttributes = ctrl_inObservations_->to<mrs_natural>() - 1;
    mrs_natural nLabels = ctrl_nLabels_->to<mrs_natural>();

    // Print the attribute names.
    // TODO: this is could be done way more elegant
    // (e.g. using a 'split()' or 'explode()' function).
    mrs_natural i;
    for (i =0; i < nAttributes; ++i)
    {
      mrs_string inObsName;
      mrs_string temp;
      inObsName = inObsNames.substr(0, inObsNames.find(","));
      temp = inObsNames.substr(inObsNames.find(",") + 1, inObsNames.length());
      inObsNames = temp;
      // TODO: what's the point of using an extra ostringstream here?
      ostringstream oss;
      // oss << "attribute" << i;
      (*mos_) << "@attribute " << inObsName << " real" << endl;
    }

    // The attribute for the label.
    if (!ctrl_regression_->isTrue())
    {
      (*mos_) << "@attribute output {";
      // TODO: this could be done way more elegant
      // (e.g. with a 'join()' or 'implode()' function).
      for (i=0; i < nLabels; ++i)
      {
        // TODO: what's the point of using an extra ostringstream here?
        ostringstream oss;
        // oss << "label" << i;
        oss << labelNames_[i];
        (*mos_) << oss.str();
        if (i < nLabels - 1)
        {
          (*mos_) << ",";
        }
        // (*mos_) << "@attribute output {music,speech}" << endl;
      }
      (*mos_) << "}" << endl;
    }
    else
    {
      (*mos_) << "@attribute output real" << endl;
    }

    // End of header, now we are ready for outputting the data.
    (*mos_) << "\n\[email protected]" << endl;
  }
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:89,代码来源:WekaSink.cpp


示例13: os

void
Filter::write(mrs_string filename)
{
  ofstream os(filename.c_str());
  os << (*this) << endl;
}
开发者ID:Amos-zq,项目名称:marsyas,代码行数:6,代码来源:Filter.cpp


示例14: pitchextract_caricature

void
pitchextract_caricature(mrs_string sfName, mrs_natural winSize, mrs_natural hopSize,
                        mrs_real lowPitch, mrs_real highPitch, mrs_real threshold,
                        mrs_bool playPitches, mrs_string ofName)
{
  (void) winSize;
  (void) threshold;
  MRSDIAG("pitchextract.cpp - pitchextract");

  MarSystemManager mng;
  // Build pitch contour extraction network
  MarSystem* pitchContour     = mng.create("Series", "pitchContour");

  MarSystem* pitchExtractor = mng.create("Series", "pitchExtractor");
  pitchExtractor->addMarSystem(mng.create("SoundFileSource", "src"));
  pitchExtractor->addMarSystem(mng.create("Stereo2Mono", "s2m"));
  if (mode == "praat") {
    pitchExtractor->addMarSystem(mng.create("PitchPraat", "pitchPraat"));
  } else {
    pitchExtractor->addMarSystem(mng.create("PitchSACF", "pitchSACF"));
  }

  pitchExtractor->updControl("SoundFileSource/src/mrs_string/filename", sfName);

  mrs_natural fileSize;
  fileSize= pitchExtractor->getctrl("SoundFileSource/src/mrs_natural/size")->to<mrs_natural>();
  mrs_natural contourSize = fileSize / hopSize;

  // Accumulate the extracted pitches and confidences in a single vector
  // of size contourSize
  MarSystem* pitchAccumulator = mng.create("Accumulator", "pitchAccumulator");
  pitchAccumulator->addMarSystem(pitchExtractor);
  pitchAccumulator->updControl("mrs_natural/nTimes", contourSize);
  pitchContour->addMarSystem(pitchAccumulator);

  pitchExtractor->updControl("mrs_natural/inSamples", hopSize);

  mrs_real srate = pitchExtractor->getctrl("SoundFileSource/src/mrs_real/osrate")->to<mrs_real>();

  ofstream ofs1;
  ofs1.open("p.mpl");
  ofs1 << *pitchExtractor << endl;
  ofs1.close();



  // Using explicit loop
  mrs_natural len = contourSize;
  mrs_realvec pitches(len);
  mrs_realvec confidences(len);
  mrs_realvec chords(len);
  mrs_realvec booms(len);
  mrs_realvec chicks(len);


  vector<mrs_string> chord_names;


  mrs_realvec pitchres;
  mrs_realvec peak_in;

  ofstream ofs;
  ofs.open(ofName.c_str());


  for (int i=0; i < contourSize; ++i)
  {
    pitchExtractor->tick();
    pitchres = pitchExtractor->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
    confidences(i) = pitchres(0);
    pitches(i) = samples2hertz(pitchres(1), srate);
    // cout << "Pitch = " << pitches(i) << "- (conf) - " << confidences(i) << endl;

    float scaled_pitch = pitches(i);
    if (frsopt == "bark") {
      scaled_pitch = hertz2bark(pitches(i));
    }
    if (frsopt == "mel") {
      scaled_pitch = hertz2mel(pitches(i),1);
    }
    if (frsopt == "midi") {
      scaled_pitch = hertz2pitch(pitches(i));
    }


    if (pitches(i) <= pitch2hertz(lowPitch))
    {
      // confidences(i) = 0.0;
      pitches(i) += 12;
    }
    if (pitches(i) >= pitch2hertz(highPitch))
    {
      pitches(i) -= 12;
      // confidences(i) = 0.0;
    }



    ofs << scaled_pitch << endl;

//.........这里部分代码省略.........
开发者ID:sanyaade-teachings,项目名称:marsyas,代码行数:101,代码来源:pitchextract.cpp


示例15: fclose

void
AuFileSource::getHeader(mrs_string filename)
{
  if (sfp_ != NULL)
    fclose(sfp_);
  sfp_ = fopen(filename.c_str(), "rb");
  if (sfp_)
  {
    mrs_natural n = fread(hdr_, sizeof(snd_header), 1, sfp_);
    if ((n != 1) ||((hdr_->pref[0] != '.') &&(hdr_->pref[1] != 's')))
    {
      MRSWARN("Filename " + filename + " is not correct .au file \n or has settings that are not supported in Marsyas");
      setctrl("mrs_natural/onObservations", (mrs_natural)1);
      setctrl("mrs_real/israte", (mrs_real)22050.0);
      setctrl("mrs_natural/size", (mrs_natural)0);
      hasData_ = false;
      lastTickWithData_ = true;
      setctrl("mrs_bool/hasData", false);
      setctrl("mrs_bool/lastTickWithData", true);
    }
    else
    {
#if defined(MARSYAS_BIGENDIAN)
      hdr_->hdrLength = hdr_->hdrLength;
      hdr_->comment[hdr_->hdrLength-24] = '\0';
      hdr_->srate = hdr_->srate;
      hdr_->channels = hdr_->channels;
      hdr_->mode = hdr_->mode;
      hdr_->fileLength = hdr_->fileLength;
#else
      hdr_->hdrLength = ByteSwapLong(hdr_->hdrLength);
      hdr_->comment[hdr_->hdrLength-24] = '\0';
      hdr_->srate = ByteSwapLong(hdr_->srate);
      hdr_->channels = ByteSwapLong(hdr_->channels);
      hdr_->mode = ByteSwapLong(hdr_->mode);
      hdr_->fileLength = ByteSwapLong(hdr_->fileLength);
#endif

      sampleSize_ = 2;
      size_ = (hdr_->fileLength) / sndFormatSizes_[hdr_->mode] / hdr_->channels;
      // csize_ = size_ * hdr_->channels;
      csize_ = size_;

      fseek(sfp_, hdr_->hdrLength, 0);
      sfp_begin_ = ftell(sfp_);
      setctrl("mrs_natural/onObservations", (mrs_natural)hdr_->channels);

      setctrl("mrs_real/israte", (mrs_real)hdr_->srate);
      setctrl("mrs_natural/size", size_);
      ctrl_currentlyPlaying_->setValue(filename, NOUPDATE);
      ctrl_previouslyPlaying_->setValue(filename, NOUPDATE);
      ctrl_currentLabel_->setValue(0.0, NOUPDATE);
      ctrl_previousLabel_->setValue(0.0, NOUPDATE);
      ctrl_labelNames_->setValue(",", NOUPDATE);
      ctrl_nLabels_->setValue(0, NOUPDATE);
      setctrl("mrs_bool/hasData", true);
      hasData_ = true;
      lastTickWithData_ = false;
      samplesOut_ = 0;
      pos_ = 0;
      setctrl("mrs_natural/pos", 0);
    }
  }
  else
  {
    setctrl("mrs_natural/onObservations", (mrs_natural)1);
    setctrl("mrs_real/israte", (mrs_real)22050.0);
    setctrl("mrs_natural/size", (mrs_natural)0);
    hasData_ = false;
    setctrl("mrs_bool/hasData", false);
    lastTickWithData_ = true;
    setctrl("mrs_bool/lastTickWithData", true);
    pos_ = 0;
  }
  nChannels_ = getctrl("mrs_natural/onObservations")->to<mrs_natural>();
  samplesRead_ = 0;
}
开发者ID:BitMax,项目名称:marsyas,代码行数:77,代码来源:AuFileSource.cpp


示例16: os

void 
Collection::write(mrs_string filename)
{
    ofstream os(filename.c_str());
    os << (*this) << endl;
}
开发者ID:GanAlps,项目名称:Extracting-Features-from-audio,代码行数:6,代码来源:Collection.cpp


示例17: peaks

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);
//.........这里部分代码省略.........
开发者ID:Amos-zq,项目名称:marsyas,代码行数:101,代码来源:Talk.cpp


示例18: predict

void
predict(mrs_string mode)
{

	MarSystemManager mng;

	cout << "Predicting using " << trainedclassifier_ << endl;

	ifstream pluginStream(trainedclassifier_.c_str());
    MRS_WARNINGS_OFF;
	MarSystem* net = mng.getMarSystem(pluginStream);
	MRS_WARNINGS_ON;

  if (!twekafname_Set()) return;

   vector<string> classNames;
   string s = net->getctrl("WekaSource/wsrc/mrs_string/classNames")->to<mrs_string>();
   char *str = (char *)s.c_str();
   char * pch;
   pch = strtok (str,",");
   classNames.push_back(pch);
   while (pch != NULL) {
 	pch = strtok (NULL, ",");
 	if (pch != NULL)
 	  classNames.push_back(pch);
   }





  ////////////////////////////////////////////////////////////
  //
  // Predict the classes of the test data
  //
  net->updControl("WekaSource/wsrc/mrs_string/filename", twekafname_);
  net->updControl("Classifier/cl/mrs_string/mode", "predict");
  ////////////////////////////////////////////////////////////
  //
  // Tick over the test WekaSource until all lines in the
  // test file have been read.
  //


  ofstream prout;
  prout.open(predictcollectionfname_.c_str());

  ofstream prtout;
  prtout.open(predicttimeline_.c_str());



  realvec data;
  int end=0;
  int start=0;

  mrs_string prev_name = "";
  mrs_string name;

  mrs_real srate;




  while (!net->getctrl("WekaSource/wsrc/mrs_bool/done")->to<mrs_bool>()) {
   	net->tick();
   	data = net->getctrl("mrs_realvec/processedData")->to<mrs_realvec>();
	srate = net->getctrl("WekaSource/wsrc/mrs_real/currentSrate")->to<mrs_real>();


	if (mode == "default")
	{
		cout << net->getctrl("WekaSource/wsrc/mrs_string/currentFilename")->to<mrs_string>() << "\t";
		cout << classNames[(int)data(0,0)] << endl;
		prout << net->getctrl("WekaSource/wsrc/mrs_string/currentFilename")->to<mrs_string>() << "\t";
		prout << classNames[(int)data(0,0)] << endl;
	}
	else if (mode == "timeline")
	{

	  name = classNames[(int)data(0,0)];

	  if (name != prev_name)
	  {
		if ((end * (1.0/srate)-start*(1.0 / srate) > minspan_))
		{
		  if (predicttimeline_ == EMPTYSTRING)
		  {
			cout << start*(1.0 / srate) << "\t" << end*(1.0 / srate) << "\t";
			cout << prev_name << endl;
		  }
		  else
		  {
			prtout << start*(1.0 / srate) << "\t" << end*(1.0 / srate) << "\t";
			prtout << prev_name << endl;
		  }
		  
		}
		start = end;
		
//.........这里部分代码省略.........
开发者ID:murraymeehan,项目名称:marsyas,代码行数:101,代码来源:kea.cpp


示例19: train_classifier

void
train_classifier()
{

  if (!wekafname_Set()) return;

  wekafname_  = inputdir_ + wekafname_;

  cout << "Training classifier using .arff file: " << wekafname_ << endl;
  cout << "Classifier type : " << classifier_ << endl;

  MarSystemManager mng;

  ////////////////////////////////////////////////////////////
  //
  // The network that we will use to train and predict
  //
  MarSystem* net = mng.create("Series", "series");

  ////////////////////////////////////////////////////////////
  //
  // The WekaSource we read the train and test .arf files into
  //
  net->addMarSystem(mng.create("WekaSource", "wsrc"));

  ////////////////////////////////////////////////////////////
  //
  // The classifier
  //
  MarSystem* classifier = mng.create("Classifier", "cl");
  net->addMarSystem(classifier);

  ////////////////////////////////////////////////////////////
  //
  // Which classifier function to use
  //
  if (classifier_ == "GS")
	net->updControl("Classifier/cl/mrs_string/enableChild", "GaussianClassifier/gaussiancl");
  if (classifier_ == "ZEROR")
	net->updControl("Classifier/cl/mrs_string/enableChild", "ZeroRClassifier/zerorcl");
  if (classifier_ == "SVM")
    net->updControl("Classifier/cl/mrs_string/enableChild", "SVMClassifier/svmcl");

  ////////////////////////////////////////////////////////////
  //
  // The training file we are feeding into the WekaSource
  //
  net->updControl("WekaSource/wsrc/mrs_string/filename", wekafname_);
  net->updControl("mrs_natural/inSamples", 1);

  ////////////////////////////////////////////////////////////
  //
  // Set the classes of the Summary and Classifier to be
  // the same as the WekaSource
  //
  net->updControl("Classifier/cl/mrs_natural/nClasses", net->getctrl("WekaSource/wsrc/mrs_natural/nClasses"));
  net->updControl("Classifier/cl/mrs_string/mode", "train");

  ////////////////////////////////////////////////////////////
  //
  // Tick over the training WekaSource until all lines in the
  // training file have been read.
  //


  while (!net->getctrl("WekaSource/wsrc/mrs_bool/done")->to<mrs_bool>()) {
	string mode = net->getctrl("WekaSource/wsrc/mrs_string/mode")->to<mrs_string>();
  	net->tick();
	net->updControl("Classifier/cl/mrs_string/mode", mode);
  }


  ofstream clout;
  clout.open(trainedclassifier_.c_str());
  net->updControl("Classifier/cl/mrs_string/mode", "predict");


  clout << *net << endl;

  cout << "Done training " << endl;

}
开发者ID:murraymeehan,项目名称:marsyas,代码行数:82,代码来源:kea.cpp


示例20: outputSpectrogramPNG

void outputSpectrogramPNG(string inFileName, string outFileName)
{

	cout << "SPECTROGRAM " << endl;
	
#ifdef MARSYAS_PNG
	double fftBins = windowSize_ / 2.0 + 1;  // N/2 + 1

	double min = 99999999999.9;
	double max = -99999999999.9;
	double average;

	int length = getFileLengthForSpectrogram(inFileName,min,max,average);

	
	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 pngLength = length;

	mrs_natural nChannels = net->getctrl("SoundFileSource/src/mrs_natural/onObservations")->to<mrs_natural>();


	
	double pngHeight = fftBins * ((highFreq_-lowFreq_) / (frequency / nChannels));
	
	
	if (verboseopt_)
	{
		cout << "highFreq_ = " << highFreq_ << endl;
		cout << "lowFreq_ = " << lowFreq_ << endl;
		cout << "fftBins = " << fftBins << endl;
		cout << "pngLength = " << pngLength << endl;
		cout << "pngHeight = " << pngHeight << endl;
		cout << "width = " << width_ << endl;
		cout << "height = " << height_ << endl;
	}
	
	

	pngwriter png(int(pngLength),int(pngHeight),0,outFileName.c_str());

	realvec processedData;
	double normalizedData;

	// Iterate over the whole input file by ticking, outputting columns
	// of data to the .png file with each tick
	double x = 0;
	double y = 0;
	double colour = 0;
	double diff;
	double pdiff;
	
	 
	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>();
		
		diff = 0.0;
		
		for (int i = 0; i < pngHeight; ++i) {
			double data_y = i;
			
			double data = processedData(int(data_y),0);

			normalizedData = ((data - min) / (max - min)) * gain_;


			diff += normalizedData;

			// Make the spectrogram black on white instead of white on black
			// TODO - Add the ability to generate different color maps, like Sonic Visualiser
			colour = 1.0 - normalizedData;
			if (colour > 1.0) {
				colour = 1.0;
			}
			if (colour < 0.0) {
				colour = 0.0;
			}

			y = i;
			png.plot(int(x),int(y),colour,colour,colour);
		
		}
		/* if (fabs(pdiff-diff) > 4.0)
		   for (int i=0; i < 20; i++)
		   png.plot(int(x),pngHeight- i, 1.0, 0.0, 0.0);
//.........这里部分代码省略.........
开发者ID:murraymeehan,项目名称:marsyas,代码行数:101,代码来源:sound2png.cpp



注:本文中的mrs_string类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ msg_ptr类代码示例发布时间:2022-05-31
下一篇:
C++ mrpt类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap