Skip to content
Commits on Source (4)
/* ERPWindow.cpp
*
* Copyright (C) 2012-2018 Paul Boersma
* Copyright (C) 2012-2019 Paul Boersma
*
* 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
......@@ -172,7 +172,7 @@ void ERP_drawScalp (ERP me, Graphics graphics, double tmin, double tmax, double
Graphics_setWindow (graphics, -1.0, 1.0, -1.0, 1.0);
//Graphics_setGrey (graphics, 1.0);
//Graphics_fillRectangle (graphics, -1.1, 1.1, -1.01, 1.19);
//Graphics_setColour (graphics, Graphics_BLACK);
//Graphics_setColour (graphics, Melder_BLACK);
integer numberOfDrawableChannels =
my ny >= 64 && Melder_equ (my channelNames [64].get(), U"O2") ? 64 :
my ny >= 32 && Melder_equ (my channelNames [32].get(), U"Cz") ? 32 :
......@@ -243,7 +243,7 @@ void ERP_drawScalp (ERP me, Graphics graphics, double tmin, double tmax, double
double x [3] = { -0.08, 0.0, 0.08 }, y [3] = { 0.99, 1.18, 0.99 };
Graphics_fillArea (graphics, 3, x, y);
}
Graphics_setColour (graphics, Graphics_BLACK);
Graphics_setColour (graphics, Melder_BLACK);
Graphics_line (graphics, -0.08, 0.99, 0.0, 1.18);
Graphics_line (graphics, 0.08, 0.99, 0.0, 1.18);
/*
......@@ -252,7 +252,7 @@ void ERP_drawScalp (ERP me, Graphics graphics, double tmin, double tmax, double
Graphics_setGrey (graphics, colourScale == kGraphics_colourScale::BLUE_TO_RED ? 1.0 : 0.5);
Graphics_fillRectangle (graphics, -1.09, -1.00, -0.08, 0.08);
Graphics_fillRectangle (graphics, 1.09, 1.00, -0.08, 0.08);
Graphics_setColour (graphics, Graphics_BLACK);
Graphics_setColour (graphics, Melder_BLACK);
Graphics_line (graphics, -0.99, 0.08, -1.09, 0.08);
Graphics_line (graphics, -1.09, 0.08, -1.09, -0.08);
Graphics_line (graphics, -1.09, -0.08, -0.99, -0.08);
......@@ -273,9 +273,9 @@ void ERP_drawScalp (ERP me, Graphics graphics, double tmin, double tmax, double
void structERPWindow :: v_drawSelectionViewer () {
ERP erp = (ERP) our data;
Graphics_setWindow (our graphics.get(), -1.1, 1.1, -1.01, 1.19);
Graphics_setColour (our graphics.get(), Graphics_WINDOW_BACKGROUND_COLOUR);
Graphics_setColour (our graphics.get(), Melder_WINDOW_BACKGROUND_COLOUR);
Graphics_fillRectangle (our graphics.get(), -1.1, 1.1, -1.01, 1.19);
Graphics_setColour (our graphics.get(), Graphics_BLACK);
Graphics_setColour (our graphics.get(), Melder_BLACK);
integer numberOfDrawableChannels =
erp -> ny >= 64 && Melder_equ (erp -> channelNames [64].get(), U"O2") ? 64 :
erp -> ny >= 32 && Melder_equ (erp -> channelNames [32].get(), U"Cz") ? 32 :
......@@ -368,7 +368,7 @@ void structERPWindow :: v_drawSelectionViewer () {
double x [3] = { -0.08, 0.0, 0.08 }, y [3] = { 0.99, 1.18, 0.99 };
Graphics_fillArea (our graphics.get(), 3, x, y);
}
Graphics_setColour (our graphics.get(), Graphics_BLACK);
Graphics_setColour (our graphics.get(), Melder_BLACK);
Graphics_line (our graphics.get(), -0.08, 0.99, 0.0, 1.18);
Graphics_line (our graphics.get(), 0.08, 0.99, 0.0, 1.18);
/*
......@@ -377,7 +377,7 @@ void structERPWindow :: v_drawSelectionViewer () {
Graphics_setGrey (our graphics.get(), our p_scalp_colourScale == kGraphics_colourScale::BLUE_TO_RED ? 1.0 : 0.5);
Graphics_fillRectangle (our graphics.get(), -1.09, -1.00, -0.08, 0.08);
Graphics_fillRectangle (our graphics.get(), 1.09, 1.00, -0.08, 0.08);
Graphics_setColour (our graphics.get(), Graphics_BLACK);
Graphics_setColour (our graphics.get(), Melder_BLACK);
Graphics_line (our graphics.get(), -0.99, 0.08, -1.09, 0.08);
Graphics_line (our graphics.get(), -1.09, 0.08, -1.09, -0.08);
Graphics_line (our graphics.get(), -1.09, -0.08, -0.99, -0.08);
......
......@@ -547,7 +547,7 @@ void FFNet_drawTopology (FFNet me, Graphics g) {
x2WC += dx2;
}
}
Graphics_setColour (g, Graphics_RED);
Graphics_setColour (g, Melder_RED);
x2WC = x2;
for (integer j = 1; j <= numberOfUnitsInLayer; j ++) {
Graphics_circle (g, x2WC, y2WC, radius);
......@@ -555,7 +555,7 @@ void FFNet_drawTopology (FFNet me, Graphics g) {
Graphics_fillCircle (g, x2WC, y2WC, radius);
x2WC += dx2;
}
Graphics_setColour (g, Graphics_BLACK);
Graphics_setColour (g, Melder_BLACK);
if (i > 0) {
integer numberOfUnitsInLayer_m1 = ( i == 1 ? my numberOfInputs : my numberOfUnitsInLayer [i - 1] );
double dx1 = dx;
......@@ -595,7 +595,7 @@ void FFNet_drawTopology (FFNet me, Graphics g) {
void FFNet_drawActivation (FFNet me, Graphics g) {
integer node = 1, maxNumOfUnits = my numberOfInputs;
int dxIsFixed = 1;
Graphics_Colour colour = Graphics_inqColour (g);
MelderColour colour = Graphics_inqColour (g);
double dy = 1.0 / (my numberOfLayers + 1);
Graphics_setInner (g);
......@@ -618,7 +618,7 @@ void FFNet_drawActivation (FFNet me, Graphics g) {
for (integer j = 1; j <= numberOfUnitsInLayer; j ++, node ++) {
double activity = my activity [node];
double radius = r1 * (fabs (activity) < 0.05 ? 0.05 : fabs (activity));
/*Graphics_setColour (g, activity < 0 ? Graphics_BLACK : Graphics_RED);*/
/*Graphics_setColour (g, activity < 0 ? Melder_BLACK : Melder_RED);*/
Graphics_circle (g, x2WC, y2WC, radius);
if (activity < 0)
Graphics_fillCircle (g, x2WC, y2WC, radius);
......
......@@ -68,7 +68,7 @@ void Cepstrumc_init (Cepstrumc me, double tmin, double tmax, integer nt, double
my samplingFrequency = samplingFrequency;
my maxnCoefficients = nCoefficients;
Sampled_init (me, tmin, tmax, nt, dt, t1);
my frame = NUMvector<structCepstrumc_Frame> (1, nt);
my frame = newvectorzero <structCepstrumc_Frame> (nt);
}
autoCepstrumc Cepstrumc_create (double tmin, double tmax, integer nt, double dt, double t1,
......
......@@ -45,7 +45,7 @@ oo_DEFINE_CLASS (Cepstrumc, Sampled)
oo_DOUBLE (samplingFrequency) // from Sound
oo_INT (maxnCoefficients)
oo_STRUCT_VECTOR (Cepstrumc_Frame, frame, nx)
oo_STRUCTVEC (Cepstrumc_Frame, frame, nx)
#if oo_DECLARING
void v_info ()
......
......@@ -23,18 +23,20 @@ void Formant_formula (Formant me, double tmin, double tmax, integer formantmin,
try {
integer numberOfPossibleFormants = my maxnFormants;
if (tmax <= tmin) {
tmin = my xmin; tmax = my xmax;
tmin = my xmin;
tmax = my xmax;
}
if (formantmax >= formantmin) {
formantmin = 1; formantmax = numberOfPossibleFormants;
formantmin = 1;
formantmax = numberOfPossibleFormants;
}
formantmin = formantmin < 1 ? 1 : formantmin;
formantmax = formantmax > numberOfPossibleFormants ? numberOfPossibleFormants : formantmax;
Melder_clipLeft (integer (1), & formantmin);
Melder_clipRight (& formantmax, numberOfPossibleFormants);
autoMatrix fb = Matrix_create (my xmin, my xmax, my nx, my dx, my x1, 1.0, 2 * numberOfPossibleFormants, 2 * numberOfPossibleFormants, 1.0, 1.0);
for (integer iframe = 1; iframe <= my nx; iframe ++) {
Formant_Frame frame = & my d_frames [iframe];
int numberOfFormants = frame -> nFormants < numberOfPossibleFormants ? frame -> nFormants : numberOfPossibleFormants;
Formant_Frame frame = & my frames [iframe];
integer numberOfFormants = std::min (integer (frame -> nFormants), numberOfPossibleFormants);
for (integer iformant = 1; iformant <= numberOfFormants; iformant++) {
if (iformant <= frame -> nFormants) {
fb -> z [2 * iformant - 1] [iframe] = frame -> formant [iformant]. frequency;
......@@ -43,7 +45,7 @@ void Formant_formula (Formant me, double tmin, double tmax, integer formantmin,
}
}
// Apply formula
double ymin = 2.0 * formantmin - 1.0, ymax = 2.0 * formantmax;
const double ymin = 2.0 * formantmin - 1.0, ymax = 2.0 * formantmax;
Matrix_formula_part (fb.get(), tmin, tmax, ymin, ymax, expression, interpreter, nullptr);
// Put results back in Formant
integer ixmin, ixmax, iymin, iymax;
......@@ -52,12 +54,12 @@ void Formant_formula (Formant me, double tmin, double tmax, integer formantmin,
for (integer iframe = ixmin; iframe <= ixmax; iframe ++) {
// if some of the formant frequencies are set to zero => remove the formant
Formant_Frame frame = & my d_frames [iframe];
int numberOfFormants = frame -> nFormants < formantmax ? frame -> nFormants : formantmax;
int iformantto = formantmin > 1 ? formantmin - 1 : 0;
Formant_Frame frame = & my frames [iframe];
integer numberOfFormants = std::min (integer (frame -> nFormants), formantmax);
integer iformantto = ( formantmin > 1 ? formantmin - 1 : 0 );
for (integer iformant = formantmin; iformant <= numberOfFormants; iformant++) {
double frequency = fb -> z [2 * iformant - 1] [iframe];
double bandWidth = fb -> z [2 * iformant ] [iframe];
const double frequency = fb -> z [2 * iformant - 1] [iframe];
const double bandWidth = fb -> z [2 * iformant ] [iframe];
if (frequency > 0 && bandWidth > 0) {
iformantto ++;
frame -> formant [iformantto]. frequency = frequency;
......@@ -94,20 +96,19 @@ autoIntensityTier Formant_Spectrogram_to_IntensityTier (Formant me, Spectrogram
double previousValue = -80000.0; // can never occur
double previousTime = my xmin;
for (integer iframe = 1; iframe <= my nx; iframe ++) {
Formant_Frame frame = & my d_frames [iframe];
Formant_Frame frame = & my frames [iframe];
integer numberOfFormants = frame -> nFormants;
double time = Sampled_indexToX (me, iframe);
double value = 0;
const double time = Sampled_indexToX (me, iframe);
double value = 0.0;
if (iformant <= numberOfFormants) {
double f = frame -> formant [iformant].frequency;
const double f = frame -> formant [iformant]. frequency;
value = Matrix_getValueAtXY (thee, time, f);
value = isdefined (value) ? value : 0.0;
}
value = 10.0 * log10 ((value + 1e-30) / 4.0e-10); /* dB / Hz */
if (value != previousValue) {
if (iframe > 1 && previousTime < time - 1.5 * my dx) { // mark the end of the same interval
if (iframe > 1 && previousTime < time - 1.5 * my dx) // mark the end of the same interval
RealTier_addPoint (him.get(), time - my dx, previousValue);
}
RealTier_addPoint (him.get(), time, value);
previousTime = time;
}
......
......@@ -70,7 +70,7 @@ void LPC_init (LPC me, double tmin, double tmax, integer nt, double dt, double t
my samplingPeriod = samplingPeriod;
my maxnCoefficients = predictionOrder;
Sampled_init (me, tmin, tmax, nt, dt, t1);
my d_frames = NUMvector<structLPC_Frame> (1, nt);
my d_frames = newvectorzero <structLPC_Frame> (nt);
}
autoLPC LPC_create (double tmin, double tmax, integer nt, double dt, double t1, integer predictionOrder, double samplingPeriod) {
......@@ -167,7 +167,8 @@ autoMatrix LPC_downto_Matrix_area (LPC me) {
LPC_Frame lpc = & my d_frames [j];
VECrc_from_lpc (rc.part (1, lpc -> nCoefficients), lpc -> a.part (1, lpc -> nCoefficients));
VECarea_from_rc (area.part (1, lpc -> nCoefficients), rc.part (1, lpc -> nCoefficients));
if (lpc -> nCoefficients < my maxnCoefficients) area.part (lpc -> nCoefficients + 1, my maxnCoefficients) <<= 0.0;
if (lpc -> nCoefficients < my maxnCoefficients)
area.part (lpc -> nCoefficients + 1, my maxnCoefficients) <<= 0.0;
thy z.column (j) <<= area.get();
}
return thee;
......
......@@ -24,20 +24,16 @@
#include "LPC_and_Cepstrumc.h"
void LPC_Frame_into_Cepstrumc_Frame (LPC_Frame me, Cepstrumc_Frame thee) {
integer n = my nCoefficients > thy nCoefficients ? thy nCoefficients : my nCoefficients;
integer n = std::min (my nCoefficients, thy nCoefficients);
double *c = thy c, *a = my a.at;
c [0] = 0.5 * log (my gain);
if (n == 0) {
if (n == 0)
return;
}
c [1] = -a [1];
for (integer i = 2; i <= n; i ++) {
c [i] = 0;
for (integer k = 1; k < i; k ++) {
for (integer k = 1; k < i; k ++)
c [i] += a [i - k] * c [k] * k;
}
c [i] = -a [i] - c [i] / i;
}
}
......@@ -45,29 +41,24 @@ void LPC_Frame_into_Cepstrumc_Frame (LPC_Frame me, Cepstrumc_Frame thee) {
void Cepstrumc_Frame_into_LPC_Frame (Cepstrumc_Frame me, LPC_Frame thee) {
double *c = my c, *a = thy a.at;
thy gain = exp (2.0 * c [0]);
if (thy nCoefficients == 0) {
if (thy nCoefficients == 0)
return;
}
a [1] = -c [1];
for (integer i = 2; i <= thy nCoefficients; i ++) {
for (integer i = 2; i <= thy nCoefficients; i ++)
c [i] *= i;
}
for (integer i = 2; i <= thy nCoefficients; i ++) {
a [i] = c [i];
for (integer j = 1 ; j < i; j++) {
for (integer j = 1 ; j < i; j ++)
a [i] += a [j] * c [i - j];
}
a [i] /= -i;
}
for (integer i = 2; i <= thy nCoefficients; i ++) {
for (integer i = 2; i <= thy nCoefficients; i ++)
c [i] /= i;
}
}
autoCepstrumc LPC_to_Cepstrumc (LPC me) {
try {
autoCepstrumc thee = Cepstrumc_create (my xmin, my xmax, my nx, my dx, my x1, my maxnCoefficients, 1.0 / my samplingPeriod);
for (integer i = 1; i <= my nx; i ++) {
Cepstrumc_Frame_init (& thy frame [i], my d_frames [i]. nCoefficients);
LPC_Frame_into_Cepstrumc_Frame (& my d_frames [i], & thy frame [i]);
......
......@@ -26,10 +26,10 @@
#include "LPC_and_Polynomial.h"
#include "NUM2.h"
void Formant_Frame_init (Formant_Frame me, integer nFormants) {
my nFormants = nFormants;
if (nFormants > 0) {
my formant = NUMvector<structFormant_Formant> (1, my nFormants);
void Formant_Frame_init (Formant_Frame me, integer numberOfFormants) {
my nFormants = numberOfFormants;
if (numberOfFormants > 0) {
my formant = newvectorzero <structFormant_Formant> (my nFormants);
}
}
......@@ -97,7 +97,7 @@ autoFormant LPC_to_Formant (LPC me, double margin) {
autoMelderProgress progress (U"LPC to Formant");
for (integer i = 1; i <= my nx; i ++) {
Formant_Frame formant = & thy d_frames [i];
Formant_Frame formant = & thy frames [i];
LPC_Frame lpc = & my d_frames [i];
// Initialisation of Formant_Frame is taken care of in Roots_into_Formant_Frame!
......@@ -158,10 +158,9 @@ autoLPC Formant_to_LPC (Formant me, double samplingPeriod) {
autoLPC thee = LPC_create (my xmin, my xmax, my nx, my dx, my x1, 2 * my maxnFormants, samplingPeriod);
for (integer i = 1; i <= my nx; i ++) {
Formant_Frame f = & my d_frames [i];
LPC_Frame lpc = & thy d_frames [i];
integer m = 2 * f -> nFormants;
const Formant_Frame f = & my frames [i];
const LPC_Frame lpc = & thy d_frames [i];
const integer m = 2 * f -> nFormants; // TODO: what is m?
LPC_Frame_init (lpc, m);
Formant_Frame_into_LPC_Frame (f, lpc, samplingPeriod);
}
......
......@@ -55,7 +55,7 @@ void CC_Frame_into_LPC_Frame (CC_Frame me, LPC_Frame thee) {
longdouble ai = my c [i] * i;
for (integer j = 1; j < i; j ++)
ai += thy a [j] * my c [i - j] * (i - j);
thy a [i] = -ai / i;
thy a [i] = - double (ai) / i;
}
}
......
......@@ -23,11 +23,10 @@
#include "LPC_and_Polynomial.h"
autoPolynomial LPC_Frame_to_Polynomial (LPC_Frame me) {
integer degree = (integer) my nCoefficients;
integer degree = my nCoefficients;
autoPolynomial thee = Polynomial_create (-1, 1, degree);
for (integer i = 1; i <= degree; i ++) {
for (integer i = 1; i <= degree; i ++)
thy coefficients [i] = my a [degree - i + 1];
}
thy coefficients[degree + 1] = 1.0;
return thee;
}
......@@ -35,12 +34,7 @@ autoPolynomial LPC_Frame_to_Polynomial (LPC_Frame me) {
autoPolynomial LPC_to_Polynomial (LPC me, double time) {
try {
integer iFrame = Sampled_xToIndex (me, time);
if (iFrame < 1) {
iFrame = 1;
}
if (iFrame > my nx) {
iFrame = my nx;
}
Melder_clip (integer (1), & iFrame, my nx); // constant extrapolation
autoPolynomial thee = LPC_Frame_to_Polynomial (& my d_frames [iFrame]);
return thee;
} catch (MelderError) {
......
/* LPC_and_Tube.cpp
*
* Copyright (C) 1993-2018 David Weenink
* Copyright (C) 1993-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
......@@ -44,18 +44,18 @@ void LPC_Frame_into_Tube_Frame_area (LPC_Frame me, Tube_Frame thee) {
double VocalTract_LPC_Frame_getMatchingLength (VocalTract me, LPC_Frame thee, double glottalDamping, bool radiationDamping, bool internalDamping) {
try {
// match the average distance between the first two formants in the VocaTract and the LPC spectrum
integer numberOfFrequencies = 1000;
double maximumFrequency = 5000.0;
const integer numberOfFrequencies = 1000;
const double maximumFrequency = 5000.0;
autoSpectrum vts = VocalTract_to_Spectrum (me, numberOfFrequencies, maximumFrequency, glottalDamping, radiationDamping, internalDamping);
double samplingFrequency = 1000.0 * my nx;
const double samplingFrequency = 1000.0 * my nx;
autoSpectrum lps = Spectrum_create (0.5 * samplingFrequency, numberOfFrequencies);
LPC_Frame_into_Spectrum (thee, lps.get(), 0, 50);
autoSpectrumTier vtst = Spectrum_to_SpectrumTier_peaks (vts.get());
autoSpectrumTier lpst = Spectrum_to_SpectrumTier_peaks (lps.get());
double vt_f1 = vtst -> points.at [1] -> number, vt_f2 = vtst -> points.at [2] -> number;
double lp_f1 = lpst -> points.at [1] -> number, lp_f2 = lpst -> points.at [2] -> number;
double df1 = lp_f1 - vt_f1, df2 = lp_f2 - vt_f2, df = 0.5 * (df1 + df2);
double dl = - df / lp_f2;
const double vt_f1 = vtst -> points.at [1] -> number, vt_f2 = vtst -> points.at [2] -> number;
const double lp_f1 = lpst -> points.at [1] -> number, lp_f2 = lpst -> points.at [2] -> number;
const double df1 = lp_f1 - vt_f1, df2 = lp_f2 - vt_f2, df = 0.5 * (df1 + df2);
const double dl = - df / lp_f2;
return my dx * my nx * (1 + dl);
} catch (MelderError) {
Melder_throw (U"Length could not be determined from VocalTract and LPC_Frame.");
......@@ -64,13 +64,13 @@ double VocalTract_LPC_Frame_getMatchingLength (VocalTract me, LPC_Frame thee, do
double LPC_Frame_getVTL_wakita (LPC_Frame me, double samplingPeriod, double refLength) {
struct structLPC_Frame lpc_struct;
LPC_Frame lpc = & lpc_struct;
const LPC_Frame lpc = & lpc_struct;
struct structFormant_Frame f_struct;
Formant_Frame f = & f_struct;
const Formant_Frame f = & f_struct;
struct structTube_Frame rc_struct, af_struct;
Tube_Frame rc = & rc_struct, af = & af_struct;
const Tube_Frame rc = & rc_struct, af = & af_struct;
try {
integer m = my nCoefficients;
const integer m = my nCoefficients;
double length, dlength = 0.001, wakita_length = undefined;
double varMin = 1e308;
......@@ -99,7 +99,7 @@ double LPC_Frame_getVTL_wakita (LPC_Frame me, double samplingPeriod, double refL
while (length <= 0.25) {
// Step 3
double fscale = plength / length;
const double fscale = plength / length;
for (integer i = 1; i <= f -> nFormants; i ++) {
f -> formant [i]. frequency *= fscale;
f -> formant [i]. bandwidth *= fscale;
......@@ -140,12 +140,13 @@ double LPC_Frame_getVTL_wakita (LPC_Frame me, double samplingPeriod, double refL
// step 6.3 and 7
double var = 0.0;
for (integer i = 1; i <= af -> numberOfSegments; i ++) {
double delta = area [i] - logSum / af -> numberOfSegments;
const double delta = area [i] - logSum / af -> numberOfSegments;
var += delta * delta;
}
if (var < varMin) {
lmin = length; varMin = var;
lmin = length;
varMin = var;
}
plength = length;
length += dlength;
......@@ -184,14 +185,13 @@ void VocalTract_setLength (VocalTract me, double newLength) {
my x1 = 0.5 * my dx;
}
autoVocalTract LPC_to_VocalTract (LPC me, double time, double glottalDamping, bool radiationDamping, bool internalDamping) {
autoVocalTract LPC_to_VocalTract_slice_special (LPC me, double time, double glottalDamping, bool radiationDamping, bool internalDamping) {
try {
integer iframe = Sampled_xToLowIndex (me, time); // ppgb: BUG? Is rounding down the correct thing to do? not nearestIndex?
if (iframe < 1) iframe = 1;
if (iframe > my nx) iframe = my nx;
LPC_Frame lpc = & my d_frames [iframe];
integer frameNumber = Sampled_xToLowIndex (me, time); // ppgb: BUG? Is rounding down the correct thing to do? not nearestIndex?
Melder_clip (integer (1), & frameNumber, my nx); // constant extrapolation
LPC_Frame lpc = & my d_frames [frameNumber];
autoVocalTract thee = LPC_Frame_to_VocalTract (lpc, 0.17);
double length = VocalTract_LPC_Frame_getMatchingLength (thee.get(), lpc, glottalDamping, radiationDamping, internalDamping);
const double length = VocalTract_LPC_Frame_getMatchingLength (thee.get(), lpc, glottalDamping, radiationDamping, internalDamping);
VocalTract_setLength (thee.get(), length);
return thee;
} catch (MelderError) {
......@@ -201,7 +201,7 @@ autoVocalTract LPC_to_VocalTract (LPC me, double time, double glottalDamping, bo
autoVocalTract LPC_Frame_to_VocalTract (LPC_Frame me, double length) {
try {
integer m = my nCoefficients;
const integer m = my nCoefficients;
autoVocalTract thee = VocalTract_create (m, length / m);
VECarea_from_lpc (thy z.row (1), my a.part (1, m));
// area [lips..glottis] (m^2) to VocalTract [glottis..lips] (m^2)
......@@ -214,12 +214,11 @@ autoVocalTract LPC_Frame_to_VocalTract (LPC_Frame me, double length) {
}
}
autoVocalTract LPC_to_VocalTract (LPC me, double time, double length) {
autoVocalTract LPC_to_VocalTract_slice (LPC me, double time, double length) {
try {
integer iframe = Sampled_xToNearestIndex (me, time);
if (iframe < 1) iframe = 1;
if (iframe > my nx) iframe = my nx;
LPC_Frame lpc = & my d_frames [iframe];
integer frameNumber = Sampled_xToNearestIndex (me, time);
Melder_clip (integer (1), & frameNumber, my nx); // constant extrapolation
LPC_Frame lpc = & my d_frames [frameNumber];
autoVocalTract thee = LPC_Frame_to_VocalTract (lpc, length);
return thee;
} catch (MelderError) {
......
......@@ -39,9 +39,9 @@ int Tube_Frame_into_LPC_Frame_area (Tube_Frame me, LPC_Frame thee);
int Tube_Frame_into_LPC_Frame_rc (Tube_Frame me, LPC_Frame thee);
autoVocalTract LPC_to_VocalTract (LPC me, double time, double length);
autoVocalTract LPC_to_VocalTract_slice (LPC me, double time, double length);
void VocalTract_setLength (VocalTract me, double newLength);
autoVocalTract LPC_to_VocalTract (LPC me, double time, double glottalDamping, bool radiationDamping, bool internalDamping);
autoVocalTract LPC_to_VocalTract_slice_special (LPC me, double time, double glottalDamping, bool radiationDamping, bool internalDamping);
#endif /* _LPC_and_Tube_h_ */
......@@ -41,10 +41,9 @@ oo_END_STRUCT (LPC_Frame)
#define ooSTRUCT LPC
oo_DEFINE_CLASS (LPC, Sampled)
/* samplingPeriod */
oo_DOUBLE (samplingPeriod) /* from Sound */
oo_DOUBLE (samplingPeriod) // from Sound
oo_INT (maxnCoefficients)
oo_STRUCT_VECTOR (LPC_Frame, d_frames, nx)
oo_STRUCTVEC (LPC_Frame, d_frames, nx)
#if oo_DECLARING
void v_info ()
......
......@@ -63,7 +63,7 @@ void LineSpectralFrequencies_init (LineSpectralFrequencies me, double tmin, doub
my maximumFrequency = maximumFrequency;
my maximumNumberOfFrequencies = numberOfFrequencies;
Sampled_init (me, tmin, tmax, nt, dt, t1);
my d_frames = NUMvector<structLineSpectralFrequencies_Frame> (1, nt);
my d_frames = newvectorzero <structLineSpectralFrequencies_Frame> (nt);
}
autoLineSpectralFrequencies LineSpectralFrequencies_create (double tmin, double tmax, integer nt, double dt, double t1, integer numberOfFrequencies, double maximumFrequency) {
......@@ -82,9 +82,8 @@ void LineSpectralFrequencies_drawFrequencies (LineSpectralFrequencies me, Graphi
tmax = my xmax;
}
integer itmin, itmax;
if (! Sampled_getWindowSamples (me, tmin, tmax, & itmin, & itmax)) {
if (! Sampled_getWindowSamples (me, tmin, tmax, & itmin, & itmax))
return;
}
if (fmax <= fmin) {
double f1max, f2min;
integer numberOfSelected = itmax - itmin + 1;
......
......@@ -33,7 +33,7 @@ oo_DEFINE_CLASS (LineSpectralFrequencies, Sampled)
oo_DOUBLE (maximumFrequency)
oo_INT (maximumNumberOfFrequencies)
oo_STRUCT_VECTOR (LineSpectralFrequencies_Frame, d_frames, nx)
oo_STRUCTVEC (LineSpectralFrequencies_Frame, d_frames, nx)
#if oo_DECLARING
void v_info ()
......
......@@ -552,26 +552,19 @@ autoSound LPC_Sound_filter (LPC me, Sound thee, bool useGain) {
void LPC_Sound_filterWithFilterAtTime_inplace (LPC me, Sound thee, integer channel, double time) {
integer frameIndex = Sampled_xToNearestIndex (me, time);
if (frameIndex < 1) {
frameIndex = 1;
}
if (frameIndex > my nx) {
frameIndex = my nx;
}
if (channel > thy ny) {
Melder_clip (integer (1), & frameIndex, my nx); // constant extrapolation
if (channel > thy ny)
channel = 1;
}
Melder_require (frameIndex > 0 && frameIndex <= my nx,
U"Frame should be in the range [1, ", my nx, U"].");
if (channel > 0) {
LPC_Frame_Sound_filter (& my d_frames [frameIndex], thee, channel);
} else {
for (integer ichan = 1; ichan <= thy ny; ichan ++) {
for (integer ichan = 1; ichan <= thy ny; ichan ++)
LPC_Frame_Sound_filter (& my d_frames [frameIndex], thee, ichan);
}
}
}
autoSound LPC_Sound_filterWithFilterAtTime (LPC me, Sound thee, integer channel, double time) {
try {
......@@ -586,22 +579,15 @@ autoSound LPC_Sound_filterWithFilterAtTime (LPC me, Sound thee, integer channel,
void LPC_Sound_filterInverseWithFilterAtTime_inplace (LPC me, Sound thee, integer channel, double time) {
try {
integer frameIndex = Sampled_xToNearestIndex (me, time);
if (frameIndex < 1) {
frameIndex = 1;
}
if (frameIndex > my nx) {
frameIndex = my nx;
}
if (channel > thy ny) {
Melder_clip (integer (1), & frameIndex, my nx); // constant extrapolation
if (channel > thy ny)
channel = 1;
}
if (channel > 0) {
LPC_Frame_Sound_filterInverse (& (my d_frames [frameIndex]), thee, channel);
} else {
for (integer ichan = 1; ichan <= thy ny; ichan ++) {
for (integer ichan = 1; ichan <= thy ny; ichan ++)
LPC_Frame_Sound_filterInverse (& (my d_frames [frameIndex]), thee, ichan);
}
}
} catch (MelderError) {
Melder_throw (thee, U": not inverse filtered.");
}
......
......@@ -169,9 +169,9 @@ autoLPC LPC_Sound_to_LPC_robust (LPC thee, Sound me, double analysisWidth, doubl
Sound_preEmphasis (sound.get(), preEmphasisFrequency);
for (integer i = 1; i <= numberOfFrames; i ++) {
LPC_Frame lpc = (LPC_Frame) & thy d_frames [i];
LPC_Frame lpcto = (LPC_Frame) & his d_frames [i];
double t = Sampled_indexToX (thee, i);
LPC_Frame lpc = & thy d_frames [i];
LPC_Frame lpcto = & his d_frames [i];
const double t = Sampled_indexToX (thee, i);
Sound_into_Sound (sound.get(), sframe.get(), t - windowDuration / 2);
Vector_subtractMean (sframe.get());
......
......@@ -73,14 +73,14 @@ void Tube_Frames_rc_into_area (Tube_Frame me, Tube_Frame thee) {
static void Tube_setLengths (Tube me, double length) {
for (integer i = 1; i <= my nx; i ++) {
Tube_Frame f = & my frame [i];
if (f) f -> length = length;
f -> length = length;
}
}
void Tube_init (Tube me, double tmin, double tmax, integer nt, double dt, double t1, integer maxNumberOfSegments, double defaultLength) {
my maxNumberOfSegments = maxNumberOfSegments;
Sampled_init (me, tmin, tmax, nt, dt, t1);
my frame = NUMvector<structTube_Frame> (1, nt);
my frame = newvectorzero <structTube_Frame> (nt);
Tube_setLengths (me, defaultLength);
}
......
......@@ -32,7 +32,7 @@ oo_END_STRUCT (Tube_Frame)
oo_DEFINE_CLASS (Tube, Sampled)
oo_INT16 (maxNumberOfSegments)
oo_STRUCT_VECTOR (Tube_Frame, frame, nx)
oo_STRUCTVEC (Tube_Frame, frame, nx)
#if oo_DECLARING
void v_info ()
......
......@@ -168,7 +168,7 @@ FORM (REAL_PowerCepstrum_getRNR, U"PowerCepstrum: Get rhamonics to noise ration"
OK
DO
NUMBER_ONE (PowerCepstrum)
double result = PowerCepstrum_getRNR (me, fromPitch, toPitch, fractionalWIdth);
const double result = PowerCepstrum_getRNR (me, fromPitch, toPitch, fractionalWIdth);
NUMBER_ONE_END (U" (rnr)")
}
......@@ -178,7 +178,8 @@ FORM (REAL_PowerCepstrum_getPeakProminence_hillenbrand, U"PowerCepstrum: Get pea
OK
DO
NUMBER_ONE (PowerCepstrum)
double qpeak, result = PowerCepstrum_getPeakProminence_hillenbrand (me, fromPitch, toPitch, & qpeak);
double qpeak;
const double result = PowerCepstrum_getPeakProminence_hillenbrand (me, fromPitch, toPitch, & qpeak);
NUMBER_ONE_END (U" dB; quefrency=", qpeak, U" s (f=", 1.0 / qpeak, U" Hz).")
}
......@@ -223,7 +224,8 @@ FORM (REAL_PowerCepstrum_getPeakProminence, U"PowerCepstrum: Get peak prominence
OK
DO
NUMBER_ONE (PowerCepstrum)
double qpeak, result = PowerCepstrum_getPeakProminence (me, fromPitch, toPitch, interpolationMethod - 1, fromQuefrency_trendLine, toQuefrency_trendLine, lineType, fitMethod, & qpeak);
double qpeak;
const double result = PowerCepstrum_getPeakProminence (me, fromPitch, toPitch, interpolationMethod - 1, fromQuefrency_trendLine, toQuefrency_trendLine, lineType, fitMethod, & qpeak);
NUMBER_ONE_END (U" dB; quefrency=", qpeak, U" s (f=", 1.0 / qpeak, U" Hz).");
}
......@@ -329,25 +331,25 @@ DO
DIRECT (REAL_PowerCepstrogram_getStartQuefrency) {
NUMBER_ONE (PowerCepstrogram)
double result = my ymin;
const double result = my ymin;
NUMBER_ONE_END (U" (s)")
}
DIRECT (REAL_PowerCepstrogram_getEndQuefrency) {
NUMBER_ONE (PowerCepstrogram)
double result = my ymax;
const double result = my ymax;
NUMBER_ONE_END (U" (s)")
}
DIRECT (INTEGER_PowerCepstrogram_getNumberOfQuefrencyBins) {
INTEGER_ONE (PowerCepstrogram)
integer result = my ny;
const integer result = my ny;
INTEGER_ONE_END (U" quefrency bins")
}
DIRECT (REAL_PowerCepstrogram_getQuefrencyStep) {
NUMBER_ONE (PowerCepstrogram)
double result = my dy;
const double result = my dy;
NUMBER_ONE_END (U" s (quefrency step)")
}
......@@ -386,7 +388,7 @@ FORM (REAL_PowerCepstrogram_getCPPS_hillenbrand, U"PowerCepstrogram: Get CPPS",
OK
DO
NUMBER_ONE (PowerCepstrogram)
double result = PowerCepstrogram_getCPPS_hillenbrand (me, subtractTrendBeforeSmoothing, smoothinWindowDuration, quefrencySmoothinWindowDuration, fromPitch, toPitch);
const double result = PowerCepstrogram_getCPPS_hillenbrand (me, subtractTrendBeforeSmoothing, smoothinWindowDuration, quefrencySmoothinWindowDuration, fromPitch, toPitch);
NUMBER_ONE_END (U" dB")
}
......@@ -412,7 +414,7 @@ FORM (REAL_PowerCepstrogram_getCPPS, U"PowerCepstrogram: Get CPPS", U"PowerCepst
OK
DO
NUMBER_ONE (PowerCepstrogram)
double result = PowerCepstrogram_getCPPS (me, subtractTrendBeforeSmoothing, smoothingWindowDuration, quefrencySmoothingWindowDuration, fromPitch, toPitch, tolerance, interpolationMethod - 1, fromQuefrency_trendLine, toQuefrency_trendLine, lineType, fitMethod);
const double result = PowerCepstrogram_getCPPS (me, subtractTrendBeforeSmoothing, smoothingWindowDuration, quefrencySmoothingWindowDuration, fromPitch, toPitch, tolerance, interpolationMethod - 1, fromQuefrency_trendLine, toQuefrency_trendLine, lineType, fitMethod);
NUMBER_ONE_END (U" dB");
}
......@@ -606,7 +608,7 @@ DO
DIRECT (REAL_LPC_getSamplingInterval) {
NUMBER_ONE (LPC)
double result = my samplingPeriod;
const double result = my samplingPeriod;
NUMBER_ONE_END (U" s");
}
......@@ -617,7 +619,7 @@ DO
INTEGER_ONE (LPC)
Melder_require (frameNumber <= my nx,
U"Your frame number (", frameNumber, U") is too large. It should be between 1 and ", my nx, U".");
integer result = my d_frames[frameNumber].nCoefficients;
const integer result = my d_frames [frameNumber]. nCoefficients;
INTEGER_ONE_END (U" coefficients")
}
......@@ -702,17 +704,17 @@ FORM (NEW_LPC_to_VocalTract_slice_special, U"LPC: To VocalTract", U"LPC: To Voca
OK
DO
CONVERT_EACH (LPC)
autoVocalTract result = LPC_to_VocalTract (me, time, glottalDamping, radiationDamping, internalDamping);
autoVocalTract result = LPC_to_VocalTract_slice_special (me, time, glottalDamping, radiationDamping, internalDamping);
CONVERT_EACH_END (my name.get(), NUMstring_timeNoDot (time))
}
FORM (NEW_LPC_to_VocalTract_slice, U"LPC: To VocalTract", U"LPC: To VocalTract (slice)...") {
REAL (time, U"Time (s)", U"0.0")
POSITIVE (lenght, U"Length (m)", U"0.17")
POSITIVE (length, U"Length (m)", U"0.17")
OK
DO
CONVERT_EACH (LPC)
autoVocalTract result = LPC_to_VocalTract (me, time, lenght);
autoVocalTract result = LPC_to_VocalTract_slice (me, time, length);
CONVERT_EACH_END (my name.get(), NUMstring_timeNoDot (time))
}
......