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 espeakdata_voices_to_Table (FilesInMemory me) { try { autoTable thee = Table_createWithColumnNames (my size, U"id name"); for (long ifile = 1; ifile <= my size; ifile++) { FileInMemory fim = (FileInMemory) my item[ifile]; Table_setStringValue (thee.peek(), ifile, 1, fim -> d_id); const char *p = strstr (fim -> d_data, "name"); if (p == NULL) continue; // copy the name part to the following new line char buf[40], *bufp = buf; long len = 0; while ((*bufp++ = *p++) != '\n' && len < 39) { len++; } // remove trailing white space *bufp = 0; while (ESPEAK_ISSPACE (buf[len]) && len > 0) { buf[len] = 0; len--; } // skip leading white space bufp = & buf[4]; while (ESPEAK_ISSPACE (*bufp)) { *bufp++; } Table_setStringValue (thee.peek(), ifile, 2, Melder_peek8to32 (bufp)); TableRow row = static_cast <TableRow> (thy rows -> item [ifile]); wint_t c0 = row -> cells [2]. string[0]; row -> cells [2]. string[0] = towupper (c0); } return thee.transfer(); } catch (MelderError) { Melder_throw (U"Espeakdata: voice table not initialized."); } }
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 void Table_setEventTypeString (Table me) { try { for (long i = 1; i <= my rows.size; i ++) { int type = Table_getNumericValue_Assert (me, i, 2); const char32 *label = U"0"; if (type == espeakEVENT_WORD) { label = U"word"; } else if (type == espeakEVENT_SENTENCE) { label = U"sent"; } else if (type == espeakEVENT_MARK) { label = U"mark"; } else if (type == espeakEVENT_PLAY) { label = U"play"; } else if (type == espeakEVENT_END) { label = U"s-end"; } else if (type == espeakEVENT_MSG_TERMINATED) { label = U"msg_term"; } else if (type == espeakEVENT_PHONEME) { label = U"phoneme"; } Table_setStringValue (me, i, 3, label); } } catch (MelderError) { Melder_throw (U"Event types not set."); } }
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; }
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."); } }
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."); } }