Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pda_main.cc
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 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 : May 1994 */
35 /*-----------------------------------------------------------------------*/
36 /* Pitch Detection Algorithm Main routine */
37 /* */
38 /*=======================================================================*/
39 #include <fstream>
40 #include "EST.h"
41 #include "sigpr/EST_sigpr_utt.h"
42 #include "EST_cmd_line_options.h"
43 
44 void set_parameters(EST_Features &a_list, EST_Option &al);
45 
46 void option_override(EST_Features &op, EST_Option al,
47  const EST_String &option, const EST_String &arg);
48 
49 static int save_pm(EST_String filename, EST_Track fz);
50 
51 
52 
53 int main (int argc, char *argv[])
54 {
55  EST_Track fz;
56  EST_Wave sig;
57  EST_Option al;
58  EST_Features op;
59  EST_String out_file("-");
60  EST_StrList files;
61 
62  parse_command_line
63  (argc, argv,
64  EST_String("[input file] -o [output file] [options]\n")+
65  "Summary: pitch track waveform files\n"
66  "use \"-\" to make input and output files stdin/out\n"
67  "-h Options help\n\n"+
68  options_wave_input()+
69  options_pda_general()+
70  options_pda_srpd()+
71  options_track_output(),
72  files, al);
73 
75  set_parameters(op, al);
76 
77  if (read_wave(sig, files.first(), al) != format_ok)
78  exit(-1);
79 
80  out_file = al.present("-o") ? al.val("-o") : (EST_String)"-";
81 
82  pda(sig, fz, op); // do f0 tracking
83 
84  if (al.present("-pm"))
85  save_pm(out_file, fz);
86  else
87  fz.save(out_file, op.S("f0_file_type", "0"));
88 
89  if (al.present("-diff"))
90  {
91  fz = differentiate(fz);
92  fz.save(out_file + ".diff", op.S("f0_file_type", "0"));
93  }
94  return 0;
95 }
96 
97 
98 void set_parameters(EST_Features &op, EST_Option &al)
99 {
100  op.set("srpd_resize", 1);
101 
102  // general options
103  option_override(op, al, "pda_frame_shift", "-shift");
104  option_override(op, al, "pda_frame_length", "-length");
105  option_override(op, al, "max_pitch", "-fmax");
106  option_override(op, al, "min_pitch", "-fmin");
107 
108  // low pass filtering options.
109  option_override(op, al, "lpf_cutoff", "-u");
110  option_override(op, al, "lpf_order", "-forder");
111 
112  option_override(op, al, "decimation", "-d");
113  option_override(op, al, "noise_floor", "-n");
114  option_override(op, al, "min_v2uv_coef_thresh", "-m");
115  option_override(op, al, "v2uv_coef_thresh_ratio", "-R");
116  option_override(op, al, "v2uv_coef_thresh", "-H");
117  option_override(op, al, "anti_doubling_thresh", "-t");
118  option_override(op, al, "peak_tracking", "-P");
119 
120  option_override(op, al, "f0_file_type", "-otype");
121  option_override(op, al, "wave_file_type", "-itype");
122 
123  if (al.val("-L", 0) == "true")
124  op.set("do_low_pass", "true");
125  if (al.val("-R", 0) == "true")
126  op.set("do_low_pass", "false");
127 
128 
129 /* op.set("lpf_cutoff",al.val("-u", 0));
130  op.set("lpf_order",al.val("-forder", 0));
131 
132  //sprd options
133  op.set("decimation", al.val("-d", 0));
134  op.set("noise_floor", al.val("-n", 0));
135  op.set("min_v2uv_coef_thresh", al.val("-m", 0));
136  op.set("v2uv_coef_thresh_ratio", al.val("-r", 0));
137  op.set("v2uv_coef_thresh", al.val("-H", 0));
138  op.set("anti_doubling_thresh", al.val("-t", 0));
139  op.set("peak_tracking", al.val("-P", 0));
140  if (al.val("-L", 0) == "true")
141  op.set("do_low_pass", "true");
142  if (al.val("-R", 0) == "true")
143  op.set("do_low_pass", "false");
144  op.set("f0_file_type", al.val("-otype", 0));
145  op.set("wave_file_type", al.val("-itype", 0));
146 */
147 }
148 
149 /* a_list.override_val("sample_rate", al.val("-f", 0));
150  a_list.override_val("min_pitch", al.val("-fmin", 0));
151  a_list.override_val("max_pitch", al.val("-fmax", 0));
152  a_list.override_val("pda_frame_shift", al.val("-s", 0));
153  a_list.override_val("pda_frame_length",al.val("-l", 0));
154 
155  // low pass filtering options.
156  a_list.override_val("lpf_cutoff",al.val("-u", 0));
157  a_list.override_val("lpf_order",al.val("-forder", 0));
158 
159  //sprd options
160  a_list.override_val("decimation", al.val("-d", 0));
161  a_list.override_val("noise_floor", al.val("-n", 0));
162  a_list.override_val("min_v2uv_coef_thresh", al.val("-m", 0));
163  a_list.override_val("v2uv_coef_thresh_ratio", al.val("-r", 0));
164  a_list.override_val("v2uv_coef_thresh", al.val("-H", 0));
165  a_list.override_val("anti_doubling_thresh", al.val("-t", 0));
166  a_list.override_val("peak_tracking", al.val("-P", 0));
167  if (al.val("-L", 0) == "true")
168  a_list.override_val("do_low_pass", "true");
169  if (al.val("-R", 0) == "true")
170  a_list.override_val("do_low_pass", "false");
171  a_list.override_val("f0_file_type", al.val("-otype", 0));
172  a_list.override_val("wave_file_type", al.val("-itype", 0));
173 */
174 
175 
176 static int save_pm(EST_String filename, EST_Track fz)
177 {
178  ostream *outf;
179  float position, period;
180 
181  if (filename == "-")
182  outf = &cout;
183  else
184  outf = new ofstream(filename);
185 
186  if (!(*outf))
187  {
188  cerr << "save_pm: can't write to file \"" << filename << "\"" << endl;
189  return -1;
190  }
191 
192  *outf << "XAO1\n\n"; // xmg header identifier.
193  *outf << "LineType bars \n";
194  *outf << "LineStyle solid \n";
195  *outf << "LineWidth 0 \n";
196  *outf << "Freq 16\n";
197  *outf << "Format Binary \n";
198  *outf << char(12) << "\n"; // control L character
199 
200  position = 0.0;
201  int gap = 0;
202  for (int i = 0; i < fz.num_frames(); ++i)
203  {
204  if (fz.val(i))
205  {
206  if (gap)
207  {
208  position = fz.t(i);
209  gap = 0;
210  }
211  period = 1.0 / fz.a(i);
212  *outf << (position + period) * 1000.0 << endl;
213  position += period;
214  }
215  else
216  gap = 1;
217  }
218 
219  if (outf != &cout)
220  delete outf;
221 
222  return 0;
223 }
224 
225 
A class for storing digital waveforms. The waveform is stored as an array of 16 bit shorts...
Definition: EST_Wave.h:64
float & t(int i=0)
return time position of frame i
Definition: EST_Track.h:477
float & a(int i, int c=0)
Definition: EST_Track.cc:1022
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
const EST_String S(const EST_String &path) const
Definition: EST_Features.h:158
void default_pda_options(EST_Features &al)
Definition: pda.cc:227
EST_write_status save(const EST_String name, const EST_String EST_filetype="")
Definition: EST_Track.cc:1230
int val(int i) const
return true if frame i is a value
Definition: EST_Track.cc:539
const T & first() const
return const reference to first item in list
Definition: EST_TList.h:154
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
void pda(EST_Wave &sig, EST_Track &fz, EST_Features &op, EST_String method="")
Definition: pda.cc:51
int num_frames() const
return number of frames in track
Definition: EST_Track.h:650
EST_Track differentiate(EST_Track &c, float samp_int=0.0)