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