Skip to content

Commit 5a97409

Browse files
committed
Reverted format to master
1 parent 7cd86db commit 5a97409

2 files changed

Lines changed: 226 additions & 241 deletions

File tree

src/parselmouth/Pitch.cpp

Lines changed: 135 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ PRAAT_STRUCT_BINDING(Frame, Pitch_Frame) {
6969
def_readonly("intensity", &structPitch_Frame::intensity);
7070

7171
def_property("selected",
72-
[](Pitch_Frame self) { return &self->candidates[1]; },
73-
[](Pitch_Frame self, Pitch_Candidate candidate) {
74-
for (long j = 1; j <= self->nCandidates; j++) {
75-
if (&self->candidates[j] == candidate) {
76-
std::swap(self->candidates[1], self->candidates[j]);
77-
return;
78-
}
79-
}
80-
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
81-
});
72+
[](Pitch_Frame self) { return &self->candidates[1]; },
73+
[](Pitch_Frame self, Pitch_Candidate candidate) {
74+
for (long j = 1; j <= self->nCandidates; j++) {
75+
if (&self->candidates[j] == candidate) {
76+
std::swap(self->candidates[1], self->candidates[j]);
77+
return;
78+
}
79+
}
80+
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
81+
});
8282

8383
def_property_readonly("candidates", [](Pitch_Frame self) { return std::vector<structPitch_Candidate>(&self->candidates[1], &self->candidates[self->nCandidates + 1]); });
8484

@@ -93,32 +93,32 @@ PRAAT_STRUCT_BINDING(Frame, Pitch_Frame) {
9393
});
9494

9595
def("select",
96-
[](Pitch_Frame self, Pitch_Candidate candidate) {
97-
for (long j = 1; j <= self->nCandidates; j++) {
98-
if (self->candidates[j].frequency == candidate->frequency && self->candidates[j].strength == candidate->strength) {
99-
std::swap(self->candidates[1], self->candidates[j]);
100-
return;
101-
}
102-
}
103-
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
104-
},
105-
"candidate"_a.none(false));
96+
[](Pitch_Frame self, Pitch_Candidate candidate) {
97+
for (long j = 1; j <= self->nCandidates; j++) {
98+
if (self->candidates[j].frequency == candidate->frequency && self->candidates[j].strength == candidate->strength) {
99+
std::swap(self->candidates[1], self->candidates[j]);
100+
return;
101+
}
102+
}
103+
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
104+
},
105+
"candidate"_a.none(false));
106106

107107
def("select",
108-
[](Pitch_Frame self, long i) {
108+
[](Pitch_Frame self, long i) {
109109
if (i < 0) i += self->nCandidates; // Python-style negative indexing
110-
if (i < 0 || i >= self->nCandidates) throw py::index_error("Pitch Frame index out of range");
110+
if (i < 0 || i >= self->nCandidates) throw py::index_error("Pitch Frame index out of range");
111111
return std::swap(self->candidates[1], self->candidates[i+1]);
112-
},
113-
"i"_a);
112+
},
113+
"i"_a);
114114

115115
def("__getitem__",
116-
[](Pitch_Frame self, long i) {
116+
[](Pitch_Frame self, long i) {
117117
if (i < 0) i += self->nCandidates; // Python-style negative indexing
118-
if (i < 0 || i >= self->nCandidates) throw py::index_error("Pitch Frame index out of range");
118+
if (i < 0 || i >= self->nCandidates) throw py::index_error("Pitch Frame index out of range");
119119
return self->candidates[i+1]; // Not a(n) (internal) reference, because unvoice and select would then change the value of a returned Pitch_Candidate
120-
},
121-
"i"_a);
120+
},
121+
"i"_a);
122122

123123
def("__len__",
124124
[](Pitch_Frame self) { return self->nCandidates; });
@@ -140,69 +140,69 @@ PRAAT_CLASS_BINDING(Pitch) {
140140
// TODO Which constructors? From Sound?
141141

142142
def("to_sound_pulses",
143-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) { return Pitch_to_Sound(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), false); },
144-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
143+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) { return Pitch_to_Sound(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), false); },
144+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
145145

146146
def("to_sound_hum",
147-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) { return Pitch_to_Sound(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), true); },
148-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
147+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) { return Pitch_to_Sound(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), true); },
148+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
149149

