Edinburgh Speech Tools  2.4-release
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 
97  EST_Wave sig;
98  EST_Track spec;
99 
100  parse_command_line
101  (argc, argv,
102  EST_String("[input file] -o [output file]\n")+
103  "Summary: make spectrogram\n"+
104  "use \"-\" to make input and output files stdin/out\n"+
105  "-h Options help\n"+
106  options_wave_input()+
107  "\n"+
108  options_track_output()+
109  "-shift <float> frame spacing in seconds for fixed frame analysis. This \n"
110  " doesn't have to be the same as the output file spacing - the \n"
111  " S option can be used to resample the track before saving \n"
112  " default: "+ftoString(DEFAULT_FRAME_SIZE) +"\n\n"
113  "-length <float> input frame length in milliseconds\n"+
114  "-sr <float> range in which output values should lie\n"+
115  "-slow slow FFT code\n"+
116  "-w <float> white cut off (0.0 to 1.0)\n"+
117  "-b <float> black cut off (0.0 to 1.0)\n"+
118  "-raw Don't perform any scaling\n"+
119  "-order <int> cepstral order\n", files, al);
120 
121  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
122  set_options(op, al);
123 
124  if (read_wave(sig, files.first(), al) != format_ok)
125  exit(-1);
126 
127  make_spectrogram(sig, spec, op);
128 
129  spec.save(out_file, al.val("-otype", 0));
130 
131  return 0;
132 }
133 
134 void set_options(EST_Features &op, EST_Option &al)
135 {
136  op.set("frame_shift", DEFAULT_FRAME_SIZE);
137  op.set("frame_length", DEFAULT_FRAME_LENGTH);
138  op.set("preemph", DEFAULT_PREEMPH);
139  op.set("frame_order", DEFAULT_ORDER);
140 
141  if (al.present("-shift"))
142  op.set("frame_shift", al.fval("-shift"));
143 
144  if (al.present("-length"))
145  op.set("frame_length", al.fval("-length"));
146 
147  if (al.present("-order"))
148  op.set("frame_order", al.fval("-order"));
149 
150  if (al.present("-sr"))
151  op.set("sp_range", al.fval("-sr"));
152 
153  if (al.present("-w"))
154  op.set("sp_wcut", al.fval("-w"));
155 
156  if (al.present("-b"))
157  op.set("sp_bcut", al.fval("-b"));
158 
159  if (al.present("-preemph"))
160  op.set("preemph", al.fval("-preemph", 1));
161 
162  if (al.present("-raw"))
163  op.set("raw", 1);
164 }
EST_Features::set
void set(const EST_String &name, int ival)
Definition: EST_Features.h:185
EST_Option
Definition: EST_Option.h:50
EST_Features
Definition: EST_Features.h:62
EST_Wave
Definition: EST_Wave.h:65
EST_TList
Definition: EST_TList.h:59
EST_TList::first
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:146
EST_TKVL::present
const int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
EST_Option::fval
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:98
EST_String
Definition: EST_String.h:70
EST_Track
Definition: EST_Track.h:89
EST_Track::save
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1230
EST_TKVL::val
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145