1 /*
2 MPEG Maaate: An Australian MPEG audio analysis toolkit
3 Copyright (C) 2000 Commonwealth Scientific and Industrial Research Organisation
4 (CSIRO), Australia.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include "maaateM_brief.H"
26
27 #include "SOUNDfile.H"
28 #include "plugins.H"
29
30 using namespace std;
31
32 // parameters to control what is to be extracted
33 static float from = 0.0; // start at second 0.0
34 static float to = FLT_MAX; // end at end of file
35 static bool verbose = false;
36 static short fromSb = 0; // first subband to be extracted
37 static short toSb = 575; // last subband to be extracted
38 static float thresh = 0.07; // threshold between [0;1]
39 static float minDur = 0.1; // minimum duration [sec]
40 static float maxInterrupt = 0.0; // mamixum tolerated disruption [sec]
41 static float releaseTime = 0.01; // release time for silence start [sec]
42 static float onsetTime = 0.01; // onset time for silence end [sec]
43 static int bins = 10; // number of bins for histogram
44 static float starthisto = FLT_MAX; // start of the histogram values
45 static float endhisto = DBL_MIN; // end of the histogram values
46 static float tolerance = 0.0; // time identity tolerance for compare
47 static bool wantSilence = false; // want silence?
48 static bool wantNoise = false; // want noise?
49 static bool wantBgLevel = false; // want background noise level?
50 static bool wantSumSCF = false; // want sum of scalefactors?
51 static bool wantCentroid = false; // want spectral centroid?
52 static bool wantSSCFhisto = false; // want histogram of SumSCF?
53 static bool wantSBnrj = false; // want normalised subband energies?
54 static bool wantSBmean = false; // want subband mean?
55 static bool wantSBrms = false; // want subband rms?
56 static bool wantSBv = false; // want subband value?
57 static bool wantSBvmean = false; // want subband value mean?
58 static bool wantSBvrms = false; // want subband value rms?
59 static bool wantSBvnrj = false; // want subband value normalised nrj?
60 static bool wantSBscf = false; // want subband scalefactor?
61 static bool wantsignrj = false; // want signal energy?
62 static bool wantsigsb = false; // want significant subbands?
63 static bool wantbandnrj = false; // want band signal energy?
64 static bool wantsigmag = false; // want signal magnitude?
65 static bool wantpauserate = false; // want pause rate?
66 static bool wantbandratio = false; // want band nrj ratio?
67 static bool wantrolloff = false; // want roll off?
68 static bool wantbw = false; // want bandwidth?
69 static bool wantbdw = false; // want signal bandwidth?
70 static bool wantspflux = false; // want spectral flux?
71 static bool wantcm = false; // want central moment?
72 static bool wantlownrj = false; // want lownrj?
73 static bool wantvariance = false; // want variance?
74 static bool wantmatoutput = false; // want output in MATLAB mat-file
75 static char *matfilename = NULL; // MATLAB mat-file
76 static char *filename = NULL; // mpeg-audio-file
77
78 Plugins * plugins;
79
80 //----------------------------------
81 void
PrintUsage(char * prog)82 PrintUsage(char *prog) {
83 cerr << "\nUsage:" << endl;
84 cerr << prog << " [Options] <mpeg-audio-file>" << endl;
85 cerr << "Default Options: -S 0.0 -E eof" << endl;
86 cerr << " (i.e. analyse whole file)" << endl;
87 cerr << endl;
88 cerr << "Possible Options:" << endl;
89 cerr << "-h help = prints this information" << endl;
90 cerr << "-S <from> the second (float) to start analysing from" << endl;
91 cerr << " Default: 0.0" << endl;
92 cerr << "-E <to> the second (float) to stop analysing at" << endl;
93 cerr << " Default: end of file" << endl;
94 cerr << "-V verbose" << endl;
95 cerr << "-B <from> <to> subband range (ints) that gets extracted" << endl;
96 cerr << " (only required with -X sscf)" << endl;
97 cerr << " Default: 0 31 (Layers I, II)" << endl;
98 cerr << " 0 575 (Layer III)" << endl;
99 cerr << "-T <thresh> threshold value between [0;1]" << endl;
100 cerr << " Default: 0.07" << endl;
101 cerr << "-M <minDur> minimum duration [sec] of specified content" << endl;
102 cerr << " Default: 0.1" << endl;
103 cerr << "-N <maxInter> mamimum tolerated disruption [sec]" << endl;
104 cerr << " Default: 0.0" << endl;
105 cerr << "-R <releaseT> release time [sec] delaying start of silence" << endl;
106 cerr << "-O <onsetT> onset time [sec] earlying end of silence" << endl;
107 cerr << " Default: 0.01 (must be < minDur)" << endl;
108 cerr << "-Z <bins> number of bins for histogram" << endl;
109 cerr << " Default: 10" << endl;
110 cerr << "-Y <from> <to> start and end of histogram values (float)" << endl;
111 cerr << " Default: -1 -1 (meaning: minvalue maxvalue)" << endl;
112 cerr << "-F <filename> filename and path of outputfile in MATLAB binary mat-format" <<endl;
113 cerr << " Default: default.mat" <<endl;
114 cerr << "-X [content] specifies content to extract from audio file" <<endl;
115 cerr << " Possible content types:" << endl;
116 cerr << " silence -T <thresh> -M <minDur> -N <maxInter> -O <onsetT> -R <releaseT>" << endl;
117 cerr << " Temporal Segmentation: silence segments based on sumscf" << endl;
118 cerr << " noise -T <thresh> -M <minDur> -N <maxInter> -O <onsetT> -R <releaseT>" << endl;
119 cerr << " Temporal Segmentation: noise segments based on sumscf" << endl;
120 cerr << " bglevel -M <minDur> -N <maxInter> -O <onsetT> -R <releaseT>" << endl;
121 cerr << " sumscf -B <fromsb> <tosb>" << endl;
122 cerr << " 1D Curve: sum of scalefactors as loudness approximation" << endl;
123 cerr << " centroid -B <fromsb> <tosb>" << endl;
124 cerr << " 1D Curve: spectral centroid" << endl;
125 cerr << " histo -Z <bins> -Y <fromVal> <toVal>" << endl;
126 cerr << " Vector: loudness distribution for whole duration based on sumscf" << endl;
127 cerr << " sbnrj -B <fromsb> <tosb>" << endl;
128 cerr << " Vector: normalised subband energies in each selected subbands" << endl;
129 cerr << " sbmean -B <fromsb> <tosb>" << endl;
130 cerr << " Vector: subband mean over one window in each selected subbands" << endl;
131 cerr << " sbrms -B <fromsb> <tosb>" << endl;
132 cerr << " Vector: subband rms over one window in each selected subbands" << endl;
133 cerr << " sbscf -B <fromsb> <tosb>" << endl;
134 cerr << " Vector: subband scalefactor over one window in each selected subbands" << endl;
135 cerr << " sbv -B <fromsb> <tosb>" << endl;
136 cerr << " Vector: subband values in each selected subbands" << endl;
137 cerr << " sbvmean -B <fromsb> <tosb>" << endl;
138 cerr << " Vector: subband values mean in each selected subbands" << endl;
139 cerr << " sbvrms -B <fromsb> <tosb>" << endl;
140 cerr << " Vector: subband values mean in each selected subbands" << endl;
141 cerr << " sbvnrj -B <fromsb> <tosb>" << endl;
142 cerr << " Vector: subband values normalised energies in each selected subbands" << endl;
143 cerr << " signrj -Z <window_number>" << endl;
144 cerr << " Curve: short time energy function" << endl;
145 cerr << " Window: 0: square, 1: Hamming, 2: Welch, 3: Bartlett(default)" << endl;
146 cerr << " bandnrj -B <fromsb> <tosb> -Z <window_number>" << endl;
147 cerr << " Curve: short time band energy function" << endl;
148 cerr << " Window: 0: square, 1: Hamming, 2: Welch, 3: Bartlett(default)" << endl;
149 cerr << " sigsb -T <thresh> " << endl;
150 cerr << " Curve: number of significant subbands function" << endl;
151 cerr << " Window: 0: square, 1: Hamming, 2: Welch, 3: Bartlett(default)" << endl;
152 cerr << " sigmag -Z <window_number>" << endl;
153 cerr << " Curve: short time magnitude function" << endl;
154 cerr << " Window: 0: square, 1: Hamming, 2: Welch, 3: Bartlett(default)" << endl;
155 cerr << " pauser -T <thresh> -M <duration>" << endl;
156 cerr << " Curve: values of pause rate for each segment of duration seconds" << endl;
157 cerr << " bandnrj -B <subband boundary> <window_number>" << endl;
158 cerr << " Curve: values of band nrj ratio" << endl;
159 cerr << " rolloff " << endl;
160 cerr << " Curve: values of roll of, resolution: granule" << endl;
161 cerr << " bdwidth -T <thresh>" << endl;
162 cerr << " Curves: values of bandwidth, fcmin, fcmax resolution granule" << endl;
163 cerr << " sbdw -T <thresh>" << endl;
164 cerr << " Curves: values of bandwidth, fcmin, fcmax resolution granule" << endl;
165 cerr << " spflux " << endl;
166 cerr << " Curve: spectral flux between 2 successive frames" << endl;
167 cerr << " cmoment -B <fromsb> <tosb> -Z <k_pow> -M <duration>" << endl;
168 cerr << " Vector: central moments for each selected subbands" << endl;
169 cerr << " lownrj -M <duration>" << endl;
170 cerr << " Curve: number of low energy windows" << endl;
171 cerr << " variance -M <duration>" << endl;
172 cerr << " Curve: variance of signal nrj" << endl;
173 exit (1);
174 }
175
176 //----------------------------------
177 void
ParseArguments(int argc,char ** argv)178 ParseArguments (int argc, char **argv) {
179 // go through parameters and check values
180 for (int i=1; i<argc; i++) {
181 if (argv[i][0] == '-' && argv[i][1]) {
182 switch (argv[i][1]) {
183 case 'H': case 'h': // help
184 PrintUsage(argv[0]);
185 break;
186 case 'S': case 's': // second to start from
187 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
188 from = atof(argv[++i]);
189 }
190 break;
191 case 'E': case 'e': // second to end at
192 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
193 to = atof(argv[++i]);
194 }
195 break;
196 case 'V': case 'v':// verbose
197 verbose = true;
198 break;
199 case 'B': case 'b': // subband range
200 if ((i+2<argc) && !isalpha(argv[i+1][0])
201 && !isalpha(argv[i+2][0])) {
202 fromSb = atoi(argv[++i]);
203 toSb = atoi(argv[++i]);
204 } else {
205 cerr << argv[0] << ": -B option needs two integers to follow"
206 << endl;
207 exit(1);
208 }
209 break;
210 case 'T': case 't': // threshold
211 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
212 thresh = atof(argv[++i]);
213 }
214 break;
215 case 'M': case 'm': // minimum duration
216 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
217 minDur = atof(argv[++i]);
218 }
219 break;
220 case 'N': case 'n': // maximum interrupt
221 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
222 maxInterrupt = atof(argv[++i]);
223 }
224 break;
225 case 'R': case 'r': // release time
226 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
227 releaseTime = atof (argv[++i]);
228 }
229 break;
230 case 'O': case 'o': // onset time
231 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
232 onsetTime = atof (argv[++i]);
233 }
234 break;
235 case 'Z': case 'z': // no bins
236 if ((i+1<argc) && !isalpha(argv[i+1][0])) {
237 bins = atoi(argv[++i]);
238 }
239 break;
240 case 'Y': case 'y': // histogram range
241 if ((i+2<argc) && !isalpha(argv[i+1][0]) && !isalpha(argv[i+2][0])) {
242 starthisto = atof(argv[++i]);
243 endhisto = atof(argv[++i]);
244 }
245 else {
246 cerr << argv[0] << ": -Y option needs two floats to follow" << endl;
247 exit(1);
248 }
249 break;
250 case 'F': case 'f': // MATLAB output
251 if ((i+1 == argc) || !isalpha(argv[i+1][0])) {
252 cerr << argv[0] << ": -X option needs string-argument" << endl;
253 exit(1);
254 }
255 else {
256 wantmatoutput = true;
257 matfilename = argv[i+1];
258 i++;
259 }
260 break;
261 case 'X': case 'x': // extract content
262 if ((i+1 == argc) || !isalpha(argv[i+1][0])) {
263 cerr << argv[0] << ": -X option needs string-argument"
264 << endl;
265 exit(1);
266 } else {
267 if (!strncmp(argv[i+1],"silence",3)) {
268 wantSilence = true; i++;
269 } else if (!strncmp(argv[i+1],"noise",3)) {
270 wantNoise = true; i++;
271 } else if (!strncmp(argv[i+1],"centroid",3)) {
272 wantCentroid = true; i++;
273 } else if (!strncmp(argv[i+1],"bglevel",3)) {
274 wantBgLevel = true; i++;
275 } else if (!strncmp(argv[i+1],"sumscf",3)) {
276 wantSumSCF = true; i++;
277 } else if (!strncmp(argv[i+1],"histo",3)) {
278 wantSSCFhisto = true; i++;
279 } else if (!strncmp(argv[i+1],"sbnrj",3)) {
280 wantSBnrj = true; i++;
281 } else if (!strncmp(argv[i+1],"sbmean",3)) {
282 wantSBmean = true; i++;
283 } else if (!strncmp(argv[i+1],"sbrms",3)) {
284 wantSBrms = true; i++;
285 } else if (!strncmp(argv[i+1],"sbscf",3)) {
286 wantSBscf = true; i++;
287 } else if (!strncmp(argv[i+1],"sbvmean",4)) {
288 wantSBvmean = true; i++;
289 } else if (!strncmp(argv[i+1],"sbvrms",4)) {
290 wantSBvrms = true; i++;
291 } else if (!strncmp(argv[i+1],"sbvnrj",4)) {
292 wantSBvnrj = true; i++;
293 } else if (!strncmp(argv[i+1],"sbv",3)) {
294 wantSBv = true; i++;
295 } else if (!strncmp(argv[i+1],"signrj",4)) {
296 wantsignrj = true; i++;
297 } else if (!strncmp(argv[i+1],"sigsb",4)) {
298 wantsigsb = true; i++;
299 } else if (!strncmp(argv[i+1],"bandnrj",5)) {
300 wantbandnrj = true; i++;
301 } else if (!strncmp(argv[i+1],"sigmag",4)) {
302 wantsigmag = true; i++;
303 } else if (!strncmp(argv[i+1],"pauser",3)) {
304 wantpauserate = true; i++;
305 } else if (!strncmp(argv[i+1],"bandnrj",3)) {
306 wantbandratio = true; i++;
307 } else if (!strncmp(argv[i+1],"rolloff",3)) {
308 wantrolloff = true; i++;
309 } else if (!strncmp(argv[i+1],"bdwidth",3)) {
310 wantbw = true; i++;
311 } else if (!strncmp(argv[i+1],"sbdw",3)) {
312 wantbdw = true; i++;
313 } else if (!strncmp(argv[i+1],"spflux",3)) {
314 wantspflux = true; i++;
315 } else if (!strncmp(argv[i+1],"cmoment",3)) {
316 wantcm = true; i++;
317 } else if (!strncmp(argv[i+1],"lownrj",3)) {
318 wantlownrj = true; i++;
319 } else if (!strncmp(argv[i+1],"variance",3)) {
320 wantvariance = true; i++;
321 } else if (argv[i+1][0] != '-') {
322 cerr << argv[0] << ": -X unknown string-argument "
323 << argv[i+1] << endl;
324 exit(1);
325 }
326 }
327 break;
328 } // switch
329 } else {
330 filename = argv[i];
331 }
332 }
333 }
334
335 //----------------------------------
336 void
CheckArguments(char * prgname)337 CheckArguments(char *prgname) {
338 if (filename == NULL) {
339 cerr << prgname << ": Mpeg audio filename missing" << endl;
340 exit(1);
341 }
342 if (from < 0.0) from = 0.0;
343 if (to < from) to = from;
344 if (fromSb < 0) fromSb = 0;
345 if (toSb < fromSb && !(wantbandratio)) toSb = fromSb;
346 if (thresh < 0.0 && !(wantbdw)) thresh = 0.0;
347 if (thresh > 1.0) thresh = 1.0;
348 if (releaseTime > minDur) releaseTime = 0.0;
349 if (onsetTime > minDur) onsetTime = 0.0;
350 if (bins <= 0 && !(wantsignrj || wantcm || wantbandnrj || wantvariance)) bins = 10;
351 if (tolerance < 0) tolerance = -tolerance;
352
353 #ifdef DEBUG
354 cout << "Parameter Settings:" << endl;
355 cout << "From=" << from << endl;
356 cout << "To=" << to << endl;
357 cout << "Verbose=" << verbose << endl;
358 cout << "fromSb=" << fromSb << endl;
359 cout << "toSb=" << toSb << endl;
360 cout << "thresh=" << thresh << endl;
361 cout << "minDur=" << minDur << endl;
362 cout << "maxInterrupt=" << maxInterrupt << endl;
363 cout << "releaseTime=" << releaseTime << endl;
364 cout << "onsetTime=" << onsetTime << endl;
365 cout << "bins=" << bins << endl;
366 cout << "starthisto=" << starthisto << endl;
367 cout << "endhisto=" << endhisto << endl;
368 cout << "tolerance=" << tolerance << endl;
369 cout << "wantSilence=" << wantSilence << endl;
370 cout << "wantNoise=" << wantNoise << endl;
371 cout << "wantBgLevel=" << wantBgLevel << endl;
372 cout << "wantSumSCF=" << wantSumSCF << endl;
373 cout << "wantCentroid=" << wantCentroid << endl;
374 cout << "wantSSCFhisto=" << wantSSCFhisto << endl;
375 cout << "wantSBnrj=" << wantSBnrj << endl;
376 cout << "wantSBmean=" << wantSBmean << endl;
377 cout << "wantSBrms=" << wantSBrms << endl;
378 cout << "wantSBv=" << wantSBv << endl;
379 cout << "wantSBvnrj=" << wantSBvnrj << endl;
380 cout << "wantSBvmean=" << wantSBvmean << endl;
381 cout << "wantSBscf=" << wantSBscf << endl;
382 cout << "wantSBvrms=" << wantSBvrms << endl;
383 cout << "wantsigsb=" << wantsigsb << endl;
384 cout << "wantbandnrj=" << wantbandnrj << endl;
385 cout << "wantsignrj=" << wantsignrj << endl;
386 cout << "wantsigmag=" << wantsigmag << endl;
387 cout << "wantpauserate=" << wantpauserate << endl;
388 cout << "wantbandratio=" << wantbandratio << endl;
389 cout << "wantrolloff=" << wantrolloff << endl;
390 cout << "wantbw=" << wantbw << endl;
391 cout << "wantbdw=" << wantbdw << endl;
392 cout << "wantspflux=" << wantspflux << endl;
393 cout << "wantcm=" << wantcm << endl;
394 cout << "wantlownrj=" << wantlownrj << endl;
395 cout << "wantvariance=" << wantvariance << endl;
396 cout << "wantmatoutput=" << wantmatoutput << endl;
397 cout << "matfilename=" << matfilename << endl;
398 cout << "filename=" << filename << endl;
399
400 #endif // debug
401 }
402
403 //----------------------------------
404 int
main(int argc,char ** argv)405 main(int argc, char **argv) {
406
407 // check no. of args
408 if (argc < 2) {
409 PrintUsage(argv[0]);
410 }
411
412 // parse arguments
413 ParseArguments (argc, argv);
414
415 // check arguments and correct if appropriate
416 CheckArguments (argv[0]);
417
418 // open SOUNDfile
419 SOUNDfile * mpfile = new SOUNDfile(filename);
420
421 if (mpfile->file_type() == NOFILE) {
422 cerr << "analyseSDaudio: Sorry can`t analysis this file:" << filename << endl;
423 exit(1);
424 }
425
426 if (verbose) {
427 cout << "SOUND file opened: " << filename << endl;
428 }
429
430 // open known plugin libraries
431 plugins = new Plugins();
432 #if (defined (WIN32) || (_WIN32))
433 #ifdef _DEBUG
434 string libName = "libMaaateMD.dll";
435 if (!plugins->AddLibrary(libName)) {
436 cerr << "Error loading library libMaaateMD.dll" << endl;
437 delete plugins;
438 exit (1);
439 }
440 #else
441 string libName = "libMaaateM.dll";
442 if (!plugins->AddLibrary(libName)) {
443 cerr << "Error loading library libMaaateM.dll" << endl;
444 delete plugins;
445 exit (1);
446 }
447 #endif
448 #else
449 if (!plugins->AddLibrary(string("libMaaateM.so"))) {
450 cerr << "Error loading library libMaaateM.so" << endl;
451 delete plugins;
452 exit (1);
453 }
454 #endif
455
456 //----------------- sum of scalefactors ------------------------------
457
458 SegmentData *sscf = NULL;
459 if (wantSilence || wantNoise || wantBgLevel || wantSumSCF ||
460 wantSSCFhisto) {
461 // calculate sum of scalefactors between from and to
462 if (verbose) {
463 cout << "\nCalculating sum of scalefactors ..." << endl;
464 }
465 sscf = sumScalefactors(plugins, mpfile, from, to, fromSb, toSb);
466 if (sscf == NULL) {
467 cout << "NULL sscf" << endl;
468 }
469 }
470
471 // if sum of scalefactors requested, print these
472 if (wantSumSCF) {
473 if (wantmatoutput)
474 sscf->matOut(matfilename);
475 else
476 cout << *sscf;
477 }
478
479 //----------------- spectral centroid ------------------------------
480
481 SegmentData *cntroid;
482 if (wantCentroid) {
483 // calculate spectral centroid between from and to
484 if (verbose) {
485 cout << "\nCalculating spectral centroid ..." << endl;
486 }
487 cntroid = spectralCentroid(plugins, mpfile, from, to, fromSb, toSb);
488 if (cntroid == NULL) {
489 cout << "NULL centroid" << endl;
490 }
491 }
492
493 // if spectral centroid requested, print these
494 if (wantCentroid) {
495 if (wantmatoutput)
496 cntroid->matOut(matfilename);
497 else
498 cout << *cntroid;
499 }
500
501 //----------------- background noise level ------------------------------
502
503 double bgLevel;
504 if (wantBgLevel) {
505 if (verbose) {
506 cout << "\nCalculating background noise level ..." << endl;
507 }
508 bgLevel = backgroundNoiseLevel(plugins, sscf, from, to,
509 minDur, maxInterrupt,
510 onsetTime, releaseTime);
511 cout << "BackgroundNoiseLevel=" << bgLevel << endl;
512 }
513
514 // if silence segments requested, calculate
515 SegmentTable *sil;
516 if (wantSilence) {
517 if (verbose) {
518 cout << "\nCalculating silence segments ..." << endl;
519 }
520 sil = silenceSegmentation(plugins, sscf, from, to,
521 thresh, minDur, maxInterrupt,
522 onsetTime, releaseTime);
523 if (sil == NULL) {
524 cerr << argv[0] << ": silence segmentation failed" << endl;
525 } else {
526 if (verbose) {
527 cout << "\nCalculated " << sil->size()
528 << " silence segments ..." << endl;
529 cout << "Start\t\tEnd\t\tDuration\tConfidence" << endl;
530 }
531 // easier: sil->printPlain(false);
532 // this is only to demonstrate how to process one by one
533 int i=0;
534 while(i<sil->size()) {
535 cout << (*sil)[i].start() << "\t"
536 << (*sil)[i].end() << "\t"
537 << (*sil)[i].duration() << "\t"
538 << (*sil)[i].confidence() << endl;
539 i++;
540 }
541 }
542 }
543
544 //----------------- noise segments ------------------------------
545
546 SegmentTable *noise;
547 if (wantNoise) {
548 if (verbose) {
549 cout << "\nCalculating noisy segments ..." << endl;
550 }
551 noise = noiseSegmentation(plugins, sscf, from, to,
552 thresh, minDur, maxInterrupt,
553 onsetTime, releaseTime);
554 if (noise == NULL) {
555 cerr << argv[0] << ": noise segmentation failed" << endl;
556 } else {
557 if (verbose) {
558 cout << "\nCalculated " << noise->size()
559 << " noise segments ..." << endl;
560 cout << "Start - End - Duration" << endl;
561 }
562 noise->printPlain(false);
563 }
564 }
565
566 //----------------- histo of SSCF ------------------------------
567
568 // if want histo of SSCF, print
569 SegmentData *histo = NULL;
570 if (wantSSCFhisto) {
571 if (verbose) {
572 cout << "\nCalculating SSCF histogram ..." << endl;
573 }
574 list<ModuleParam> * paramsOut =
575 histo1D (plugins, sscf, from, to, bins, starthisto, endhisto);
576 list<ModuleParam>::iterator iter;
577 if (paramsOut->size() == 0) {
578 cout << "No paramsOut" << endl;
579 }
580
581 // get resulting data
582 double binwidth;
583 int nrvalues;
584 iter=paramsOut->begin();
585 histo = (*iter).get_sd();
586 ++iter; starthisto = (*iter).get_r();
587 ++iter; endhisto = (*iter).get_r();
588 ++iter; binwidth = (*iter).get_r();
589 ++iter; nrvalues = (*iter).get_i();
590
591 if (histo == NULL) {
592 cerr << argv[0] << ": histogram calculation failed" << endl;
593 } else {
594 cout << "Histogram values:" << endl;
595 cout << *histo;
596 cout << "Values lie between " << starthisto
597 << " and " << endhisto << endl;
598 cout << "Bins are " << binwidth
599 << " wide." << endl;
600 cout << "There were " << nrvalues << " values." << endl;
601 }
602 }
603
604 //----------------- SBnrj ------------------------------
605
606 SegmentData *sbnrj = NULL;
607 if (wantSBnrj || wantbdw) {
608 if (verbose) {
609 cout << "\nCalculating SBnrj ..." << endl;
610 }
611 sbnrj = SBnrj(plugins, mpfile, from, to, fromSb, toSb);
612 if (sbnrj == NULL) {
613 cout << "NULL sbnrj" << endl;
614 }
615 }
616 if (wantSBnrj) {
617 if (wantmatoutput)
618 sbnrj->matOut(matfilename);
619 else
620 cout << *sbnrj;
621 }
622
623
624 //----------------- SBmean ------------------------------
625
626 SegmentData *sbmean;
627 if (wantSBmean) {
628 if (verbose) {
629 cout << "\nCalculating SBmean ..." << endl;
630 }
631 sbmean = SBmean(plugins, mpfile, from, to, fromSb, toSb);
632 if (sbmean == NULL) {
633 cout << "NULL sbmean" << endl;
634 }
635 }
636 if (wantSBmean) {
637 if (wantmatoutput)
638 sbmean->matOut(matfilename);
639 else
640 cout << *sbmean;
641 }
642
643
644 //----------------- SBrms ------------------------------
645
646 SegmentData *sbrms;
647 if (wantSBrms) {
648 if (verbose) {
649 cout << "\nCalculating SBrms ..." << endl;
650 }
651 sbrms = SBrms(plugins, mpfile, from, to, fromSb, toSb);
652 if (sbrms == NULL) {
653 cout << "NULL sbrms" << endl;
654 }
655 }
656 if (wantSBrms) {
657 if (wantmatoutput)
658 sbrms->matOut(matfilename);
659 else
660 cout << *sbrms;
661 }
662
663 //----------------- SBscf ------------------------------
664
665 SegmentData *sbscf;
666 if (wantSBscf) {
667 if (verbose) {
668 cout << "\nCalculating SBscf ..." << endl;
669 }
670 sbscf = SBscf(plugins, mpfile, from, to, fromSb, toSb);
671 if (sbscf == NULL) {
672 cout << "NULL sbscf" << endl;
673 }
674 }
675 if (wantSBscf) {
676 if (wantmatoutput)
677 sbscf->matOut(matfilename);
678 else
679 cout << *sbscf;
680 }
681
682 //----------------- SBv ------------------------------
683
684 SegmentData *sbv;
685 if (wantSBv) {
686 if (verbose) {
687 cout << "\nCalculating SBv ..." << endl;
688 }
689 sbv = SBvalue(plugins, mpfile, from, to, fromSb, toSb);
690 if (sbv == NULL) {
691 cout << "NULL sbv" << endl;
692 }
693 }
694 if (wantSBv) {
695 if (wantmatoutput)
696 sbv->matOut(matfilename);
697 else
698 cout << *sbv;
699 }
700
701 //----------------- SBvmean ------------------------------
702
703 SegmentData *sbvmean;
704 if (wantSBvmean) {
705 if (verbose) {
706 cout << "\nCalculating SBvmean ..." << endl;
707 }
708 sbvmean = SBvaluemean(plugins, mpfile, from, to, fromSb, toSb);
709 if (sbvmean == NULL) {
710 cout << "NULL sbvmean" << endl;
711 }
712 }
713 if (wantSBvmean) {
714 if (wantmatoutput)
715 sbvmean->matOut(matfilename);
716 else
717 cout << *sbvmean;
718 }
719
720 //----------------- SBvrms ------------------------------
721
722 SegmentData *sbvrms;
723 if (wantSBvrms) {
724 if (verbose) {
725 cout << "\nCalculating SBvrms ..." << endl;
726 }
727 sbvrms = SBvaluerms(plugins, mpfile, from, to, fromSb, toSb);
728 if (sbvrms == NULL) {
729 cout << "NULL sbvrms" << endl;
730 }
731 }
732 if (wantSBvrms) {
733 if (wantmatoutput)
734 sbvrms->matOut(matfilename);
735 else
736 cout << *sbvrms;
737 }
738
739 //----------------- SBvnrj ------------------------------
740
741 SegmentData *sbvnrj;
742 if (wantSBvnrj) {
743 if (verbose) {
744 cout << "\nCalculating SBvnrj ..." << endl;
745 }
746 sbvnrj = SBvaluenrj(plugins, mpfile, from, to, fromSb, toSb);
747 if (sbvnrj == NULL) {
748 cout << "NULL sbvnrj" << endl;
749 }
750 }
751 if (wantSBvnrj) {
752 if (wantmatoutput)
753 sbvnrj->matOut(matfilename);
754 else
755 cout << *sbvnrj;
756 }
757
758
759
760 //----------------- signrj ------------------------------
761
762 SegmentData *signrj = NULL;
763 if (wantsignrj || wantpauserate || wantlownrj || wantvariance) {
764 if (verbose) {
765 cout << "\nCalculating signrj ..." << endl;
766 }
767 signrj = signalnrj(plugins, mpfile, from, to, bins);
768 if (signrj == NULL) {
769 cout << "NULL signrj" << endl;
770 }
771 }
772 if (wantsignrj) {
773 if (wantmatoutput)
774 signrj->matOut(matfilename);
775 else
776 cout << *signrj;
777 }
778
779 //----------------- bandnrj ------------------------------
780
781 SegmentData *bandnrj;
782 if (wantbandnrj) {
783 if (verbose) {
784 cout << "\nCalculating bandnrj ..." << endl;
785 }
786 bandnrj = bandNrj(plugins, mpfile, from, to, fromSb, toSb, bins);
787 if (bandnrj == NULL) {
788 cout << "NULL bandnrj" << endl;
789 }
790 }
791 if (wantbandnrj) {
792 if (wantmatoutput)
793 bandnrj->matOut(matfilename);
794 else
795 cout << *bandnrj;
796 }
797
798 //----------------- sigsb ------------------------------
799
800 SegmentData *sigsb;
801 if (wantsigsb) {
802 if (verbose) {
803 cout << "\nCalculating sigsb ..." << endl;
804 }
805 sigsb = sigSb(plugins, mpfile, from, to, thresh);
806 if (sigsb == NULL) {
807 cout << "NULL sigsb" << endl;
808 }
809 }
810 if (wantsigsb) {
811 if (wantmatoutput)
812 sigsb->matOut(matfilename);
813 else
814 cout << *sigsb;
815 }
816
817 //----------------- sigmag ------------------------------
818
819 SegmentData *sigmag;
820 if (wantsigmag) {
821 if (verbose) {
822 cout << "\nCalculating sigmag ..." << endl;
823 }
824 sigmag = signalMagnitude(plugins, mpfile, from, to, bins);
825 if (sigmag == NULL) {
826 cout << "NULL sigmag" << endl;
827 }
828 }
829 if (wantsigmag) {
830 if (wantmatoutput)
831 sigmag->matOut(matfilename);
832 else
833 cout << *sigmag;
834 }
835
836 //----------------- pauserate ------------------------------
837
838 SegmentData *pauserate;
839 if (wantpauserate) {
840 if (verbose) {
841 cout << "\nCalculating pauserate ..." << endl;
842 }
843 pauserate = pauseRate(plugins, signrj, from, to, thresh, minDur);
844 if (pauserate == NULL) {
845 cout << "NULL pauserate" << endl;
846 }
847 }
848 if (wantpauserate) {
849 if (wantmatoutput)
850 pauserate->matOut(matfilename);
851 else
852 cout << *pauserate;
853 }
854
855 //----------------- bandratio ------------------------------
856
857 SegmentData *bandratio;
858 if (wantbandratio) {
859 if (verbose) {
860 cout << "\nCalculating bandratio ..." << endl;
861 }
862 bandratio = BandNrjRatio(plugins, mpfile, from, to, fromSb, toSb);
863 if (bandratio == NULL) {
864 cout << "NULL bandratio" << endl;
865 }
866 }
867 if (wantbandratio) {
868 if (wantmatoutput)
869 bandratio->matOut(matfilename);
870 else
871 cout << *bandratio;
872 }
873
874 //----------------- rolloff ------------------------------
875
876 SegmentData *rolloff;
877 if (wantrolloff) {
878 if (verbose) {
879 cout << "\nCalculating rolloff ..." << endl;
880 }
881 rolloff = rollOff(plugins, mpfile, from, to);
882 if (rolloff == NULL) {
883 cout << "NULL rolloff" << endl;
884 }
885 }
886 if (wantrolloff) {
887 if (wantmatoutput)
888 rolloff->matOut(matfilename);
889 else
890 cout << *rolloff;
891 }
892
893 //----------------- bandwidth ------------------------------
894
895 Trio bd;
896 if (wantbw) {
897 if (verbose) {
898 cout << "\nCalculating bandwidth ..." << endl;
899 }
900 bd = bandwidth(plugins, mpfile, from, to, thresh);
901 if (bd.uno == 0) {
902 cout << "NULL bd" << endl;
903 }
904 }
905 if (wantbw) {
906 cout << "bandwidth :" << endl;
907 cout << *(bd.uno) << endl;
908 cout << "fc min :" << endl;
909 cout << *(bd.dos) << endl;
910 cout << "fc max :" << endl;
911 cout << *(bd.tres) << endl;
912
913 if (wantmatoutput)
914 // only output of bandwidth
915 bd.uno->matOut(matfilename);
916 }
917
918 //----------------- signal bandwidth ------------------------------
919
920 Trio bdw;
921 if (wantbdw) {
922 if (verbose) {
923 cout << "\nCalculating signal bandwidth ..." << endl;
924 }
925 bdw = sigBdwidth(plugins, sbnrj, from, to, thresh);
926 if (bdw.uno == 0) {
927 cout << "NULL bdw" << endl;
928 }
929 }
930 if (wantbdw) {
931 cout << "bandwidth :" << endl;
932 cout << *(bdw.uno) << endl;
933 cout << "fc min :" << endl;
934 cout << *(bdw.dos) << endl;
935 cout << "fc max :" << endl;
936 cout << *(bdw.tres) << endl;
937
938 if (wantmatoutput)
939 // only output of bandwidth
940 bdw.uno->matOut(matfilename);
941 }
942
943 //----------------- spectralflux ------------------------------
944
945 SegmentData *spflux ;
946 if (wantspflux ) {
947 if (verbose) {
948 cout << "\nCalculating spectralflux ..." << endl;
949 }
950 spflux = spectralFlux(plugins, mpfile, from, to);
951 if (spflux == NULL) {
952 cout << "NULL spflux" << endl;
953 }
954 }
955 if (wantspflux) {
956 if (wantmatoutput)
957 spflux->matOut(matfilename);
958 else
959 cout << *spflux;
960 }
961
962 //----------------- centralmoment ------------------------------
963
964 SegmentData *cm;
965 if (wantcm) {
966 if (verbose) {
967 cout << "\nCalculating central moment ..." << endl;
968 }
969 cm = centralMoment(plugins, mpfile, from, to, fromSb, toSb, minDur, bins);
970 if (cm == NULL) {
971 cout << "NULL cm" << endl;
972 }
973 }
974 if (wantcm) {
975 if (wantmatoutput)
976 cm->matOut(matfilename);
977 else
978 cout << *cm;
979 }
980
981 //----------------- lownrj ------------------------------
982
983 SegmentData *lownrj;
984 if (wantlownrj) {
985 if (verbose) {
986 cout << "\nCalculating lownrj ..." << endl;
987 }
988 lownrj = lowNrj(plugins, signrj, from, to, minDur);
989 if (lownrj == NULL) {
990 cout << "NULL lownrj" << endl;
991 }
992 }
993 if (wantlownrj) {
994 if (wantmatoutput)
995 lownrj->matOut(matfilename);
996 else
997 cout << *lownrj;
998 }
999
1000 //----------------- variance ------------------------------
1001
1002 SegmentData *var;
1003 if (wantvariance) {
1004 if (verbose) {
1005 cout << "\nCalculating var ..." << endl;
1006 }
1007 var = variance(plugins, signrj, from, to, minDur);
1008 if (var == NULL) {
1009 cout << "NULL var" << endl;
1010 }
1011 }
1012 if (wantvariance) {
1013 if (wantmatoutput)
1014 var->matOut(matfilename);
1015 else
1016 cout << *var;
1017 }
1018
1019 exit (0);
1020 return 0;
1021 }
1022