Debian Codegraph @

fon/Intensity.cpp

raw symbols SCIP
1 /* Intensity.cpp
2 *
3 * Copyright (C) 1992-2007,2011,2012,2015-2019,2022,2023 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 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 "Intensity.h"
20
21 Thing_implement (Intensity, Vector, 2);
22
23 void structIntensity :: v1_info () {
24 structDaata :: v1_info ();
25 MelderInfo_writeLine (U"Time domain:");
26 MelderInfo_writeLine (U" Start time: ", xmin, U" seconds");
27 MelderInfo_writeLine (U" End time: ", xmax, U" seconds");
28 MelderInfo_writeLine (U" Total duration: ", xmax - xmin, U" seconds");
29 MelderInfo_writeLine (U"Time sampling:");
30 MelderInfo_writeLine (U" Number of frames: ", nx);
31 MelderInfo_writeLine (U" Time step: ", dx, U" seconds");
32 MelderInfo_writeLine (U" First frame centred at: ", x1, U" seconds");
33 }
34
35 double structIntensity :: v_convertStandardToSpecialUnit (double value, integer /* level */, int unit) const {
36 if (unit == 1) {
37 return pow (10.0, 0.1 * value); // energy
38 } else if (unit == 2) {
39 return pow (2.0, 0.1 * value); // sones
40 }
41 return value; // default, especially if units == 0 (as in Vector_getMean) or units == 3 (averaging_DB)
42 }
43
44 double structIntensity :: v_convertSpecialToStandardUnit (double value, integer /* level */, int unit) const {
45 return
46 unit == 1 ?
47 10.0 * log10 (value) : // value = energy
48 unit == 2 ?
49 10.0 * NUMlog2 (value) : // value = sones
50 value; // value = dB
51 }
52
53 void Intensity_init (Intensity me, double tmin, double tmax, integer nt, double dt, double t1) {
54 Matrix_init (me, tmin, tmax, nt, dt, t1, 1.0, 1.0, 1, 1.0, 1.0);
55 }
56
57 autoIntensity Intensity_create (double tmin, double tmax, integer nt, double dt, double t1) {
58 try {
59 autoIntensity me = Thing_new (Intensity);
60 Intensity_init (me.get(), tmin, tmax, nt, dt, t1);
61 return me;
62 } catch (MelderError) {
63 Melder_throw (U"Intensity not created.");
64 }
65 }
66
67 autoMatrix Intensity_to_Matrix (Intensity me) {
68 try {
69 autoMatrix thee = Thing_new (Matrix);
70 my structMatrix :: v1_copy (thee.get());
71 return thee;
72 } catch (MelderError) {
73 Melder_throw (me, U": not converted to Matrix.");
74 }
75 }
76
77 autoIntensity Matrix_to_Intensity (Matrix me) {
78 try {
79 autoIntensity thee = Thing_new (Intensity);
80 my structMatrix :: v1_copy (thee.get());
81 return thee;
82 } catch (MelderError) {
83 Melder_throw (me, U": not converted to Intensity.");
84 }
85 }
86
87 void Intensity_drawInside (Intensity me, Graphics g, double tmin, double tmax, double minimum, double maximum) {
88 Function_unidirectionalAutowindow (me, & tmin, & tmax);
89 integer itmin, itmax;
90 Matrix_getWindowSamplesX (me, tmin, tmax, & itmin, & itmax);
91 if (maximum <= minimum)
92 Matrix_getWindowExtrema (me, itmin, itmax, 1, 1, & minimum, & maximum); // autoscale
93 if (maximum <= minimum) { minimum -= 10; maximum += 10; }
94 Graphics_setWindow (g, tmin, tmax, minimum, maximum);
95 Graphics_function (g, & my z [1] [0], itmin, itmax, Matrix_columnToX (me, itmin), Matrix_columnToX (me, itmax));
96 }
97
98 void Intensity_draw (Intensity me, Graphics g, double tmin, double tmax,
99 double minimum, double maximum, bool garnish)
100 {
101 Graphics_setInner (g);
102 Intensity_drawInside (me, g, tmin, tmax, minimum, maximum);
103 Graphics_unsetInner (g);
104 if (garnish) {
105 Graphics_drawInnerBox (g);
106 Graphics_textBottom (g, true, U"Time (s)");
107 Graphics_marksBottom (g, 2, true, true, false);
108 Graphics_marksLeft (g, 2, true, true, false);
109 Graphics_textLeft (g, true, U"Intensity (dB)");
110 }
111 }
112
113 double Intensity_getQuantile (Intensity me, double tmin, double tmax, double quantile) {
114 return Sampled_getQuantile (me, tmin, tmax, quantile, 0, Intensity_units_DB);
115 }
116
117 double Intensity_getAverage (Intensity me, double tmin, double tmax, int averagingMethod) {
118 return
119 averagingMethod == Intensity_averaging_MEDIAN ?
120 Intensity_getQuantile (me, tmin, tmax, 0.50) :
121 Sampled_getMean_standardUnit (me, tmin, tmax, 0, averagingMethod, true);
122 }
123
124 /* End of file Intensity.cpp */