Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hokiedsp committed Feb 21, 2021
1 parent 205397e commit 4fadc04
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
19 changes: 18 additions & 1 deletion src/parselmouth/Harmonicity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ namespace parselmouth

// TODO Mixins (or something else?) for TimeFrameSampled, TimeFunction, and TimeVector functionality

def(py::init([](std::vector<double> 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(
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions tests/resource_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

15 changes: 0 additions & 15 deletions tests/test_harmonicity.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)

0 comments on commit 4fadc04

Please sign in to comment.