Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
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
49void 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/**
65spectgen is used to create spectrograms, which are 3d plots of
66amplitude against time and frequency. Spectgen takes a waveform and
67produces a track, where each channel represents one frequency bin.
68
69By default spectgen produces a "wide-band" spectrogram, that is one
70with high time resolution and low frequency resolution. "Narrow-band"
71spectrograms can be produced by using the -shift and -length options.
72
73Typical 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
90int main(int argc, char *argv[])
91{
92 EST_String out_file;
95 EST_Features op;
96
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
134void 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}
void set(const EST_String &name, int ival)