autoSound Sound_filter_formula (Sound me, const char32 *formula, Interpreter interpreter) { try { autoSound thee = Data_copy (me); if (my ny == 1) { autoSpectrum spec = Sound_to_Spectrum (me, true); Matrix_formula ((Matrix) spec.peek(), formula, interpreter, nullptr); autoSound him = Spectrum_to_Sound (spec.peek()); NUMvector_copyElements (his z [1], thy z [1], 1, thy nx); } else { for (long ichan = 1; ichan <= my ny; ichan ++) { autoSound channel = Sound_extractChannel (me, ichan); autoSpectrum spec = Sound_to_Spectrum (channel.peek(), true); Matrix_formula ((Matrix) spec.peek(), formula, interpreter, nullptr); autoSound him = Spectrum_to_Sound (spec.peek()); NUMvector_copyElements (his z [1], thy z [ichan], 1, thy nx); } } return thee; } catch (MelderError) { Melder_throw (me, U": not filtered (with formula)."); } }
int praat_Matrix_formula (UiForm dia, Interpreter interpreter) { int IOBJECT; LOOP { iam (Matrix); try { Matrix_formula (me, GET_STRING (U"formula"), interpreter, nullptr); praat_dataChanged (me); } catch (MelderError) { praat_dataChanged (me); throw; } } return 1; }
void Pitch_formula (Pitch me, const wchar_t *formula, Interpreter interpreter) { try { autoMatrix m = Matrix_create (my xmin, my xmax, my nx, my dx, my x1, 1, my maxnCandidates, my maxnCandidates, 1, 1); for (long iframe = 1; iframe <= my nx; iframe ++) { Pitch_Frame frame = & my frame [iframe]; for (long icand = 1; icand <= frame -> nCandidates; icand ++) m -> z [icand] [iframe] = frame -> candidate [icand]. frequency; } Matrix_formula (m.peek(), formula, interpreter, NULL); for (long iframe = 1; iframe <= my nx; iframe ++) { Pitch_Frame frame = & my frame [iframe]; for (long icand = 1; icand <= frame -> nCandidates; icand ++) frame -> candidate [icand]. frequency = m -> z [icand] [iframe]; } } catch (MelderError) { Melder_throw (me, ": formula not completed."); } }
void TableOfReal_drawAsNumbers_if (TableOfReal me, Graphics graphics, long rowmin, long rowmax, int iformat, int precision, const wchar_t *conditionFormula, Interpreter interpreter) { try { autoMatrix original = TableOfReal_to_Matrix (me); autoMatrix conditions = original.clone (); fixRows (me, & rowmin, & rowmax); Graphics_setInner (graphics); Graphics_setWindow (graphics, 0.5, my numberOfColumns + 0.5, 0, 1); double leftMargin = getLeftMargin (graphics); // not earlier! double lineSpacing = getLineSpacing (graphics); // not earlier! double maxTextWidth = getMaxRowLabelWidth (me, graphics, rowmin, rowmax); double maxTextHeight = getMaxColumnLabelHeight (me, graphics, 1, my numberOfColumns); Matrix_formula (original.peek(), conditionFormula, interpreter, conditions.peek()); Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_BOTTOM); for (long icol = 1; icol <= my numberOfColumns; icol ++) { if (my columnLabels && my columnLabels [icol] && my columnLabels [icol] [0]) Graphics_text (graphics, icol, 1, my columnLabels [icol]); } for (long irow = rowmin; irow <= rowmax; irow ++) { double y = 1 - lineSpacing * (irow - rowmin + 0.6); Graphics_setTextAlignment (graphics, Graphics_RIGHT, Graphics_HALF); if (my rowLabels && my rowLabels [irow] && my rowLabels [irow] [0]) Graphics_text (graphics, 0.5 - leftMargin, y, my rowLabels [irow]); Graphics_setTextAlignment (graphics, Graphics_CENTRE, Graphics_HALF); for (long icol = 1; icol <= my numberOfColumns; icol ++) if (conditions -> z [irow] [icol] != 0.0) { wchar_t text [40]; print4 (text, my data [irow] [icol], iformat, 0, precision); Graphics_text (graphics, icol, y, text); } } if (maxTextHeight) { double left = 0.5; if (maxTextWidth > 0.0) left -= maxTextWidth + 2 * leftMargin; Graphics_line (graphics, left, 1, my numberOfColumns + 0.5, 1); } Graphics_unsetInner (graphics); } catch (MelderError) { Melder_throw (me, ": numbers not drawn."); } }
void Formant_formula_frequencies (Formant me, const char32 *formula, Interpreter interpreter) { try { long nrow = Formant_getMaxNumFormants (me); if (nrow < 1) Melder_throw (U"No formants available."); autoMatrix mat = Matrix_create (my xmin, my xmax, my nx, my dx, my x1, 0.5, nrow + 0.5, nrow, 1, 1); for (long iframe = 1; iframe <= my nx; iframe ++) { Formant_Frame frame = & my d_frames [iframe]; for (long iformant = 1; iformant <= frame -> nFormants; iformant ++) mat -> z [iformant] [iframe] = frame -> formant [iformant]. frequency; } Matrix_formula (mat.peek(), formula, interpreter, NULL); for (long iframe = 1; iframe <= my nx; iframe ++) { Formant_Frame frame = & my d_frames [iframe]; for (long iformant = 1; iformant <= frame -> nFormants; iformant ++) frame -> formant [iformant]. frequency = mat -> z [iformant] [iframe]; } } catch (MelderError) { Melder_throw (me, U": frequency formula not executed."); } }