Edinburgh Speech Tools  2.1-release
spectgen_main.cc
Go to the documentation of this file.
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 using namespace std;
45 
46 #define DEFAULT_FRAME_SIZE 0.001
47 #define DEFAULT_FRAME_LENGTH 0.008
48 #define DEFAULT_ORDER 256
49 #define DEFAULT_PREEMPH 0.94
50 
51 void set_options(EST_Features &op, EST_Option &al);
52 
53 
54 
55 int main(int argc, char *argv[])
56 {
57  EST_String out_file;
58  EST_StrList files;
59  EST_Option al;
60  EST_Features op;
61 
62  EST_Wave sig;
63  EST_Track spec;
64 
66  (argc, argv,
67  EST_String("[input file] -o [output file]\n")+
68  "Summary: make spectrogram\n"+
69  "use \"-\" to make input and output files stdin/out\n"+
70  "-h Options help\n"+
72  "\n"+
74  "-shift <float> frame spacing in seconds for fixed frame analysis. This \n"
75  " doesn't have to be the same as the output file spacing - the \n"
76  " S option can be used to resample the track before saving \n"
77  " default: "+ftoString(DEFAULT_FRAME_SIZE) +"\n\n"
78  "-length <float> input frame length in milliseconds\n"+
79  "-sr <float> range in which output values should lie\n"+
80  "-slow slow FFT code\n"+
81  "-w <float> white cut off (0.0 to 1.0)\n"+
82  "-b <float> black cut off (0.0 to 1.0)\n"+
83  "-raw Don't perform any scaling\n"+
84  "-order <int> cepstral order\n", files, al);
85 
86  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
87  set_options(op, al);
88 
89  if (read_wave(sig, files.first(), al) != format_ok)
90  exit(-1);
91 
92  make_spectrogram(sig, spec, op);
93 
94  spec.save(out_file, al.val("-otype", 0));
95 
96  return 0;
97 }
98 
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
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:104
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:149
#define DEFAULT_FRAME_SIZE
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1233
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:152
EST_String options_wave_input(void)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
EST_String options_track_output(void)
void make_spectrogram(EST_Wave &sig, EST_Track &sp, EST_Features &op)
Definition: spectrogram.cc:53
EST_read_status read_wave(EST_Wave &sig, const EST_String &in_file, EST_Option &al)
void set_options(EST_Features &op, EST_Option &al)
#define format_ok
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222
#define DEFAULT_PREEMPH
EST_String
int parse_command_line(int argc, char *argv[], const EST_String &usage, EST_StrList &files, EST_Option &al, int make_stdio=1)
Definition: cmd_line.cc:101
int main(int argc, char *argv[])
#define DEFAULT_ORDER
#define DEFAULT_FRAME_LENGTH