41#include "EST_WaveFile.h"
43#include "EST_cutils.h"
44#include "EST_Option.h"
45#include "EST_io_aux.h"
56 EST_sample_type_t *
stype,
int *
bo,
57 int offset,
int length);
60EST_write_status (*standard_save_fn_fp)(
FILE *fp,
62 int offset,
int nsamp,
64 EST_sample_type_t
stype,
int bo);
67EST_write_status (*standard_save_header_fn_fp)(
FILE *fp,
70 EST_sample_type_t
stype,
int bo);
73EST_read_status load_using(standard_load_fn_fp
fn,
78 int offset,
int length)
104EST_write_status save_using(standard_save_fn_fp
fn,
106 EST_sample_type_t
stype,
int bo)
108EST_write_status
status = (*fn)(fp,
109 wv.values().memory(),
110 0,
wv.num_samples(),
wv.num_channels(),
118EST_write_status save_header_using(standard_save_header_fn_fp
fn,
120 EST_sample_type_t
stype,
int bo)
123EST_write_status
status = (*fn)(fp,
124 wv.num_samples(),
wv.num_channels(),
134 int offset,
int length)
136 return load_using(load_wave_nist,
142EST_write_status EST_WaveFile::save_nist(
FILE *fp,
144 EST_sample_type_t
stype,
int bo)
146 return save_using(save_wave_nist, fp,
wv,
stype,
bo);
149EST_write_status EST_WaveFile::save_nist_data(
FILE *fp,
151 EST_sample_type_t
stype,
int bo)
153 return save_using(save_wave_nist_data, fp,
wv,
stype,
bo);
156EST_write_status EST_WaveFile::save_nist_header(
FILE *fp,
158 EST_sample_type_t
stype,
int bo)
160 return save_header_using(save_wave_nist_header, fp,
wv,
stype,
bo);
167 int offset,
int length)
170 return load_using(load_wave_est,
177EST_write_status EST_WaveFile::save_est(
FILE *fp,
179 EST_sample_type_t
stype,
int bo)
181 return save_using(save_wave_est,
186EST_write_status EST_WaveFile::save_est_data(
FILE *fp,
188 EST_sample_type_t
stype,
int bo)
190 return save_using(save_wave_est_data,
195EST_write_status EST_WaveFile::save_est_header(
FILE *fp,
197 EST_sample_type_t
stype,
int bo)
199 return save_header_using(save_wave_est_header,
208 int offset,
int length)
210 return load_using(load_wave_aiff,
216EST_write_status EST_WaveFile::save_aiff(
FILE *fp,
218 EST_sample_type_t
stype,
int bo)
220 return save_using(save_wave_aiff, fp,
wv,
stype,
bo);
223EST_write_status EST_WaveFile::save_aiff_data(
FILE *fp,
225 EST_sample_type_t
stype,
int bo)
227 return save_using(save_wave_aiff_data, fp,
wv,
stype,
bo);
230EST_write_status EST_WaveFile::save_aiff_header(
FILE *fp,
232 EST_sample_type_t
stype,
int bo)
234 return save_header_using(save_wave_aiff_header, fp,
wv,
stype,
bo);
241 int offset,
int length)
243 return load_using(load_wave_riff,
249EST_write_status EST_WaveFile::save_riff(
FILE *fp,
251 EST_sample_type_t
stype,
int bo)
253 return save_using(save_wave_riff, fp,
wv,
stype,
bo);
256EST_write_status EST_WaveFile::save_riff_data(
FILE *fp,
258 EST_sample_type_t
stype,
int bo)
260 return save_using(save_wave_riff_data, fp,
wv,
stype,
bo);
263EST_write_status EST_WaveFile::save_riff_header(
FILE *fp,
265 EST_sample_type_t
stype,
int bo)
267 return save_header_using(save_wave_riff_header, fp,
wv,
stype,
bo);
274 int offset,
int length)
276 return load_using(load_wave_sd,
282EST_write_status EST_WaveFile::save_esps(
FILE *fp,
284 EST_sample_type_t
stype,
int bo)
286 return save_using(save_wave_sd,
291EST_write_status EST_WaveFile::save_esps_data(
FILE *fp,
293 EST_sample_type_t
stype,
int bo)
295 return save_using(save_wave_sd_data,
300EST_write_status EST_WaveFile::save_esps_header(
FILE *fp,
302 EST_sample_type_t
stype,
int bo)
304 return save_header_using(save_wave_sd_header,
313 int offset,
int length)
315 return load_using(load_wave_audlab,
321EST_write_status EST_WaveFile::save_audlab(
FILE *fp,
323 EST_sample_type_t
stype,
int bo)
325 return save_using(save_wave_audlab, fp,
wv,
stype,
bo);
328EST_write_status EST_WaveFile::save_audlab_data(
FILE *fp,
330 EST_sample_type_t
stype,
int bo)
332 return save_using(save_wave_audlab_data, fp,
wv,
stype,
bo);
335EST_write_status EST_WaveFile::save_audlab_header(
FILE *fp,
337 EST_sample_type_t
stype,
int bo)
339 return save_header_using(save_wave_audlab_header, fp,
wv,
stype,
bo);
346 int offset,
int length)
348 return load_using(load_wave_snd,
354EST_write_status EST_WaveFile::save_snd(
FILE *fp,
356 EST_sample_type_t
stype,
int bo)
358 return save_using(save_wave_snd, fp,
wv,
stype,
bo);
361EST_write_status EST_WaveFile::save_snd_data(
FILE *fp,
363 EST_sample_type_t
stype,
int bo)
365 return save_using(save_wave_snd_data, fp,
wv,
stype,
bo);
368EST_write_status EST_WaveFile::save_snd_header(
FILE *fp,
370 EST_sample_type_t
stype,
int bo)
372 return save_header_using(save_wave_snd_header, fp,
wv,
stype,
bo);
381 int offset,
int length)
388 EST_read_status
status = load_wave_raw(
ts,
404EST_write_status EST_WaveFile::save_raw(
FILE *fp,
406 EST_sample_type_t
stype,
int bo)
408EST_write_status
status = save_wave_raw(fp,
409 (
short *)
wv.values().memory(),
410 0,
wv.num_samples(),
wv.num_channels(),
416EST_write_status EST_WaveFile::save_raw_data(
FILE *fp,
418 EST_sample_type_t
stype,
int bo)
424EST_write_status EST_WaveFile::save_raw_header(
FILE *fp,
426 EST_sample_type_t
stype,
int bo)
428 return save_header_using(save_wave_raw_header, fp,
wv,
stype,
bo);
435 int offset,
int length)
437 return load_using(load_wave_ulaw,
443EST_write_status EST_WaveFile::save_ulaw(
FILE *fp,
445 EST_sample_type_t
stype,
int bo)
452EST_write_status EST_WaveFile::save_ulaw_data(
FILE *fp,
454 EST_sample_type_t
stype,
int bo)
462EST_write_status EST_WaveFile::save_ulaw_header(
FILE *fp,
464 EST_sample_type_t
stype,
int bo)
468 return save_header_using(save_wave_ulaw_header, fp,
localwv,
stype,
bo);
475 int offset,
int length)
477 return load_using(load_wave_alaw,
483EST_write_status EST_WaveFile::save_alaw_header(
FILE *fp,
485 EST_sample_type_t
stype,
int bo)
489 return save_header_using(save_wave_alaw_header, fp,
localwv,
stype,
bo);
492EST_write_status EST_WaveFile::save_alaw_data(
FILE *fp,
494 EST_sample_type_t
stype,
int bo)
501EST_write_status EST_WaveFile::save_alaw(
FILE *fp,
503 EST_sample_type_t
stype,
int bo)
510static int parse_esps_r_option(
EST_String arg,
int &offset,
int &length)
514 if (
arg.contains(
"-"))
519 else if (
arg.contains(
":"))
526 cerr <<
"Argument to -r is illformed " <<
arg <<
endl;
532 cerr <<
"First argument to -r must be an integer " <<
arg <<
endl;
543 length =
atoi(
e) - offset;
547 cerr <<
"length is negative or zero " <<
arg <<
endl;
560 EST_read_status
rval;
562 int offset=0, length=0;
566 fname = stdin_to_file();
570 if (
al.present(
"-n"))
571 num_channels =
al.ival(
"-n", 0);
575 if (
al.present(
"-ulaw"))
577 al.add_item(
"-itype",
"ulaw");
578 al.add_item(
"-f",
"8000");
580 if (
al.present(
"-alaw"))
582al.add_item(
"-itype",
"alaw");
583al.add_item(
"-f",
"8000");
585 if (
al.present(
"-iswap"))
586 al.add_item(
"-ibo",
"other");
588 if (
al.present(
"-istype"))
589 sample_type =
al.val(
"-istype");
591 sample_type =
sig.sample_type();
593 if (
al.present(
"-itype"))
594 file_type =
al.val(
"-itype");
599 if (
al.present(
"-f"))
600 sample_rate =
al.ival(
"-f", 0);
601 else if ((
sr = getenv(
"NA_PLAY_SAMPLE_RATE")) != NULL)
604 cerr <<
"Warning: no sample rate specified, " <<
605 " using NA_PLAY_SAMPLE_RATE environment variable\n";
609 sample_rate = EST_Wave::default_sample_rate;
610 if (file_type ==
"raw")
611 cerr <<
"Warning: no sample rate specified - using default " <<
615 if (file_type ==
"ulaw")
618 sample_type =
"mulaw";
621 if (
al.present(
"-r"))
623 if (parse_esps_r_option(
al.val(
"-r"), offset, length) != 0)
629 if (
al.present(
"-iswap"))
630 bo = str_to_bo(
"swap");
632 bo = str_to_bo(
"native");
633 if (
al.present(
"-ibo"))
634 bo = str_to_bo(
al.val(
"-ibo"));
636 if (file_type ==
"" ||file_type ==
"undef")
640 sample_type,
bo, num_channels, offset, length);
642 if ((
rval == wrong_format) && (
al.present(
"-basic")))
647 "mulaw",
bo, 1, offset, length);
649 if (
rval != format_ok)
652 cerr <<
"Cannot recognize file format or cannot access file: \"" <<
in_file <<
"\"\n";
655 if (file_type ==
"alaw")
661 if (
al.present(
"-start") ||
al.present(
"-end")
662 ||
al.present(
"-to") ||
al.present(
"-from"))
675 if (
al.present(
"-otype"))
676 file_type =
al.val(
"-otype");
678 file_type =
sig.file_type();
680 if (
al.present(
"-ostype"))
681 sample_type =
al.val(
"-ostype");
683 sample_type =
"undef";
685 if (
al.present(
"-oswap"))
686 bo = str_to_bo(
"swap");
688 bo = str_to_bo(
"native");
690 if (
al.present(
"-obo"))
691 bo = str_to_bo(
al.val(
"-obo"));
693 if (sample_type ==
"undef" || sample_type ==
"")
694 sample_type =
"short";
696 if (
sig.save_file(out_file, file_type,
697 sample_type,
bo) != write_ok)
699 cerr <<
"Cannot write file: \"" << out_file <<
"\"\n";
710 for(
int n=0; n< EST_WaveFile::map.n() ; n++)
712 const char *
nm = EST_WaveFile::map.name(EST_WaveFile::map.token(n));
723EST_String EST_WaveFile::options_supported(
void)
725 EST_String s(
"Available wave file formats:\n");
727 for(
int n=0; n< EST_WaveFile::map.n() ; n++)
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;
737typedef struct TInfo {
739 const char *description;
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,
755 { TRUE, EST_WaveFile::load_est, EST_WaveFile::save_est,
756 EST_WaveFile::save_est_header, EST_WaveFile::save_est_data,
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,
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" } },
791#if defined(INSTANTIATE_TEMPLATES)
793#include "../base_class/EST_TNamedEnum.cc"
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)
int matches(const char *e, int pos=0) const
Exactly match this string?