41 #include "EST_WaveFile.h"
43 #include "EST_cutils.h"
44 #include "EST_Option.h"
45 #include "EST_io_aux.h"
53 short **data,
int *nsamp,
int *nchan,
56 EST_sample_type_t *stype,
int *bo,
57 int offset,
int length);
60 EST_write_status (*standard_save_fn_fp)(FILE *fp,
62 int offset,
int nsamp,
64 EST_sample_type_t stype,
int bo);
68 EST_read_status load_using(standard_load_fn_fp fn,
72 EST_sample_type_t stype,
int bo,
int nchan,
73 int offset,
int length)
80 EST_read_status status = (*fn)(ts,
81 &data, &nsamp, &nchan,
86 if (status == read_ok)
88 wv.values().
set_memory(data, 0, nsamp, nchan, TRUE);
96 EST_write_status save_using(standard_save_fn_fp fn,
98 EST_sample_type_t stype,
int bo)
100 EST_write_status status = (*fn)(fp,
112 EST_sample_type_t stype,
int bo,
int nchan,
113 int offset,
int length)
115 return load_using(load_wave_nist,
121 EST_write_status EST_WaveFile::save_nist(FILE *fp,
123 EST_sample_type_t stype,
int bo)
125 return save_using(save_wave_nist, fp, wv, stype, bo);
131 EST_sample_type_t stype,
int bo,
int nchan,
132 int offset,
int length)
135 return load_using(load_wave_est,
142 EST_write_status EST_WaveFile::save_est(FILE *fp,
144 EST_sample_type_t stype,
int bo)
146 return save_using(save_wave_est,
155 EST_sample_type_t stype,
int bo,
int nchan,
156 int offset,
int length)
158 return load_using(load_wave_aiff,
164 EST_write_status EST_WaveFile::save_aiff(FILE *fp,
166 EST_sample_type_t stype,
int bo)
168 return save_using(save_wave_aiff, fp, wv, stype, bo);
175 EST_sample_type_t stype,
int bo,
int nchan,
176 int offset,
int length)
178 return load_using(load_wave_riff,
184 EST_write_status EST_WaveFile::save_riff(FILE *fp,
186 EST_sample_type_t stype,
int bo)
188 return save_using(save_wave_riff, fp, wv, stype, bo);
195 EST_sample_type_t stype,
int bo,
int nchan,
196 int offset,
int length)
198 return load_using(load_wave_sd,
204 EST_write_status EST_WaveFile::save_esps(FILE *fp,
206 EST_sample_type_t stype,
int bo)
208 return save_using(save_wave_sd,
217 EST_sample_type_t stype,
int bo,
int nchan,
218 int offset,
int length)
220 return load_using(load_wave_audlab,
226 EST_write_status EST_WaveFile::save_audlab(FILE *fp,
228 EST_sample_type_t stype,
int bo)
230 return save_using(save_wave_audlab, fp, wv, stype, bo);
237 EST_sample_type_t stype,
int bo,
int nchan,
238 int offset,
int length)
240 return load_using(load_wave_snd,
246 EST_write_status EST_WaveFile::save_snd(FILE *fp,
248 EST_sample_type_t stype,
int bo)
250 return save_using(save_wave_snd, fp, wv, stype, bo);
257 EST_sample_type_t stype,
int bo,
int nchan,
258 int offset,
int length)
265 EST_read_status status = load_wave_raw(ts,
266 &data, &nsamp, &nchan,
270 rate, stype, bo, nchan);
272 if (status == read_ok)
274 wv.values().
set_memory(data, 0, nsamp, nchan, TRUE);
281 EST_write_status EST_WaveFile::save_raw(FILE *fp,
283 EST_sample_type_t stype,
int bo)
285 EST_write_status status = save_wave_raw(fp,
286 (
short *)wv.values().
memory(),
297 EST_sample_type_t stype,
int bo,
int nchan,
298 int offset,
int length)
300 return load_using(load_wave_ulaw,
306 EST_write_status EST_WaveFile::save_ulaw(FILE *fp,
308 EST_sample_type_t stype,
int bo)
312 return save_using(save_wave_ulaw, fp, localwv, stype, bo);
315 static int parse_esps_r_option(
EST_String arg,
int &offset,
int &length)
331 cerr <<
"Argument to -r is illformed " << arg << endl;
337 cerr <<
"First argument to -r must be an integer " << arg << endl;
348 length = atoi(e) - offset;
352 cerr <<
"length is negative or zero " << arg << endl;
365 EST_read_status rval;
367 int offset=0, length=0;
371 fname = stdin_to_file();
376 num_channels = al.
ival(
"-n", 0);
389 sample_type = al.
val(
"-istype");
394 file_type = al.
val(
"-itype");
400 sample_rate = al.
ival(
"-f", 0);
401 else if ((sr = getenv(
"NA_PLAY_SAMPLE_RATE")) != NULL)
403 sample_rate = atoi(sr);
404 cerr <<
"Warning: no sample rate specified, " <<
405 " using NA_PLAY_SAMPLE_RATE environment variable\n";
409 sample_rate = EST_Wave::default_sample_rate;
410 if (file_type ==
"raw")
411 cerr <<
"Warning: no sample rate specified - using default " <<
415 if (file_type ==
"ulaw")
418 sample_type =
"mulaw";
423 if (parse_esps_r_option(al.
val(
"-r"), offset, length) != 0)
430 bo = str_to_bo(
"swap");
432 bo = str_to_bo(
"native");
434 bo = str_to_bo(al.
val(
"-ibo"));
436 if (file_type ==
"" ||file_type ==
"undef")
437 rval = sig.
load(fname, offset, length, sample_rate);
439 rval = sig.
load_file(fname,file_type, sample_rate,
440 sample_type, bo, num_channels, offset, length);
442 if ((rval == wrong_format) && (al.
present(
"-basic")))
447 "mulaw", bo, 1, offset, length);
449 if (rval != format_ok)
451 if (in_file ==
"-") unlink(fname);
452 cerr <<
"Cannot recognize file format or cannot access file: \"" << in_file <<
"\"\n";
460 if (in_file ==
"-") unlink(fname);
471 file_type = al.
val(
"-otype");
473 file_type = sig.file_type();
476 sample_type = al.
val(
"-ostype");
478 sample_type =
"undef";
481 bo = str_to_bo(
"swap");
483 bo = str_to_bo(
"native");
486 bo = str_to_bo(al.
val(
"-obo"));
488 if (sample_type ==
"undef" || sample_type ==
"")
489 sample_type =
"short";
491 if (sig.save_file(out_file, file_type,
492 sample_type, bo) != write_ok)
494 cerr <<
"Cannot write file: \"" << out_file <<
"\"\n";
505 for(
int n=0; n< EST_WaveFile::map.n() ; n++)
507 const char *nm = EST_WaveFile::map.name(EST_WaveFile::map.token(n));
518 EST_String EST_WaveFile::options_supported(
void)
520 EST_String s(
"Available wave file formats:\n");
522 for(
int n=0; n< EST_WaveFile::map.n() ; n++)
524 const char *nm = EST_WaveFile::map.name(EST_WaveFile::map.token(n));
525 const char *d = EST_WaveFile::map.info(EST_WaveFile::map.token(n)).description;
532 typedef struct TInfo {
534 const char *description;
543 { wff_none, { NULL },
544 { FALSE, NULL, NULL,
"unknown track file type"} },
545 { wff_nist, {
"nist",
"timit" },
546 { TRUE, EST_WaveFile::load_nist, EST_WaveFile::save_nist,
"nist/timit" } },
548 { TRUE, EST_WaveFile::load_est, EST_WaveFile::save_est,
"est" } },
549 { wff_esps, {
"esps",
"sd"},
550 { TRUE, EST_WaveFile::load_esps, EST_WaveFile::save_esps,
"esps SD waveform" } },
551 { wff_audlab, {
"audlab",
"vox"},
552 { TRUE, EST_WaveFile::load_audlab, EST_WaveFile::save_audlab,
"audlab waveform" } },
553 { wff_snd, {
"snd",
"au"},
554 { TRUE, EST_WaveFile::load_snd, EST_WaveFile::save_snd,
"Sun snd file" } },
555 { wff_aiff, {
"aiff" },
556 { TRUE, EST_WaveFile::load_aiff, EST_WaveFile::save_aiff,
"Apple aiff file" } },
557 { wff_riff, {
"riff",
"wav" },
558 { TRUE, EST_WaveFile::load_riff, EST_WaveFile::save_riff,
"Microsoft wav/riff file" } },
559 { wff_raw, {
"raw" },
560 { FALSE, EST_WaveFile::load_raw, EST_WaveFile::save_raw,
"Headerless File" } },
561 { wff_ulaw, {
"ulaw",
"basic" },
562 { FALSE, EST_WaveFile::load_ulaw, EST_WaveFile::save_ulaw,
"Headerless 8K ulaw File" } },
568 #if defined(INSTANTIATE_TEMPLATES)
570 #include "../base_class/EST_TNamedEnum.cc"