diff --git a/src/parselmouth/Harmonicity.cpp b/src/parselmouth/Harmonicity.cpp index 1bc08fe0..6478bda9 100644 --- a/src/parselmouth/Harmonicity.cpp +++ b/src/parselmouth/Harmonicity.cpp @@ -38,6 +38,23 @@ namespace parselmouth // TODO Mixins (or something else?) for TimeFrameSampled, TimeFunction, and TimeVector functionality + def(py::init([](std::vector values, double tmin, double tmax, double dt){ + Harmonicity_create (double tmin, double tmax, integer nt, double dt, double t1); + + autoHarmonicity thee = Harmonicity_create (my xmin, my xmax, pitch -> nx, + pitch -> dx, pitch -> x1); + for (integer i = 1; i <= thy nx; i ++) { + if (pitch -> frames [i]. candidates [1]. frequency == 0.0) { + thy z [1] [i] = -200.0; + } else { + double r = pitch -> frames [i]. candidates [1]. strength; + thy z [1] [i] = ( r <= 1e-15 ? -150.0 : r > 1.0 - 1e-15 ? 150.0 : 10.0 * log10 (r / (1.0 - r)) ); + } + } + return thee; + + + }),"double tmin, double tmax, integer nt, double dt, double t1"); // Make PointProcess class a s sequence-like Python class def( @@ -46,7 +63,7 @@ namespace parselmouth if (i < 0) i += self->nx; if (i < 0 || i >= self->nx) - throw std::out_of_range("time point index out of range"); + throw std::out_of_range("index out of range"); return self->z[1][i + 1]; }, "i"_a); diff --git a/tests/resource_fixtures.py b/tests/resource_fixtures.py index c289f59b..6357f4e5 100644 --- a/tests/resource_fixtures.py +++ b/tests/resource_fixtures.py @@ -73,3 +73,8 @@ def text_grid(text_grid_path): @pytest.fixture def script_path(resources): yield resources["script.praat"] + +@pytest +def harmonicity(sound): + return sound.to_harmonicity("CC") # "ac", "gne" + \ No newline at end of file diff --git a/tests/test_harmonicity.py b/tests/test_harmonicity.py index 5b91cf38..b0f25b92 100644 --- a/tests/test_harmonicity.py +++ b/tests/test_harmonicity.py @@ -1,15 +1,5 @@ import numpy as np -if __name__ == "__main__": - from os import path - import sys - - rootdir = path.dirname(path.dirname(__file__)) - sys.path.append(path.join(rootdir, "build", "src")) - resources = { - "the_north_wind_and_the_sun.wav": "tests/data/the_north_wind_and_the_sun.wav" - } - import parselmouth @@ -49,8 +39,3 @@ def test_harmonicity(resources): ) print(f"Average={harmonicity.get_mean()} dB") print(f"Maximum={harmonicity.get_standard_deviation()} dB") - - -if __name__ == "__main__": - test_pitch_harmonicity(resources) - test_harmonicity(resources)