Edinburgh Speech Tools  2.4-release
EST_WaveFile.cc
1  /*************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1995,1996 */
6  /* All Rights Reserved. */
7  /* */
8  /* Permission is hereby granted, free of charge, to use and distribute */
9  /* this software and its documentation without restriction, including */
10  /* without limitation the rights to use, copy, modify, merge, publish, */
11  /* distribute, sublicense, and/or sell copies of this work, and to */
12  /* permit persons to whom this work is furnished to do so, subject to */
13  /* the following conditions: */
14  /* 1. The code must retain the above copyright notice, this list of */
15  /* conditions and the following disclaimer. */
16  /* 2. Any modifications must be clearly marked as such. */
17  /* 3. Original authors' names are not deleted. */
18  /* 4. The authors' names are not used to endorse or promote products */
19  /* derived from this software without specific prior written */
20  /* permission. */
21  /* */
22  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30  /* THIS SOFTWARE. */
31  /* */
32  /*************************************************************************/
33  /* */
34  /* Author : Richard Caley <rjc@cstr.ed.ac.uk> */
35  /* ------------------------------------------------------------------- */
36  /* Wave file input and output. */
37  /* */
38  /*************************************************************************/
39 #include <cstdlib>
40 #include "EST_Wave.h"
41 #include "EST_WaveFile.h"
42 #include "waveP.h"
43 #include "EST_cutils.h"
44 #include "EST_Option.h"
45 #include "EST_io_aux.h"
46 #include <cstdio>
47 #include <cmath>
48 
49 void extract(EST_Wave &sig, EST_Option &al);
50 
51 typedef
52 EST_read_status (*standard_load_fn_fp)(EST_TokenStream &ts,
53  short **data, int *nsamp, int *nchan,
54  int *wsize,
55  int *srate,
56  EST_sample_type_t *stype, int *bo,
57  int offset, int length);
58 
59 typedef
60 EST_write_status (*standard_save_fn_fp)(FILE *fp,
61  const short *data,
62  int offset, int nsamp,
63  int nchan, int srate,
64  EST_sample_type_t stype, int bo);
65 
66 typedef
67 EST_write_status (*standard_save_header_fn_fp)(FILE *fp,
68  int nsamp,
69  int nchan, int srate,
70  EST_sample_type_t stype, int bo);
71 
72 static
73 EST_read_status load_using(standard_load_fn_fp fn,
74  EST_TokenStream &ts,
75  EST_Wave &wv,
76  int rate,
77  EST_sample_type_t stype, int bo, int nchan,
78  int offset, int length)
79 {
80  short *data;
81  int nsamp;
82  int wsize;
83  int srate = rate;
84 
85  EST_read_status status = (*fn)(ts,
86  &data, &nsamp, &nchan,
87  &wsize,
88  &srate, &stype, &bo,
89  offset, length);
90 
91  if (status == read_ok)
92  {
93  short *data2 = new short[nsamp*nchan];
94  memcpy(data2, data, nsamp*nchan*sizeof(short));
95  wfree(data);
96  wv.values().set_memory(data2, 0, nsamp, nchan, TRUE);
97  wv.set_sample_rate(srate);
98  }
99 
100  return status;
101 }
102 
103 static
104 EST_write_status save_using(standard_save_fn_fp fn,
105  FILE *fp, const EST_Wave wv,
106  EST_sample_type_t stype, int bo)
107 {
108 EST_write_status status = (*fn)(fp,
109  wv.values().memory(),
110  0, wv.num_samples(), wv.num_channels(),
111  wv.sample_rate(),
112  stype, bo);
113 
114 return status;
115 }
116 
117 static
118 EST_write_status save_header_using(standard_save_header_fn_fp fn,
119  FILE *fp, const EST_Wave wv,
120  EST_sample_type_t stype, int bo)
121 {
122 
123 EST_write_status status = (*fn)(fp,
124  wv.num_samples(), wv.num_channels(),
125  wv.sample_rate(),
126  stype, bo);
127 return status;
128 }
129 
130 EST_read_status EST_WaveFile::load_nist(EST_TokenStream &ts,
131  EST_Wave &wv,
132  int rate,
133  EST_sample_type_t stype, int bo, int nchan,
134  int offset, int length)
135 {
136  return load_using(load_wave_nist,
137  ts, wv, rate,
138  stype, bo, nchan,
139  offset, length);
140 }
141 
142 EST_write_status EST_WaveFile::save_nist(FILE *fp,
143  const EST_Wave &wv,
144  EST_sample_type_t stype, int bo)
145 {
146  return save_using(save_wave_nist, fp, wv, stype, bo);
147 }
148 
149 EST_write_status EST_WaveFile::save_nist_data(FILE *fp,
150  const EST_Wave &wv,
151  EST_sample_type_t stype, int bo)
152 {
153  return save_using(save_wave_nist_data, fp, wv, stype, bo);
154 }
155 
156 EST_write_status EST_WaveFile::save_nist_header(FILE *fp,
157  const EST_Wave &wv,
158  EST_sample_type_t stype, int bo)
159 {
160  return save_header_using(save_wave_nist_header, fp, wv, stype, bo);
161 }
162 
163 EST_read_status EST_WaveFile::load_est(EST_TokenStream &ts,
164  EST_Wave &wv,
165  int rate,
166  EST_sample_type_t stype, int bo, int nchan,
167  int offset, int length)
168 {
169  (void) ts;
170  return load_using(load_wave_est,
171  ts, wv, rate,
172  stype, bo, nchan,
173  offset, length);
174 
175 }
176 
177 EST_write_status EST_WaveFile::save_est(FILE *fp,
178  const EST_Wave &wv,
179  EST_sample_type_t stype, int bo)
180 {
181  return save_using(save_wave_est,
182  fp, wv,
183  stype, bo);
184 }
185 
186 EST_write_status EST_WaveFile::save_est_data(FILE *fp,
187  const EST_Wave &wv,
188  EST_sample_type_t stype, int bo)
189 {
190  return save_using(save_wave_est_data,
191  fp, wv,
192  stype, bo);
193 }
194 
195 EST_write_status EST_WaveFile::save_est_header(FILE *fp,
196  const EST_Wave &wv,
197  EST_sample_type_t stype, int bo)
198 {
199  return save_header_using(save_wave_est_header,
200  fp, wv,
201  stype, bo);
202 }
203 
204 EST_read_status EST_WaveFile::load_aiff(EST_TokenStream &ts,
205  EST_Wave &wv,
206  int rate,
207  EST_sample_type_t stype, int bo, int nchan,
208  int offset, int length)
209 {
210  return load_using(load_wave_aiff,
211  ts, wv, rate,
212  stype, bo, nchan,
213  offset, length);
214 }
215 
216 EST_write_status EST_WaveFile::save_aiff(FILE *fp,
217  const EST_Wave &wv,
218  EST_sample_type_t stype, int bo)
219 {
220  return save_using(save_wave_aiff, fp, wv, stype, bo);
221 }
222 
223 EST_write_status EST_WaveFile::save_aiff_data(FILE *fp,
224  const EST_Wave &wv,
225  EST_sample_type_t stype, int bo)
226 {
227  return save_using(save_wave_aiff_data, fp, wv, stype, bo);
228 }
229 
230 EST_write_status EST_WaveFile::save_aiff_header(FILE *fp,
231  const EST_Wave &wv,
232  EST_sample_type_t stype, int bo)
233 {
234  return save_header_using(save_wave_aiff_header, fp, wv, stype, bo);
235 }
236 
237 EST_read_status EST_WaveFile::load_riff(EST_TokenStream &ts,
238  EST_Wave &wv,
239  int rate,
240  EST_sample_type_t stype, int bo, int nchan,
241  int offset, int length)
242 {
243  return load_using(load_wave_riff,
244  ts, wv, rate,
245  stype, bo, nchan,
246  offset, length);
247 }
248 
249 EST_write_status EST_WaveFile::save_riff(FILE *fp,
250  const EST_Wave &wv,
251  EST_sample_type_t stype, int bo)
252 {
253  return save_using(save_wave_riff, fp, wv, stype, bo);
254 }
255 
256 EST_write_status EST_WaveFile::save_riff_data(FILE *fp,
257  const EST_Wave &wv,
258  EST_sample_type_t stype, int bo)
259 {
260  return save_using(save_wave_riff_data, fp, wv, stype, bo);
261 }
262 
263 EST_write_status EST_WaveFile::save_riff_header(FILE *fp,
264  const EST_Wave &wv,
265  EST_sample_type_t stype, int bo)
266 {
267  return save_header_using(save_wave_riff_header, fp, wv, stype, bo);
268 }
269 
270 EST_read_status EST_WaveFile::load_esps(EST_TokenStream &ts,
271  EST_Wave &wv,
272  int rate,
273  EST_sample_type_t stype, int bo, int nchan,
274  int offset, int length)
275 {
276  return load_using(load_wave_sd,
277  ts, wv, rate,
278  stype, bo, nchan,
279  offset, length);
280 }
281 
282 EST_write_status EST_WaveFile::save_esps(FILE *fp,
283  const EST_Wave &wv,
284  EST_sample_type_t stype, int bo)
285 {
286  return save_using(save_wave_sd,
287  fp, wv,
288  stype, bo);
289 }
290 
291 EST_write_status EST_WaveFile::save_esps_data(FILE *fp,
292  const EST_Wave &wv,
293  EST_sample_type_t stype, int bo)
294 {
295  return save_using(save_wave_sd_data,
296  fp, wv,
297  stype, bo);
298 }
299 
300 EST_write_status EST_WaveFile::save_esps_header(FILE *fp,
301  const EST_Wave &wv,
302  EST_sample_type_t stype, int bo)
303 {
304  return save_header_using(save_wave_sd_header,
305  fp, wv,
306  stype, bo);
307 }
308 
309 EST_read_status EST_WaveFile::load_audlab(EST_TokenStream &ts,
310  EST_Wave &wv,
311  int rate,
312  EST_sample_type_t stype, int bo, int nchan,
313  int offset, int length)
314 {
315  return load_using(load_wave_audlab,
316  ts, wv, rate,
317  stype, bo, nchan,
318  offset, length);
319 }
320 
321 EST_write_status EST_WaveFile::save_audlab(FILE *fp,
322  const EST_Wave &wv,
323  EST_sample_type_t stype, int bo)
324 {
325  return save_using(save_wave_audlab, fp, wv, stype, bo);
326 }
327 
328 EST_write_status EST_WaveFile::save_audlab_data(FILE *fp,
329  const EST_Wave &wv,
330  EST_sample_type_t stype, int bo)
331 {
332  return save_using(save_wave_audlab_data, fp, wv, stype, bo);
333 }
334 
335 EST_write_status EST_WaveFile::save_audlab_header(FILE *fp,
336  const EST_Wave &wv,
337  EST_sample_type_t stype, int bo)
338 {
339  return save_header_using(save_wave_audlab_header, fp, wv, stype, bo);
340 }
341 
342 EST_read_status EST_WaveFile::load_snd(EST_TokenStream &ts,
343  EST_Wave &wv,
344  int rate,
345  EST_sample_type_t stype, int bo, int nchan,
346  int offset, int length)
347 {
348  return load_using(load_wave_snd,
349  ts, wv, rate,
350  stype, bo, nchan,
351  offset, length);
352 }
353 
354 EST_write_status EST_WaveFile::save_snd(FILE *fp,
355  const EST_Wave &wv,
356  EST_sample_type_t stype, int bo)
357 {
358  return save_using(save_wave_snd, fp, wv, stype, bo);
359 }
360 
361 EST_write_status EST_WaveFile::save_snd_data(FILE *fp,
362  const EST_Wave &wv,
363  EST_sample_type_t stype, int bo)
364 {
365  return save_using(save_wave_snd_data, fp, wv, stype, bo);
366 }
367 
368 EST_write_status EST_WaveFile::save_snd_header(FILE *fp,
369  const EST_Wave &wv,
370  EST_sample_type_t stype, int bo)
371 {
372  return save_header_using(save_wave_snd_header, fp, wv, stype, bo);
373 }
374 
375 
376 
377 EST_read_status EST_WaveFile::load_raw(EST_TokenStream &ts,
378  EST_Wave &wv,
379  int rate,
380  EST_sample_type_t stype, int bo, int nchan,
381  int offset, int length)
382 {
383  short *data;
384  int nsamp;
385  int wsize;
386  int srate = rate;
387 
388  EST_read_status status = load_wave_raw(ts,
389  &data, &nsamp, &nchan,
390  &wsize,
391  &srate, &stype, &bo,
392  offset, length,
393  rate, stype, bo, nchan);
394 
395  if (status == read_ok)
396  {
397  wv.values().set_memory(data, 0, nsamp, nchan, TRUE);
398  wv.set_sample_rate(srate);
399  }
400 
401  return status;
402 }
403 
404 EST_write_status EST_WaveFile::save_raw(FILE *fp,
405  const EST_Wave &wv,
406  EST_sample_type_t stype, int bo)
407 {
408 EST_write_status status = save_wave_raw(fp,
409  (short *)wv.values().memory(),
410  0, wv.num_samples(), wv.num_channels(),
411  wv.sample_rate(),
412  stype, bo);
413 return status;
414 }
415 
416 EST_write_status EST_WaveFile::save_raw_data(FILE *fp,
417  const EST_Wave &wv,
418  EST_sample_type_t stype, int bo)
419 {
420 return save_raw(fp, wv, stype, bo);
421 }
422 
423 
424 EST_write_status EST_WaveFile::save_raw_header(FILE *fp,
425  const EST_Wave &wv,
426  EST_sample_type_t stype, int bo)
427 {
428  return save_header_using(save_wave_raw_header, fp, wv, stype, bo);
429 }
430 
431 EST_read_status EST_WaveFile::load_ulaw(EST_TokenStream &ts,
432  EST_Wave &wv,
433  int rate,
434  EST_sample_type_t stype, int bo, int nchan,
435  int offset, int length)
436 {
437  return load_using(load_wave_ulaw,
438  ts, wv, rate,
439  stype, bo, nchan,
440  offset, length);
441 }
442 
443 EST_write_status EST_WaveFile::save_ulaw(FILE *fp,
444  const EST_Wave &wv,
445  EST_sample_type_t stype, int bo)
446 {
447  EST_Wave localwv = wv;
448  localwv.resample(8000);
449  return save_using(save_wave_ulaw, fp, localwv, stype, bo);
450 }
451 
452 EST_write_status EST_WaveFile::save_ulaw_data(FILE *fp,
453  const EST_Wave &wv,
454  EST_sample_type_t stype, int bo)
455 {
456  EST_Wave localwv = wv;
457  localwv.resample(8000);
458  return save_using(save_wave_ulaw_data, fp, localwv, stype, bo);
459 }
460 
461 
462 EST_write_status EST_WaveFile::save_ulaw_header(FILE *fp,
463  const EST_Wave &wv,
464  EST_sample_type_t stype, int bo)
465 {
466  EST_Wave localwv = wv;
467  localwv.resample(8000);
468  return save_header_using(save_wave_ulaw_header, fp, localwv, stype, bo);
469 }
470 
471 EST_read_status EST_WaveFile::load_alaw(EST_TokenStream &ts,
472  EST_Wave &wv,
473  int rate,
474  EST_sample_type_t stype, int bo, int nchan,
475  int offset, int length)
476 {
477  return load_using(load_wave_alaw,
478  ts, wv, rate,
479  stype, bo, nchan,
480  offset, length);
481 }
482 
483 EST_write_status EST_WaveFile::save_alaw_header(FILE *fp,
484  const EST_Wave &wv,
485  EST_sample_type_t stype, int bo)
486 {
487  EST_Wave localwv = wv;
488  localwv.resample(8000);
489  return save_header_using(save_wave_alaw_header, fp, localwv, stype, bo);
490 }
491 
492 EST_write_status EST_WaveFile::save_alaw_data(FILE *fp,
493  const EST_Wave &wv,
494  EST_sample_type_t stype, int bo)
495 {
496  EST_Wave localwv = wv;
497  localwv.resample(8000);
498  return save_using(save_wave_alaw_data, fp, localwv, stype, bo);
499 }
500 
501 EST_write_status EST_WaveFile::save_alaw(FILE *fp,
502  const EST_Wave &wv,
503  EST_sample_type_t stype, int bo)
504 {
505  EST_Wave localwv = wv;
506  localwv.resample(8000);
507  return save_using(save_wave_alaw, fp, localwv, stype, bo);
508 }
509 
510 static int parse_esps_r_option(EST_String arg, int &offset, int &length)
511 {
512  EST_String s, e;
513 
514  if (arg.contains("-"))
515  {
516  s = arg.before("-");
517  e = arg.after("-");
518  }
519  else if (arg.contains(":"))
520  {
521  s = arg.before(":");
522  e = arg.after(":");
523  }
524  else
525  {
526  cerr << "Argument to -r is illformed " << arg << endl;
527  return -1;
528  }
529 
530  if (!s.matches(RXint))
531  {
532  cerr << "First argument to -r must be an integer " << arg << endl;
533  return -1;
534  }
535 
536  offset = atoi(s);
537  if (e.contains("+"))
538  {
539  e = e.after("+");
540  length = atoi(e);
541  }
542  else
543  length = atoi(e) - offset;
544 
545  if (length <= 0)
546  {
547  cerr << "length is negative or zero " << arg << endl;
548  return -1;
549  }
550 
551  return 0;
552 }
553 
554 EST_read_status read_wave(EST_Wave &sig, const EST_String &in_file,
555  EST_Option &al)
556 {
557  char *sr;
558  EST_String fname, file_type, sample_type;
559  int sample_rate;
560  EST_read_status rval;
561  int num_channels;
562  int offset=0, length=0;
563  int bo;
564 
565  if (in_file == "-")
566  fname = stdin_to_file();
567  else
568  fname = in_file;
569 
570  if (al.present("-n"))
571  num_channels = al.ival("-n", 0);
572  else
573  num_channels = 1;
574 
575  if (al.present("-ulaw"))
576  {
577  al.add_item("-itype","ulaw");
578  al.add_item("-f","8000");
579  }
580  if (al.present("-alaw"))
581  {
582 al.add_item("-itype","alaw");
583 al.add_item("-f","8000");
584  }
585  if (al.present("-iswap"))
586  al.add_item("-ibo","other");
587 
588  if (al.present("-istype"))
589  sample_type = al.val("-istype");
590  else
591  sample_type = sig.sample_type(); // else default type;
592 
593  if (al.present("-itype"))
594  file_type = al.val("-itype"); // else default type;
595  else
596  file_type = "undef";
597 
598 
599  if (al.present("-f"))
600  sample_rate = al.ival("-f", 0);
601  else if ((sr = getenv("NA_PLAY_SAMPLE_RATE")) != NULL)
602  {
603  sample_rate = atoi(sr);
604  cerr << "Warning: no sample rate specified, " <<
605  " using NA_PLAY_SAMPLE_RATE environment variable\n";
606  }
607  else
608  {
609  sample_rate = EST_Wave::default_sample_rate;
610  if (file_type == "raw")
611  cerr << "Warning: no sample rate specified - using default " <<
612  sample_rate << endl;
613  }
614 
615  if (file_type == "ulaw")
616  {
617  sample_rate = 8000;
618  sample_type = "mulaw";
619  }
620 
621  if (al.present("-r")) // only load in part of waveform
622  {
623  if (parse_esps_r_option(al.val("-r"), offset, length) != 0)
624  return read_error;
625  }
626  else
627  offset = length = 0;
628 
629  if (al.present("-iswap"))
630  bo = str_to_bo("swap");
631  else
632  bo = str_to_bo("native");
633  if (al.present("-ibo")) // can override -iswap
634  bo = str_to_bo(al.val("-ibo"));
635 
636  if (file_type == "" ||file_type == "undef")
637  rval = sig.load(fname, offset, length, sample_rate);
638  else
639  rval = sig.load_file(fname,file_type, sample_rate,
640  sample_type, bo, num_channels, offset, length);
641 
642  if ((rval == wrong_format) && (al.present("-basic")))
643  {
644  // For HTML audio/basic, it seems to mean headered or ulaw 8k
645  // so try to load it again as ulaw 8k.
646  rval = sig.load_file(fname, "raw", 8000,
647  "mulaw", bo, 1, offset, length);
648  }
649  if (rval != format_ok)
650  {
651  if (in_file == "-") unlink(fname);
652  cerr << "Cannot recognize file format or cannot access file: \"" << in_file << "\"\n";
653  return read_error;
654  }
655  if (file_type == "alaw")
656  {
657 sample_rate = 8000;
658 sample_type = "alaw";
659  }
660 
661  if (al.present("-start") || al.present("-end")
662  || al.present("-to") || al.present("-from"))
663  extract(sig, al);
664 
665  if (in_file == "-") unlink(fname);
666  return read_ok;
667 }
668 
669 EST_write_status write_wave(EST_Wave &sig, const EST_String &out_file,
670  EST_Option &al)
671 {
672  EST_String file_type, sample_type;
673  int bo;
674 
675  if (al.present("-otype"))
676  file_type = al.val("-otype");
677  else
678  file_type = sig.file_type();
679 
680  if (al.present("-ostype"))
681  sample_type = al.val("-ostype");
682  else
683  sample_type = "undef";
684 
685  if (al.present("-oswap"))
686  bo = str_to_bo("swap");
687  else
688  bo = str_to_bo("native");
689 
690  if (al.present("-obo")) // can over ride -oswap
691  bo = str_to_bo(al.val("-obo"));
692 
693  if (sample_type == "undef" || sample_type == "")
694  sample_type = "short";
695 
696  if (sig.save_file(out_file, file_type,
697  sample_type, bo) != write_ok)
698  {
699  cerr << "Cannot write file: \"" << out_file << "\"\n";
700  return write_error;
701  }
702 
703  return write_ok;
704 }
705 
706 EST_String EST_WaveFile::options_short(void)
707 {
708  EST_String s("");
709 
710  for(int n=0; n< EST_WaveFile::map.n() ; n++)
711  {
712  const char *nm = EST_WaveFile::map.name(EST_WaveFile::map.token(n));
713 
714  if (s != "")
715  s += ", ";
716 
717  s += nm;
718 
719  }
720  return s;
721 }
722 
723 EST_String EST_WaveFile::options_supported(void)
724 {
725  EST_String s("Available wave file formats:\n");
726 
727  for(int n=0; n< EST_WaveFile::map.n() ; n++)
728  {
729  const char *nm = EST_WaveFile::map.name(EST_WaveFile::map.token(n));
730  const char *d = EST_WaveFile::map.info(EST_WaveFile::map.token(n)).description;
731 
732  s += EST_String::cat(" ", nm, EST_String(" ")*(12-strlen(nm)), d, "\n");
733  }
734  return s;
735 }
736 
737 typedef struct TInfo {
738  bool recognise;
739  const char *description;
740 } TInfo;
741 
742 // note the order here defines the order in which loads are tried.
743 
744 
745 static
747 {
748  { wff_none, { NULL },
749  { FALSE, NULL, NULL, NULL, NULL, "unknown track file type"} },
750  { wff_nist, { "nist", "timit" },
751  { TRUE, EST_WaveFile::load_nist, EST_WaveFile::save_nist,
752  EST_WaveFile::save_nist_header, EST_WaveFile::save_nist_data,
753  "nist/timit" } },
754  { wff_est, { "est"},
755  { TRUE, EST_WaveFile::load_est, EST_WaveFile::save_est,
756  EST_WaveFile::save_est_header, EST_WaveFile::save_est_data,
757  "est" } },
758  { wff_esps, { "esps", "sd"},
759  { TRUE, EST_WaveFile::load_esps, EST_WaveFile::save_esps,
760  EST_WaveFile::save_esps_header, EST_WaveFile::save_esps_data,
761  "esps SD waveform" } },
762  { wff_audlab, { "audlab", "vox"},
763  { TRUE, EST_WaveFile::load_audlab, EST_WaveFile::save_audlab,
764  EST_WaveFile::save_audlab_header, EST_WaveFile::save_audlab_data,
765  "audlab waveform" } },
766  { wff_snd, { "snd", "au"},
767  { TRUE, EST_WaveFile::load_snd, EST_WaveFile::save_snd,
768  EST_WaveFile::save_snd_header, EST_WaveFile::save_snd_data,
769  "Sun snd file" } },
770  { wff_aiff, { "aiff" },
771  { TRUE, EST_WaveFile::load_aiff, EST_WaveFile::save_aiff,
772  EST_WaveFile::save_aiff_header, EST_WaveFile::save_aiff_data,
773  "Apple aiff file" } },
774  { wff_riff, { "riff", "wav" },
775  { TRUE, EST_WaveFile::load_riff, EST_WaveFile::save_riff,
776  EST_WaveFile::save_riff_header, EST_WaveFile::save_riff_data,
777  "Microsoft wav/riff file" } },
778  { wff_raw, { "raw" },
779  { FALSE, EST_WaveFile::load_raw, EST_WaveFile::save_raw,
780  EST_WaveFile::save_raw_header, EST_WaveFile::save_raw_data,
781  "Headerless File" } },
782  { wff_ulaw, { "ulaw", "basic" },
783  { FALSE, EST_WaveFile::load_ulaw, EST_WaveFile::save_ulaw,
784  EST_WaveFile::save_ulaw_header, EST_WaveFile::save_ulaw_data,
785  "Headerless 8K ulaw File" } },
786  { wff_none, {NULL} }
787 };
788 
789 EST_TNamedEnumI<EST_WaveFileType, EST_WaveFile::Info> EST_WaveFile::map(wavefile_names);
790 
791 #if defined(INSTANTIATE_TEMPLATES)
792 
793 #include "../base_class/EST_TNamedEnum.cc"
795 template class EST_TValuedEnumI<EST_WaveFileType, const char *,
796 EST_WaveFile::Info>;
797 
798 #endif
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
EST_String before(int pos, int len=0) const
Part before position.
Definition: EST_String.h:286
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
Definition: EST_String.cc:1096
int contains(const char *s, int pos=-1) const
Does it contain this substring?
Definition: EST_String.h:375
EST_String after(int pos, int len=1) const
Part after pos+len.
Definition: EST_String.h:318
int matches(const char *e, int pos=0) const
Exactly match this string?
Definition: EST_String.cc:652
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
Definition: EST_TKVL.cc:248
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
void set_memory(T *buffer, int offset, int rows, int columns, int free_when_destroyed=0)
Definition: EST_TMatrix.cc:371
const T * memory() const
Definition: EST_TVector.h:241
EST_read_status load_file(const EST_String filename, const EST_String filetype, int sample_rate, const EST_String sample_type, int bo, int nc, int offset=0, int length=0)
Definition: EST_Wave.cc:288
int num_channels() const
return the number of channels in the waveform
Definition: EST_Wave.h:145
int sample_rate() const
return the sampling rate (frequency)
Definition: EST_Wave.h:147
EST_read_status load(const EST_String filename, int offset=0, int length=0, int rate=default_sample_rate)
Definition: EST_Wave.cc:180
void resample(int rate)
Resample waveform to rate
Definition: EST_Wave.cc:489
EST_String sample_type() const
Definition: EST_Wave.h:163
int num_samples() const
return the number of samples in the waveform
Definition: EST_Wave.h:143
void set_sample_rate(const int n)
Set sampling rate to n
Definition: EST_Wave.h:149