150150
def("to_sound_sine",
151-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime, Positive<double> samplingFrequency, double roundToNearestZeroCrossing) { return Pitch_to_Sound_sine(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), samplingFrequency, roundToNearestZeroCrossing); },
152-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt, "sampling_frequency"_a = 44100.0, "round_to_nearest_zero_crossing"_a = true);
151+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime, Positive<double> samplingFrequency, double roundToNearestZeroCrossing) { return Pitch_to_Sound_sine(self, fromTime.value_or(self->xmin), toTime.value_or(self->xmax), samplingFrequency, roundToNearestZeroCrossing); },
152+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt, "sampling_frequency"_a = 44100.0, "round_to_nearest_zero_crossing"_a = true);
153153

154154
def("count_voiced_frames",
155-
&Pitch_countVoicedFrames);
155+
&Pitch_countVoicedFrames);
156156

157157
def("get_value_at_time",
158-
[](Pitch self, double time, kPitch_unit unit, kVector_valueInterpolation interpolation) {
159-
if (interpolation != kVector_valueInterpolation::NEAREST && interpolation != kVector_valueInterpolation::LINEAR)
160-
Melder_throw(U"Pitch values can only be queried using NEAREST or LINEAR interpolation");
161-
auto value = Sampled_getValueAtX(self, time, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit), interpolation == kVector_valueInterpolation::LINEAR);
162-
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
163-
},
164-
"time"_a, "unit"_a = kPitch_unit::HERTZ, "interpolation"_a = kVector_valueInterpolation::LINEAR);
158+
[](Pitch self, double time, kPitch_unit unit, kVector_valueInterpolation interpolation) {
159+
if (interpolation != kVector_valueInterpolation::NEAREST && interpolation != kVector_valueInterpolation::LINEAR)
160+
Melder_throw(U"Pitch values can only be queried using NEAREST or LINEAR interpolation");
161+
auto value = Sampled_getValueAtX(self, time, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit), interpolation == kVector_valueInterpolation::LINEAR);
162+
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
163+
},
164+
"time"_a, "unit"_a = kPitch_unit::HERTZ, "interpolation"_a = kVector_valueInterpolation::LINEAR);
165165

166166
// TODO get_strength_at_time ? -> Pitch strength unit enum
167167

168168
def("get_value_in_frame",
169-
[](Pitch self, long frameNumber, kPitch_unit unit) {
170-
auto value = Sampled_getValueAtSample(self, frameNumber, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
171-
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
172-
},
173-
"frame_number"_a, "unit"_a = kPitch_unit::HERTZ);
169+
[](Pitch self, long frameNumber, kPitch_unit unit) {
170+
auto value = Sampled_getValueAtSample(self, frameNumber, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
171+
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
172+
},
173+
"frame_number"_a, "unit"_a = kPitch_unit::HERTZ);
174174

175175
// TODO Minimum, Time of minimum, Maximum, Time of maximum, ...
176176

177177
def("get_mean_absolute_slope",
178-
[](Pitch self, kPitch_unit unit) {
179-
double slope;
180-
long nVoiced = 0;
181-
switch (unit) {
182-
case kPitch_unit::HERTZ:
183-
nVoiced = Pitch_getMeanAbsSlope_hertz(self, &slope);
184-
break;
185-
case kPitch_unit::MEL:
186-
nVoiced = Pitch_getMeanAbsSlope_mel(self, &slope);
187-
break;
188-
case kPitch_unit::SEMITONES_1:
189-
case kPitch_unit::SEMITONES_100:
190-
case kPitch_unit::SEMITONES_200:
191-
case kPitch_unit::SEMITONES_440:
192-
nVoiced = Pitch_getMeanAbsSlope_semitones(self, &slope);
193-
break;
194-
case kPitch_unit::ERB:
195-
nVoiced = Pitch_getMeanAbsSlope_erb(self, &slope);
196-
break;
197-
case kPitch_unit::HERTZ_LOGARITHMIC:
198-
case kPitch_unit::LOG_HERTZ:
199-
Melder_throw(U"The mean absolute slope of a Pitch object can only be calculated with units HERTZ, MEL, SEMITONES_1, SEMITONES_100, SEMITONES_200, SEMITONES_440, and ERB");
200-
case kPitch_unit::UNDEFINED:
201-
Melder_throw(U"ERROR: PitchUnit should never be UNDEFINED!");
202-
}
203-
if (nVoiced < 2)
204-
return double{undefined};
205-
return slope;
178+
[](Pitch self, kPitch_unit unit) {
179+
double slope;
180+
long nVoiced = 0;
181+
switch (unit) {
182+
case kPitch_unit::HERTZ:
183+
nVoiced = Pitch_getMeanAbsSlope_hertz(self, &slope);
184+
break;
185+
case kPitch_unit::MEL:
186+
nVoiced = Pitch_getMeanAbsSlope_mel(self, &slope);
187+
break;
188+
case kPitch_unit::SEMITONES_1:
189+
case kPitch_unit::SEMITONES_100:
190+
case kPitch_unit::SEMITONES_200:
191+
case kPitch_unit::SEMITONES_440:
192+
nVoiced = Pitch_getMeanAbsSlope_semitones(self, &slope);
193+
break;
194+
case kPitch_unit::ERB:
195+
nVoiced = Pitch_getMeanAbsSlope_erb(self, &slope);
196+
break;
197+
case kPitch_unit::HERTZ_LOGARITHMIC:
198+
case kPitch_unit::LOG_HERTZ:
199+
Melder_throw(U"The mean absolute slope of a Pitch object can only be calculated with units HERTZ, MEL, SEMITONES_1, SEMITONES_100, SEMITONES_200, SEMITONES_440, and ERB");
200+
case kPitch_unit::UNDEFINED:
201+
Melder_throw(U"ERROR: PitchUnit should never be UNDEFINED!");
202+
}
203+
if (nVoiced < 2)
204+
return double{undefined};
205+
return slope;
206206
}, "unit"_a = kPitch_unit::HERTZ);
207207

208208
def("get_slope_without_octave_jumps",
@@ -213,16 +213,16 @@ PRAAT_CLASS_BINDING(Pitch) {
213213
});
214214

215215
def("count_differences",
216-
[](Pitch self, Pitch other) {
217-
MelderInfoInterceptor info;
218-
Pitch_difference(self, other);
219-
return info.get();
220-
},
221-
"other"_a.none(false));
216+
[](Pitch self, Pitch other) {
217+
MelderInfoInterceptor info;
218+
Pitch_difference(self, other);
219+
return info.get();
220+
},
221+
"other"_a.none(false));
222222

223223
def("formula",
224-
[](Pitch self, const std::u32string &formula) { Pitch_formula(self, formula.c_str(), nullptr); },
225-
"formula"_a);
224+
[](Pitch self, const std::u32string &formula) { Pitch_formula(self, formula.c_str(), nullptr); },
225+
"formula"_a);
226226

