Table ERP_tabulate (ERP me, bool includeSampleNumbers, bool includeTime, int timeDecimals, int voltageDecimals, int units) { double voltageScaling = 1.0; const wchar_t *unitText = L"(V)"; if (units == 2) { voltageDecimals -= 6; voltageScaling = 1000000.0; unitText = L"(uV)"; } try { autoTable thee = Table_createWithoutColumnNames (my nx, includeSampleNumbers + includeTime + my ny); long icol = 0; if (includeSampleNumbers) Table_setColumnLabel (thee.peek(), ++ icol, L"sample"); if (includeTime) Table_setColumnLabel (thee.peek(), ++ icol, L"time(s)"); for (long ichan = 1; ichan <= my ny; ichan ++) { Table_setColumnLabel (thee.peek(), ++ icol, Melder_wcscat (my channelNames [ichan], unitText)); } for (long isamp = 1; isamp <= my nx; isamp ++) { icol = 0; if (includeSampleNumbers) Table_setNumericValue (thee.peek(), isamp, ++ icol, isamp); if (includeTime) Table_setStringValue (thee.peek(), isamp, ++ icol, Melder_fixed (my x1 + (isamp - 1) * my dx, timeDecimals)); for (long ichan = 1; ichan <= my ny; ichan ++) { Table_setStringValue (thee.peek(), isamp, ++ icol, Melder_fixed (voltageScaling * my z [ichan] [isamp], voltageDecimals)); } } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not converted to Table."); } }
Table Formant_downto_Table (Formant me, bool includeFrameNumbers, bool includeTimes, int timeDecimals, bool includeIntensity, int intensityDecimals, bool includeNumberOfFormants, int frequencyDecimals, bool includeBandwidths) { try { autoTable thee = Table_createWithoutColumnNames (my nx, includeFrameNumbers + includeTimes + includeIntensity + includeNumberOfFormants + my maxnFormants * (1 + includeBandwidths)); long icol = 0; if (includeFrameNumbers) Table_setColumnLabel (thee.peek(), ++ icol, U"frame"); if (includeTimes) Table_setColumnLabel (thee.peek(), ++ icol, U"time(s)"); if (includeIntensity) Table_setColumnLabel (thee.peek(), ++ icol, U"intensity"); if (includeNumberOfFormants) Table_setColumnLabel (thee.peek(), ++ icol, U"nformants"); for (long iformant = 1; iformant <= my maxnFormants; iformant ++) { Table_setColumnLabel (thee.peek(), ++ icol, Melder_cat (U"F", iformant, U"(Hz)")); if (includeBandwidths) { Table_setColumnLabel (thee.peek(), ++ icol, Melder_cat (U"B", iformant, U"(Hz)")); } } for (long iframe = 1; iframe <= my nx; iframe ++) { icol = 0; if (includeFrameNumbers) Table_setNumericValue (thee.peek(), iframe, ++ icol, iframe); if (includeTimes) Table_setStringValue (thee.peek(), iframe, ++ icol, Melder_fixed (my x1 + (iframe - 1) * my dx, timeDecimals)); Formant_Frame frame = & my d_frames [iframe]; if (includeIntensity) Table_setStringValue (thee.peek(), iframe, ++ icol, Melder_fixed (frame -> intensity, intensityDecimals)); if (includeNumberOfFormants) Table_setNumericValue (thee.peek(), iframe, ++ icol, frame -> nFormants); for (long iformant = 1; iformant <= frame -> nFormants; iformant ++) { Formant_Formant formant = & frame -> formant [iformant]; Table_setStringValue (thee.peek(), iframe, ++ icol, Melder_fixed (formant -> frequency, frequencyDecimals)); if (includeBandwidths) Table_setStringValue (thee.peek(), iframe, ++ icol, Melder_fixed (formant -> bandwidth, frequencyDecimals)); } for (long iformant = frame -> nFormants + 1; iformant <= my maxnFormants; iformant ++) { Table_setNumericValue (thee.peek(), iframe, ++ icol, NUMundefined); if (includeBandwidths) Table_setNumericValue (thee.peek(), iframe, ++ icol, NUMundefined); } } return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not converted to Table."); } }
autoTable ResultsMFCs_to_Table (OrderedOf<structResultsMFC>* me) { try { long irow = 0; bool hasGoodnesses = false, hasReactionTimes = false; for (long iresults = 1; iresults <= my size; iresults ++) { ResultsMFC results = my at [iresults]; for (long itrial = 1; itrial <= results -> numberOfTrials; itrial ++) { irow ++; if (results -> result [itrial]. goodness != 0) hasGoodnesses = true; if (results -> result [itrial]. reactionTime != 0.0) hasReactionTimes = true; } } autoTable thee = Table_create (irow, 3 + hasGoodnesses + hasReactionTimes); Table_setColumnLabel (thee.get(), 1, U"subject"); Table_setColumnLabel (thee.get(), 2, U"stimulus"); Table_setColumnLabel (thee.get(), 3, U"response"); if (hasGoodnesses) Table_setColumnLabel (thee.get(), 4, U"goodness"); if (hasReactionTimes) Table_setColumnLabel (thee.get(), 4 + hasGoodnesses, U"reactionTime"); irow = 0; for (long iresults = 1; iresults <= my size; iresults ++) { ResultsMFC results = my at [iresults]; for (long itrial = 1; itrial <= results -> numberOfTrials; itrial ++) { irow ++; Table_setStringValue (thee.get(), irow, 1, results -> name); Table_setStringValue (thee.get(), irow, 2, results -> result [itrial]. stimulus); Table_setStringValue (thee.get(), irow, 3, results -> result [itrial]. response); if (hasGoodnesses) { Table_setNumericValue (thee.get(), irow, 4, results -> result [itrial]. goodness); } if (hasReactionTimes) { Table_setNumericValue (thee.get(), irow, 4 + hasGoodnesses, results -> result [itrial]. reactionTime); } } } return thee; } catch (MelderError) { Melder_throw (U"ResultsMFC objects not collected to Table."); } }
Table PowerCepstrogram_to_Table_hillenbrand (PowerCepstrogram me, double pitchFloor, double pitchCeiling) { try { autoTable thee = Table_createWithColumnNames (my nx, L"time quefrency cpp f0"); autoPowerCepstrum him = PowerCepstrum_create (my ymax, my ny); for (long i = 1; i <= my nx; i++) { for (long j = 1; j <= my ny; j++) { his z[1][j] = my z[j][i]; } double qpeak, cpp = PowerCepstrum_getPeakProminence_hillenbrand (him.peek(), pitchFloor, pitchCeiling, &qpeak); double time = Sampled_indexToX (me, i); Table_setNumericValue (thee.peek(), i, 1, time); Table_setNumericValue (thee.peek(), i, 2, qpeak); Table_setNumericValue (thee.peek(), i, 3, cpp); // Cepstrogram_getCPPS depends on this index 3!! Table_setNumericValue (thee.peek(), i, 4, 1.0 / qpeak); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no Table with cepstral peak prominence values created."); } }
autoTable RealTier_downto_Table (RealTier me, const char32 *indexText, const char32 *timeText, const char32 *valueText) { try { autoTable thee = Table_createWithoutColumnNames (my points.size, (!! indexText) + (!! timeText) + (!! valueText)); long icol = 0; if (indexText) Table_setColumnLabel (thee.get(), ++ icol, indexText); if (timeText ) Table_setColumnLabel (thee.get(), ++ icol, timeText); if (valueText) Table_setColumnLabel (thee.get(), ++ icol, valueText); for (long ipoint = 1; ipoint <= my points.size; ipoint ++) { RealPoint point = my points.at [ipoint]; icol = 0; if (indexText) Table_setNumericValue (thee.get(), ipoint, ++ icol, ipoint); if (timeText) Table_setNumericValue (thee.get(), ipoint, ++ icol, point -> number); if (valueText) Table_setNumericValue (thee.get(), ipoint, ++ icol, point -> value); } return thee; } catch (MelderError) { Melder_throw (me, U": not converted to Table."); } }
Table RealTier_downto_Table (RealTier me, const char32 *indexText, const char32 *timeText, const char32 *valueText) { try { autoTable thee = Table_createWithoutColumnNames (my numberOfPoints (), (indexText != NULL) + (timeText != NULL) + (valueText != NULL)); long icol = 0; if (indexText != NULL) Table_setColumnLabel (thee.peek(), ++ icol, indexText); if (timeText != NULL) Table_setColumnLabel (thee.peek(), ++ icol, timeText); if (valueText != NULL) Table_setColumnLabel (thee.peek(), ++ icol, valueText); for (long ipoint = 1; ipoint <= my numberOfPoints (); ipoint ++) { RealPoint point = my point (ipoint); icol = 0; if (indexText != NULL) Table_setNumericValue (thee.peek(), ipoint, ++ icol, ipoint); if (timeText != NULL) Table_setNumericValue (thee.peek(), ipoint, ++ icol, point -> number); if (valueText != NULL) Table_setNumericValue (thee.peek(), ipoint, ++ icol, point -> value); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, U": not converted to Table."); } }
Table Cepstrogram_to_Table_cpp (Cepstrogram me, double lowestQuefrency, double highestQuefrency, int interpolation, double qstartFit, double qendFit, int method) { try { autoTable thee = Table_createWithColumnNames (my nx, L"time quefrency cpp f0"); autoCepstrum him = Cepstrum_create (my ymin, my ymax, my ny); for (long i = 1; i <= my nx; i++) { for (long j = 1; j <= my ny; j++) { his z[1][j] = my z[j][i]; } double qpeak, cpp = Cepstrum_getPeakProminence (him.peek(), lowestQuefrency, highestQuefrency, interpolation, qstartFit, qendFit, method, &qpeak); double time = Sampled_indexToX (me, i); Table_setNumericValue (thee.peek(), i, 1, time); Table_setNumericValue (thee.peek(), i, 2, qpeak); Table_setNumericValue (thee.peek(), i, 3, cpp); Table_setNumericValue (thee.peek(), i, 4, 1.0 / qpeak); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no Table with cepstral peak prominence values created."); } }
Table Spectrum_downto_Table (Spectrum me, bool includeBinNumbers, bool includeFrequency, bool includeRealPart, bool includeImaginaryPart, bool includeEnergyDensity, bool includePowerDensity) { try { autoTable thee = Table_createWithoutColumnNames (my nx, includeBinNumbers + includeFrequency + includeRealPart + includeImaginaryPart + includeEnergyDensity + includePowerDensity); long icol = 0; if (includeBinNumbers) Table_setColumnLabel (thee.peek(), ++ icol, L"bin"); if (includeFrequency) Table_setColumnLabel (thee.peek(), ++ icol, L"freq(Hz)"); if (includeRealPart) Table_setColumnLabel (thee.peek(), ++ icol, L"re(Pa/Hz)"); if (includeImaginaryPart) Table_setColumnLabel (thee.peek(), ++ icol, L"im(Pa/Hz)"); if (includeEnergyDensity) Table_setColumnLabel (thee.peek(), ++ icol, L"energy(Pa^2/Hz^2)"); if (includePowerDensity) Table_setColumnLabel (thee.peek(), ++ icol, L"pow(dB/Hz)"); for (long ibin = 1; ibin <= my nx; ibin ++) { icol = 0; if (includeBinNumbers) Table_setNumericValue (thee.peek(), ibin, ++ icol, ibin); if (includeFrequency) Table_setNumericValue (thee.peek(), ibin, ++ icol, my x1 + (ibin - 1) * my dx); if (includeRealPart) Table_setNumericValue (thee.peek(), ibin, ++ icol, my z [1] [ibin]); if (includeImaginaryPart) Table_setNumericValue (thee.peek(), ibin, ++ icol, my z [2] [ibin]); if (includeEnergyDensity) Table_setNumericValue (thee.peek(), ibin, ++ icol, Sampled_getValueAtSample (me, ibin, 0, 1)); if (includePowerDensity) Table_setNumericValue (thee.peek(), ibin, ++ icol, Sampled_getValueAtSample (me, ibin, 0, 2)); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": not converted to Table."); } }
Table PowerCepstrogram_to_Table_cpp (PowerCepstrogram me, double pitchFloor, double pitchCeiling, double deltaF0, int interpolation, double qstartFit, double qendFit, int lineType, int fitMethod) { try { autoTable thee = Table_createWithColumnNames (my nx, L"time quefrency cpp f0 rnr"); autoPowerCepstrum him = PowerCepstrum_create (my ymax, my ny); for (long i = 1; i <= my nx; i++) { for (long j = 1; j <= my ny; j++) { his z[1][j] = my z[j][i]; } double qpeak, z, cpp = PowerCepstrum_getPeakProminence (him.peek(), pitchFloor, pitchCeiling, interpolation, qstartFit, qendFit, lineType, fitMethod, &qpeak); double rnr = PowerCepstrum_getRNR (him.peek(), pitchFloor, pitchCeiling, deltaF0); double time = Sampled_indexToX (me, i); Table_setNumericValue (thee.peek(), i, 1, time); Table_setNumericValue (thee.peek(), i, 2, qpeak); Table_setNumericValue (thee.peek(), i, 3, cpp); // Cepstrogram_getCPPS depends on this index!! Table_setNumericValue (thee.peek(), i, 4, 1.0 / qpeak); Table_setNumericValue (thee.peek(), i, 5, rnr); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no Table with cepstral peak prominence values created."); } }
autoTable PairDistribution_to_Table (PairDistribution me) { try { autoTable thee = Table_createWithColumnNames (my pairs -> size, U"string1 string2 weight"); for (long ipair = 1; ipair <= my pairs -> size; ipair ++) { PairProbability prob = static_cast <PairProbability> (my pairs -> item [ipair]); Table_setStringValue (thee.peek(), ipair, 1, prob -> string1); Table_setStringValue (thee.peek(), ipair, 2, prob -> string2); Table_setNumericValue (thee.peek(), ipair, 3, prob -> weight); } return thee; } catch (MelderError) { Melder_throw (me, U": not converted to Table."); } }
static int synthCallback (short *wav, int numsamples, espeak_EVENT *events) { char phoneme_name[9]; if (wav == 0) return 1; // It is essential that the SpeechSynthesizer is identified here by the user_data, // because the espeakEVENT_LIST_TERMINATED event may still be accompanied by // a piece of audio data!! SpeechSynthesizer me = (SpeechSynthesizer) (events -> user_data); while (events -> type != espeakEVENT_LIST_TERMINATED) { if (events -> type == espeakEVENT_SAMPLERATE) { my d_internalSamplingFrequency = events -> id.number; } else { //my events = Table "time type type-t t-pos length a-pos sample id uniq"; // 1 2 3 4 5 6 7 8 9 Table_appendRow (my d_events.get()); long irow = my d_events -> rows.size; double time = events -> audio_position * 0.001; Table_setNumericValue (my d_events.get(), irow, 1, time); Table_setNumericValue (my d_events.get(), irow, 2, events -> type); // Column 3 will be filled afterwards Table_setNumericValue (my d_events.get(), irow, 4, events -> text_position); Table_setNumericValue (my d_events.get(), irow, 5, events -> length); Table_setNumericValue (my d_events.get(), irow, 6, events -> audio_position); Table_setNumericValue (my d_events.get(), irow, 7, events -> sample); if (events -> type == espeakEVENT_MARK || events -> type == espeakEVENT_PLAY) { Table_setStringValue (my d_events.get(), irow, 8, Melder_peek8to32 (events -> id.name)); } else { // Ugly hack because id.string is not 0-terminated if 8 chars long! memcpy (phoneme_name, events -> id.string, 8); phoneme_name[8] = 0; Table_setStringValue (my d_events.get(), irow, 8, Melder_peek8to32 (phoneme_name)); } Table_setNumericValue (my d_events.get(), irow, 9, events -> unique_identifier); } events++; } if (me) { NUMvector_supplyStorage<int> (&my d_wav, 1, &my d_wavCapacity, my d_numberOfSamples, numsamples); for (long i = 1; i <= numsamples; i++) { my d_wav [my d_numberOfSamples + i] = wav [i - 1]; } my d_numberOfSamples += numsamples; } return 0; }
autoTable IntervalTiers_to_Table_textAlignmentment (IntervalTier target, IntervalTier source, EditCostsTable costs) { try { long numberOfTargetIntervals = target -> intervals.size; long numberOfSourceIntervals = source -> intervals.size; autoNUMvector<long> targetOrigin (1, numberOfTargetIntervals); autoNUMvector<long> sourceOrigin (1, numberOfSourceIntervals); autoStrings targets = IntervalTier_to_Strings_withOriginData (target, targetOrigin.peek()); autoStrings sources = IntervalTier_to_Strings_withOriginData (source, sourceOrigin.peek()); autoEditDistanceTable edit = EditDistanceTable_create (targets.peek(), sources.peek()); if (costs != 0) { EditDistanceTable_setEditCosts (edit.peek(), costs); EditDistanceTable_findPath (edit.peek(), nullptr); } long pathLength = edit -> warpingPath -> pathLength; autoTable thee = Table_createWithColumnNames (pathLength - 1, U"targetInterval targetText targetStart targetEnd sourceInterval sourceText sourceStart sourceEnd operation"); for (long i = 2; i <= pathLength; i++) { structPairOfInteger p = edit -> warpingPath -> path[i]; structPairOfInteger p1 = edit -> warpingPath -> path[i - 1]; double targetStart = NUMundefined, targetEnd = NUMundefined; double sourceStart = NUMundefined, sourceEnd = NUMundefined; const char32 * targetText = U"", *sourceText = U""; long targetInterval = p.y > 1 ? targetOrigin[p.y - 1] : 0; long sourceInterval = p.x > 1 ? sourceOrigin[p.x - 1] : 0; if (targetInterval > 0) { TextInterval ti = target -> intervals.at [targetInterval]; targetStart = ti -> xmin; targetEnd = ti -> xmax; targetText = ti -> text; } if (sourceInterval > 0) { TextInterval ti = source -> intervals.at [sourceInterval]; sourceStart = ti -> xmin; sourceEnd = ti -> xmax; sourceText = ti -> text; } long irow = i - 1; if (p.y == p1.y) { // deletion Table_setNumericValue (thee.peek(), irow, 1, 0); Table_setStringValue (thee.peek(), irow, 2, U""); Table_setNumericValue (thee.peek(), irow, 3, NUMundefined); Table_setNumericValue (thee.peek(), irow, 4, NUMundefined); Table_setNumericValue (thee.peek(), irow, 5, sourceInterval); Table_setStringValue (thee.peek(), irow, 6, sourceText); Table_setNumericValue (thee.peek(), irow, 7, sourceStart); Table_setNumericValue (thee.peek(), irow, 8, sourceEnd); Table_setStringValue (thee.peek(), irow, 9, U"d"); } else if (p.x == p1.x) { // insertion Table_setNumericValue (thee.peek(), irow, 1, targetInterval); Table_setStringValue (thee.peek(), irow, 2, targetText); Table_setNumericValue (thee.peek(), irow, 3, targetStart); Table_setNumericValue (thee.peek(), irow, 4, targetEnd); Table_setNumericValue (thee.peek(), irow, 5, 0); Table_setStringValue (thee.peek(), irow, 6, U""); Table_setNumericValue (thee.peek(), irow, 7, NUMundefined); Table_setNumericValue (thee.peek(), irow, 8, NUMundefined); Table_setStringValue (thee.peek(), irow, 9, U"i"); } else { // substitution ? Table_setNumericValue (thee.peek(), irow, 1, targetInterval); Table_setStringValue (thee.peek(), irow, 2, targetText); Table_setNumericValue (thee.peek(), irow, 3, targetStart); Table_setNumericValue (thee.peek(), irow, 4, targetEnd); Table_setNumericValue (thee.peek(), irow, 5, sourceInterval); Table_setStringValue (thee.peek(), irow, 6, sourceText); Table_setNumericValue (thee.peek(), irow, 7, sourceStart); Table_setNumericValue (thee.peek(), irow, 8, sourceEnd); Table_setStringValue (thee.peek(), irow, 9, Melder_equ (targetText, sourceText) ? U" " : U"s"); } } return thee; } catch (MelderError) { Melder_throw (target, U" and ", source, U" not aligned."); } }