1 #ifndef _Sampled_h_
2 #define _Sampled_h_
3 /* Sampled.h
4 *
5 * Copyright (C) 1992-2005,2007,2011,2013-2020 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 2 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
Sampled_indexToX(Sampled me,T index)32 template <typename T> static inline double Sampled_indexToX (Sampled me, T index) { return my x1 + (index - (T) 1) * my dx; }
Sampled_xToIndex(Sampled me,double x)33 static inline double Sampled_xToIndex (Sampled me, double x) { return (x - my x1) / my dx + 1.0; }
Sampled_xToLowIndex(Sampled me,double x)34 static inline integer Sampled_xToLowIndex (Sampled me, double x) { return Melder_ifloor ((x - my x1) / my dx + 1.0); }
Sampled_xToHighIndex(Sampled me,double x)35 static inline integer Sampled_xToHighIndex (Sampled me, double x) { return Melder_iceiling ((x - my x1) / my dx + 1.0); }
Sampled_xToNearestIndex(Sampled me,double x)36 static inline integer Sampled_xToNearestIndex (Sampled me, double x) { return Melder_iround ((x - my x1) / my dx + 1.0); }
37
Sampled_listAllXValues(Sampled me)38 static inline autoVEC Sampled_listAllXValues (Sampled 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 (Sampled me, double xmin, double xmax, integer *ixmin, integer *ixmax);
46
47 void Sampled_init (Sampled me, double xmin, double xmax, integer nx, double dx, double x1);
48
49 void Sampled_shortTermAnalysis (Sampled 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 (Sampled me, integer sampleNumber, integer levelNumber, int unit);
82 autoVEC Sampled_listValuesOfAllSamples (Sampled me, integer levelNumber, int unit);
83 double Sampled_getValueAtX (Sampled me, double x, integer levelNumber, int unit, bool interpolate);
84 autoVEC Sampled_listValuesAtXes (Sampled me, constVECVU const& xes, integer levelNumber, int unit, bool interpolate);
85
86 integer Sampled_countDefinedSamples
87 (Sampled me, double xmin, double xmax, integer levelNumber, int unit);
88 autoVEC Sampled_getSortedValues
89 (Sampled me, double xmin, double xmax, integer levelNumber, int unit);
90
91 double Sampled_getQuantile
92 (Sampled me, double xmin, double xmax, double quantile, integer levelNumber, int unit);
93 double Sampled_getMean
94 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
95 double Sampled_getMean_standardUnit
96 (Sampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
97 double Sampled_getIntegral
98 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
99 double Sampled_getIntegral_standardUnit
100 (Sampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
101 double Sampled_getStandardDeviation
102 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
103 double Sampled_getStandardDeviation_standardUnit
104 (Sampled me, double xmin, double xmax, integer levelNumber, int averagingUnit, bool interpolate);
105
106 void Sampled_getMinimumAndX
107 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate,
108 double *return_minimum, double *return_xOfMinimum);
109 double Sampled_getMinimum
110 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
111 double Sampled_getXOfMinimum
112 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
113 void Sampled_getMaximumAndX
114 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate,
115 double *return_maximum, double *return_xOfMaximum);
116 double Sampled_getMaximum
117 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
118 double Sampled_getXOfMaximum
119 (Sampled me, double xmin, double xmax, integer levelNumber, int unit, bool interpolate);
120
121 void Sampled_drawInside
122 (Sampled me, Graphics g, double xmin, double xmax, double ymin, double ymax, bool speckle, integer levelNumber, int unit);
123
124 /* End of file Sampled.h */
125 #endif
126