Debian Codegraph @

sensors/Electroglottogram.cpp

raw symbols SCIP
1 /* Electroglottogram.cpp
2 *
3 * Copyright (C) 2019-2023 David Weenink
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 2 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 "AmplitudeTier.h"cxx . . $ `<file>/fon/AmplitudeTier.h`/
20 #include "Electroglottogram.h"cxx . . $ `<file>/sensors/Electroglottogram.h`/
21 #include "Sound_and_Spectrum.h"cxx . . $ `<file>/fon/Sound_and_Spectrum.h`/
22 #include "Sound_extensions.h"cxx . . $ `<file>/dwtools/Sound_extensions.h`/
23 #include "Sound_to_PointProcess.h"cxx . . $ `<file>/fon/Sound_to_PointProcess.h`/
24 #include "Vector_extensions.h"cxx . . $ `<file>/dwtools/Vector_extensions.h`/
25
26 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
27 #include "Electroglottogram_enums.h"cxx . . $ `<file>/sensors/Electroglottogram_enums.h`/
28 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
29 #include "Electroglottogram_enums.h"cxx . . $ `<file>/sensors/Electroglottogram_enums.h`/
30
31 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Electroglottogram, Sound, 2);
32
33 void Electroglottogram_drawStylizedcxx . . $ Electroglottogram_drawStylized(b6aa5169b3b84bbd). (Graphicscxx . . $ Graphics# g, bool marks, bool levels) {
34 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 10.0);
35 Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g);
36 const double xmax = 3.9;
37 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, 0.0, xmax, 0, 2.0);
38 constexpr integercxx . . $ integer# numberOfPoints = 6;
39 const double x [numberOfPoints] = { 0.55, 1.0, 1.3, 2.0, 2.75, 3.1 };
40 const double y [numberOfPoints] = { 0.10, 0.3, 1.8, 1.8, 1.00, 0.1 };
41 const double maximum = y [3], minimum = y [0];
42 const double range = maximum - minimum;
43 conststring32cxx . . $ conststring32# labels [numberOfPoints] = { U"a", U"b", U"c", U"d", U"e", U"f" };
44 const double width = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, U"a");
45 const double h = 2.0 * width;
46 const double dx [numberOfPoints] = { 0.0, -width, width, -0.5 * width, 0.5 * width, 0.5 * width};
47 const double dy [numberOfPoints] = { h, h, -h, -h, h, h };
48 double tx [numberOfPoints], ty [numberOfPoints];
49 for (integercxx . . $ integer# i = 0; i < numberOfPoints; i++) {
50 tx [i] = x [i] + dx [i];
51 ty [i] = y [i] + dy [i];
52 }
53 const double lineWidth = Graphics_inqLineWidthcxx . . $ Graphics_inqLineWidth(f906975acce41a59). (g);
54 Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 3.0);
55 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, 0.2, 0.1, x [0], y [0]);
56 for (integercxx . . $ integer# i = 1; i < numberOfPoints; i ++)
57 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x [i - 1], y [i - 1], x [i], y [i]);
58 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x [5], y [5], 3.5, 0.1);
59 Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, lineWidth);
60 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
61 if (marks) {
62 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 12.0);
63 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
64 for (integercxx . . $ integer# i = 0; i < numberOfPoints; i++)
65 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, tx [i], ty [i], labels [i]);
66 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 10.0);
67 }
68 const double closingThreshold = 0.3;
69 const double at03 = minimum + closingThreshold * range;
70 // Get the two x values of intersection at y = at03 with the EGG
71 double a = (y [1] - y [2]) / (x [1] - x [2]), b = y [1] - a * x [1];
72 const double x1 = (at03 - b) / a;
73 a = (y [4] - y [5]) / (x [4] - x [5]);
74 b = y [4] - a * x [4];
75 const double x2 = (at03 - b) / a;
76 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::LEFTcxx . . $ kGraphics_horizontalAlignment#LEFT., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
77 if (levels) {
78 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DASHEDcxx . . $ `sys/Graphics.h:289:9`!);
79 Graphics_doubleArrowcxx . . $ Graphics_doubleArrow(72bdb7937dbb13da). (g, x1, at03, x2, at03);
80 const double x3 = x [2] + 0.1;
81 Graphics_doubleArrowcxx . . $ Graphics_doubleArrow(72bdb7937dbb13da). (g, x3, minimum, x3, at03);
82 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!);
83 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x3 + width, 0.5 * at03, U"0.3(%%Peak%\\--%%Valley%)");
84 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!);
85 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 0.5 * (x1 + x2), at03, U"Closed Glottis Interval");
86 }
87 Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g);
88 if (levels) {
89 Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, maximum, false, true, true, U"%Peak");
90 Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, minimum, false, true, true, U"%Valley");
91 Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, at03, false, true, false, U"%%closingThreshold% (0.3)");
92 Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, x1, false, true, true, U"%t__1_");
93 Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, x2, false, true, true, U"%t__2_");
94 }
95 Graphics_textLeftcxx . . $ Graphics_textLeft(48cf1f690ec61203). (g, false, U"norm. VFCA");
96 Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"norm. cycle progress");
97 Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g);
98 }
99
100 static void IntervalTier_insertBoundarycxx . . $ IntervalTier_insertBoundary(3a8dd7d051789e70). (IntervalTiercxx . . $ IntervalTier# me, double t) {
101 try {
102 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (! IntervalTier_hasTime (me, t),
103 U"Cannot add a boundary at ", Melder_fixed (t, 6), U" seconds, because there is already a boundary there.");
104 const integercxx . . $ integer# intervalNumber = IntervalTier_timeToIndexcxx . . $ IntervalTier_timeToIndex(726d97a25667305). (me, t);
105 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (intervalNumber != 0,
106 U"Cannot add a boundary at ", Melder_fixed (t, 6), U" seconds, because this is outside the time domain of the intervals.");
107 const TextIntervalcxx . . $ TextInterval# interval = mycxx . . $ `melder/melder.h:44:9`! intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).intervalNumber];
108 /*
109 Move the text to the left of the boundary.
110 */
111 autoTextIntervalcxx . . $ autoTextInterval# newInterval = TextInterval_createcxx . . $ TextInterval_create(69da32435edc95c8). (t, interval -> xmaxcxx . . $ structFunction#xmax., U"");
112 interval -> xmaxcxx . . $ structFunction#xmax. = t;
113 mycxx . . $ `melder/melder.h:44:9`! intervalscxx . . $ structIntervalTier#intervals.. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (newIntervalcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
114 } catch (MelderErrorcxx . . $ MelderError#) {
115 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": boundary not inserted.");
116 }
117 }
118
119 void IntervalTier_setIntervalTextcxx . . $ IntervalTier_setIntervalText(8c95def3c6fcfd70). (IntervalTiercxx . . $ IntervalTier# me, integercxx . . $ integer# intervalNumber, conststring32cxx . . $ conststring32# text) {
120 try {
121 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (intervalNumber >= 1 && intervalNumber <= mycxx . . $ `melder/melder.h:44:9`! intervals.size,
122 U"Interval ", intervalNumber, U" does not exist.");
123 const TextIntervalcxx . . $ TextInterval# interval = mycxx . . $ `melder/melder.h:44:9`! intervalscxx . . $ structIntervalTier#intervals..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).intervalNumber];
124 TextInterval_setTextcxx . . $ TextInterval_setText(bda04a1b3ff14567). (interval, text);
125 } catch (MelderErrorcxx . . $ MelderError#) {
126 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": interval text not set.");
127 }
128 }
129
130 void structElectroglottogramcxx . . $ structElectroglottogram# :: v1_infocxx . . $ structElectroglottogram#v1_info(49f6e7a06ebc5aa8). () {
131 structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). ();
132 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time domain:");
133 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Start time: ", ourcxx . . $ `melder/melder.h:42:9`! xmincxx . . $ structFunction#xmin., U" seconds");
134 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" End time: ", ourcxx . . $ `melder/melder.h:42:9`! xmaxcxx . . $ structFunction#xmax., U" seconds");
135 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Total duration: ", ourcxx . . $ `melder/melder.h:42:9`! xmaxcxx . . $ structFunction#xmax. - ourcxx . . $ `melder/melder.h:42:9`! xmincxx . . $ structFunction#xmin., U" seconds");
136 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time sampling:");
137 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Number of samples: ", ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx.);
138 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Sampling period: ", ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx., U" seconds");
139 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Sampling frequency: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (1.0 / ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx.), U" Hz");
140 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" First sample centred at: ", ourcxx . . $ `melder/melder.h:42:9`! x1cxx . . $ structSampled#x1., U" seconds");
141 }
142
143 autoElectroglottogramcxx . . $ autoElectroglottogram# Electroglottogram_createcxx . . $ Electroglottogram_create(46f24b7387f8f30f). (double xmin, double xmax, integercxx . . $ integer# nx, double dx, double x1) {
144 try {
145 autoElectroglottogramcxx . . $ autoElectroglottogram# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Electroglottogram);
146 Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmin, xmax, nx, dx, x1, 1.0, 1.0, 1.0, 1, 1.0);
147 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
148 } catch (MelderErrorcxx . . $ MelderError#) {
149 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Electroglottogram not created.");
150 }
151 }
152
153 autoElectroglottogramcxx . . $ autoElectroglottogram# Sound_extractElectroglottogramcxx . . $ Sound_extractElectroglottogram(4ea7eb8653411c6d). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, bool invert) {
154 try {
155 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channel > 0 && channel <= mycxx . . $ `melder/melder.h:44:9`! ny,
156 U"The channel number should be in the interval from 1 to ", mycxx . . $ `melder/melder.h:44:9`! ny);
157 autoElectroglottogramcxx . . $ autoElectroglottogram# thee = Electroglottogram_createcxx . . $ Electroglottogram_create(46f24b7387f8f30f). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.);
158 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(88779db6ac139909). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel);
159 if (invert)
160 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() *=cxx . . $ `operator*=`(50b469ae42a42f64). -1.0;
161 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
162 } catch (MelderErrorcxx . . $ MelderError#) {
163 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Electroglottogram.");
164 }
165 }
166
167 autoAmplitudeTiercxx . . $ autoAmplitudeTier# Electroglottogram_to_AmplitudeTier_levelscxx . . $ Electroglottogram_to_AmplitudeTier_levels(26855ed933eba4b0). (Electroglottogramcxx . . $ Electroglottogram# me, double pitchFloor, double pitchCeiling, double closingThreshold, autoAmplitudeTiercxx . . $ autoAmplitudeTier# *out_peaks, autoAmplitudeTiercxx . . $ autoAmplitudeTier# *out_valleys) {
168 try {
169 autoPointProcesscxx . . $ autoPointProcess# peakPositions = Sound_to_PointProcess_periodic_peakscxx . . $ Sound_to_PointProcess_periodic_peaks(980d566298bb5008). (me, pitchFloor, pitchCeiling, true, false);
170 autoPointProcesscxx . . $ autoPointProcess# valleyPositions = Sound_to_PointProcess_periodic_peakscxx . . $ Sound_to_PointProcess_periodic_peaks(980d566298bb5008). (me, pitchFloor, pitchCeiling, false, true);
171 /*
172 Get the values of the peaks and valleys
173 */
174 autoAmplitudeTiercxx . . $ autoAmplitudeTier# peaks = PointProcess_Sound_to_AmplitudeTier_pointcxx . . $ PointProcess_Sound_to_AmplitudeTier_point(de5cd27740dc21d9). (peakPositions.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), me);
175 autoAmplitudeTiercxx . . $ autoAmplitudeTier# valleys = PointProcess_Sound_to_AmplitudeTier_pointcxx . . $ PointProcess_Sound_to_AmplitudeTier_point(de5cd27740dc21d9). (valleyPositions.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), me);
176 autoAmplitudeTiercxx . . $ autoAmplitudeTier# thee = Electroglottogram_and_AmplitudeTiers_getLevelscxx . . $ Electroglottogram_and_AmplitudeTiers_getLevels(2c506c98b6e68fb5). (me, peaks.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), valleys.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), closingThreshold);
177 if (out_peaks)
178 *out_peaks =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). peaks.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
179 if (out_valleys)
180 *out_valleys =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). valleys.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
181 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
182 } catch (MelderErrorcxx . . $ MelderError#) {
183 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": AmplitudeTier not created.");
184 }
185 }
186
187 autoAmplitudeTiercxx . . $ autoAmplitudeTier# Electroglottogram_and_AmplitudeTiers_getLevelscxx . . $ Electroglottogram_and_AmplitudeTiers_getLevels(2c506c98b6e68fb5). (Electroglottogramcxx . . $ Electroglottogram# me, AmplitudeTiercxx . . $ AmplitudeTier# peaks, AmplitudeTiercxx . . $ AmplitudeTier# valleys, double closingThreshold) {
188 try {
189 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == peaks -> xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == peaks -> xmax,
190 U"The domains of the Electroglottogram and the peaks should be equal.");
191 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == valleys -> xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == valleys -> xmax,
192 U"The domains of the Electroglottogram and the valleys should be equal.");
193 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (peaks -> points.size > 1 && valleys -> points.size > 1,
194 U"The AmplitudeTiers cannot be empty.");
195 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (closingThreshold > 0.0 && closingThreshold < 1.0,
196 U"The closing threshold should be a number between 0.0 and 1.0.");
197 autoAmplitudeTiercxx . . $ autoAmplitudeTier# thee = AmplitudeTier_createcxx . . $ AmplitudeTier_create(80ed2f467e1fc893). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.);
198 double peakAmplitudeLeft = RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (peaks, 1);
199 double peakTimeLeft = peaks -> pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> numbercxx . . $ structSimpleDouble#number.;
200 for (integercxx . . $ integer# ipoint = 2; ipoint <= peaks -> pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size. - 1; ipoint ++) {
201 const double peakAmplitudeRight = RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (peaks, ipoint);
202 const double peakTimeRight = peaks -> pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint] -> numbercxx . . $ structSimpleDouble#number.;
203 const integercxx . . $ integer# indexValley = AnyTier_timeToNearestIndexcxx . . $ AnyTier_timeToNearestIndex(9d58fc2471e8b6f6). (valleys->asAnyTiercxx . . $ structRealTier#asAnyTier(2fecc017ee6dfbab).(), peakTimeRight);
204 const double timeValley = valleys -> pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).indexValley] -> numbercxx . . $ structSimpleDouble#number.;
205 if (timeValley > peakTimeLeft && timeValley < peakTimeRight) {
206 const double valleyAmplitude = RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (valleys, indexValley);
207 const double amplitudeRange = peakAmplitudeLeft - valleyAmplitude;
208 const double level = valleyAmplitude + amplitudeRange * closingThreshold;
209 RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), peakTimeLeft, level);
210 }
211 peakAmplitudeLeft = peakAmplitudeRight;
212 peakTimeLeft = peakTimeRight;
213 }
214 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
215 } catch (MelderErrorcxx . . $ MelderError#) {
216 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": Levels not determined.");
217 }
218 }
219
220 autoTextGridcxx . . $ autoTextGrid# Electroglottogram_to_TextGrid_closedGlottiscxx . . $ Electroglottogram_to_TextGrid_closedGlottis(5f0193a427665836). (Electroglottogramcxx . . $ Electroglottogram# me, double pitchFloor, double pitchCeiling, double closingThreshold, double peakThresholdFraction) {
221 try {
222 autoAmplitudeTiercxx . . $ autoAmplitudeTier# peakscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8)., valleyscxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
223 autoAmplitudeTiercxx . . $ autoAmplitudeTier# levels = Electroglottogram_to_AmplitudeTier_levelscxx . . $ Electroglottogram_to_AmplitudeTier_levels(26855ed933eba4b0). (me, pitchFloor, pitchCeiling, closingThreshold, & peaks, & valleys);
224
225 const double maximum = RealTier_getMaximumValuecxx . . $ RealTier_getMaximumValue(77f29e426b60f650). (peaks.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
226 const double minimumPeakAmplitude = maximum * peakThresholdFraction;
227
228 autoTextGridcxx . . $ autoTextGrid# thee = TextGrid_createcxx . . $ TextGrid_create(2af4734b8a73c5bc). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., U"closedGlottis", U"");
229 IntervalTiercxx . . $ IntervalTier# intervalTier = static_cast <IntervalTiercxx . . $ IntervalTier#> (thycxx . . $ `melder/melder.h:45:9`! tierscxx . . $ structTextGrid#tiers. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1]);
230 double previousOpeningTime = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.;
231 for (integercxx . . $ integer# ipoint = 1; ipoint <= peaks ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size.; ipoint ++) {
232 const RealPointcxx . . $ RealPoint# peak = peaks ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint];
233 const double peakPosition = peak -> numbercxx . . $ structSimpleDouble#number.;
234 const double peakAmplitude = peak -> valuecxx . . $ structRealPoint#value.;
235 double closingTime = undefinedcxx . . $ undefined., openingTime = undefinedcxx . . $ undefined.;
236 if (peakAmplitude > minimumPeakAmplitude) {
237 const double level = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (levels.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), peakPosition);
238 closingTime = Vector_getNearestLevelCrossingcxx . . $ Vector_getNearestLevelCrossing(aa6ba2edce277310). (me, 1, peakPosition, level, kVectorSearchDirectioncxx . . $ kVectorSearchDirection#::LEFTcxx . . $ kVectorSearchDirection#LEFT.);
239 openingTime = Vector_getNearestLevelCrossingcxx . . $ Vector_getNearestLevelCrossing(aa6ba2edce277310). (me, 1, peakPosition, level, kVectorSearchDirectioncxx . . $ kVectorSearchDirection#::RIGHTcxx . . $ kVectorSearchDirection#RIGHT.);
240 if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (closingTime) && isdefinedcxx . . $ isdefined(f8197d536af80c96). (openingTime) && closingTime != previousOpeningTime) {
241 IntervalTier_insertBoundarycxx . . $ IntervalTier_insertBoundary(3a8dd7d051789e70). (intervalTier, closingTime);
242 IntervalTier_insertBoundarycxx . . $ IntervalTier_insertBoundary(3a8dd7d051789e70). (intervalTier, openingTime);
243 const double midPoint = 0.5 * (closingTime + openingTime);
244 const integercxx . . $ integer# intervalNumber = IntervalTier_timeToIndexcxx . . $ IntervalTier_timeToIndex(726d97a25667305). (intervalTier, midPoint);
245 IntervalTier_setIntervalTextcxx . . $ IntervalTier_setIntervalText(8c95def3c6fcfd70). (intervalTier, intervalNumber, U"c");
246 previousOpeningTime = openingTime;
247 }
248 }
249 }
250 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
251 } catch (MelderErrorcxx . . $ MelderError#) {
252 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": TextTier not created.");
253 }
254
255 }
256
257 autoSoundcxx . . $ autoSound# Electroglottogram_firstCentralDifferencecxx . . $ Electroglottogram_firstCentralDifference(f4a160f94e6bf470). (Electroglottogramcxx . . $ Electroglottogram# me, double peakAmplitude) {
258 try {
259 autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.);
260 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 0.0;
261 for (integercxx . . $ integer# i = 2; i < mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++)
262 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + 1] - mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i - 1]) / (2.0 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.);
263
264 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.] = 0.0;
265 if (peakAmplitude != 0.0)
266 Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), peakAmplitude);
267 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
268 } catch (MelderErrorcxx . . $ MelderError#) {
269 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create the simple derivative of the Electroglottogram.");
270 }
271 }
272
273 /*
274 Derivative of x(t) = integral (X(f)exp(2*pi*f*t) * df)
275 d(x(t)/dt = integral (X(f)*2*pi*i*exp(2*pi*f*t) * df)
276 = integral ((-2*pi*f*Im(X(f)), 2*pi*f*Re(X(f))) * exp (2*pi*f*t) * df)
277 */
278 autoSoundcxx . . $ autoSound# Electroglottogram_derivativecxx . . $ Electroglottogram_derivative(d06b633b17213879). (Electroglottogramcxx . . $ Electroglottogram# me, double lowPassFrequency, double smoothing, double peakAmplitude) {
279 try {
280 autoSpectrumcxx . . $ autoSpectrum# thee = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (me, false);
281 for (integercxx . . $ integer# ifreq = 1; ifreq <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; ifreq ++) {
282 const double frequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ifreq);
283 const double im = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq];
284 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq] = NUM2picxx . . $ NUM2pi. * frequency * thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq];
285 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq] = - NUM2picxx . . $ NUM2pi. * frequency * im;
286 }
287 Spectrum_passHannBandcxx . . $ Spectrum_passHannBand(4e1fbc861a283982). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0, lowPassFrequency, smoothing);
288 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
289 if (peakAmplitude != 0.0)
290 Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), peakAmplitude);
291 return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
292 } catch (MelderErrorcxx . . $ MelderError#) {
293 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create the derivative of the Electroglottogram.");
294 }
295 }
296
297 autoElectroglottogramcxx . . $ autoElectroglottogram# Electroglottogram_highPassFiltercxx . . $ Electroglottogram_highPassFilter(2671f9865a5ef66a). (Electroglottogramcxx . . $ Electroglottogram# me, double fromFrequency, double smoothing) {
298 try {
299 autoElectroglottogramcxx . . $ autoElectroglottogram# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me);
300 autoSpectrumcxx . . $ autoSpectrum# spec = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). (me, true);
301 Spectrum_passHannBandcxx . . $ Spectrum_passHannBand(4e1fbc861a283982). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), fromFrequency, spec ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xmaxcxx . . $ structFunction#xmax., smoothing);
302 autoSoundcxx . . $ autoSound# him = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spec.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
303 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.);
304 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
305 } catch (MelderErrorcxx . . $ MelderError#) {
306 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not high-pass filered.");
307 }
308 }
309
310 autoSoundcxx . . $ autoSound# Electroglottogram_to_Soundcxx . . $ Electroglottogram_to_Sound(6d3c54e5a4940ed). (Electroglottogramcxx . . $ Electroglottogram# me) {
311 try {
312 autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.);
313 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1);
314 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
315 } catch (MelderErrorcxx . . $ MelderError#) {
316 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Sound.");
317 }
318 }
319
320 /* End of file Electroglottogram.cpp */