Skip to content

Commit

Permalink
Added Sound.to_point_process_xxx methods
Browse files Browse the repository at this point in the history
Added PeakInterpolation enum
Updated pytest
  • Loading branch information
hokiedsp committed Feb 27, 2021
1 parent ae6327e commit ed911bf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/parselmouth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ using PraatBindings = Bindings<PraatError,
PraatWarning,
PraatFatal,
ValueInterpolation,
PeakInterpolation,
WindowShape,
AmplitudeScaling,
SignalOutsideTimeDomain,
Expand Down
2 changes: 2 additions & 0 deletions src/parselmouth/Parselmouth.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum class kSound_windowShape;
enum class kSounds_convolve_scaling;
enum class kSounds_convolve_signalOutsideTimeDomain;
enum class kVector_valueInterpolation;
enum class kVector_peakInterpolation;

namespace parselmouth::detail {

Expand Down Expand Up @@ -76,6 +77,7 @@ namespace parselmouth {
enum class SoundFileFormat;

using ValueInterpolation = kVector_valueInterpolation;
using PeakInterpolation = kVector_peakInterpolation;
using WindowShape = kSound_windowShape;
using AmplitudeScaling = kSounds_convolve_scaling;
using SignalOutsideTimeDomain = kSounds_convolve_signalOutsideTimeDomain;
Expand Down
70 changes: 69 additions & 1 deletion src/parselmouth/Sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <praat/fon/Sound_to_Harmonicity.h>
#include <praat/fon/Sound_to_Intensity.h>
#include <praat/fon/Sound_to_Pitch.h>
#include <praat/fon/Sound_to_PointProcess.h>

#include <pybind11/numpy.h>
#include <pybind11/stl.h>
Expand Down Expand Up @@ -181,11 +182,24 @@ PRAAT_ENUM_BINDING(ToHarmonicityMethod) {
make_implicitly_convertible_from_string(*this);
}

enum Channel {
LEFT = 1,
RIGHT = 2
};

PRAAT_ENUM_BINDING(Channel) {
value("LEFT", Channel::LEFT);
value("RIGHT", Channel::RIGHT);

make_implicitly_convertible_from_string(*this);
}

PRAAT_CLASS_BINDING(Sound) {
addTimeFrameSampledMixin(*this);

NESTED_BINDINGS(ToPitchMethod,
ToHarmonicityMethod)
ToHarmonicityMethod,
Channel)

using signature_cast_placeholder::_;

Expand Down Expand Up @@ -611,6 +625,60 @@ PRAAT_CLASS_BINDING(Sound) {
},
"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);

// FORM (NEW_Sound_to_PointProcess_extrema, U"Sound: To PointProcess
// (extrema)", nullptr)
def(
"to_point_process_extrema",
[](Sound self, Channel channel, bool includeMaxima, bool includeMinima,
kVector_peakInterpolation peakInterpolationType) {
int ch = static_cast<int>(channel);
return Sound_to_PointProcess_extrema(self, ch > self->ny ? 1 : ch,
peakInterpolationType,
includeMaxima, includeMinima);
},
"channel"_a = Channel::LEFT, "include_maxima"_a = true, "include_minima"_a = false,
"interpolation"_a = kVector_peakInterpolation::SINC70);

// FORM (NEW_Sound_to_PointProcess_periodic_cc, U"Sound: To PointProcess
// (periodic, cc)", U"Sound: To PointProcess (periodic, cc)...") {
def(
"to_point_process_periodic",
[](Sound self, float minimumPitch, float maximumPitch) {
if (maximumPitch <= minimumPitch)
Melder_throw(
U"Your maximum pitch should be greater than your minimum pitch.");
return Sound_to_PointProcess_periodic_cc(self, minimumPitch,
maximumPitch);
},
"minimum_pitch"_a = 75.0, "maximum_pitch"_a = 600.0);

// FORM (NEW_Sound_to_PointProcess_periodic_peaks, U"Sound: To PointProcess
// (periodic, peaks)", U"Sound: To PointProcess (periodic, peaks)...") {
def(
"to_point_process_periodic_peaks",
[](Sound self, float minimumPitch, float maximumPitch, bool includeMaxima,
bool includeMinima) {
if (maximumPitch <= minimumPitch)
Melder_throw(
U"Your maximum pitch should be greater than your minimum pitch.");
return Sound_to_PointProcess_periodic_peaks(
self, minimumPitch, maximumPitch, includeMaxima, includeMinima);
},
"minimum_pitch"_a = 75.0, "maximum_pitch"_a = 600.0,
"include_maxima"_a = true, "include_minima"_a = false);

// FORM (NEW_Sound_to_PointProcess_zeroes, U"Get zeroes", nullptr) {
def(
"to_point_process_zeros",
[](Sound self, Channel ch, bool includeRaisers, bool includeFallers) {
int channel = static_cast<int>(ch);
return Sound_to_PointProcess_zeroes(self,
channel > self->ny ? 1 : channel,
includeRaisers, includeFallers);
},
"channel"_a = Channel::LEFT, "include_raisers"_a = true,
"include_fallers"_a = false);

// TODO For some reason praat_David_init.cpp also still contains Sound functionality
// TODO Still a bunch of Sound in praat_LPC_init.cpp
}
Expand Down
11 changes: 11 additions & 0 deletions src/parselmouth/Vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ PRAAT_ENUM_BINDING(ValueInterpolation) {
make_implicitly_convertible_from_string(*this);
}

PRAAT_ENUM_BINDING(PeakInterpolation)
{
value("NONE", kVector_peakInterpolation::NONE);
value("PARABOLIC", kVector_peakInterpolation::PARABOLIC);
value("CUBIC", kVector_peakInterpolation::CUBIC);
value("SINC70", kVector_peakInterpolation::SINC70);
value("SINC700", kVector_peakInterpolation::SINC700);

make_implicitly_convertible_from_string(*this);
}

PRAAT_CLASS_BINDING(Vector) {
using signature_cast_placeholder::_;

Expand Down
7 changes: 7 additions & 0 deletions tests/test_point_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def test_create_poisson_process():
assert poisson_process != parselmouth.PointProcess.create_poisson_process(0, 1, 100)


def test_from_sound(sound):
# tests both constructor and static from_pitch()
sound.to_point_process_extrema("LEFT", True, False, "SINC70")
sound.to_point_process_periodic(75.0, 600.0)
sound.to_point_process_periodic_peaks(75.0, 600.0, True, False)


def test_from_pitch(pitch, sound):
# tests both constructor and static from_pitch()
pitch.to_point_process()
Expand Down

0 comments on commit ed911bf

Please sign in to comment.