2020#include " Sound_to_Formant_mt.h"
2121#include " SoundFrameIntoFormantFrame.h"
2222#include " Sound_extensions.h"
23+ #include " LPC_and_Formant.h"
2324/*
2425 Precondition:
2526 Sound already has the 'right' sampling frequency and has been pre-emphasized
@@ -95,6 +96,7 @@ autoFormant Sound_to_Formant_robust_mt (constSound me, double dt_in, double numb
9596 autoLPCAndSoundFramesIntoLPCFrameRobust lpcAndSoundIntoLPC = LPCAndSoundFramesIntoLPCFrameRobust_create (lpc.get (), me, outputLPC.get (),
9697 effectiveAnalysisWidth, windowShape, k_stdev, itermax, tol, location, wantlocation);
9798 autoSoundFrameIntoLPCFrame soundIntoLPC2 = SoundFrameIntoLPCFrameRobust_create (soundIntoLPC1.move (), lpcAndSoundIntoLPC.move ());
99+ Melder_assert (soundIntoLPC2 -> outputlpc);
98100 autoLPCFrameIntoFormantFrame lpcFrameIntoFormant = LPCFrameIntoFormantFrame_create (outputLPC.get (), formant.get (), safetyMargin);
99101 autoSoundFrameIntoFormantFrame sif = SoundFrameIntoFormantFrame_create (soundIntoLPC2.move (), lpcFrameIntoFormant.move ());
100102 autoSoundIntoFormantRobustStatus status = SoundIntoFormantRobustStatus_create (formant -> nx);
@@ -105,6 +107,33 @@ autoFormant Sound_to_Formant_robust_mt (constSound me, double dt_in, double numb
105107 Melder_throw (me, U" : no robust Formant created." );
106108 }
107109}
110+
111+ autoFormant Sound_to_Formant_robust (Sound me, double dt_in, double numberOfFormants, double maximumFrequency,
112+ double effectiveAnalysisWidth, double preEmphasisFrequency, double safetyMargin,
113+ double numberOfStandardDeviations, integer maximumNumberOfIterations, double tolerance,
114+ double location, bool wantlocation)
115+ {
116+ const double dt = dt_in > 0.0 ? dt_in : effectiveAnalysisWidth / 4.0 ;
117+ const double nyquist = 0.5 / my dx;
118+ const integer predictionOrder = Melder_ifloor (2 * numberOfFormants);
119+ try {
120+ autoSound sound;
121+ if (maximumFrequency <= 0.0 || fabs (maximumFrequency / nyquist - 1.0 ) < 1.0e-12 )
122+ sound = Data_copy (me); // will be modified
123+ else
124+ sound = Sound_resample (me, maximumFrequency * 2.0 , 50 );
125+
126+ autoLPC lpc = Sound_to_LPC_auto (sound.get (), predictionOrder, effectiveAnalysisWidth, dt, preEmphasisFrequency);
127+ autoLPC lpcRobust = LPC_and_Sound_to_LPC_robust (lpc.get (), sound.get (), effectiveAnalysisWidth, preEmphasisFrequency,
128+ numberOfStandardDeviations, maximumNumberOfIterations, tolerance, wantlocation);
129+ autoFormant thee = LPC_to_Formant (lpcRobust.get (), safetyMargin);
130+ return thee;
131+ } catch (MelderError) {
132+ Melder_throw (me, U" : no robust Formant created." );
133+ }
134+ }
135+
136+
108137/*
109138void Sound_into_Formant_robust_mt (constSound me, mutableFormant thee, double effectiveAnalysisWidth, integer numberOfPoles, double safetyMargin,
110139 double k_stdev, integer itermax, double tol, double location, bool wantlocation)
0 commit comments