-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPraatSound.h
More file actions
273 lines (225 loc) · 17.1 KB
/
Copy pathPraatSound.h
File metadata and controls
273 lines (225 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#pragma once
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <wchar.h>
#include <limits>
#ifdef MAKEPRAATLIB
#include <sys/time.h>
extern "C" {
// Praat Stuff
#include "melder.h"
#include "Sound.h"
#include "Pitch.h"
#include "Sound_to_PointProcess.h"
#include "Pitch_to_PointProcess.h"
#include "Pitch_to_PitchTier.h"
#include "Sound_to_Pitch.h"
#include "VoiceAnalysis.h"
#include "AmplitudeTier.h"
#include "Harmonicity.h"
#include "Sound_to_Harmonicity.h"
#include "Sound_to_Intensity.h"
#include "RealTier.h"
#include "PointProcess.h"
#include "Sound_to_Formant.h"
#include "Formant.h"
#include "Intensity.h"
#include "Sampled.h"
#include "Spectrum.h"
#include "Ltas.h"
#include "Sound_and_Spectrum.h"
}
#define THROW(errno, errdesc) { if(Melder_hasError()) { fprintf(stderr, "%s", Melder_getError()); Melder_clearError(); } fprintf(stderr, "%d %s, line %d in %s\n", errno, errdesc, __LINE__, __FILE__); throw(errno); }
#else
#define Sound void*
#define Sampled void*
#define Pitch void*
#define PointProcess void*
#define AmplitudeTier void*
#define Harmonicity void*
#define PitchTier void*
#define Formant void*
#define Intensity void*
#define Spectrum void*
#define Ltas void*
#endif
class PraatSound
{
public:
enum WindowFunctions {wfRectangular, wfTriangular, wfParabolic, wfHanning, wfHamming, wfGaussian1, wfGaussian2, wfGaussian3, wfGaussian4, wfGaussian5, wfKaiser1, wfKaiser2};
enum RawEncodings {reUnknown, reLinear8bitSigned, reLinear8bitUnsigned, reLinear16bitBE, reLinear16bitLE, reLinear24bitBE, reLinear24bitLE, reLinear32bitBE, reLinear32bitLE, reMuLaw, reALaw, reShorten, rePolyphone, reFloat32bitBE, reFloat32bitLE, reFlac, reMPEG};
struct SegmentDef
{
SegmentDef(int id = -1);
virtual ~SegmentDef();
int id;
double start;
double end;
WindowFunctions func;
Sound snd;
Pitch pitch; double pitch_fmin, pitch_fmax;
PointProcess pp; Pitch pp_pitch;
PitchTier pitcht; Pitch pitcht_pitch;
AmplitudeTier peaks; PointProcess peaks_pp; double peaks_pmin, peaks_pmax, peaks_mpf;
Harmonicity harm; bool harm_ac; double harm_step, harm_fmin, harm_silence_threshold, harm_periods_per_window;
Intensity intens; bool intens_subtract_mean; double intens_step, intens_fmin;
Formant form; int form_maxform; double form_step, form_fmax, form_window_length, form_preemphasis_frequency;
Spectrum spec;
Ltas ltas; Spectrum ltas_spec; double ltas_bandwidth;
};
// Creates a sound from a file *with* header that is supported by Praat
// (WAV, AU, SPH,...)
PraatSound(char* filename);
PraatSound(wchar_t* filename);
// Creates a sound from raw (i.e. without header) data.
// The format/encoding must be specified.
PraatSound(char* rawdata, int length, int sample_rate = 16000, int channels = 1, RawEncodings encoding = reLinear16bitBE);
virtual ~PraatSound();
// Reads segments from an 'RTTM' format file, overriding any existing parts.
// If a window function should be applied to all segments, specify it here. Note that
// using a window function makes computation slower and requires up to twice the memory.
void SegmentsReadRTTM(char* filename, WindowFunctions func = PraatSound::wfRectangular);
// Resets the list of segments, i.e. deletes all segments/
void SegmentsClear(int capacity);
// Adds a new segment using the given time range and window function.
// Note: No window function (0) is faster and less memory-consuming.
void SegmentsAdd(double start, double end, WindowFunctions func = PraatSound::wfRectangular);
// Retrieves multiple features by name.
// 'features' is an array of feature names.
// 'segment' can be segment index, '-1' for full waveform, or '-2' (default) for all
// segments (or same as '-1' if no segments are defined).
// Return value is an array of 'double' values.
// To benchmark, pre-initialize 'times' with an array of the same size as the
// expected return array. It will contain one duration (in seconds) for each
// feature.
double* GetMultiple(char** features, int num_features, int segment = -2, double* times = NULL);
double GetPitchMean(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchMedian(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchMin(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchMax(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchRange(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchMAS(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool no_octave = true);
double GetPitchVoiced(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchCandidatesMean(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchCandidatesMedian(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchCandidatesMin(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchCandidatesMax(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchCandidatesRange(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchCandidatesStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchStrengthMean(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchStrengthMedian(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchStrengthMin(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchStrengthMax(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchStrengthRange(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchStrengthStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchEnergyMean(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchEnergyMedian(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchEnergyMin(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchEnergyMax(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchEnergyRange(int segment = -1, double fmin = 75.0, double fmax = 600.0, bool quant = true);
double GetPitchEnergyStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchTierNumSamples(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchTierMean(int segment = -1, double fmin = 75.0, double fmax = 600.0);
//double GetPitchTierMeanPoints(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPitchTierStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0);
//double GetPitchTierStdDevPoints(int segment = -1, double fmin = 75.0, double fmax = 600.0);
double GetPointProcessNumSamples(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetPointProcessNumPeriods(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetPointProcessPeriodMean(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetPointProcessPeriodStdDev(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetJitterRAP(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetJitterPPQ5(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetJitterLocal(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetJitterLocalAbs(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetJitterDDP(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3);
double GetShimmerAPQ3(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetShimmerAPQ5(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetShimmerAPQ11(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetShimmerLocal(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetShimmerLocalDb(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetShimmerDDA(int segment = -1, double fmin = 75.0, double fmax = 600.0, double pmin = 0.0001, double pmax = 0.02, double maximum_period_factor = 1.3, double maximum_amplitude_factor = 1.6);
double GetHarmonicityMean(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5);
double GetHarmonicityMedian(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5);
double GetHarmonicityMin(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5, bool quant = true);
double GetHarmonicityMax(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5, bool quant = true);
double GetHarmonicityRange(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5, bool quant = true);
double GetHarmonicityStdDev(int segment = -1, bool ac = true, double step = 0.01, double fmin = 75.0, double silence_threshold = 0.1, double periods_per_window = 4.5);
double GetFormantMean(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0);
double GetFormantMedian(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0);
double GetFormantMin(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetFormantMax(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetFormantRange(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetFormantStdDev(int segment = -1, int formant = 1, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0);
double GetFormantsDispMean(int segment = -1, int formants = 5, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0);
double GetFormantsDispMedian(int segment = -1, int formants = 5, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0);
double GetFormantsDispMin(int segment = -1, int formants = 5, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetFormantsDispMax(int segment = -1, int formants = 5, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetFormantsDispRange(int segment = -1, int formants = 5, double step = 0.0, double fmax = 5500.0, double window_length = 0.025, double preemphasis_frequency = 50.0, bool quant = true);
double GetEnergyMean(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true);
double GetEnergyMedian(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true);
double GetEnergyMin(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true, bool quant = true);
double GetEnergyMax(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true, bool quant = true);
double GetEnergyRange(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true, bool quant = true);
double GetEnergyStdDev(int segment = -1, double step = 0.0, double fmin = 100.0, bool subtract_mean = true);
double GetLtasEnergyMean(int segment = -1, double fmin = 0.0, double fmax = 0.0, double bandwidth = 100.0);
double GetLtasEnergyMin(int segment = -1, double fmin = 0.0, double fmax = 0.0, double bandwidth = 100.0);
double GetLtasEnergyMax(int segment = -1, double fmin = 0.0, double fmax = 0.0, double bandwidth = 100.0);
double GetLtasEnergyRange(int segment = -1, double fmin = 0.0, double fmax = 0.0, double bandwidth = 100.0);
double GetLtasEnergyStdDev(int segment = -1, double fmin = 0.0, double fmax = 0.0, double bandwidth = 100.0);
double GetLtasEnergySlope(int segment = -1, double flow_min = 0.0, double flow_max = 1000.0, double fhigh_min = 1000.0, double fhigh_max = 4000.0, double bandwidth = 100.0);
double GetLtasEnergyLocalPeakHeight(int segment = -1, double environment_min = 1700.0, double environment_max = 4200.0, double peak_min = 2400.0, double peak_max = 3200.0, double bandwidth = 100.0);
//double GetLtasHarmonicsRatio(int segment = -1, double bandwidth = 100.0, int hmax = 4);
int GetNumSegments();
double GetDuration();
// -------------- Praat Parameters --------------
bool p_Quant; // Use quantiles instead of absolute min/max (where possible)?
double p_QuantMin, p_QuantMax;
double p_Pitch_fmin, p_Pitch_fmax;
double p_PP_pmin, p_PP_pmax, p_PP_maximum_period_factor;
double p_AT_maximum_amplitude_factor;
bool p_Harm_ac; double p_Harm_step, p_Harm_fmin, p_Harm_silence_threshold, p_Harm_periods_per_window;
int p_Form_max; double p_Form_step, p_Form_fmax, p_Form_window_length, p_Form_preemphasis_frequency;
bool p_Intens_subtract_mean; double p_Intens_step, p_Intens_fmin;
int p_Ltas_hmax; double p_Ltas_bandwidth, p_Ltas_fmin, p_Ltas_fmax, p_Ltas_flow_min, p_Ltas_flow_max;
double p_Ltas_fhigh_min, p_Ltas_fhigh_max, p_Ltas_environment_min, p_Ltas_environment_max, p_Ltas_peak_min, p_Ltas_peak_max;
private:
SegmentDef whole;
SegmentDef** m_segments;
int m_num_segments;
/*
Sound m_snd;
Pitch m_pitch; Sound m_pitch_snd; double m_pitch_fmin, m_pitch_fmax;
PointProcess m_pp;
AmplitudeTier m_peaks;
Harmonicity m_harm;
Intensity m_intens;
*/
void InitInt();
void ReadSoundInt(wchar_t* filename);
void GetRange(int segment, double& min, double& max);
SegmentDef* GetSegment(int segment, bool no_range = false);
void GetSampledBounds(Sampled obj, double tmin, double tmax, int& imin, int& imax);
double currenttime();
Pitch UpdatePitch(int segment, double fmin, double fmax, bool no_range = false);
PointProcess UpdatePointProcess(int segment, double fmin, double fmax, bool no_range = false);
AmplitudeTier UpdateAmplitudeTier(int segment, double fmin, double fmax, double pmin, double pmax, double maximum_period_factor);
Harmonicity UpdateHarmonicity(int segment, bool ac, double step, double fmin, double silence_threshold, double periods_per_window, bool no_range = false);
PitchTier UpdatePitchTier(int segment, double fmin, double fmax, bool no_range = false);
Formant UpdateFormant(int segment, double step, double fmax, double window_length, double preemphasis_frequency, bool no_range = false);
Intensity UpdateIntensity(int segment, double step, double fmin, bool subtract_mean, bool no_range = false);
Spectrum UpdateSpectrum(int segment, bool no_range = false);
Ltas UpdateLtas(int segment, double bandwidth, bool no_range = false);
double* PitchCandidatesToArray(Pitch obj, double tmin, double tmax, int& length);
double* PitchIntensityToArray(Pitch obj, double tmin, double tmax, int& length);
double* PitchStrengthMeanToArray(Pitch obj, double tmin, double tmax, int& length);
double GetPitchFrameFeature (int segment, double fmin, double fmax, int feat, int measure, bool alt);
double ArrGetMean(double* arr, int length);
double ArrGetQuantile(double* arr, int length, double pos);
double ArrGetMin(double* arr, int length);
double ArrGetMax(double* arr, int length);
double ArrGetRange(double* arr, int length);
double ArrGetStdDev(double* arr, int length);
};