Skip to content

Commit

Permalink
Reverted format to master
Browse files Browse the repository at this point in the history
  • Loading branch information
hokiedsp committed Oct 4, 2024
1 parent e06f662 commit 57b5e04
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 186 deletions.
160 changes: 80 additions & 80 deletions src/parselmouth/Pitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ PRAAT_STRUCT_BINDING(Frame, Pitch_Frame) {
def_readonly("intensity", &structPitch_Frame::intensity);

def_property("selected",
[](Pitch_Frame self) { return &self->candidates[1]; },
[](Pitch_Frame self, Pitch_Candidate candidate) {
for (long j = 1; j <= self->nCandidates; j++) {
if (&self->candidates[j] == candidate) {
std::swap(self->candidates[1], self->candidates[j]);
return;
}
}
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
});
[](Pitch_Frame self) { return &self->candidates[1]; },
[](Pitch_Frame self, Pitch_Candidate candidate) {
for (long j = 1; j <= self->nCandidates; j++) {
if (&self->candidates[j] == candidate) {
std::swap(self->candidates[1], self->candidates[j]);
return;
}
}
throw py::value_error("'candidate' is not a Pitch Candidate of this frame");
});

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

Expand All @@ -93,27 +93,27 @@ PRAAT_STRUCT_BINDING(Frame, Pitch_Frame) {
});

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

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

def("__getitem__",
[](Pitch_Frame self, long i) {
[](Pitch_Frame self, long i) {
if (i < 0) i += self->nCandidates; // Python-style negative indexing
if (i < 0 || i >= self->nCandidates) throw py::index_error("Pitch Frame index out of range");
return self->candidates[i + 1]; // Not a(n) (internal) reference, because unvoice and select would then change the value of a returned Pitch_Candidate
Expand Down Expand Up @@ -144,33 +144,33 @@ PRAAT_CLASS_BINDING(Pitch) {
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);

def("to_sound_hum",
[](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); },
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
[](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); },
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt);

def("to_sound_sine",
[](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); },
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt, "sampling_frequency"_a = 44100.0, "round_to_nearest_zero_crossing"_a = true);
[](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); },
"from_time"_a = std::nullopt, "to_time"_a = std::nullopt, "sampling_frequency"_a = 44100.0, "round_to_nearest_zero_crossing"_a = true);

def("count_voiced_frames",
&Pitch_countVoicedFrames);
&Pitch_countVoicedFrames);

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

// TODO get_strength_at_time ? -> Pitch strength unit enum

def("get_value_in_frame",
[](Pitch self, long frameNumber, kPitch_unit unit) {
auto value = Sampled_getValueAtSample(self, frameNumber, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
},
"frame_number"_a, "unit"_a = kPitch_unit::HERTZ);
[](Pitch self, long frameNumber, kPitch_unit unit) {
auto value = Sampled_getValueAtSample(self, frameNumber, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
return Function_convertToNonlogarithmic(self, value, Pitch_LEVEL_FREQUENCY, static_cast<int>(unit));
},
"frame_number"_a, "unit"_a = kPitch_unit::HERTZ);

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

Expand Down Expand Up @@ -214,16 +214,16 @@ PRAAT_CLASS_BINDING(Pitch) {
});

def("count_differences",
[](Pitch self, Pitch other) {
MelderInfoInterceptor info;
Pitch_difference(self, other);
return info.get();
},
"other"_a.none(false));
[](Pitch self, Pitch other) {
MelderInfoInterceptor info;
Pitch_difference(self, other);
return info.get();
},
"other"_a.none(false));

def("formula",
[](Pitch self, const std::u32string &formula) { Pitch_formula(self, formula.c_str(), nullptr); },
"formula"_a);
[](Pitch self, const std::u32string &formula) { Pitch_formula(self, formula.c_str(), nullptr); },
"formula"_a);

// TODO To TextGrid..., To TextTier, To IntervalTier: depends TextGrid and Tiers
// TODO To PointProcess: depends on PointProcess
Expand All @@ -232,15 +232,15 @@ PRAAT_CLASS_BINDING(Pitch) {
&Pitch_interpolate);

def("smooth",
args_cast<_, Positive<_>>(Pitch_smooth),
"bandwidth"_a = 10.0);
args_cast<_, Positive<_>>(Pitch_smooth),
"bandwidth"_a = 10.0);

def("subtract_linear_fit",
&Pitch_subtractLinearFit,
"unit"_a = kPitch_unit::HERTZ);
"unit"_a = kPitch_unit::HERTZ);

def("kill_octave_jumps",
&Pitch_killOctaveJumps);
&Pitch_killOctaveJumps);

// TODO To PitchTier: depends on PitchTier

Expand All @@ -252,23 +252,23 @@ PRAAT_CLASS_BINDING(Pitch) {
def_readonly("max_n_candidates", &structPitch::maxnCandidates);

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

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

def("__getitem__",
[](Pitch self, std::tuple<long, long> ij) {
auto &[i, j] = ij;
[](Pitch self, std::tuple<long, long> ij) {
auto &[i, j] = ij;
if (i < 0) i += self->nx; // Python-style negative indexing
if (i < 0 || i >= self->nx) throw py::index_error("Pitch index out of range");
auto &frame = self->frames[i + 1];
Expand Down Expand Up @@ -325,37 +325,37 @@ PRAAT_CLASS_BINDING(Pitch) {
"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);

def("step",
[](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)); },
"step"_a, "precision"_a = 0.1, "from_time"_a = std::nullopt, "to_time"_a = std::nullopt);
[](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)); },
"step"_a, "precision"_a = 0.1, "from_time"_a = std::nullopt, "to_time"_a = std::nullopt);

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

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

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

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

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

if (ileft < 1) ileft = 1;
if (iright > self->nx) iright = self->nx;
Expand Down
Loading

0 comments on commit 57b5e04

Please sign in to comment.