Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends 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 /** @name <command>spectgen</command> <emphasis>Make spectrograms</emphasis>
52  * @id spectgen-manual
53  * @toc
54  */
55 
56 //@{
57 
58 /**@name Synopsis
59  */
60 //@{
61 
62 //@synopsis
63 
64 /**
65 spectgen is used to create spectrograms, which are 3d plots of
66 amplitude against time and frequency. Spectgen takes a waveform and
67 produces a track, where each channel represents one frequency bin.
68 
69 By default spectgen produces a "wide-band" spectrogram, that is one
70 with high time resolution and low frequency resolution. "Narrow-band"
71 spectrograms can be produced by using the -shift and -length options.
72 
73 Typical values for -shift and -length are:
74 
75 
76 
77 */
78 
79 //@}
80 
81 /**@name Options
82  */
83 //@{
84 
85 //@options
86 
87 //@}
88 
89 
90 int main(int argc, char *argv[])
91 {
92  EST_String out_file;
93  EST_StrList files;
94  EST_Option al;
95  EST_Features op;
96  int orig_sr;
97 
98  EST_Wave sig;
99  EST_Track spec;
100 
101  parse_command_line
102  (argc, argv,
103  EST_String("[input file] -o [output file]\n")+
104  "Summary: make spectrogram\n"+
105  "use \"-\" to make input and output files stdin/out\n"+
106  "-h Options help\n"+
107  options_wave_input()+
108  "\n"+
109  options_track_output()+
110  "-shift <float> frame spacing in seconds for fixed frame analysis. This \n"
111  " doesn't have to be the same as the output file spacing - the \n"
112  " S option can be used to resample the track before saving \n"
113  " default: "+ftoString(DEFAULT_FRAME_SIZE) +"\n\n"
114  "-length <float> input frame length in milliseconds\n"+
115  "-sr <float> range in which output values should lie\n"+
116  "-slow slow FFT code\n"+
117  "-w <float> white cut off (0.0 to 1.0)\n"+
118  "-b <float> black cut off (0.0 to 1.0)\n"+
119  "-raw Don't perform any scaling\n"+
120  "-order <int> cepstral order\n", files, al);
121 
122  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
123  set_options(op, al);
124 
125  if (read_wave(sig, files.first(), al) != format_ok)
126  exit(-1);
127  orig_sr = sig.sample_rate();
128 
129  make_spectrogram(sig, spec, op);
130 
131  spec.save(out_file, al.val("-otype", 0));
132 
133  return 0;
134 }
135 
136 void set_options(EST_Features &op, EST_Option &al)
137 {
138  op.set("frame_shift", DEFAULT_FRAME_SIZE);
139  op.set("frame_length", DEFAULT_FRAME_LENGTH);
140  op.set("preemph", DEFAULT_PREEMPH);
141  op.set("frame_order", DEFAULT_ORDER);
142 
143  if (al.present("-shift"))
144  op.set("frame_shift", al.fval("-shift"));
145 
146  if (al.present("-length"))
147  op.set("frame_length", al.fval("-length"));
148 
149  if (al.present("-order"))
150  op.set("frame_order", al.fval("-order"));
151 
152  if (al.present("-sr"))
153  op.set("sp_range", al.fval("-sr"));
154 
155  if (al.present("-w"))
156  op.set("sp_wcut", al.fval("-w"));
157 
158  if (al.present("-b"))
159  op.set("sp_bcut", al.fval("-b"));
160 
161  if (al.present("-preemph"))
162  op.set("preemph", al.fval("-preemph", 1));
163 
164  if (al.present("-raw"))
165  op.set("raw", 1);
166 }