Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
spectgen_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 /* Author: Paul Taylor */
34 /* Date : April 1995 */
35 /*-----------------------------------------------------------------------*/
36 /* Generate feature vectors */
37 /* */
38 /*=======================================================================*/
39 
40 #include "EST.h"
41 #include "EST_cmd_line_options.h"
42 #include "sigpr/EST_spectrogram.h"
43 
44 #define DEFAULT_FRAME_SIZE 0.001
45 #define DEFAULT_FRAME_LENGTH 0.008
46 #define DEFAULT_ORDER 256
47 #define DEFAULT_PREEMPH 0.94
48 
49 void set_options(EST_Features &op, EST_Option &al);
50 
51 
52 
53 int main(int argc, char *argv[])
54 {
55  EST_String out_file;
56  EST_StrList files;
57  EST_Option al;
58  EST_Features op;
59  int orig_sr;
60 
61  EST_Wave sig;
62  EST_Track spec;
63 
64  parse_command_line
65  (argc, argv,
66  EST_String("[input file] -o [output file]\n")+
67  "Summary: make spectrogram\n"+
68  "use \"-\" to make input and output files stdin/out\n"+
69  "-h Options help\n"+
70  options_wave_input()+
71  "\n"+
72  options_track_output()+
73  "-shift <float> frame spacing in seconds for fixed frame analysis. This \n"
74  " doesn't have to be the same as the output file spacing - the \n"
75  " S option can be used to resample the track before saving \n"
76  " default: "+ftoString(DEFAULT_FRAME_SIZE) +"\n\n"
77  "-length <float> input frame length in milliseconds\n"+
78  "-sr <float> range in which output values should lie\n"+
79  "-slow slow FFT code\n"+
80  "-w <float> white cut off (0.0 to 1.0)\n"+
81  "-b <float> black cut off (0.0 to 1.0)\n"+
82  "-raw Don't perform any scaling\n"+
83  "-order <int> cepstral order\n", files, al);
84 
85  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
86  set_options(op, al);
87 
88  if (read_wave(sig, files.first(), al) != format_ok)
89  exit(-1);
90  orig_sr = sig.sample_rate();
91 
92  make_spectrogram(sig, spec, op);
93 
94  spec.save(out_file, al.val("-otype", 0));
95 
96  return 0;
97 }
98 
99 void set_options(EST_Features &op, EST_Option &al)
100 {
101  op.set("frame_shift", DEFAULT_FRAME_SIZE);
102  op.set("frame_length", DEFAULT_FRAME_LENGTH);
103  op.set("preemph", DEFAULT_PREEMPH);
104  op.set("frame_order", DEFAULT_ORDER);
105 
106  if (al.present("-shift"))
107  op.set("frame_shift", al.fval("-shift"));
108 
109  if (al.present("-length"))
110  op.set("frame_length", al.fval("-length"));
111 
112  if (al.present("-order"))
113  op.set("frame_order", al.fval("-order"));
114 
115  if (al.present("-sr"))
116  op.set("sp_range", al.fval("-sr"));
117 
118  if (al.present("-w"))
119  op.set("sp_wcut", al.fval("-w"));
120 
121  if (al.present("-b"))
122  op.set("sp_bcut", al.fval("-b"));
123 
124  if (al.present("-preemph"))
125  op.set("preemph", al.fval("-preemph", 1));
126 
127  if (al.present("-raw"))
128  op.set("raw", 1);
129 }
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:154
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
EST_String ftoString(float n, int pres=3, int width=0, int l=0)
Make a EST_String object from an float, with variable precision.
Definition: util_io.cc:148
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1230
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 sample_rate() const
return the sampling rate (frequency)
Definition: EST_Wave.h:147