Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends 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 /** @name <command>na_play</command><emphasis> Audio Playback</emphasis>
45  @id na_play_manual
46  * @toc
47  */
48 
49 //@{
50 
51 
52 /**@name Synopsis
53  */
54 //@{
55 
56 //@synopsis
57 
58 /**
59 
60 
61 na_play is a general playback program for playing sound files on a variety
62 of platforms and sound cards.
63 
64 Currently, the following audio devices are supported:
65 
66 <itemizedlist mark='@bullet'>
67 <listitem><para>sunaudio:</para><para>
68 8k ulaw direct to <filename>/dev/audio</filename> found on most Sun machines. This
69 is also found under Linux and FreeBSD, and possibly others. This
70 is the default if <function>netaudio</function> is not supported.
71 <listitem><para>netaudio:</para><para>
72 NCD's network transparent audio system (NAS). This allows
73 use of audio devices across a network. NAS has support for, Suns,
74 Linux, FreeBSD, HPs and probably other machines by now.
75 <listitem><para>sun16audio:</para><para>
76 This is only available on newer Sun workstations and has been
77 enabled at compile time. This provides
78 16bit linear PCM at various sample rates.
79 <listitem><para>linux16audio:</para><para>
80 This is only available on Linux workstations and has been enabled
81 at compile time. This provides
82 16bit linear PCM at various sample rates.
83 <listitem><para>freebsd16audio:</para><para>
84 This is only available on workstations running FreeBSD and has
85 been enabled at compile time. This provides
86 16bit linear PCM at various sample rates.
87 <listitem><para>mplayeraudio:</para><para>
88 This is only available under Windows NT 4.0 and Windows 95 and
89 has been enabled at compile time. This provides
90 16bit linear PCM at various sample rates.
91 <listitem><para>win32audio</para><para>
92 This is only available under Windows NT 4.0 and Windows 95 and
93 has been enabled at compile time. This provides
94 16bit linear PCM at various sample rates, playing the audio directly
95 rather than saving to a file as with mplayeraudio.
96 <listitem><para>irixaudio</para><para>
97 Audio support for SGI's IRIX 6.2.
98 <listitem><para>Audio_Command:</para><para>
99 Allows the specification of an arbitrary UNIX command to play
100 the waveform. This won't normally be used with <function>na_play</function> as
101 you could just use the command directly but is necessary with some
102 systems using the speech tools.
103 </itemizedlist>
104 </para>
105 
106 <para>
107 The default audio is netaudio if it is supported. If not the platform
108 specific auido mode is the default (e.g. sun16audio, linux16audio,
109 freebsd16audio or mplayeraudio). If none of these is supported,
110 sunaudio is the default.
111 */
112 
113 //@}
114 
115 /**@name OPTIONS
116  */
117 //@{
118 
119 //@options
120 
121 //@}
122 
123 
124 int main (int argc, char *argv[])
125 {
126  EST_Wave sig;
127  EST_String in_file("-"), out_file("-");
128  EST_StrList files;
129  EST_Option al;
130  EST_Litem *p;
131 
132  parse_command_line
133  (argc,argv,
134  EST_String("[input file0] [input file1] ...\n")+
135  "Summary; play waveform files on audio device\n"+
136  "use \"-\" to make input and output files stdin/out\n"+
137  "-h options help\n"+
138  options_wave_input()+
139  "-p <string> audio device protocol. Ths supported types are\n"
140  " "+options_supported_audio()+"\n"
141  "-command <string> command to play wave when protocol\n"+
142  " is audio_command\n"
143  "-basic HTML audio/basic format, if unheadered treat\n"
144  " as ulaw 8K\n\n"
145  "-r* ESPS compatible way of selecting subrange of file.\n"
146  " The options -start, -end, -to and -from are \n"
147  " recommended\n\n"
148  "-quality <string> either [ high | low ]. \"high\" will ensure \n"
149  " that proper resampling is used. \"low\" means play \n"
150  " as fast as possible, with a minimum of processing\n\n"
151  "-server <string> play sound on machine (when protocol is\n"
152  " server-based)\n"
153  "-audiodevice <string> use specified audiodevice if approrpriate\n"
154  " for protocol\n"
155  "-scale <float> change the gain (volume) of the signal. 1.0 is default\n"
156  "-v verbose. Print file names when playing\n"
157  "-wait wait for a key to be pressed between each file\n",
158  files, al);
159 
160  // by default, parse_cl_ops adds a stdout file called "-". This is
161  // irrelevant for na_play and needs to be removed.
162  if (al.present("-server"))
163  al.add_item("-display", al.val("-server"));
164 
165  for (p = files.head(); p; )
166  {
167  if (al.present("-v"))
168  cout << "playing " << files(p) << endl;
169 
170  if (read_wave(sig, files(p), al) != format_ok)
171  exit(-1);
172 
173  EST_Wave tmp, *toplay=&sig;
174 
175  if (al.present("-c"))
176  {
177  wave_extract_channel(tmp,sig,al.ival("-c"));
178  toplay=&tmp;
179  }
180 
181  /*
182  * This is redundant as play_wave does this
183  *
184  else if (sig.num_channels() > 1)
185  {
186  wave_combine_channels(tmp, sig);
187  toplay=&tmp;
188  }
189 */
190 
191  if (al.present("-scale"))
192  (*toplay).rescale(al.fval("-scale"));
193 
194  play_wave(*toplay, al);
195 
196  // pause for a keystroke between each file
197  if (al.present("-wait") && p->next())
198  {
199  if (getc(stdin) == 'a')
200  continue;
201  }
202  p = p->next();
203  }
204  return 0;
205 }
206 
207 void override_lib_ops(EST_Option &a_list, EST_Option &al)
208 {
209  // Reorg -- can be deleted ?
210  // general options
211  a_list.override_val("sample_rate", al.val("-f", 0));
212 
213  // low pass filtering options.
214  a_list.override_val("lpf_cutoff",al.val("-u", 0));
215  a_list.override_val("lpf_order",al.val("-o", 0));
216 
217  if (al.val("-L", 0) == "true")
218  a_list.override_val("do_low_pass", "true");
219  if (al.val("-R", 0) == "true")
220  a_list.override_val("do_low_pass", "false");
221  a_list.override_val("color", al.val("-color", 0));
222  a_list.override_val("f0_file_type", al.val("-otype", 0));
223  a_list.override_val("wave_file_type", al.val("-itype", 0));
224 }
225