本文整理汇总了C++中mrs_string类的典型用法代码示例。如果您正苦于以下问题:C++ mrs_string类的具体用法?C++ mrs_string怎么用?C++ mrs_string使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mrs_string类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: is
void
Collection::read(mrs_string filename)
{
ifstream is(filename.c_str());
name_ = filename.substr(0, filename.rfind(".", filename.length()));
is >> (*this);
}
示例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);
}
示例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;
}
}
示例4: fopen
void
MP3FileSink::putHeader(mrs_string filename)
{
#ifdef MARSYAS_LAME
sfp_ = fopen(filename.c_str(), "wb");
#endif
}
示例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_);
}
示例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
示例7: from
bool
realvec::read(mrs_string filename)
{
ifstream from(filename.c_str());
if (from.is_open())
{
from >> (*this);
return true;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
//.........这里部分代码省略.........
示例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;
}
}
示例13: os
void
Filter::write(mrs_string filename)
{
ofstream os(filename.c_str());
os << (*this) << endl;
}
示例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;
//.........这里部分代码省略.........
示例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;
}