227227
// TODO To TextGrid..., To TextTier, To IntervalTier: depends TextGrid and Tiers
228228
// TODO To PointProcess: depends on PointProcess
@@ -231,15 +231,15 @@ PRAAT_CLASS_BINDING(Pitch) {
231231
&Pitch_interpolate);
232232

233233
def("smooth",
234-
args_cast<_, Positive<_>>(Pitch_smooth),
235-
"bandwidth"_a = 10.0);
234+
args_cast<_, Positive<_>>(Pitch_smooth),
235+
"bandwidth"_a = 10.0);
236236

237237
def("subtract_linear_fit",
238238
&Pitch_subtractLinearFit,
239-
"unit"_a = kPitch_unit::HERTZ);
239+
"unit"_a = kPitch_unit::HERTZ);
240240

241241
def("kill_octave_jumps",
242-
&Pitch_killOctaveJumps);
242+
&Pitch_killOctaveJumps);
243243

244244
// TODO To PitchTier: depends on PitchTier
245245

@@ -251,37 +251,37 @@ PRAAT_CLASS_BINDING(Pitch) {
251251
def_readonly("max_n_candidates", &structPitch::maxnCandidates);
252252

253253
def("get_frame",
254-
[](Pitch self, Positive<integer> frameNumber) {
255-
if (frameNumber > self->nx) Melder_throw(U"Frame number out of range");
256-
return &self->frames[frameNumber];
257-
},
258-
"frame_number"_a, py::return_value_policy::reference_internal);
254+
[](Pitch self, Positive<integer> frameNumber) {
255+
if (frameNumber > self->nx) Melder_throw(U"Frame number out of range");
256+
return &self->frames[frameNumber];
257+
},
258+
"frame_number"_a, py::return_value_policy::reference_internal);
259259

260260
def("__getitem__",
261-
[](Pitch self, long i) {
261+
[](Pitch self, long i) {
262262
if (i < 0) i += self->nx; // Python-style negative indexing
263-
if (i < 0 || i >= self->nx) throw py::index_error("Pitch index out of range");
263+
if (i < 0 || i >= self->nx) throw py::index_error("Pitch index out of range");
264264
return &self->frames[i+1];
265-
},
266-
"i"_a, py::return_value_policy::reference_internal);
265+
},
266+
"i"_a, py::return_value_policy::reference_internal);
267267

