Skip to content
Commits on Source (5)
/* FFNet.cpp
*
* Copyright (C) 1997-2018 David Weenink
* Copyright (C) 1997-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -630,7 +630,7 @@ void FFNet_drawActivation (FFNet me, Graphics g) {
}
/* This routine is deprecated since praat-4.2.4 20040422 and will be removed in the future. */
void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int layer, int scaling, int garnish) {
void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int layer, int scaling, bool garnish) {
Melder_require (layer > 0 && layer <= my numberOfLayers, U"Layer number should be between 1 and ", my numberOfLayers, U".");
autoMatrix weights = FFNet_weightsToMatrix (me, layer, false);
......@@ -653,12 +653,12 @@ void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int layer, int scaling, int
}
}
void FFNet_drawWeights (FFNet me, Graphics g, integer layer, int garnish) {
void FFNet_drawWeights (FFNet me, Graphics g, integer layer, bool garnish) {
autoTableOfReal thee = FFNet_extractWeights (me, layer);
TableOfReal_drawAsSquares (thee.get(), g, 1, thy numberOfRows, 1, thy numberOfColumns, garnish);
}
void FFNet_drawCostHistory (FFNet me, Graphics g, integer iFrom, integer iTo, double costMin, double costMax, int garnish) {
void FFNet_drawCostHistory (FFNet me, Graphics g, integer iFrom, integer iTo, double costMin, double costMax, bool garnish) {
if (my minimizer)
Minimizer_drawHistory (my minimizer.get(), g, iFrom, iTo, costMin, costMax, 0);
......
......@@ -2,7 +2,7 @@
#define _FFNet_h_
/* FFNet.h
*
* Copyright (C) 1997-2018 David Weenink
* Copyright (C) 1997-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -210,20 +210,20 @@ void FFNet_drawTopology (FFNet me, Graphics g);
void FFNet_drawActivation (FFNet me, Graphics g);
void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int toLayer, int scaling, int garnish);
void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int toLayer, int scaling, bool garnish);
/* Deprecated: the strengths of the weights that connect to the nodes in later 'layer' */
/* are drawn with boxes. The area of each box corresponds to the strength. */
/* Black boxes have negative strength? */
void FFNet_drawCostHistory (FFNet me, Graphics g, integer from_iteration, integer to_iteration,
double from_cost, double to_cost, int garnish);
double from_cost, double to_cost, bool garnish);
/* draw cost vs epochs */
autoCollection FFNet_createIrisExample (integer numberOfHidden1, integer numberOfHidden2);
autoTableOfReal FFNet_extractWeights (FFNet me, integer layer);
void FFNet_drawWeights (FFNet me, Graphics g, integer layer, int garnish);
void FFNet_drawWeights (FFNet me, Graphics g, integer layer, bool garnish);
autoFFNet FFNet_TabelOfReal_to_FFNet (FFNet me, TableOfReal him, integer layer);
......
/* manual_FFNet.c
*
* Copyright (C) 1994-2013, 2016 David Weenink
* Copyright (C) 1994-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/* Cepstrogram.cpp
*
* Copyright (C) 2013 - 2017 David Weenink
* Copyright (C) 2013 - 2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -29,6 +29,12 @@
#include "Sound_and_Spectrum.h"
#include "Sound_extensions.h"
#include "enums_getText.h"
#include "Cepstrum_enums.h"
#include "enums_getValue.h"
#include "Cepstrum_enums.h"
#define TOLOG(x) ((1 / NUMln10) * log ((x) + 1e-30))
#define TO10LOG(x) ((10 / NUMln10) * log ((x) + 1e-30))
#define FROMLOG(x) (exp ((x) * (NUMln10 / 10.0)) - 1e-30)
......@@ -58,7 +64,7 @@ autoPowerCepstrogram PowerCepstrogram_create (double tmin, double tmax, integer
}
}
void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, int garnish) {
void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, bool garnish) {
if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; }
if (qmax <= qmin) { qmin = my ymin; qmax = my ymax; }
integer itmin, itmax, ifmin, ifmax;
......@@ -112,12 +118,12 @@ void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, doubl
}
}
void PowerCepstrogram_subtractTilt_inplace (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod) {
void PowerCepstrogram_subtractTrend_inplace (PowerCepstrogram me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
try {
autoPowerCepstrum thee = PowerCepstrum_create (my ymax, my ny);
for (integer i = 1; i <= my nx; i ++) {
thy z.row (1) <<= my z.column (i);
PowerCepstrum_subtractTilt_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
PowerCepstrum_subtractTrend_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
my z.column (i) <<= thy z.row (1);
}
} catch (MelderError) {
......@@ -125,10 +131,10 @@ void PowerCepstrogram_subtractTilt_inplace (PowerCepstrogram me, double qstartFi
}
}
autoPowerCepstrogram PowerCepstrogram_subtractTilt (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod) {
autoPowerCepstrogram PowerCepstrogram_subtractTrend (PowerCepstrogram me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
try {
autoPowerCepstrogram thee = Data_copy (me);
PowerCepstrogram_subtractTilt_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
PowerCepstrogram_subtractTrend_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
return thee;
} catch (MelderError) {
Melder_throw (me, U": no tilt subtracted.");
......@@ -155,7 +161,7 @@ autoTable PowerCepstrogram_to_Table_hillenbrand (PowerCepstrogram me, double pit
}
}
autoTable PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod) {
autoTable PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
try {
autoTable thee = Table_createWithColumnNames (my nx, U"time quefrency cpp f0 rnr");
autoPowerCepstrum him = PowerCepstrum_create (my ymax, my ny);
......@@ -347,13 +353,14 @@ autoPowerCepstrogram Sound_to_PowerCepstrogram_hillenbrand (Sound me, double pit
thy z [1] [i] -= 0.9 * thy z [1] [i - 1];
integer nosInWindow = Melder_ifloor (analysisWidth * samplingFrequency), numberOfFrames;
Melder_require (nosInWindow >= 8, U"Analysis window too short.");
Melder_require (nosInWindow >= 8,
U"Analysis window too short.");
double t1;
Sampled_shortTermAnalysis (thee.get(), analysisWidth, dt, & numberOfFrames, & t1);
autoVEC hamming = newVECraw (nosInWindow);
for (integer i = 1; i <= nosInWindow; i ++)
hamming [i] = 0.54 - 0.46 * cos (2.0 * NUMpi * (i - 1) / (nosInWindow - 1));
hamming [i] = 0.54 - 0.46 * cos (NUM2pi * (i - 1) / (nosInWindow - 1));
integer nfft = 8; // minimum possible
while (nfft < nosInWindow) { nfft *= 2; }
......@@ -406,11 +413,11 @@ autoPowerCepstrogram Sound_to_PowerCepstrogram_hillenbrand (Sound me, double pit
}
}
double PowerCepstrogram_getCPPS (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod) {
double PowerCepstrogram_getCPPS (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
try {
autoPowerCepstrogram flattened;
if (subtractTiltBeforeSmoothing)
flattened = PowerCepstrogram_subtractTilt (me, qstartFit, qendFit, lineType, fitMethod);
flattened = PowerCepstrogram_subtractTrend (me, qstartFit, qendFit, lineType, fitMethod);
autoPowerCepstrogram smooth = PowerCepstrogram_smooth (flattened ? flattened.get() : me, timeAveragingWindow, quefrencyAveragingWindow);
autoTable table = PowerCepstrogram_to_Table_cpp (smooth.get(), pitchFloor, pitchCeiling, deltaF0, interpolation, qstartFit, qendFit, lineType, fitMethod);
......@@ -425,7 +432,7 @@ double PowerCepstrogram_getCPPS_hillenbrand (PowerCepstrogram me, bool subtractT
try {
autoPowerCepstrogram him;
if (subtractTiltBeforeSmoothing)
him = PowerCepstrogram_subtractTilt (me, 0.001, 0, 1, 1);
him = PowerCepstrogram_subtractTrend (me, 0.001, 0, kCepstrumTrendType::Linear, kCepstrumTrendFit::LeastSquares);
autoPowerCepstrogram smooth = PowerCepstrogram_smooth (subtractTiltBeforeSmoothing ? him.get() : me, timeAveragingWindow, quefrencyAveragingWindow);
autoTable table = PowerCepstrogram_to_Table_hillenbrand (smooth.get(), pitchFloor, pitchCeiling);
......
......@@ -2,7 +2,7 @@
#define _Cepstrogram_h_
/* Cepstrogram.h
*
* Copyright (C) 2012-2017 David Weenink
* Copyright (C) 2012-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -37,6 +37,7 @@ Thing_define (Cepstrogram, Matrix) {
};
Thing_define (PowerCepstrogram, Cepstrogram) {
};
/*
xmin, xmax : time domain
nx, dx, x1 : sampling in the time domain
......@@ -52,7 +53,7 @@ autoCepstrogram Cepstrogram_create (double tmin, double tmax, integer nt, double
autoPowerCepstrogram PowerCepstrogram_create (double tmin, double tmax, integer nt, double dt, double t1, double qmin, double qmax, integer nq, double dq, double q1);
void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, int garnish);
void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, bool garnish);
autoPowerCepstrogram PowerCepstrogram_smooth (PowerCepstrogram me, double timeAveragingWindow, double quefrencyAveragingWindow);
......@@ -62,17 +63,17 @@ autoPowerCepstrogram Sound_to_PowerCepstrogram_hillenbrand (Sound me, double ana
autoTable PowerCepstrogram_to_Table_hillenbrand (PowerCepstrogram me, double pitchFloor, double pitchCeiling);
autoTable PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int method);
autoTable PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit method);
autoPowerCepstrum PowerCepstrogram_to_PowerCepstrum_slice (PowerCepstrogram me, double time);
autoPowerCepstrogram PowerCepstrogram_subtractTilt (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod);
autoPowerCepstrogram PowerCepstrogram_subtractTrend (PowerCepstrogram me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod);
void PowerCepstrogram_subtractTilt_inplace (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod);
void PowerCepstrogram_subtractTrend_inplace (PowerCepstrogram me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod);
double PowerCepstrogram_getCPPS_hillenbrand (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling);
double PowerCepstrogram_getCPPS (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod);
double PowerCepstrogram_getCPPS (PowerCepstrogram me, bool subtractTiltBeforeSmoothing, double timeAveragingWindow, double quefrencyAveragingWindow, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod);
autoMatrix PowerCepstrogram_to_Matrix (PowerCepstrogram me);
......
/* Cepstrum.cpp
*
* Copyright (C) 1994-2016 David Weenink
* Copyright (C) 1994-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -86,7 +86,7 @@ autoPowerCepstrum PowerCepstrum_create (double qmax, integer nq) {
}
}
static void _Cepstrum_draw (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, int power, int garnish) {
static void _Cepstrum_draw (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, int power, bool garnish) {
int autoscaling = minimum >= maximum;
Graphics_setInner (g);
......@@ -126,15 +126,15 @@ static void _Cepstrum_draw (Cepstrum me, Graphics g, double qmin, double qmax, d
}
}
void Cepstrum_drawLinear (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, int garnish) {
void Cepstrum_drawLinear (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, bool garnish) {
_Cepstrum_draw (me, g, qmin, qmax, minimum, maximum, 0, garnish);
}
void PowerCepstrum_draw (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, int garnish) {
void PowerCepstrum_draw (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, bool garnish) {
_Cepstrum_draw (me, g, qmin, qmax, dBminimum, dBmaximum, 1, garnish);
}
void PowerCepstrum_drawTiltLine (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, double qstart, double qend, int lineType, int method) {
void PowerCepstrum_drawTrendLine (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, double qstart, double qend, kCepstrumTrendType lineType, kCepstrumTrendFit method) {
Graphics_setInner (g);
......@@ -168,13 +168,13 @@ void PowerCepstrum_drawTiltLine (PowerCepstrum me, Graphics g, double qmin, doub
qend = qend > my xmax ? my xmax : qend;
double a, intercept;
PowerCepstrum_fitTiltLine (me, qstart, qend, &a, &intercept, lineType, method);
PowerCepstrum_fitTrendLine (me, qstart, qend, & a, & intercept, lineType, method);
/*
* Don't draw part outside window
*/
double lineWidth = Graphics_inqLineWidth (g);
Graphics_setLineWidth (g, 2);
if (lineType == 2) {
if (lineType == kCepstrumTrendType::ExponentialDecay ) {
integer n = 500;
double dq = (qend - qstart) / (n + 1);
double q1 = qstart;
......@@ -207,11 +207,10 @@ void PowerCepstrum_drawTiltLine (PowerCepstrum me, Graphics g, double qmin, doub
Graphics_unsetInner (g);
}
/* Fit line y = ax+b (lineType ==1) or y = a log(x) + b (lineType == 2) on interval [qmin,qmax]
* method == 1 : Least squares fit
* method == 2 : Theil's partial robust fit
/*
Fit line y = ax+b or y = a log(x) + b on interval [qmin,qmax]
*/
void PowerCepstrum_fitTiltLine (PowerCepstrum me, double qmin, double qmax, double *out_a, double *out_intercept, int lineType, int method) {
void PowerCepstrum_fitTrendLine (PowerCepstrum me, double qmin, double qmax, double *out_a, double *out_intercept, kCepstrumTrendType lineType, kCepstrumTrendFit method) {
try {
double a, intercept;
if (qmax <= qmin) {
......@@ -222,43 +221,34 @@ void PowerCepstrum_fitTiltLine (PowerCepstrum me, double qmin, double qmax, doub
integer imin, imax;
if (! Matrix_getWindowSamplesX (me, qmin, qmax, & imin, & imax))
return;
imin = (lineType == 2 && imin == 1) ? 2 : imin; // log(0) is undefined!
if (imin == 1 && lineType == kCepstrumTrendType::ExponentialDecay)
imin = 2; // because log(0) is undefined
integer numberOfPoints = imax - imin + 1;
Melder_require (numberOfPoints > 1, U"Not enough points for fit.");
Melder_require (numberOfPoints > 1,
U"Not enough points for fit.");
autoVEC y = newVECraw (numberOfPoints);
autoVEC x = newVECraw (numberOfPoints);
for (integer i = 1; i <= numberOfPoints; i ++) {
integer isamp = imin + i - 1;
x [i] = my x1 + (isamp - 1) * my dx;
if (lineType == 2)
if (lineType == kCepstrumTrendType::ExponentialDecay)
x [i] = log (x [i]);
y [i] = my v_getValueAtSample (isamp, 1, 0);
}
if (method == 3) { // try local maxima first
autoVEC ym = newVECraw (numberOfPoints / 2 + 1);
autoVEC xm = newVECraw (numberOfPoints / 2 + 1);
integer numberOfLocalPeaks = 0;
// forget y [1] if y [2]<y [1] and y [n] if y [n-1]<y [n] !
for (integer i = 2; i <= numberOfPoints; i ++) {
if (y [i - 1] <= y [i] && y [i] > y [i + 1]) {
ym [++ numberOfLocalPeaks] = y [i];
xm [numberOfLocalPeaks] = x [i];
}
}
if (numberOfLocalPeaks > numberOfPoints / 10) {
for (integer i = 1; i <= numberOfLocalPeaks; i ++) {
x [i] = xm [i];
y [i] = ym [i];
}
numberOfPoints = numberOfLocalPeaks;
}
method = 2; // robust fit of peaks
}
// fit a straight line through (x,y)'s
NUMlineFit (x.get(), y.get(), & a, & intercept, method);
if (out_intercept) *out_intercept = intercept;
if (out_a) *out_a = a;
if (method == kCepstrumTrendFit::LeastSquares)
NUMlineFit_LS (x.get(), y.get(), & a, & intercept);
else if (method == kCepstrumTrendFit::RobustFast)
NUMlineFit_theil (x.get(), y.get(), & a, & intercept, false);
else if (method == kCepstrumTrendFit::RobustSlow)
NUMlineFit_theil (x.get(), y.get(), & a, & intercept, true);
else {
Melder_throw (U"Invalid method.");
}
if (out_intercept)
*out_intercept = intercept;
if (out_a)
*out_a = a;
} catch (MelderError) {
Melder_throw (me, U": couldn't fit a line.");
}
......@@ -266,7 +256,7 @@ void PowerCepstrum_fitTiltLine (PowerCepstrum me, double qmin, double qmax, doub
#if 0
// Hillenbrand subtracts dB values and if the result is negative it is made zero
static void PowerCepstrum_subtractTiltLine_inline2 (PowerCepstrum me, double slope, double intercept, int lineType) {
static void PowerCepstrum_subtractTrendLine_inline2 (PowerCepstrum me, double slope, double intercept, int lineType) {
for (integer j = 1; j <= my nx; j ++) {
double q = my x1 + (j - 1) * my dx;
q = j == 1 ? 0.5 * my dx : q; // approximation
......@@ -280,11 +270,11 @@ static void PowerCepstrum_subtractTiltLine_inline2 (PowerCepstrum me, double slo
#endif
// clip with tilt line
static void PowerCepstrum_subtractTiltLine_inplace (PowerCepstrum me, double slope, double intercept, int lineType) {
static void PowerCepstrum_subtractTrendLine_inplace (PowerCepstrum me, double slope, double intercept, kCepstrumTrendType lineType) {
for (integer j = 1; j <= my nx; j ++) {
double q = my x1 + (j - 1) * my dx;
q = j == 1 ? 0.5 * my dx : q; // approximation
double xq = lineType == 2 ? log(q) : q;
double xq = lineType == kCepstrumTrendType::ExponentialDecay ? log(q) : q;
double db_background = slope * xq + intercept;
double db_cepstrum = my v_getValueAtSample (j, 1, 0);
double diff = db_cepstrum - db_background;
......@@ -296,16 +286,16 @@ static void PowerCepstrum_subtractTiltLine_inplace (PowerCepstrum me, double slo
}
void PowerCepstrum_subtractTilt_inplace (PowerCepstrum me, double qstartFit, double qendFit, int lineType, int fitMethod) {
void PowerCepstrum_subtractTrend_inplace (PowerCepstrum me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
double slope, intercept;
PowerCepstrum_fitTiltLine (me, qstartFit, qendFit, &slope, &intercept, lineType, fitMethod);
PowerCepstrum_subtractTiltLine_inplace (me, slope, intercept, lineType);
PowerCepstrum_fitTrendLine (me, qstartFit, qendFit, & slope, & intercept, lineType, fitMethod);
PowerCepstrum_subtractTrendLine_inplace (me, slope, intercept, lineType);
}
autoPowerCepstrum PowerCepstrum_subtractTilt (PowerCepstrum me, double qstartFit, double qendFit, int lineType, int fitMethod) {
autoPowerCepstrum PowerCepstrum_subtractTrend (PowerCepstrum me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod) {
try {
autoPowerCepstrum thee = Data_copy (me);
PowerCepstrum_subtractTilt_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
PowerCepstrum_subtractTrend_inplace (thee.get(), qstartFit, qendFit, lineType, fitMethod);
return thee;
} catch (MelderError) {
Melder_throw (me, U": couldn't subtract tilt line.");
......@@ -344,9 +334,10 @@ void PowerCepstrum_getMaximumAndQuefrency (PowerCepstrum me, double pitchFloor,
}
double peakdB, quefrency;
Vector_getMaximumAndX ((Vector) thee.get(), lowestQuefrency, highestQuefrency, 1, interpolation, & peakdB, & quefrency); // FIXME cast
if (out_peakdB) *out_peakdB = peakdB;
if (out_quefrency) *out_quefrency = quefrency;
if (out_peakdB)
*out_peakdB = peakdB;
if (out_quefrency)
*out_quefrency = quefrency;
}
double PowerCepstrum_getRNR (PowerCepstrum me, double pitchFloor, double pitchCeiling, double f0fractionalWidth) {
......@@ -390,22 +381,24 @@ double PowerCepstrum_getRNR (PowerCepstrum me, double pitchFloor, double pitchCe
double PowerCepstrum_getPeakProminence_hillenbrand (PowerCepstrum me, double pitchFloor, double pitchCeiling, double *out_qpeak) {
double slope, intercept, quefrency, peakdB;
PowerCepstrum_fitTiltLine (me, 0.001, 0, & slope, & intercept, 1, 1);
PowerCepstrum_fitTrendLine (me, 0.001, 0, & slope, & intercept, kCepstrumTrendType::Linear, kCepstrumTrendFit::LeastSquares);
autoPowerCepstrum thee = Data_copy (me);
PowerCepstrum_subtractTiltLine_inplace (thee.get(), slope, intercept, 1);
PowerCepstrum_subtractTrendLine_inplace (thee.get(), slope, intercept, kCepstrumTrendType::Linear);
PowerCepstrum_getMaximumAndQuefrency (thee.get(), pitchFloor, pitchCeiling, 0, & peakdB, & quefrency);
if (out_qpeak) *out_qpeak = quefrency;
if (out_qpeak)
*out_qpeak = quefrency;
return peakdB;
}
double PowerCepstrum_getPeakProminence (PowerCepstrum me, double pitchFloor, double pitchCeiling, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod, double *out_qpeak) {
double PowerCepstrum_getPeakProminence (PowerCepstrum me, double pitchFloor, double pitchCeiling, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod, double *out_qpeak) {
double slope, intercept, qpeak, peakdB;
PowerCepstrum_fitTiltLine (me, qstartFit, qendFit, &slope, &intercept, lineType, fitMethod);
PowerCepstrum_fitTrendLine (me, qstartFit, qendFit, & slope, & intercept, lineType, fitMethod);
PowerCepstrum_getMaximumAndQuefrency (me, pitchFloor, pitchCeiling, interpolation, & peakdB, & qpeak);
double xq = lineType == 2 ? log(qpeak) : qpeak;
double xq = lineType == kCepstrumTrendType::ExponentialDecay ? log(qpeak) : qpeak;
double db_background = slope * xq + intercept;
double cpp = peakdB - db_background;
if (out_qpeak) *out_qpeak = qpeak;
if (out_qpeak)
*out_qpeak = qpeak;
return cpp;
}
......
......@@ -2,7 +2,7 @@
#define _Cepstrum_h_
/* Cepstrum.h
*
* Copyright (C) 1994-2018 David Weenink
* Copyright (C) 1994-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -46,6 +46,9 @@ Thing_define (PowerCepstrum, Cepstrum) {
override;
};
#include "Cepstrum_enums.h"
/*
xmin // Lowest quefrency.
xmax // Highest quefrency.
......@@ -71,11 +74,11 @@ autoPowerCepstrum PowerCepstrum_create (double qmax, integer nq);
my z [1..ny] [1..nx] == 0.0;
*/
void PowerCepstrum_draw (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, int garnish);
void PowerCepstrum_draw (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, bool garnish);
void Cepstrum_drawLinear (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, int garnish);
void Cepstrum_drawLinear (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, bool garnish);
void PowerCepstrum_drawTiltLine (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, double qstart, double qend, int lineType, int method);
void PowerCepstrum_drawTrendLine (PowerCepstrum me, Graphics g, double qmin, double qmax, double dBminimum, double dBmaximum, double qstart, double qend, kCepstrumTrendType lineType, kCepstrumTrendFit method);
/*
Function:
Draw a Cepstrum
......@@ -94,18 +97,27 @@ void PowerCepstrum_getMaximumAndQuefrency (PowerCepstrum me, double pitchFloor,
double PowerCepstrum_getPeakProminence_hillenbrand (PowerCepstrum me, double pitchFloor, double pitchCeiling, double *qpeak);
double PowerCepstrum_getRNR (PowerCepstrum me, double pitchFloor, double pitchCeiling, double f0fractionalWidth);
double PowerCepstrum_getPeakProminence (PowerCepstrum me, double pitchFloor, double pitchCeiling, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod, double *qpeak);
void PowerCepstrum_fitTiltLine (PowerCepstrum me, double qmin, double qmax, double *out_slope, double *out_intercept, int lineType, int method);
autoPowerCepstrum PowerCepstrum_subtractTilt (PowerCepstrum me, double qstartFit, double qendFit, int lineType, int fitMethod);
void PowerCepstrum_subtractTilt_inplace (PowerCepstrum me, double qstartFit, double qendFit, int lineType, int fitMethod);
double PowerCepstrum_getPeakProminence (PowerCepstrum me, double pitchFloor, double pitchCeiling, int interpolation, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod, double *qpeak);
void PowerCepstrum_fitTrendLine (PowerCepstrum me, double qmin, double qmax, double *out_slope, double *out_intercept, kCepstrumTrendType lineType, kCepstrumTrendFit method);
autoPowerCepstrum PowerCepstrum_subtractTrend (PowerCepstrum me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod);
void PowerCepstrum_subtractTrend_inplace (PowerCepstrum me, double qstartFit, double qendFit, kCepstrumTrendType lineType, kCepstrumTrendFit fitMethod);
void PowerCepstrum_smooth_inplace (PowerCepstrum me, double quefrencyAveragingWindow, integer numberOfIterations);
autoPowerCepstrum PowerCepstrum_smooth (PowerCepstrum me, double quefrencyAveragingWindow, integer numberOfIterations);
autoMatrix PowerCepstrum_to_Matrix (PowerCepstrum me);
autoPowerCepstrum Matrix_to_PowerCepstrum (Matrix me);
autoPowerCepstrum Matrix_to_PowerCepstrum_row (Matrix me, integer row);
autoPowerCepstrum Matrix_to_PowerCepstrum_column (Matrix me, integer col);
autoPowerCepstrum Cepstrum_downto_PowerCepstrum (Cepstrum me);
#endif /* _Cepstrum_h_ */
/* Cepstrum_and_Spectrum.cpp
*
* Copyright (C) 1994-2017 David Weenink
* Copyright (C) 1994-2019 David Weenink
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......
/* Electroglottogram_def.h
/* Cepstrum_enums.h
*
* Copyright (C) 2019 David Weenink
*
......@@ -9,24 +9,22 @@
*
* This code is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this work. If not, see <http://www.gnu.org/licenses/>.
*/
#define ooSTRUCT Electroglottogram
oo_DEFINE_CLASS (Electroglottogram, Sound)
enums_begin (kCepstrumTrendType, 1)
enums_add (kCepstrumTrendType, 1, Linear, U"Straight")
enums_add (kCepstrumTrendType, 2, ExponentialDecay, U"Exponential decay")
enums_end (kCepstrumTrendType, 2, ExponentialDecay)
oo_OBJECT (Sound, 2, sound)
enums_begin (kCepstrumTrendFit, 1)
enums_add (kCepstrumTrendFit, 1, RobustFast, U"Robust")
enums_add (kCepstrumTrendFit, 2, LeastSquares, U"Least squares")
enums_add (kCepstrumTrendFit, 3, RobustSlow, U"Robust slow")
enums_end (kCepstrumTrendFit, 3, RobustSlow)
#if oo_DECLARING
void v_info ()
override;
#endif
oo_END_CLASS (Electroglottogram)
#undef ooSTRUCT
/* End of file Electroglottogram_def.h */
/* End of file Cepstrum_enums.h */
......@@ -136,7 +136,7 @@ void Formant_Frame_into_LPC_Frame (Formant_Frame me, LPC_Frame thee, double samp
D(z): 1 + p z^-1 + q z^-2
*/
const double r = exp (- NUMpi * my formant [iformant]. bandwidth * samplingPeriod);
const double p = - 2.0 * r * cos (2.0 * NUMpi * formantFrequency * samplingPeriod);
const double p = - 2.0 * r * cos (NUM2pi * formantFrequency * samplingPeriod);
const double q = r * r;
/*
By setting the two extra elements (0, 1) in the lpc vector we can avoid boundary testing;
......
......@@ -56,7 +56,7 @@ void LPC_Frame_into_Spectrum (LPC_Frame me, Spectrum thee, double bandwidthReduc
if (deEmphasisFrequency < thy xmax) {
// Multiply (1, a [1] z^-1, ... a [p] z^-p) by (1 - b z^-1)
double b = exp (- 2.0 * NUMpi * deEmphasisFrequency / thy xmax);
double b = exp (- NUM2pi * deEmphasisFrequency / thy xmax);
ndata ++;
for (integer i = ndata; i > 1; i--)
fftbuffer [i] -= b * fftbuffer [i - 1];
......
This diff is collapsed.
This diff is collapsed.
praat (6.1.04-1) unstable; urgency=medium
* New upstream version 6.1.04
* d/p/fix-test-electroglottogram.patch: Drop patch (applied upstream)
* d/t/run-tests: Exclude unit test KlattGrid_test
* d/control: Bump Standards-Version to 4.4.1 (no changes needed)
-- Rafael Laboissiere <rafael@debian.org> Wed, 02 Oct 2019 02:16:20 -0300
praat (6.1.03-1) unstable; urgency=medium
* New upstream version 6.1.03
......
Description: Fix Electroglottogram unit test
Author: Rafael Laboissiere <rafael@debian.org>
Origin: https://github.com/rlaboiss/praat/commit/87b0067a86b73dadd35cf119d8082d3790f0594d
Last-Update: 2019-09-24
--- praat-6.1.03.orig/dwtest/test_Electroglottogram.praat
+++ praat-6.1.03/dwtest/test_Electroglottogram.praat
@@ -8,18 +8,16 @@ pitchCeiling = 500
closingThreshold = 0.30
silenceThreshold = 0.03
sound = Read from file: "s_egg_test.wav"
-egg = Extract Electroglottogram: 1
-intervalTier = To IntervalTier: pitchFloor, pitchCeiling, closingThreshold, silenceThreshold
+egg = Extract Electroglottogram: 1, "no"
+intervalTier = Get closed glottis intervals: pitchFloor, pitchCeiling, closingThreshold, silenceThreshold
selectObject: egg
-degg = To Electroglottogram (derivative): 5000, 50
+degg = Derivative: 5000, 50, "yes"
selectObject: egg
To AmplitudeTier (levels): pitchFloor, pitchCeiling, closingThreshold, "yes", "yes"
peaks = selected ("AmplitudeTier", 1)
valleys = selected ("AmplitudeTier", 2)
levels = selected ("AmplitudeTier", 3)
-selectObject: sound, egg, degg
-combined = Combine to multi-channel
-removeObject: levels, valleys, peaks, degg, intervalTier, egg, sound, combined
+removeObject: levels, valleys, peaks, degg, intervalTier, egg, sound
appendInfoLine : "test_Electroglottogram.praat OK"
......@@ -2,4 +2,3 @@ use-ldflags.patch
remove-time-date-macros.patch
fix-procrustes-unit-test.patch
cross-build.patch
fix-test-electroglottogram.patch
......@@ -82,6 +82,7 @@ for f in $(ls *.praat) ; do
## or that crash on unstable as on 2018-01-27
## (see Bug#887685 and Bug#889703).
if [ $f != runAllTests.praat \
-a $f != KlattGrid_test.praat \
-a $f != speechsynthesizer_test.praat \
-a $f != test_bss_twoSoundsMixed.praat \
-a $f != test_Discriminant.praat \
......
......@@ -125,7 +125,8 @@ void VECsmoothByMovingAverage_preallocated (VECVU const& out, constVECVU const&
}
autoMAT MATcovarianceFromColumnCentredMatrix (constMATVU const& x, integer ndf) {
Melder_require (ndf >= 0 && x.nrow - ndf > 0, U"Invalid arguments.");
Melder_require (ndf >= 0 && x.nrow - ndf > 0,
U"Invalid arguments.");
autoMAT covar = newMATmtm (x);
covar.all() *= 1.0 / (x.nrow - ndf);
return covar;
......@@ -229,7 +230,8 @@ double NUMdeterminant_fromSymmetricMatrix (constMAT m) {
char uplo = 'U';
integer lda = m.nrow, info;
NUMlapack_dpotf2 (& uplo, & a.nrow, & a [1] [1], & lda, & info);
Melder_require (info == 0, U"dpotf2 cannot determine Cholesky decomposition.");
Melder_require (info == 0,
U"dpotf2 cannot determine Cholesky decomposition.");
longdouble lnd = 0.0;
for (integer i = 1; i <= a.nrow; i ++) {
lnd += log (a [i] [i]);
......@@ -247,7 +249,8 @@ void MATlowerCholeskyInverse_inplace (MAT a, double *out_lnd) {
// Fortran storage -> use uplo='U' to get 'L'.
(void) NUMlapack_dpotf2 (& uplo, & a.nrow, & a [1] [1], & a.nrow, & info);
Melder_require (info == 0, U"dpotf2 fails with code ", info, U".");
Melder_require (info == 0,
U"dpotf2 fails with code ", info, U".");
// Determinant from diagonal, diagonal is now sqrt (a [i] [i]) !
......@@ -261,7 +264,8 @@ void MATlowerCholeskyInverse_inplace (MAT a, double *out_lnd) {
// Get the inverse */
(void) NUMlapack_dtrtri (& uplo, & diag, & a.nrow, & a [1] [1], & a.nrow, & info);
Melder_require (info == 0, U"dtrtri fails with code ", info, U".");
Melder_require (info == 0,
U"dtrtri fails with code ", info, U".");
}
autoMAT newMATinverse_fromLowerCholeskyInverse (constMAT m) {
......@@ -430,7 +434,8 @@ void NUMsolveConstrainedLSQuadraticRegression (constMAT o, constVEC d, double *o
char uplo = 'U';
(void) NUMlapack_dpotf2 (& uplo, & n3, & ftinv [1] [1], & n3, & info);
Melder_require (info == 0, U"dpotf2 fails.");
Melder_require (info == 0,
U"dpotf2 fails.");
ftinv [1] [2] = ftinv [1] [3] = ftinv [2] [3] = 0.0;
......@@ -677,7 +682,8 @@ void NUMprocrustes (constMATVU const& x, constMATVU const& y, autoMAT *out_rotat
autoSVD svd = SVD_createFromGeneralMatrix (c.get());
double trace = NUMsum (svd -> d.all());
Melder_require (trace > 0.0, U"NUMprocrustes: degenerate configuration(s).");
Melder_require (trace > 0.0,
U"NUMprocrustes: degenerate configuration(s).");
// 3. T = VU'
......@@ -1599,7 +1605,8 @@ int NUMgetIntersectionsWithRectangle (double x1, double y1, double x2, double y2
continue;
ni ++;
Melder_require (ni <= 3, U"Too many intersections.");
Melder_require (ni <= 3,
U"Too many intersections.");
xi [ni] = x3;
yi [ni] = y3;
......@@ -1897,7 +1904,7 @@ integer NUMgetIndexFromProbability (constVEC probs, double p) {
// straight line fitting
void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_intercept, bool incompleteMethod) {
void NUMlineFit_theil (constVEC const& x, constVEC const& y, double *out_m, double *out_intercept, bool completeMethod) {
try {
Melder_require (x.size == y.size,
U"NUMlineFit_theil: the sizes of the two vectors should be equal.");
......@@ -1919,9 +1926,9 @@ void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_interc
} else {
integer numberOfCombinations;
autoVEC mbs;
if (incompleteMethod) {
if (! completeMethod) {
numberOfCombinations = x.size / 2;
mbs = newVECzero (x.size); // allocate twice the space for convenience later
mbs = newVECzero (x.size); // allocate twice to get the intercepts
integer n2 = x.size % 2 == 1 ? numberOfCombinations + 1 : numberOfCombinations;
for (integer i = 1; i <= numberOfCombinations; i ++)
mbs [i] = (y [n2 + i] - y [i]) / (x [n2 + i] - x [i]);
......@@ -1932,6 +1939,7 @@ void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_interc
for (integer i = 1; i < x.size; i ++)
for (integer j = i + 1; j <= x.size; j ++)
mbs [++ index] = (y [j] - y [i]) / (x [j] - x [i]);
Melder_assert (index == numberOfCombinations);
}
VECsort_inplace (mbs.part (1, numberOfCombinations));
m = NUMquantile (mbs.part (1, numberOfCombinations), 0.5);
......@@ -1949,7 +1957,7 @@ void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_interc
}
}
void NUMlineFit_LS (constVEC x, constVEC y, double *out_m, double *out_intercept) {
void NUMlineFit_LS (constVEC const& x, constVEC const& y, double *out_m, double *out_intercept) {
Melder_require (x.size == y.size,
U"NUMlineFit_LS: the sizes of the two vectors should be equal.");
double sx = NUMsum (x);
......@@ -1973,9 +1981,9 @@ void NUMlineFit (constVEC x, constVEC y, double *out_m, double *out_intercept, i
if (method == 1)
NUMlineFit_LS (x, y, out_m, out_intercept);
else if (method == 3)
NUMlineFit_theil (x, y, out_m, out_intercept, false);
else
NUMlineFit_theil (x, y, out_m, out_intercept, true);
else
NUMlineFit_theil (x, y, out_m, out_intercept, false);
}
// IEEE: Programs for digital signal processing section 4.3 LPTRN
......@@ -1988,7 +1996,8 @@ void VECrc_from_lpc (VEC rc, constVEC lpc) {
a.get() <<= lpc;
for (integer m = lpc.size; m > 0; m--) {
rc [m] = a [m];
Melder_require (fabs (rc [m]) <= 1.0, U"Relection coefficient [", m, U"] larger than 1.");
Melder_require (fabs (rc [m]) <= 1.0,
U"Relection coefficient [", m, U"] larger than 1.");
b.part (1, m) <<= a.part (1, m);
for (integer i = 1; i < m; i ++)
a [i] = (b [i] - rc [m] * b [m - i]) / (1.0 - rc [m] * rc [m]);
......@@ -2049,7 +2058,8 @@ void NUMlpc_lpc_to_rc (double *lpc, integer p, double *rc) {
autoVEC a <<= VEC(lpc, p);
for (integer m = p; m > 0; m--) {
rc [m] = a [m];
Melder_require (fabs (rc [m]) <= 1.0, U"Relection coefficient [", m, U"] larger than 1.");
Melder_require (fabs (rc [m]) <= 1.0,
U"Relection coefficient [", m, U"] larger than 1.");
for (integer i = 1; i < m; i ++) {
b [i] = a [i];
}
......@@ -2530,9 +2540,11 @@ void NUMfixIndicesInRange (integer lowerLimit, integer upperLimit, integer *lowI
if (*highIndex < *lowIndex) {
*lowIndex = lowerLimit; *highIndex = upperLimit;
} else if (*highIndex == *lowIndex) {
Melder_require (*lowIndex >= lowerLimit && *highIndex <= upperLimit, U"Both lower and upper indices are out of range.");
Melder_require (*lowIndex >= lowerLimit && *highIndex <= upperLimit,
U"Both lower and upper indices are out of range.");
} else { // low < high
Melder_require (*lowIndex < upperLimit && *highIndex > lowerLimit, U"Both lower and upper indices are out of range.");
Melder_require (*lowIndex < upperLimit && *highIndex > lowerLimit,
U"Both lower and upper indices are out of range.");
if (*lowIndex < lowerLimit)
*lowIndex = lowerLimit;
if (*highIndex > upperLimit)
......
......@@ -1154,7 +1154,7 @@ void NUMlineFit (constVEC x, constVEC y, double *out_m, double *out_intercept, i
* 3 robust complete Theil (very slow for large N, O(N^2))
*/
void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_intercept, bool incompleteMethod);
void NUMlineFit_theil (constVEC const& x, constVEC const& y, double *out_m, double *out_intercept, bool completeMethod);
/*
* Preconditions:
* all x[i] should be different, i.e. x[i] != x[j] for all i = 1..(numberOfPoints - 1), j = (i+1) ..numberOfPoints
......@@ -1174,7 +1174,7 @@ void NUMlineFit_theil (constVEC x, constVEC y, double *out_m, double *out_interc
*/
void NUMlineFit_LS (constVEC x, constVEC y, double *out_m, double *out_intercept);
void NUMlineFit_LS (constVEC const& x, constVEC const& y, double *out_m, double *out_intercept);
/* The binomial distribution has the form,
......
......@@ -8,18 +8,16 @@ pitchCeiling = 500
closingThreshold = 0.30
silenceThreshold = 0.03
sound = Read from file: "s_egg_test.wav"
egg = Extract Electroglottogram: 1
intervalTier = To IntervalTier: pitchFloor, pitchCeiling, closingThreshold, silenceThreshold
egg = Extract Electroglottogram: 1, "no"
intervalTier = Get closed glottis intervals: pitchFloor, pitchCeiling, closingThreshold, silenceThreshold
selectObject: egg
degg = To Electroglottogram (derivative): 5000, 50
degg = Derivative: 5000, 50, "yes"
selectObject: egg
To AmplitudeTier (levels): pitchFloor, pitchCeiling, closingThreshold, "yes", "yes"
peaks = selected ("AmplitudeTier", 1)
valleys = selected ("AmplitudeTier", 2)
levels = selected ("AmplitudeTier", 3)
selectObject: sound, egg, degg
combined = Combine to multi-channel
removeObject: levels, valleys, peaks, degg, intervalTier, egg, sound, combined
removeObject: levels, valleys, peaks, degg, intervalTier, egg, sound
appendInfoLine : "test_Electroglottogram.praat OK"