Debian Codegraph @

fon/Sampled.h

raw symbols SCIP
1 #ifndef _Sampled_h_
2 #define _Sampled_h_
3 /* Sampled.h
4 *
5 * Copyright (C) 1992-2005,2007,2011,2013-2020,2024,2025 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /* Sampled inherits from Function */
22 #include "Function.h"
23 #include "Graphics.h"
24
25 #include "Sampled_def.h"
26
27 /* A Sampled is a Function that is sampled at nx points [1..nx], */
28 /* which are spaced apart by a constant distance dx. */
29 /* The first sample point is at x1, the second at x1 + dx, */
30 /* and the last at x1 + (nx - 1) * dx. */
31
32 template <typename T> static inline double Sampled_indexToX (constSampled me, T index) { return my x1 + (index - (T) 1) * my dx; }
33 static inline double Sampled_xToIndex (constSampled me, double x) { return (x - my x1) / my dx + 1.0; }
34 static inline integer Sampled_xToLowIndex (constSampled me, double x) { return Melder_ifloor ((x - my x1) / my dx + 1.0); }
35 static inline integer Sampled_xToHighIndex (constSampled me, double x) { return Melder_iceiling ((x - my x1) / my dx + 1.0); }
36 static inline integer Sampled_xToNearestIndex (constSampled me, double x) { return Melder_iround ((x - my x1) / my dx + 1.0); }
37
38 static inline autoVEC Sampled_listAllXValues (constSampled me) {
39 autoVEC result = raw_VEC (my nx);
40 for (integer i = 1; i <= my nx; i ++)
41 result [i] = my x1 + (i - 1) * my dx;
42 return result;
43 }
44
45 integer Sampled_getWindowSamples (constSampled me, double xmin, double xmax, integer *ixmin, integer *ixmax);
46
47 void Sampled_init (mutableSampled me, double xmin, double xmax, integer nx, double dx, double x1);
48
49 void Sampled_shortTermAnalysis (constSampled me, double windowDuration, double timeStep,
50 integer *numberOfFrames, double *firstTime);
51 /*
52 Function:
53 how to put as many analysis windows of length 'windowDuration' as possible into my duration,
54 when they are equally spaced by 'timeStep'.
55 Input arguments:
56 windowDuration:
57 the duration of the analysis window, in seconds.
58 timeStep:
59 the time step, in seconds.
60 Output arguments:
61 numberOfFrames:
62 at least 1 (if no failure); equals floor ((nx * dx - windowDuration) / timeStep) + 1.
63 firstTime:
64 the centre of the first frame, in seconds.
65 Failures:
66 Window longer than signal.
67 Postconditions:
68 the frames are divided symmetrically over my defined domain,
69 which is [x1 - dx/2, x[nx] + dx/2], where x[nx] == x1 + (nx - 1) * dx.
70 All analysis windows will fit into this domain.
71 Usage:
72 the resulting Sampled (analysis sequence, e.g., Pitch, Formant, Spectrogram, etc.)
73 will have the following attributes:
74 result -> xmin == my xmin; // Copy logical domain.
75 result -> xmax == my xmax;
76 result -> nx == numberOfFrames;
77 result -> dx == timeStep;
78 result -> x1 == firstTime;
79 */
80
81 double Sampled_getValueAtSample (constSampled me, integer sampleNumber, integer levelNumber, int unit);
82 autoVEC Sampled_listValuesOfAllSamples (constSampled me, integer levelNumber, int unit);
83 double Sampled_getValueAtX (constSampled me, double x, integer levelNumber, int unit, bool interpolate);
84 autoVEC Sampled_listValuesAtXes (constSampled me, constVECVU const& xes, integer levelNumber, int unit, bool interpolate);
85
86 integer Sampled_countDefinedSamples
87 (constSampled me, double xmin, double xmax, integer levelNumber, int unit);
88 autoVEC Sampled_getSortedValues
89 (constSampled me, double xmin, double xmax, integer levelNumber, int unit);
90
91 double Sampled_getQuantile
92 (constSampled me, double xmin, double xmax, double quantile, integer levelNumber, int unit);
93 double Sampled_getMean
94 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
95 double Sampled_getMeanOfSquared
96 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
97 double Sampled_getMean_standardUnit
98 (constSampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
99 double Sampled_getMeanOfSquared_standardUnit
100 (constSampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
101 double Sampled_getIntegral
102 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
103 double Sampled_getIntegralOfSquared
104 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
105 double Sampled_getIntegral_standardUnit
106 (constSampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
107 double Sampled_getIntegralOfSquared_standardUnit
108 (constSampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
109 double Sampled_getStandardDeviation
110 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
111 double Sampled_getStandardDeviation_standardUnit
112 (constSampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
113
114 void Sampled_getMinimumAndX
115 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate,
116 double *return_minimum, double *return_xOfMinimum);
117 double Sampled_getMinimum
118 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
119 double Sampled_getXOfMinimum
120 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
121 void Sampled_getMaximumAndX
122 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate,
123 double *return_maximum, double *return_xOfMaximum);
124 double Sampled_getMaximum
125 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
126 double Sampled_getXOfMaximum
127 (constSampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
128
129 void Sampled_drawInside
130 (constSampled me, Graphics g, double xmin, double xmax, double ymin, double ymax, bool speckle, integer levelNumber, int unit);
131
132 inline void Sampleds_requireEqualSampling (constSampled me, constSampled thee) {
133 Melder_require (my x1 == thy x1 && my nx == thy nx && my dx == thy dx,
134 U"The sampling of ", me, U" and ", thee, U" should be equal.");
135 }
136
137 inline void Sampleds_assertEqualSampling (constSampled me, constSampled thee) {
138 Melder_assert (my x1 == thy x1 && my nx == thy nx && my dx == thy dx);
139 }
140
141 inline void Sampleds_requireEqualDomains (constSampled me, constSampled thee) {
142 Melder_require (my xmin == thy xmin && my xmax == thy xmax,
143 U"The domains of ", me, U" and ", thee, U" should be equal.");
144 }
145
146 inline void Sampleds_assertEqualDomains (constSampled me, constSampled thee) {
147 Melder_assert (my xmin == thy xmin && my xmax == thy xmax);
148 }
149
150 inline void Sampleds_requireEqualDomainsAndSampling (constSampled me, constSampled thee) {
151 Sampleds_requireEqualDomains (me, thee);
152 Sampleds_requireEqualSampling (me, thee);
153 }
154
155 inline void Sampleds_assertEqualDomainsAndSampling (constSampled me, constSampled thee) {
156 Sampleds_assertEqualDomains (me, thee);
157 Sampleds_assertEqualSampling (me, thee);
158 }
159
160 /* End of file Sampled.h */
161 #endif