268268
def("__getitem__",
269-
[](Pitch self, std::tuple<long, long> ij) {
270-
auto &[i, j] = ij;
269+
[](Pitch self, std::tuple<long, long> ij) {
270+
auto &[i, j] = ij;
271271
if (i < 0) i += self->nx; // Python-style negative indexing
272-
if (i < 0 || i >= self->nx) throw py::index_error("Pitch index out of range");
272+
if (i < 0 || i >= self->nx) throw py::index_error("Pitch index out of range");
273273
auto &frame = self->frames[i+1];
274274
if (j < 0) j += frame.nCandidates; // Python-style negative indexing
275-
if (j < 0 || j >= frame.nCandidates) throw py::index_error("Pitch Frame index out of range");
275+
if (j < 0 || j >= frame.nCandidates) throw py::index_error("Pitch Frame index out of range");
276276
return frame.candidates[j+1];
277-
},
278-
"ij"_a);
277+
},
278+
"ij"_a);
279279

280280
// TODO __setitem__
281281

282282
def("__iter__",
283283
[](Pitch self) { return py::make_iterator(&self->frames[1], &self->frames[self->nx+1]); },
284-
py::keep_alive<0, 1>());
284+
py::keep_alive<0, 1>());
285285

286286
def("to_array",
287287
[](Pitch self) {
@@ -324,52 +324,52 @@ PRAAT_CLASS_BINDING(Pitch) {
324324
"silence_threshold"_a = 0.03, "voicing_threshold"_a = 0.45, "octave_cost"_a = 0.01, "octave_jump_cost"_a = 0.35, "voiced_unvoiced_cost"_a = 0.14, "ceiling"_a = 600.0, "pull_formants"_a = false);
325325

326326
def("step",
327-
[](Pitch self, double step, Positive<double> precision, std::optional<double> fromTime, std::optional<double> toTime) { Pitch_step(self, step, precision, fromTime.value_or(self->xmin), toTime.value_or(self->xmax)); },
328-
"step"_a, "precision"_a = 0.1, "from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
327+
[](Pitch self, double step, Positive<double> precision, std::optional<double> fromTime, std::optional<double> toTime) { Pitch_step(self, step, precision, fromTime.value_or(self->xmin), toTime.value_or(self->xmax)); },
328+
"step"_a, "precision"_a = 0.1, "from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
329329

330330
def("octave_up",
331-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
332-
Pitch_step(self, 2.0, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
333-
},
334-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
331+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
332+
Pitch_step(self, 2.0, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
333+
},
334+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
335335

336336
def("fifth_up",
337-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
338-
Pitch_step(self, 1.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
339-
},
340-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
337+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
338+
Pitch_step(self, 1.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
339+
},
340+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
341341

342342
def("fifth_down",
343-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
344-
Pitch_step(self, 1 / 1.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
345-
},
346-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
343+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
344+
Pitch_step(self, 1 / 1.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
345+
},
346+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
347347

348348
def("octave_down",
349-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
350-
Pitch_step(self, 0.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
351-
},
352-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
349+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
350+
Pitch_step(self, 0.5, 0.1, fromTime.value_or(self->xmin), toTime.value_or(self->xmax));
351+
},
352+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
353353

354354
def("unvoice",
355-
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
356-
long ileft = Sampled_xToHighIndex(self, fromTime.value_or(self->xmin));
357-
long iright = Sampled_xToLowIndex(self, toTime.value_or(self->xmax));
355+
[](Pitch self, std::optional<double> fromTime, std::optional<double> toTime) {
356+
long ileft = Sampled_xToHighIndex(self, fromTime.value_or(self->xmin));
357+
long iright = Sampled_xToLowIndex(self, toTime.value_or(self->xmax));
358358

359-
if (ileft < 1) ileft = 1;
359+
if (ileft < 1) ileft = 1;
360360
if (iright > self->nx) iright = self-> nx;
361361

362362
for (auto i = ileft; i <= iright; i ++) {
363-
auto &frame = self->frames[i];
364-
for (long j = 1; j <= frame.nCandidates; j++) {
365-
if (frame.candidates[j].frequency == 0.0) {
366-
std::swap(frame.candidates[1], frame.candidates[j]);
367-
break;
368-
}
369-
}
370-
}
371-
},
372-
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
363+
auto &frame = self->frames[i];
364+
for (long j = 1; j <= frame.nCandidates; j++) {
365+
if (frame.candidates[j].frequency == 0.0) {
366+
std::swap(frame.candidates[1], frame.candidates[j]);
367+
break;
368+
}
369+
}
370+
}
371+
},
372+
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
373373

374374
// Added by @hokiedsp on 2/17/21
375375
def(

0 commit comments

Comments
 (0)