Edinburgh Speech Tools  2.1-release
na_play_main.cc
Go to the documentation of this file.
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 /* Authors: Paul Taylor, Alan Black */
34 /* (c) 1995-1999 */
35 /*-----------------------------------------------------------------------*/
36 /* General play back program */
37 /* */
38 /*=======================================================================*/
39 
40 #include "EST.h"
41 #include "EST_audio.h"
42 #include "EST_cmd_line_options.h"
43 
44 using namespace std;
45 
46 int main (int argc, char *argv[])
47 {
48  EST_Wave sig;
49  EST_String in_file("-"), out_file("-");
50  EST_StrList files;
51  EST_Option al;
52  EST_Litem *p;
53 
55  (argc,argv,
56  EST_String("[input file0] [input file1] ...\n")+
57  "Summary; play waveform files on audio device\n"+
58  "use \"-\" to make input and output files stdin/out\n"+
59  "-h options help\n"+
61  "-p <string> audio device protocol. Ths supported types are\n"
62  " "+options_supported_audio()+"\n"
63  "-command <string> command to play wave when protocol\n"+
64  " is audio_command\n"
65  "-basic HTML audio/basic format, if unheadered treat\n"
66  " as ulaw 8K\n\n"
67  "-r* ESPS compatible way of selecting subrange of file.\n"
68  " The options -start, -end, -to and -from are \n"
69  " recommended\n\n"
70  "-quality <string> either [ high | low ]. \"high\" will ensure \n"
71  " that proper resampling is used. \"low\" means play \n"
72  " as fast as possible, with a minimum of processing\n\n"
73  "-server <string> play sound on machine (when protocol is\n"
74  " server-based)\n"
75  "-audiodevice <string> use specified audiodevice if approrpriate\n"
76  " for protocol\n"
77  "-scale <float> change the gain (volume) of the signal. 1.0 is default\n"
78  "-v verbose. Print file names when playing\n"
79  "-wait wait for a key to be pressed between each file\n",
80  files, al);
81 
82  // by default, parse_cl_ops adds a stdout file called "-". This is
83  // irrelevant for na_play and needs to be removed.
84  if (al.present("-server"))
85  al.add_item("-display", al.val("-server"));
86 
87  for (p = files.head(); p; )
88  {
89  if (al.present("-v"))
90  cout << "playing " << files(p) << endl;
91 
92  if (read_wave(sig, files(p), al) != format_ok)
93  exit(-1);
94 
95  EST_Wave tmp, *toplay=&sig;
96 
97  if (al.present("-c"))
98  {
99  wave_extract_channel(tmp,sig,al.ival("-c"));
100  toplay=&tmp;
101  }
102 
103  /*
104  * This is redundant as play_wave does this
105  *
106  else if (sig.num_channels() > 1)
107  {
108  wave_combine_channels(tmp, sig);
109  toplay=&tmp;
110  }
111 */
112 
113  if (al.present("-scale"))
114  (*toplay).rescale(al.fval("-scale"));
115 
116  play_wave(*toplay, al);
117 
118  // pause for a keystroke between each file
119  if (al.present("-wait") && p->next())
120  {
121  if (getc(stdin) == 'a')
122  continue;
123  }
124  p = p->next();
125  }
126  return 0;
127 }
128 
130 {
131  // Reorg -- can be deleted ?
132  // general options
133  a_list.override_val("sample_rate", al.val("-f", 0));
134 
135  // low pass filtering options.
136  a_list.override_val("lpf_cutoff",al.val("-u", 0));
137  a_list.override_val("lpf_order",al.val("-o", 0));
138 
139  if (al.val("-L", 0) == "true")
140  a_list.override_val("do_low_pass", "true");
141  if (al.val("-R", 0) == "true")
142  a_list.override_val("do_low_pass", "false");
143  a_list.override_val("color", al.val("-color", 0));
144  a_list.override_val("f0_file_type", al.val("-otype", 0));
145  a_list.override_val("wave_file_type", al.val("-itype", 0));
146 }
147 
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
int override_val(const EST_String rkey, const EST_String rval)
add to end of list or overwrite. If rval is empty, do nothing
Definition: EST_Option.cc:54
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
int wave_extract_channel(EST_Wave &single, const EST_Wave &multi, int channel)
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:104
void rescale(float gain, int normalize=0)
Definition: EST_Wave.cc:506
EST_UItem * next()
Definition: EST_UList.h:55
int main(int argc, char *argv[])
Definition: na_play_main.cc:46
EST_String options_wave_input(void)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
Definition: EST_TKVL.cc:248
EST_read_status read_wave(EST_Wave &sig, const EST_String &in_file, EST_Option &al)
#define format_ok
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_UItem * head() const
Definition: EST_UList.h:97
EST_String options_supported_audio(void)
Definition: gen_audio.cc:249
void override_lib_ops(EST_Option &a_list, EST_Option &al)
EST_String
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101
int play_wave(EST_Wave &inwave, EST_Option &al)
Definition: gen_audio.cc:62