Debian Codegraph @

fon/H1minusH2Tier.cpp

raw symbols SCIP
1 /* H1minusH2Tier.cpp
2 *
3 * Copyright (C) 2025 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "H1minusH2Tier.h"cxx . . $ `<file>/fon/H1minusH2Tier.h`/
20
21 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (H1minusH2Tier, RealTier, 0);
22
23 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# H1minusH2Tier_createcxx . . $ H1minusH2Tier_create(61a2003a045dd490). (double tmin, double tmax) {
24 try {
25 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (H1minusH2Tier);
26 RealTier_initcxx . . $ RealTier_init(d84c0874d617a544). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax);
27 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
28 } catch (MelderErrorcxx . . $ MelderError#) {
29 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"H1minusH2Tier not created.");
30 }
31 }
32
33 void H1minusH2Tier_drawcxx . . $ H1minusH2Tier_draw(3b9fafeaa996a305). (H1minusH2Tiercxx . . $ H1minusH2Tier# me, Graphicscxx . . $ Graphics# g, double tmin, double tmax,
34 double ymin, double ymax, conststring32cxx . . $ conststring32# method, bool garnish)
35 {
36 RealTier_drawcxx . . $ RealTier_draw(91d4c8857589b937). (me, g, tmin, tmax, ymin, ymax, garnish, method, U"H1-H2 (dB)");
37 }
38
39 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# RealTier_to_H1minusH2Tiercxx . . $ RealTier_to_H1minusH2Tier(899a20bde2180dbc). (RealTiercxx . . $ RealTier# me) {
40 try {
41 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (H1minusH2Tier);
42 mycxx . . $ `melder/melder.h:44:9`! structRealTiercxx . . $ structRealTier# :: v1_copycxx . . $ structRealTier#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
43 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
44 } catch (MelderErrorcxx . . $ MelderError#) {
45 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to H1minusH2Tier.");
46 }
47 }
48
49 static double Sound_getHarmonicStrengthcxx . . $ Sound_getHarmonicStrength(28816256005b0879). (Soundcxx . . $ Sound# me, double tmin, double tmax, integercxx . . $ integer# harmonic) {
50 integercxx . . $ integer# imin, imax;
51 const integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & imin, & imax);
52 if (n < 3)
53 return undefinedcxx . . $ undefined.;
54 autoVECcxx . . $ autoVEC# cosine = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (n), sine = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (n);
55 for (integercxx . . $ integer# i = 1; i <= n; i ++) {
56 const double phase = harmonic * NUM2picxx . . $ NUM2pi. * (i - 0.5) / n;
57 cosine [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = coscxx . . $ cos(fee4f1d22bc8e617). (phase);
58 sine [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = sincxx . . $ sin(fee4f1d22bc8e617). (phase);
59 }
60 longdoublecxx . . $ longdouble# re = 0.0, im = 0.0;
61 for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) {
62 re += NUMinnercxx . . $ NUMinner(5e5adb47f563a3e3). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (imin, imax), cosinecxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).());
63 im += NUMinnercxx . . $ NUMinner(5e5adb47f563a3e3). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (imin, imax), sinecxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).());
64 }
65 return sqrcxx . . $ sqr(ada6a8422704cf8a). (double (re)) + sqrcxx . . $ sqr(ada6a8422704cf8a). (double (im));
66 }
67 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# PointProcess_Sound_to_H1minusH2Tier_ucxx . . $ PointProcess_Sound_to_H1minusH2Tier_u(9aa57514c657ba33). (PointProcesscxx . . $ PointProcess# me, Soundcxx . . $ Sound# you, double tmin, double tmax,
68 double pmin, double pmax, double maximumPeriodFactor)
69 {
70 try {
71 Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax);
72 const MelderIntegerRangecxx . . $ MelderIntegerRange# peaks = PointProcess_getWindowPointscxx . . $ PointProcess_getWindowPoints(7cc368e5a055f865). (me, tmin, tmax);
73 //if (peaks.size() < 3)
74 // Melder_throw (U"Too few pulses between ", tmin, U" and ", tmax, U" seconds.");
75 autoH1minusH2Tiercxx . . $ autoH1minusH2Tier# him = H1minusH2Tier_createcxx . . $ H1minusH2Tier_create(61a2003a045dd490). (tmin, tmax);
76 for (integercxx . . $ integer# i = peaks.firstcxx . . $ MelderIntegerRange#first. + 1; i <= peaks.lastcxx . . $ MelderIntegerRange#last.; i ++) {
77 const double period = mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] - mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1];
78 if (pmin == pmax || (period >= pmin && period <= pmax)) {
79 const double h1_Pa2 = Sound_getHarmonicStrengthcxx . . $ Sound_getHarmonicStrength(28816256005b0879). (you, mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1], mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], 1);
80 const double h2_Pa2 = Sound_getHarmonicStrengthcxx . . $ Sound_getHarmonicStrength(28816256005b0879). (you, mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1], mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i], 2);
81 const double h1minusH2 = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (h1_Pa2 / h2_Pa2);
82 if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (h1minusH2))
83 RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.5 * (mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1] + mycxx . . $ `melder/melder.h:44:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]), h1minusH2);
84 }
85 }
86 return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
87 } catch (MelderErrorcxx . . $ MelderError#) {
88 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", you, U": not converted to H1minusH2Tier.");
89 }
90 }
91
92 /* End of file H1minusH2Tier.cpp */