void Permutation_checkInvariant (Permutation me) { autoPermutation thee = Data_copy (me); NUMsort_l (thy numberOfElements, thy p); for (long i = 1; i <= my numberOfElements; i++) { if (thy p[i] != i) { Melder_throw (me, ":not a valid permutation."); } } }
Sound Sound_FormantTier_filter_noscale (Sound me, FormantTier formantTier) { try { autoSound thee = Data_copy (me); Sound_FormantTier_filter_inline (thee.peek(), formantTier); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not filtered with ", formantTier, "."); } }
void EditDistanceTable_setEditCosts (EditDistanceTable me, EditCostsTable thee) { try { forget (my d_editCostsTable); autoEditCostsTable ect = (EditCostsTable) Data_copy (thee); my d_editCostsTable = ect.transfer(); } catch (MelderError) { Melder_throw (me, ": edit costs not set."); } }
autoSortedSetOfString SpellingChecker_extractUserDictionary (SpellingChecker me) { try { if (! my userDictionary) Melder_throw (U"This spelling checker does not contain a user dictionary."); return Data_copy (my userDictionary.get()); } catch (MelderError) { Melder_throw (me, U": user dictionary not extracted."); } }
Sound Sound_filter_oneFormant (Sound me, double frequency, double bandwidth) { try { autoSound thee = Data_copy (me); Sound_filterWithOneFormantInline (thee.peek(), frequency, bandwidth); return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not filtered (one formant)."); } }
autoPowerCepstrum PowerCepstrum_subtractTilt (PowerCepstrum me, double qstartFit, double qendFit, int lineType, int fitMethod) { try { autoPowerCepstrum thee = Data_copy (me); PowerCepstrum_subtractTilt_inline (thee.get(), qstartFit, qendFit, lineType, fitMethod); return thee; } catch (MelderError) { Melder_throw (me, U": couldn't subtract tilt line."); } }
Sound LPC_and_Sound_filterInverseWithFilterAtTime (LPC me, Sound thee, int channel, double time) { try { autoSound him = Data_copy (thee); LPC_and_Sound_filterInverseWithFilterAtTime_inline (me, him.peek(), channel, time); return him.transfer(); } catch (MelderError) { Melder_throw (thee, ": not inverse filtered."); } }
Permutation Permutation_permuteRandomly (Permutation me, long from, long to) { try { autoPermutation thee = Data_copy (me); Permutation_permuteRandomly_inline (thee.peek(), from, to); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not permuted."); } }
static LPC _Sound_to_LPC (Sound me, int predictionOrder, double analysisWidth, double dt, double preEmphasisFrequency, int method, double tol1, double tol2) { double t1, samplingFrequency = 1.0 / my dx; double windowDuration = 2 * analysisWidth; /* gaussian window */ long nFrames, frameErrorCount = 0; if (floor (windowDuration / my dx) < predictionOrder + 1) Melder_throw ("Analysis window duration too short.\n" "For a prediction order of ", predictionOrder, " the analysis window duration has to be greater than ", my dx * (predictionOrder + 1), "Please increase the analysis window duration or lower the prediction order."); // Convenience: analyse the whole sound into one LPC_frame if (windowDuration > my dx * my nx) { windowDuration = my dx * my nx; } Sampled_shortTermAnalysis (me, windowDuration, dt, & nFrames, & t1); autoSound sound = Data_copy (me); autoSound sframe = Sound_createSimple (1, windowDuration, samplingFrequency); autoSound window = Sound_createGaussian (windowDuration, samplingFrequency); autoLPC thee = LPC_create (my xmin, my xmax, nFrames, dt, t1, predictionOrder, my dx); autoMelderProgress progress (L"LPC analysis"); if (preEmphasisFrequency < samplingFrequency / 2) { Sound_preEmphasis (sound.peek(), preEmphasisFrequency); } for (long i = 1; i <= nFrames; i++) { LPC_Frame lpcframe = (LPC_Frame) & thy d_frames[i]; double t = Sampled_indexToX (thee.peek(), i); LPC_Frame_init (lpcframe, predictionOrder); Sound_into_Sound (sound.peek(), sframe.peek(), t - windowDuration / 2); Vector_subtractMean (sframe.peek()); Sounds_multiply (sframe.peek(), window.peek()); if (method == LPC_METHOD_AUTO) { if (! Sound_into_LPC_Frame_auto (sframe.peek(), lpcframe)) { frameErrorCount++; } } else if (method == LPC_METHOD_COVAR) { if (! Sound_into_LPC_Frame_covar (sframe.peek(), lpcframe)) { frameErrorCount++; } } else if (method == LPC_METHOD_BURG) { if (! Sound_into_LPC_Frame_burg (sframe.peek(), lpcframe)) { frameErrorCount++; } } else if (method == LPC_METHOD_MARPLE) { if (! Sound_into_LPC_Frame_marple (sframe.peek(), lpcframe, tol1, tol2)) { frameErrorCount++; } } if ( (i % 10) == 1) { Melder_progress ( (double) i / nFrames, L"LPC analysis of frame ", Melder_integer (i), L" out of ", Melder_integer (nFrames), L"."); } } return thee.transfer(); }
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) { if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } if (qmax <= qmin) { qmin = my ymin; qmax = my ymax; } long itmin, itmax, ifmin, ifmax; if (! Matrix_getWindowSamplesX (me, tmin - 0.49999 * my dx, tmax + 0.49999 * my dx, & itmin, & itmax) || ! Matrix_getWindowSamplesY (me, qmin - 0.49999 * my dy, qmax + 0.49999 * my dy, & ifmin, & ifmax)) { return; } autoMatrix thee = Data_copy (me); double min = 1e308, max = -min; for (long i = 1; i <= my ny; i++) { for (long j = 1; j <= my nx; j++) { double val = TO10LOG (my z[i][j]); min = val < min ? val : min; max = val > max ? val : max; thy z[i][j] = val; } } double dBminimum = dBmaximum - dynamicRangedB; if (autoscaling) { dBminimum = min; dBmaximum = max; } for (long j = 1; j <= my nx; j++) { double lmax = thy z[1][j]; for (long i = 2; i <= my ny; i++) { if (thy z[i][j] > lmax) { lmax = thy z[i][j]; } } double factor = dynamicCompression * (max - lmax); for (long i = 1; i <= my ny; i++) { thy z[i][j] += factor; } } Graphics_setInner (g); Graphics_setWindow (g, tmin, tmax, qmin, qmax); Graphics_image (g, thy z, itmin, itmax, Matrix_columnToX (thee.get(), itmin - 0.5), Matrix_columnToX (thee.get(), itmax + 0.5), ifmin, ifmax, Matrix_rowToY (thee.get(), ifmin - 0.5), Matrix_rowToY (thee.get(), ifmax + 0.5), dBminimum, dBmaximum); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_marksLeft (g, 2, true, true, false); Graphics_textLeft (g, true, U"Quefrency (s)"); } }
autoOrderedOfString OrderedOfString_selectUniqueItems (OrderedOfString me) { try { autoStringSet thee = StringSet_create (); for (long i = 1; i <= my size; i ++) { if (! thy hasItem (my at [i])) { // FIXME: first sort, then unicize autoSimpleString item = Data_copy (my at [i]); thy addItem_move (item.move()); } } autoOrderedOfString him = OrderedOfString_create (); for (long i = 1; i <= thy size; i ++) { autoSimpleString item = Data_copy (thy at [i]); his addItem_move (item.move()); } return him; } catch (MelderError) { Melder_throw (me, U": unique items not selected."); } }
autoSound Sound_AmplitudeTier_multiply (Sound me, AmplitudeTier amplitude) { try { autoSound thee = Data_copy (me); Sound_AmplitudeTier_multiply_inline (thee.peek(), amplitude); Vector_scale (thee.peek(), 0.9); return thee; } catch (MelderError) { Melder_throw (me, U": not multiplied by ", amplitude, U"."); } }
autoConfiguration Configuration_varimax (Configuration me, int normalizeRows, int quartimax, long maximumNumberOfIterations, double tolerance) { try { autoConfiguration thee = Data_copy (me); NUMvarimax (my data, thy data, my numberOfRows, my numberOfColumns, normalizeRows, quartimax, maximumNumberOfIterations, tolerance); return thee; } catch (MelderError) { Melder_throw (me, U": varimax rotation not performed."); } }
autoVocalTractPoint VocalTract_to_VocalTractPoint (VocalTract me, double time) { try { autoVocalTractPoint thee = Thing_new (VocalTractPoint); thy number = time; thy d_vocalTract = Data_copy (me).transfer(); return thee; } catch (MelderError) { Melder_throw (me, U": not converted to VocalTractPoint."); } }
Sound Sound_FormantGrid_filter (Sound me, FormantGrid formantGrid) { try { autoSound thee = Data_copy (me); Sound_FormantGrid_filter_inline (thee.peek(), formantGrid); Vector_scale (thee.peek(), 0.99); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not filtered with ", formantGrid, "."); } }
SpellingChecker WordList_upto_SpellingChecker (WordList me) { try { autoSpellingChecker thee = Thing_new (SpellingChecker); thy wordList = Data_copy (me); thy separatingCharacters = Melder_dup (U".,;:()\""); return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not converted to SpellingChecker."); } }
autoSSCP Discriminant_extractWithinGroupSSCP (Discriminant me, long index) { try { if (index < 1 || index > my numberOfGroups) Melder_throw (U"Index must be in interval [1,", my numberOfGroups, U"]."); autoSSCP thee = Data_copy (my groups->at [index]); return thee; } catch (MelderError) { Melder_throw (me, U": within group SSCP not created."); } }
Sound Sound_filter_deemphasis (Sound me, double frequency) { try { autoSound thee = Data_copy (me); Sound_deEmphasis (thee.peek(), frequency); Matrix_scaleAbsoluteExtremum (thee.peek(), 0.99); return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not filtered (de-emphasis)."); } }
autoSound Sound_IntensityTier_multiply (Sound me, IntensityTier intensity, int scale) { try { autoSound thee = Data_copy (me); Sound_IntensityTier_multiply_inline (thee.peek(), intensity); if (scale) Vector_scale (thee.peek(), 0.9); return thee; } catch (MelderError) { Melder_throw (me, U": not multiplied with ", intensity, U"."); } }
autoSound Sound_FormantTier_filter (Sound me, FormantTier formantTier) { try { autoSound thee = Data_copy (me); Sound_FormantTier_filter_inline (thee.peek(), formantTier); Vector_scale (thee.peek(), 0.99); return thee; } catch (MelderError) { Melder_throw (me, U": not filtered with ", formantTier, U"."); } }
autoManipulation Manipulation_AnyTier_to_Manipulation (Manipulation me, AnyTier tier) { try { if (! my pitch) Melder_throw (U"Missing pitch manipulation."); autoManipulation result = Data_copy (me); result -> pitch = PitchTier_AnyTier_to_PitchTier (my pitch.get(), tier); return result; } catch (MelderError) { Melder_throw (me, U": not converted."); } }
PowerCepstrogram PowerCepstrogram_subtractTilt (PowerCepstrogram me, double qstartFit, double qendFit, int lineType, int fitMethod) { try { autoPowerCepstrogram thee = Data_copy (me); PowerCepstrogram_subtractTilt_inline (thee.peek(), qstartFit, qendFit, lineType, fitMethod); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no tilt subtracted."); } }
static int CategoriesEditorRemove_undo (CategoriesEditorRemove me) { CategoriesEditor editor = (CategoriesEditor) my boss; Categories categories = (Categories) editor -> data; for (long i = 1; i <= my nSelected; i++) { autoSimpleString item = Data_copy ((SimpleString) my categories -> item[i]); Ordered_addItemAtPosition_move (categories, item.move(), my selection[i]); } update (editor, my selection[1], 0, my selection, my nSelected); return 1; }
Transition Transition_power (Transition me, long power) { try { autoTransition thee = Data_copy (me); autoTransition him = Data_copy (me); for (long ipow = 2; ipow <= power; ipow ++) { double **tmp = his data; his data = thy data; thy data = tmp; // OPTIMIZE for (long irow = 1; irow <= my numberOfStates; irow ++) { for (long icol = 1; icol <= my numberOfStates; icol ++) { thy data [irow] [icol] = 0.0; for (long i = 1; i <= my numberOfStates; i ++) { thy data [irow] [icol] += his data [irow] [i] * my data [i] [icol]; } } } } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": power not computed."); } }
double PowerCepstrum_getPeakProminence_hillenbrand (PowerCepstrum me, double pitchFloor, double pitchCeiling, double *qpeak) { double slope, intercept, quefrency, peakdB; PowerCepstrum_fitTiltLine (me, 0.001, 0, &slope, &intercept, 1, 1); autoPowerCepstrum thee = Data_copy (me); PowerCepstrum_subtractTiltLine_inline (thee.get(), slope, intercept, 1); PowerCepstrum_getMaximumAndQuefrency (thee.get(), pitchFloor, pitchCeiling, 0, & peakdB, & quefrency); if (qpeak) { *qpeak = quefrency; } return peakdB; }
static int CategoriesEditorReplace_undo (CategoriesEditorReplace me) { CategoriesEditor editor = static_cast<CategoriesEditor> (my boss); Categories categories = static_cast<Categories> (editor -> data); for (long i = 1; i <= my nSelected; i++) { autoSimpleString str = Data_copy ( (SimpleString) my categories -> item[i + 1]); OrderedOfString_replaceItemPos (categories, str.move(), my selection[i]); } update (editor, my selection[1], my selection[my nSelected], my selection, my nSelected); return 1; }
Permutation Permutation_invert (Permutation me) { try { autoPermutation thee = Data_copy (me); for (long i = 1; i <= my numberOfElements; i++) { thy p[my p[i]] = i; } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not inverted."); } }
autoPointProcess PointProcesses_difference (PointProcess me, PointProcess thee) { try { autoPointProcess him = Data_copy (me); for (long i = my nt; i >= 1; i --) if (PointProcess_findPoint (thee, my t [i])) PointProcess_removePoint (him.get(), i); return him; } catch (MelderError) { Melder_throw (me, U" & ", thee, U": difference not computed."); } }
static int CategoriesEditorRemove_execute (CategoriesEditorRemove me) { CategoriesEditor editor = static_cast<CategoriesEditor> (my boss); Categories categories = static_cast<Categories> (editor -> data); for (long i = my nSelected; i >= 1; i--) { autoSimpleString item = Data_copy ((SimpleString) categories -> item[my selection[i]]); Ordered_addItemAtPosition_move (my categories.peek(), item.move(), 1); Collection_removeItem (categories, my selection[i]); } update (editor, my selection[1], 0, nullptr, 0); return 1; }
static int CategoriesEditorReplace_execute (CategoriesEditorReplace me) { CategoriesEditor editor = static_cast<CategoriesEditor> (my boss); Categories categories = static_cast<Categories> (editor -> data); for (long i = my nSelected; i >= 1; i--) { autoSimpleString str = Data_copy ((SimpleString) my categories -> item[1]); Ordered_addItemAtPosition_move (my categories.peek(), (SimpleString) categories -> item[my selection[i]], 2); // YUCK categories -> item[my selection[i]] = str.releaseToAmbiguousOwner(); } update (editor, my selection[1], my selection[my nSelected], my selection, my nSelected); return 1; }