Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
na_play_main.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 /* 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 int main (int argc, char *argv[])
45 {
46  EST_Wave sig;
47  EST_String in_file("-"), out_file("-");
48  EST_StrList files;
49  EST_Option al;
50  EST_Litem *p;
51 
52  parse_command_line
53  (argc,argv,
54  EST_String("[input file0] [input file1] ...\n")+
55  "Summary; play waveform files on audio device\n"+
56  "use \"-\" to make input and output files stdin/out\n"+
57  "-h options help\n"+
58  options_wave_input()+
59  "-p <string> audio device protocol. Ths supported types are\n"
60  " "+options_supported_audio()+"\n"
61  "-command <string> command to play wave when protocol\n"+
62  " is audio_command\n"
63  "-basic HTML audio/basic format, if unheadered treat\n"
64  " as ulaw 8K\n\n"
65  "-r* ESPS compatible way of selecting subrange of file.\n"
66  " The options -start, -end, -to and -from are \n"
67  " recommended\n\n"
68  "-quality <string> either [ high | low ]. \"high\" will ensure \n"
69  " that proper resampling is used. \"low\" means play \n"
70  " as fast as possible, with a minimum of processing\n\n"
71  "-server <string> play sound on machine (when protocol is\n"
72  " server-based)\n"
73  "-audiodevice <string> use specified audiodevice if approrpriate\n"
74  " for protocol\n"
75  "-scale <float> change the gain (volume) of the signal. 1.0 is default\n"
76  "-v verbose. Print file names when playing\n"
77  "-wait wait for a key to be pressed between each file\n",
78  files, al);
79 
80  // by default, parse_cl_ops adds a stdout file called "-". This is
81  // irrelevant for na_play and needs to be removed.
82  if (al.present("-server"))
83  al.add_item("-display", al.val("-server"));
84 
85  for (p = files.head(); p; )
86  {
87  if (al.present("-v"))
88  cout << "playing " << files(p) << endl;
89 
90  if (read_wave(sig, files(p), al) != format_ok)
91  exit(-1);
92 
93  EST_Wave tmp, *toplay=&sig;
94 
95  if (al.present("-c"))
96  {
97  wave_extract_channel(tmp,sig,al.ival("-c"));
98  toplay=&tmp;
99  }
100 
101  /*
102  * This is redundant as play_wave does this
103  *
104  else if (sig.num_channels() > 1)
105  {
106  wave_combine_channels(tmp, sig);
107  toplay=&tmp;
108  }
109 */
110 
111  if (al.present("-scale"))
112  (*toplay).rescale(al.fval("-scale"));
113 
114  play_wave(*toplay, al);
115 
116  // pause for a keystroke between each file
117  if (al.present("-wait") && p->next())
118  {
119  if (getc(stdin) == 'a')
120  continue;
121  }
122  p = p->next();
123  }
124  return 0;
125 }
126 
127 void override_lib_ops(EST_Option &a_list, EST_Option &al)
128 {
129  // Reorg -- can be deleted ?
130  // general options
131  a_list.override_val("sample_rate", al.val("-f", 0));
132 
133  // low pass filtering options.
134  a_list.override_val("lpf_cutoff",al.val("-u", 0));
135  a_list.override_val("lpf_order",al.val("-o", 0));
136 
137  if (al.val("-L", 0) == "true")
138  a_list.override_val("do_low_pass", "true");
139  if (al.val("-R", 0) == "true")
140  a_list.override_val("do_low_pass", "false");
141  a_list.override_val("color", al.val("-color", 0));
142  a_list.override_val("f0_file_type", al.val("-otype", 0));
143  a_list.override_val("wave_file_type", al.val("-itype", 0));
144 }
145 
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:48
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:76
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
void rescale(float gain, int normalize=0)
Definition: EST_Wave.cc:501
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
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