Skip to content

Commit e37d662

Browse files
committed
wip
1 parent ae6327e commit e37d662

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

src/parselmouth/Sound.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <praat/fon/Sound_to_Harmonicity.h>
3636
#include <praat/fon/Sound_to_Intensity.h>
3737
#include <praat/fon/Sound_to_Pitch.h>
38+
#include <praat/fon/Sound_to_PointProcess.h>
3839

3940
#include <pybind11/numpy.h>
4041
#include <pybind11/stl.h>
@@ -181,11 +182,24 @@ PRAAT_ENUM_BINDING(ToHarmonicityMethod) {
181182
make_implicitly_convertible_from_string(*this);
182183
}
183184

185+
enum Channel {
186+
LEFT = 1,
187+
RIGHT = 2
188+
};
189+
190+
PRAAT_ENUM_BINDING(Channel) {
191+
value("LEFT", Channel::LEFT);
192+
value("RIGHT", Channel::RIGHT);
193+
194+
make_implicitly_convertible_from_string(*this);
195+
}
196+
184197
PRAAT_CLASS_BINDING(Sound) {
185198
addTimeFrameSampledMixin(*this);
186199

187200
NESTED_BINDINGS(ToPitchMethod,
188-
ToHarmonicityMethod)
201+
ToHarmonicityMethod,
202+
Channel)
189203

190204
using signature_cast_placeholder::_;
191205

@@ -611,6 +625,60 @@ PRAAT_CLASS_BINDING(Sound) {
611625
},
612626
"number_of_coefficients"_a = 12, "window_length"_a = 0.015, "time_step"_a = 0.005, "firstFilterFreqency"_a = 100.0, "distance_between_filters"_a = 100.0, "maximum_frequency"_a = std::nullopt);
613627

628+
// FORM (NEW_Sound_to_PointProcess_extrema, U"Sound: To PointProcess
629+
// (extrema)", nullptr)
630+
def(
631+
"to_point_process_extrema",
632+
[](Sound self, Channel channel, bool includeMaxima, bool includeMinima,
633+
kVector_peakInterpolation peakInterpolationType) {
634+
int ch = static_cast<int>(channel);
635+
return Sound_to_PointProcess_extrema(self, ch > self->ny ? 1 : ch,
636+
peakInterpolationType,
637+
includeMaxima, includeMinima);
638+
},
639+
"channel"_a = Channel::LEFT, "include_maxima"_a = true, "include_minima"_a = false,
640+
"interpolation"_a = kVector_peakInterpolation::SINC70);
641+
642+
// FORM (NEW_Sound_to_PointProcess_periodic_cc, U"Sound: To PointProcess
643+
// (periodic, cc)", U"Sound: To PointProcess (periodic, cc)...") {
644+
def(
645+
"to_point_process_periodic",
646+
[](Sound self, float minimumPitch, float maximumPitch) {
647+
if (maximumPitch <= minimumPitch)
648+
Melder_throw(
649+
U"Your maximum pitch should be greater than your minimum pitch.");
650+
return Sound_to_PointProcess_periodic_cc(self, minimumPitch,
651+
maximumPitch);
652+
},
653+
"minimum_pitch"_a = 75.0, "maximum_pitch"_a = 600.0);
654+
655+
// FORM (NEW_Sound_to_PointProcess_periodic_peaks, U"Sound: To PointProcess
656+
// (periodic, peaks)", U"Sound: To PointProcess (periodic, peaks)...") {
657+
def(
658+
"to_point_process_periodic_peaks",
659+
[](Sound self, float minimumPitch, float maximumPitch, bool includeMaxima,
660+
bool includeMinima) {
661+
if (maximumPitch <= minimumPitch)
662+
Melder_throw(
663+
U"Your maximum pitch should be greater than your minimum pitch.");
664+
return Sound_to_PointProcess_periodic_peaks(
665+
self, minimumPitch, maximumPitch, includeMaxima, includeMinima);
666+
},
667+
"minimum_pitch"_a = 75.0, "maximum_pitch"_a = 600.0,
668+
"include_maxima"_a = true, "include_minima"_a = false);
669+
670+
// FORM (NEW_Sound_to_PointProcess_zeroes, U"Get zeroes", nullptr) {
671+
def(
672+
"to_point_process_zeros",
673+
[](Sound self, Channel ch, bool includeRaisers, bool includeFallers) {
674+
int channel = static_cast<int>(ch);
675+
return Sound_to_PointProcess_zeroes(self,
676+
channel > self->ny ? 1 : channel,
677+
includeRaisers, includeFallers);
678+
},
679+
"channel"_a = Channel::LEFT, "include_raisers"_a = true,
680+
"include_fallers"_a = false);
681+
614682
// TODO For some reason praat_David_init.cpp also still contains Sound functionality
615683
// TODO Still a bunch of Sound in praat_LPC_init.cpp
616684
}

tests/test_point_process.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def test_create_poisson_process():
3434
assert poisson_process != parselmouth.PointProcess.create_poisson_process(0, 1, 100)
3535

3636

37+
def test_from_sound(sound):
38+
# tests both constructor and static from_pitch()
39+
sound.to_point_process_extrema("LEFT", True, False, "SINC70")
40+
sound.to_point_process_periodic(75.0, 600.0)
41+
sound.to_point_process_periodic_peaks(75.0, 600.0, True, False)
42+
43+
3744
def test_from_pitch(pitch, sound):
3845
# tests both constructor and static from_pitch()
3946
pitch.to_point_process()

0 commit comments

Comments
 (0)