Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include <marsyas/common_source.h> 00020 #include "Talk.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 Talk::Talk() 00026 { 00027 } 00028 00029 00030 Talk::~Talk() 00031 { 00032 // delete src_; 00033 } 00034 00035 void 00036 Talk::init(Communicator *in_com) 00037 { 00038 communicator_ = in_com; 00039 dest_ = new AudioSink("dest"); 00040 } 00041 00042 00043 struct ltstr 00044 { 00045 bool operator()(const char* s1, const char* s2) const 00046 { 00047 return strcmp(s1, s2) < 0; 00048 } 00049 }; 00050 00051 void 00052 Talk::cmd_colorgram(mrs_string collection, mrs_string system, unsigned int start, unsigned int end, unsigned int winSize) 00053 { 00054 // FIXME All the code to this function is commented out, so none of the parameters are used. 00055 (void) collection; 00056 (void) system; 00057 (void) start; 00058 (void) end; 00059 (void) winSize; 00060 00061 // fmatrix projectMatrix; 00062 // fvec statVector; 00063 00064 00065 // mrs_string projectStr1 = MARSYAS_MFDIR; 00066 // projectStr1 += "/projectfiles/"; 00067 // projectStr1 += collection; 00068 // projectStr1 += system; 00069 // projectStr1 += "prj.mf"; 00070 // projectMatrix.read(projectStr1); 00071 00072 // mrs_string projectStr2 = MARSYAS_MFDIR; 00073 // projectStr2 += "/projectfiles/"; 00074 // projectStr2 += collection; 00075 // projectStr2 += system; 00076 // projectStr2 += "sta.mf"; 00077 // statVector.read(projectStr2); 00078 00079 // cerr << "Colorgram called with " << projectStr1 << endl; 00080 // cerr << "Colorgram called with " << projectStr2 << endl; 00081 00082 // mrs_string extractorstr = system; 00083 00084 // int iwinSize = winSize; 00085 // if (winSize != DEFAULT_WIN_SIZE) 00086 // { 00087 // start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00088 // end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00089 // winSize = DEFAULT_WIN_SIZE; 00090 // } 00091 // src_->initWindow(winSize); 00092 // cerr << "Src winSize = " << src_->winSize() << endl; 00093 00094 00095 // Spectral spectral(src_); 00096 // SpectralSegm spectralsegm(src_, 10); 00097 // MemMFCC mfcc(src_); 00098 00099 // FeatExtractor mfccExtractor(src_, &mfcc); 00100 // FeatExtractor spectralExtractor(src_, &spectral); 00101 // FeatExtractor segmExtractor(src_, &spectralsegm); 00102 // SfxExtractor sfxExtractor(src_); 00103 00104 // FeatMatrix mfccRes(src_->iterations(), mfcc.outSize()); 00105 // FeatMatrix spectralRes(src_->iterations(), spectral.outSize()); 00106 // FeatMatrix spectralSegmRes(src_->iterations(), spectralsegm.outSize()); 00107 // FeatMatrix sfxRes(1, 2); 00108 00109 00110 // map<const char *, FeatMatrix *, ltstr> results; 00111 // results["FFT"] = &spectralRes; 00112 // results["FFT_SEGM"] = &spectralSegmRes; 00113 // results["MFCC"] = &mfccRes; 00114 // results["SFX"] = &sfxRes; 00115 00116 00117 // map<const char *, Extractor *, ltstr> extractors; 00118 // extractors["FFT"] = &spectralExtractor; 00119 // extractors["FFT_SEGM"] = &segmExtractor; 00120 // extractors["MFCC"] = &mfccExtractor; 00121 // extractors["SFX"] = &sfxExtractor; 00122 00123 00124 // map<const char *, Extractor *, ltstr>::iterator cur; 00125 // const char *ch = extractorstr.c_str(); 00126 // cur = extractors.find(ch); 00127 00128 // if (cur == extractors.end()) 00129 // { 00130 // cerr << "Extractor " << extractorstr << " is not supported\n" << endl; 00131 // return; 00132 // } 00133 // else 00134 // { 00135 // extractors[extractorstr.c_str()]->extract(*(results[extractorstr.c_str()])); 00136 // } 00137 00138 // (*(results[extractorstr.c_str()])) *= projectMatrix; 00139 // unsigned int rows; 00140 // rows = (*(results[extractorstr.c_str()])).rows(); 00141 // unsigned int cols; 00142 // cols = (*(results[extractorstr.c_str()])).cols(); 00143 // mrs_string name; 00144 // name = (*(results[extractorstr.c_str()])).name(); 00145 00146 00147 // fvec pc1(rows); 00148 // fvec pc2(rows); 00149 // fvec pc3(rows); 00150 00151 // pc1 = (*(results[extractorstr.c_str()])).col(cols-1); 00152 // pc2 = (*(results[extractorstr.c_str()])).col(cols-2); 00153 // pc3 = (*(results[extractorstr.c_str()])).col(cols-3); 00154 00155 // pc1.renorm(statVector(0), statVector(1), 0.5f, 0.2f); 00156 // pc2.renorm(statVector(2), statVector(3), 0.5f, 0.2f); 00157 // pc3.renorm(statVector(4), statVector(5), 0.5f, 0.2f); 00158 00159 // int scale; 00160 // scale = iwinSize / winSize; 00161 // fvec rvec(rows / scale); 00162 // fvec gvec(rows / scale); 00163 // fvec bvec(rows / scale); 00164 00165 // unsigned int i; 00166 // unsigned int skip = 0; 00167 00168 // for (i=0; i < rows / scale; ++i) 00169 // { 00170 // rvec(i) = pc1(i * scale + skip); 00171 // gvec(i) = pc2(i * scale + skip); 00172 // bvec(i) = pc3(i * scale + skip); 00173 // } 00174 // ColorPlot cplot; 00175 // cplot.init(name, rvec, gvec, bvec); 00176 00177 // cerr << "Colorgram called with " << projectStr1 << endl; 00178 // cerr << "Colorgram called with " << projectStr2 << endl; 00179 // cplot.send(communicator_); 00180 } 00181 00182 00183 void 00184 Talk::cmd_fullfft(unsigned int winSize) 00185 { 00186 // FIXME The code to this function is gone, winSize is unused. 00187 (void) winSize; 00188 00189 // src_->initWindow(winSize, winSize, 0, 0); 00190 // unsigned int iterations = src_->iterations(); 00191 // fvec win(winSize); 00192 // fvec fftmag(winSize/2); 00193 // fvec fullmag((winSize/2)* iterations); 00194 // MagFFT mag(winSize); 00195 // unsigned int i,j; 00196 // for (i=0; i < iterations; ++i) 00197 // { 00198 // src_->get(win, i); 00199 // mag.process(win, fftmag); 00200 // for (j=0; j < winSize/2; j++) 00201 // fullmag(i * (winSize/2) + j) = fftmag(j); 00202 // } 00203 // fullmag.send(communicator_); 00204 } 00205 00206 00207 void 00208 Talk::cmd_fft(unsigned int start, unsigned int winSize) 00209 { 00210 // FIXME Missing code (again). 00211 (void) start; 00212 (void) winSize; 00213 // fvec win(winSize); 00214 // fvec fftmag(winSize/2); 00215 // src_->initWindow(winSize, winSize, 0, 0); 00216 // MagFFT mag(winSize); 00217 // src_->get(win, start); 00218 // mag.process(win, fftmag); 00219 // fftmag.send(communicator_); 00220 } 00221 00222 00223 00224 void Talk::cmd_play(mrs_natural start, mrs_natural end, mrs_natural lineSize) 00225 { 00226 communicator_->send_message("From Server: Play command received\n"); 00227 00228 00229 00230 src_->updControl("mrs_natural/pos", (mrs_natural)start * lineSize); 00231 src_->updControl("mrs_natural/inSamples", lineSize); 00232 00233 00234 00235 Series *series = new Series("playbacknet"); 00236 series->addMarSystem(src_); 00237 series->addMarSystem(dest_); 00238 00239 00240 series->updControl("AudioSink/dest/mrs_natural/nChannels", 00241 series->getctrl("SoundFileSource/src/mrs_natural/nChannels")->to<mrs_natural>()); 00242 for (int i=0; i < end-start; ++i) 00243 { 00244 series->tick(); 00245 // communicator_->send_message("tick\n"); 00246 } 00247 00248 } 00249 00250 00251 void 00252 Talk::cmd_load(mrs_string fname, mrs_natural lineSize) 00253 { 00254 cout << "cmd_load called" << endl; 00255 00256 src_ = new SoundFileSource("src"); 00257 src_->updControl("mrs_string/filename", fname); 00258 fname_ = fname; 00259 src_->updControl("mrs_natural/inSamples", lineSize); 00260 AbsMax* absmax = new AbsMax("absmax"); 00261 00262 Series *series = new Series("plot"); 00263 series->addMarSystem(src_); 00264 series->addMarSystem(absmax); 00265 00266 00267 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; 00268 00269 00270 Accumulator* acc = new Accumulator("acc"); 00271 acc->updControl("mrs_natural/nTimes", hops); 00272 acc->addMarSystem(series); 00273 00274 00275 00276 realvec in(acc->getctrl("mrs_natural/inObservations")->to<mrs_natural>(), 00277 acc->getctrl("mrs_natural/inSamples")->to<mrs_natural>()); 00278 00279 realvec out(acc->getctrl("mrs_natural/onObservations")->to<mrs_natural>(), 00280 acc->getctrl("mrs_natural/onSamples")->to<mrs_natural>()); 00281 00282 00283 00284 acc->process(in,out); 00285 00286 out.send(communicator_); 00287 00288 00289 00290 // Util util; 00291 // fname_ = fname; 00292 // src_ = util.sfopen(fname, MRS_SF_READ); 00293 // if (src_ == NULL) 00294 // cout << "src_ = NULL" << endl; 00295 00296 // if (src_ != NULL) // File exists 00297 // { 00298 // src_->initWindow(lineSize, lineSize, 0, 0); 00299 // PlotExtractor pextractor(src_, src_->winSize()); 00300 // fvec res(src_->iterations()); 00301 // pextractor.extract(0, src_->iterations(), res); 00302 // res.send(communicator_); 00303 // } 00304 // else 00305 // { 00306 // fvec res(0); 00307 // res.send(communicator_); 00308 // } 00309 } 00310 00311 void 00312 Talk::cmd_extract(mrs_string systemName, mrs_string fileName, TimeLine tline) 00313 { 00314 // FIXME See above. 00315 (void) systemName; 00316 (void) fileName; 00317 (void) tline; 00318 // cerr << "cmd_extract::systemName " << systemName << endl; 00319 // cerr << "cmd_extract::fileName " << fileName << endl; 00320 00321 // FileName fromFile(fname_); 00322 // mrs_string fromName = fromFile.name(); 00323 // mrs_string extractorstr = systemName; 00324 00325 // src_->initWindow(512, 512, 0, 0); 00326 00327 // /* Special window sizes for specific extractors */ 00328 // if (extractorstr == "LPC") 00329 // src_->initWindow(512, 128, 0, 0); 00330 // if (extractorstr == "BEAT") 00331 // src_->initWindow(65536, 65536/2,0,0); 00332 // if (extractorstr == "DWTC") 00333 // src_->initWindow(16384, 512, 0, 0); 00334 // if (extractorstr == "MPITCH") 00335 // src_->initWindow(512, 512, 0, 0); 00336 00337 00338 // /* Extractor dictionary contains all the available 00339 // extractors for feature calculation */ 00340 // ExtractorDictionary dict(src_); 00341 00342 // /* find appropriate extractor and feature matrix result */ 00343 // Extractor *extr = dict.getExtractor(extractorstr); 00344 // FeatMatrix *featMatrix = dict.getFeatMatrix(extractorstr); 00345 00346 // /* do the feature calculation */ 00347 // extr->extract(*featMatrix); 00348 00349 // /* append the feature matrix to the output file for the collection */ 00350 // mrs_string name = fromName.substr(0, fromName.size()-3); 00351 // featMatrix->setName(name); 00352 // imatrix labels(featMatrix->rows(), 2); 00353 // ivec labelSizes(2); 00354 // labelSizes(0) = 0; 00355 // labelSizes(1) = 0; 00356 // int r; 00357 00358 // for (r=0; r < labels.rows(); ++r) 00359 // { 00360 // labels(r,0) = 0; 00361 // labels(r,1) = 1; 00362 // } 00363 // featMatrix->setLabels(labels, labelSizes); 00364 00365 00366 00367 // featMatrix->write(fileName); 00368 // src_->initWindow(512, 512, 0, 0); 00369 } 00370 00371 00372 00373 00374 void 00375 Talk::cmd_segment(mrs_string systemName, unsigned int memSize, unsigned int numPeaks, unsigned int peakSpacing, unsigned int start, unsigned int end, unsigned int winSize) 00376 { 00377 // FIXME Unused parameters 00378 (void) memSize; 00379 (void) numPeaks; 00380 (void) peakSpacing; 00381 (void) start; 00382 (void) end; 00383 (void) winSize; 00384 00385 TimeLine tline; 00386 00387 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; 00388 00389 if(!strcmp(systemName.c_str(), "REG")) 00390 tline.regular(100, hops); 00391 00392 realvec peaks(hops); 00393 00394 00395 tline.send(communicator_); 00396 peaks.send(communicator_); 00397 00398 00399 // tline.print(stdout); 00400 00401 // cerr << "cmd_segment::systemName " << systemName << endl; 00402 // cerr << "cmd_segment::memSize " << memSize << endl; 00403 // cerr << "cmd_segment::numPeaks " << numPeaks << endl; 00404 // cerr << "cmd_segment::peakSpacing " << peakSpacing << endl; 00405 // cerr << "cmd_segment::start " << start << endl; 00406 // cerr << "cmd_segment::end " << end << endl; 00407 // cerr << "cmd_segment::winSize " << winSize << endl; 00408 00409 00410 00411 00412 00413 00414 // mrs_string extractorstr = systemName; 00415 // mrs_string rextractorstr = systemName; 00416 // if (!strcmp(rextractorstr.c_str(), "REG")) 00417 // extractorstr = "FFT_SEGM"; 00418 00419 // if (winSize != DEFAULT_WIN_SIZE) 00420 // { 00421 // start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00422 // end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00423 // winSize = DEFAULT_WIN_SIZE; 00424 // } 00425 // src_->initWindow(winSize); 00426 // cerr << "Src winSize = " << src_->winSize() << endl; 00427 00428 00429 // Spectral spectral(src_); 00430 // SpectralSegm spectralsegm(src_,10); 00431 // MemMFCC mfcc(src_); 00432 00433 // FeatExtractor mfccExtractor(src_, &mfcc); 00434 // FeatExtractor spectralExtractor(src_, &spectral); 00435 // FeatExtractor segmExtractor(src_, &spectralsegm); 00436 // SfxExtractor sfxExtractor(src_); 00437 00438 // FeatMatrix mfccRes(src_->iterations(), mfcc.outSize()); 00439 // FeatMatrix spectralRes(src_->iterations(), spectral.outSize()); 00440 // FeatMatrix spectralSegmRes(src_->iterations(), spectralsegm.outSize()); 00441 // FeatMatrix sfxRes(1, 2); 00442 00443 00444 // map<const char *, FeatMatrix *, ltstr> results; 00445 // results["FFT"] = &spectralRes; 00446 // results["FFT_SEGM"] = &spectralSegmRes; 00447 // results["MFCC"] = &mfccRes; 00448 // results["SFX"] = &sfxRes; 00449 00450 00451 // map<const char *, Extractor *, ltstr> extractors; 00452 // extractors["FFT"] = &spectralExtractor; 00453 // extractors["FFT_SEGM"] = &segmExtractor; 00454 // extractors["MFCC"] = &mfccExtractor; 00455 // extractors["SFX"] = &sfxExtractor; 00456 00457 00458 // map<const char *, Extractor *, ltstr>::iterator cur; 00459 // const char *ch = extractorstr.c_str(); 00460 // cur = extractors.find(ch); 00461 00462 // if (cur == extractors.end()) 00463 // { 00464 // cerr << "Extractor " << extractorstr << " is not supported\n" << endl; 00465 // return; 00466 // } 00467 // else 00468 // { 00469 // extractors[extractorstr.c_str()]->extract(*(results[extractorstr.c_str()])); 00470 // } 00471 // TimeLine tline; 00472 // SegmentorSortedPeaks segmentor; 00473 // segmentor.init(numPeaks, peakSpacing); 00474 // fvec res((*(results[extractorstr.c_str()])).rows()); 00475 // fvec peaks((*(results[extractorstr.c_str()])).rows()); 00476 // segmentor.segment(*(results[extractorstr.c_str()]), res); 00477 // segmentor.peaks(*(results[extractorstr.c_str()]), peaks); 00478 00479 00480 } 00481 00482 00483 void 00484 Talk::cmd_merge(mrs_string systemName, unsigned int pstart, unsigned int pend, 00485 unsigned int start, unsigned int end, unsigned int winSize) 00486 { 00487 // FIXME See above (missing function body) 00488 (void) systemName; 00489 (void) pstart; 00490 (void) pend; 00491 (void) start; 00492 (void) end; 00493 (void) winSize; 00494 00495 // mrs_string extractorstr = systemName; 00496 // if (winSize != DEFAULT_WIN_SIZE) 00497 // { 00498 // pstart = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00499 // pend = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00500 // winSize = DEFAULT_WIN_SIZE; 00501 // } 00502 00503 00504 // if (winSize != DEFAULT_WIN_SIZE) 00505 // { 00506 // start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00507 // end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00508 // winSize = DEFAULT_WIN_SIZE; 00509 // } 00510 00511 // src_->initWindow(winSize); 00512 // cerr << "Src winSize = " << src_->winSize() << endl; 00513 00514 // Spectral spectral(src_); 00515 // SpectralSegm spectralsegm(src_, 10); 00516 // MemMFCC mfcc(src_); 00517 00518 // FeatExtractor mfccExtractor(src_, &mfcc); 00519 // FeatExtractor spectralExtractor(src_, &spectral); 00520 // FeatExtractor segmExtractor(src_, &spectralsegm); 00521 // SfxExtractor sfxExtractor(src_); 00522 00523 // FeatMatrix mfccRes(end-start, mfcc.outSize()); 00524 // FeatMatrix spectralRes(end-start, spectral.outSize()); 00525 // FeatMatrix spectralSegmRes(end-start, spectralsegm.outSize()); 00526 // FeatMatrix sfxRes(1, 2); 00527 00528 00529 // map<const char *, FeatMatrix *, ltstr> results; 00530 00531 // results["FFT"] = &spectralRes; 00532 // results["FFT_SEGM"] = &spectralSegmRes; 00533 // results["MFCC"] = &mfccRes; 00534 // results["SFX"] = &sfxRes; 00535 00536 00537 // FeatMatrix pmfccRes(pend-pstart, mfcc.outSize()); 00538 // FeatMatrix pspectralRes(pend-pstart, spectral.outSize()); 00539 // FeatMatrix pspectralSegmRes(pend-pstart, spectralsegm.outSize()); 00540 // FeatMatrix psfxRes(1, 2); 00541 00542 00543 // map<const char *, FeatMatrix *, ltstr> presults; 00544 // presults["FFT"] = &pspectralRes; 00545 // presults["FFT_SEGM"] = &pspectralSegmRes; 00546 // presults["MFCC"] = &pmfccRes; 00547 // presults["SFX"] = &psfxRes; 00548 00549 00550 // map<const char *, Extractor *, ltstr> extractors; 00551 // extractors["FFT"] = &spectralExtractor; 00552 // extractors["FFT_SEGM"] = &segmExtractor; 00553 // extractors["MFCC"] = &mfccExtractor; 00554 // extractors["SFX"] = &sfxExtractor; 00555 00556 00557 // map<const char *, Extractor *, ltstr>::iterator cur; 00558 // const char *ch = extractorstr.c_str(); 00559 // cur = extractors.find(ch); 00560 00561 // if (cur == extractors.end()) 00562 // { 00563 // cerr << "Extractor " << extractorstr << " is not supported\n" << endl; 00564 // return; 00565 // } 00566 // else 00567 // { 00568 // extractors[extractorstr.c_str()]->extract(pstart, pend, *(presults[extractorstr.c_str()])); 00569 // extractors[extractorstr.c_str()]->extract(start, end, *(results[extractorstr.c_str()])); 00570 // } 00571 00572 // cout << "MEANS " << endl; 00573 00574 // fvec m1 = (*(presults[extractorstr.c_str()])).meanRow(); 00575 // fvec m2 = (*(results[extractorstr.c_str()])).meanRow(); 00576 // fvec v1 = (*(presults[extractorstr.c_str()])).varRow(); 00577 // fvec v2 = (*(results[extractorstr.c_str()])).varRow(); 00578 // fvec d1 = m1; 00579 // fvec v12 = v1; 00580 // fvec v21 = v2; 00581 00582 00583 // d1 -= m2; 00584 // d1.sqr(); 00585 // d1 *= ((v1 + v2)/(v1*v2)); 00586 00587 00588 // v12 /= v2; 00589 // v21 /= v1; 00590 00591 // fvec kl1 = d1; 00592 // kl1 += v12; 00593 // kl1 += v21; 00594 // int i; 00595 00596 // float KL2 = 0.0; 00597 00598 // for (i=0; i < kl1.size(); ++i) 00599 // { 00600 // KL2 += kl1(i); 00601 // } 00602 // KL2 /= kl1.size(); 00603 00604 // cout << "KL2 = " << KL2 << endl; 00605 00606 00607 00608 } 00609 00610 00611 void 00612 Talk::cmd_classify(mrs_string systemName, mrs_string classifierName, unsigned int start, unsigned int end, unsigned int winSize) 00613 { 00614 // FIXME See above. 00615 (void) systemName; 00616 (void) classifierName; 00617 (void) start; 00618 (void) end; 00619 (void) winSize; 00620 00621 // Gaussian classifier; 00622 // classifier.read(classifierName); 00623 00624 00625 // if (winSize != DEFAULT_WIN_SIZE) 00626 // { 00627 // start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00628 // end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00629 // winSize = DEFAULT_WIN_SIZE; 00630 // } 00631 00632 // mrs_string extractorstr = systemName; 00633 00634 // if (winSize != DEFAULT_WIN_SIZE) 00635 // { 00636 // start = (unsigned int)(start * ((float)winSize / DEFAULT_WIN_SIZE)); 00637 // end = (unsigned int) (end * ((float)winSize/ DEFAULT_WIN_SIZE)); 00638 // winSize = DEFAULT_WIN_SIZE; 00639 // } 00640 // src_->initWindow(winSize); 00641 // cerr << "Src winSize = " << src_->winSize() << endl; 00642 00643 00644 // Spectral spectral(src_); 00645 // SpectralSegm spectralsegm(src_, 10); 00646 // MemMFCC mfcc(src_); 00647 00648 // FeatExtractor mfccExtractor(src_, &mfcc); 00649 // FeatExtractor spectralExtractor(src_, &spectral); 00650 // FeatExtractor segmExtractor(src_, &spectralsegm); 00651 // SfxExtractor sfxExtractor(src_); 00652 00653 // FeatMatrix mfccRes(end-start, mfcc.outSize()); 00654 // FeatMatrix spectralRes(end-start, spectral.outSize()); 00655 // FeatMatrix spectralSegmRes(end-start, spectralsegm.outSize()); 00656 // FeatMatrix sfxRes(1, 2); 00657 00658 00659 // map<const char *, FeatMatrix *, ltstr> results; 00660 // results["FFT"] = &spectralRes; 00661 // results["FFT_SEGM"] = &spectralSegmRes; 00662 // results["MFCC"] = &mfccRes; 00663 // results["SFX"] = &sfxRes; 00664 00665 00666 // map<const char *, Extractor *, ltstr> extractors; 00667 // extractors["FFT"] = &spectralExtractor; 00668 // extractors["FFT_SEGM"] = &segmExtractor; 00669 // extractors["MFCC"] = &mfccExtractor; 00670 // extractors["SFX"] = &sfxExtractor; 00671 00672 00673 // map<const char *, Extractor *, ltstr>::iterator cur; 00674 // const char *ch = extractorstr.c_str(); 00675 // cur = extractors.find(ch); 00676 00677 // if (cur == extractors.end()) 00678 // { 00679 // cerr << "Extractor " << extractorstr << " is not supported\n" << endl; 00680 // return; 00681 // } 00682 // else 00683 // { 00684 // extractors[extractorstr.c_str()]->extract(start, end, *(results[extractorstr.c_str()])); 00685 // } 00686 00687 // float conf; 00688 00689 // unsigned int classId = classifier.estimateClass(*(results[extractorstr.c_str()]),&conf); 00690 // mrs_string className = classifier.className(classId); 00691 // cerr << "Estimated className = " << className << endl; 00692 // cerr << "Estimated classId = " << classId << endl; 00693 00694 00695 00696 // communicator_->send_message(className + "\n"); 00697 00698 // static char *buf = new char[256]; 00699 // sprintf(buf, "%d\n", classId); 00700 // mrs_string classIdmessage; 00701 // classIdmessage = buf; 00702 00703 // communicator_->send_message(classIdmessage); 00704 // cerr << "Finished sending message\n" << endl; 00705 } 00706 00707 00708 00709 void 00710 Talk::process(char *message) 00711 { 00712 printf("Talk process called\n"); 00713 cerr << "Message = " << message << endl; 00714 char *word; 00715 char *filename; 00716 mrs_string fname; 00717 unsigned int lineSize; 00718 int start, end, win_size; 00719 word = strtok(message, SEPCHARS); 00720 if (!strcmp(word,"load")) 00721 { 00722 #ifdef MARSYAS_WIN32 00723 filename = _strdup(strtok(NULL,SEPCHARS)); 00724 #else 00725 filename = strdup(strtok(NULL,SEPCHARS)); 00726 #endif 00727 lineSize = atoi(strtok(NULL, SEPCHARS)); 00728 fname = filename; 00729 cerr << "load command: Filename = " << filename << endl; 00730 cerr << "load command: LineSize = " << lineSize << endl; 00731 communicator_->send_message("From Server: Load command received. Preparing plot\n"); 00732 cmd_load(fname, lineSize); 00733 00734 00735 00736 } 00737 else if (!strcmp(word,"play")) 00738 { 00739 start = atoi(strtok(NULL, SEPCHARS)); 00740 end = atoi(strtok(NULL, SEPCHARS)); 00741 lineSize = atoi(strtok(NULL, SEPCHARS)); 00742 cerr << "play command. start = " << start << " end = " << end << endl; 00743 cmd_play(start, end, lineSize); 00744 } 00745 else if (!strcmp(word,"merge")) 00746 { 00747 mrs_string systemName = strtok(NULL, SEPCHARS); 00748 unsigned int pstart = atoi(strtok(NULL, SEPCHARS)); 00749 unsigned int pend = atoi(strtok(NULL, SEPCHARS)); 00750 unsigned int start = atoi(strtok(NULL, SEPCHARS)); 00751 unsigned int end = atoi(strtok(NULL, SEPCHARS)); 00752 unsigned int win_size = atoi(strtok(NULL, SEPCHARS)); 00753 cerr << "Merge command " << endl; 00754 cerr << "System = " << systemName << " pstart = " << pstart << 00755 " pend = " << pend << " start = " << start << " end = " << end 00756 << " win_size = " << win_size << endl; 00757 communicator_->send_message("From Server; merge command received\n"); 00758 cmd_merge(systemName, pstart, pend, start, end, win_size); 00759 } 00760 00761 00762 else if (!strcmp(word,"classify")) 00763 { 00764 /* mrs_string systemName = strtok(NULL, SEPCHARS); 00765 mrs_string classifierName = MARSYAS_MFDIR; 00766 classifierName += "/classifiers/"; 00767 classifierName += strtok(NULL, SEPCHARS); 00768 classifierName += systemName; 00769 classifierName += ".mcf"; 00770 start = atoi(strtok(NULL, SEPCHARS)); 00771 end = atoi(strtok(NULL, SEPCHARS)); 00772 win_size = atoi(strtok(NULL, SEPCHARS)); 00773 cerr << "Classify command. " << endl; 00774 cerr << "System = " << systemName << " Classifier = " << classifierName << " start = " << start << " end = " << end << endl; 00775 communicator_->send_message("From Server: classify command received\n"); 00776 cmd_classify(systemName, classifierName, start, end, win_size); 00777 */ 00778 } 00779 else if (!strcmp(word,"fft")) 00780 { 00781 int start = atoi(strtok(NULL, SEPCHARS)); 00782 int winSize = atoi(strtok(NULL, SEPCHARS)); 00783 communicator_->send_message("From Server: fft command received\n"); 00784 cmd_fft(start, winSize); 00785 } 00786 else if (!strcmp(word, "fullfft")) 00787 { 00788 int winSize = atoi(strtok(NULL, SEPCHARS)); 00789 communicator_->send_message("From Server: fullfft command received\n"); 00790 cmd_fullfft(winSize); 00791 } 00792 else if (!strcmp(word,"segment")) 00793 { 00794 int mask_size = 11; 00795 int winSize; 00796 00797 realvec mask(mask_size); 00798 for (int i=0; i<mask_size; ++i) 00799 mask(i) = (mrs_real)atof(strtok(NULL, SEPCHARS)); 00800 cerr << "Segment command." << endl; 00801 mrs_string systemName = strtok(NULL, SEPCHARS); 00802 int memSize = atoi(strtok(NULL, SEPCHARS)); 00803 int numPeaks = atoi(strtok(NULL, SEPCHARS)); 00804 int peakSpacing = atoi(strtok(NULL, SEPCHARS)); 00805 start = atoi(strtok(NULL, SEPCHARS)); 00806 end = atoi(strtok(NULL, SEPCHARS)); 00807 winSize = atoi(strtok(NULL, SEPCHARS)); 00808 communicator_->send_message("From Server: segment command received\n"); 00809 cmd_segment(systemName, memSize, numPeaks, peakSpacing, start, end, winSize); 00810 } 00811 else if (!strcmp(word,"extract")) 00812 { 00813 cerr << "Extract command." << endl; 00814 mrs_string systemName = strtok(NULL, SEPCHARS); 00815 mrs_string fileName = strtok(NULL, SEPCHARS); 00816 TimeLine tline; 00817 tline.receive(communicator_); 00818 00819 communicator_->send_message("From Server: extract command received\n"); 00820 00821 cmd_extract(systemName, fileName, tline); 00822 } 00823 00824 else if (!strcmp(word,"snoop")) 00825 { 00826 cerr << "Snoop command." << endl; 00827 // these aren't used? -gp 00828 //int feat_num; 00829 //feat_num = atoi(strtok(NULL, SEPCHARS)); 00830 communicator_->send_message("Howdy. You just send a snoop command\n"); 00831 } 00832 else if (!strcmp(word,"colorgram")) 00833 { 00834 cerr << "Colorgram command." << endl; 00835 mrs_string collection = strtok(NULL, SEPCHARS); 00836 mrs_string system = strtok(NULL, SEPCHARS); 00837 start = atoi(strtok(NULL, SEPCHARS)); 00838 end = atoi(strtok(NULL, SEPCHARS)); 00839 win_size = atoi(strtok(NULL, SEPCHARS)); 00840 communicator_->send_message("From server: colorgram command received.\n"); 00841 cmd_colorgram(collection, system, start, end, win_size); 00842 } 00843 else 00844 communicator_->send_message("Howdy. Unknown command\n"); 00845 cerr << "Talk::Process is done" << endl; 00846 } 00847 00848 00849