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