void main(void) { // Initialize all tasks Speech_Init(); UART_Init(BAUD9600); Timer0_Init(500); Elecmotor_Init(); Button_Init(); Battery_Init(); Sensor_Init(); Alarm_Init(); Function_init(); Function_S_init(); // Add Tasks hSCH_Add_Task(Elecmotor_update, 1000, 1, 1); // 1ms/ticket hSCH_Add_Task(Button_update, 1500, 200, 1); // 100ms/ticket hSCH_Add_Task(Speech_update, 1500, 1000, 1); // 0.5s/ticket hSCH_Add_Task(Sensor_update, 2000, 1, 1); // 1ms/ticket hSCH_Add_Task(Alarm_update, 3000, 2000, 1); // 1s/ticket hSCH_Add_Task(Function_update, 1500, 4000, 1); // 2s/ticket hSCH_Add_Task(Function_s_update, 2000, 1, 1); // 1ms/ticket // Start the program. hSCH_Start(); while(1) { // Excute the program. hSCH_Dispatch_Tasks(); } }
ERPTier ERPTier_extractEventsWhereColumn_string (ERPTier me, Table table, long columnNumber, int which_Melder_STRING, const wchar_t *criterion) { try { Table_checkSpecifiedColumnNumberWithinRange (table, columnNumber); if (my events -> size != table -> rows -> size) Melder_throw (me, " & ", table, ": the number of rows in the table (", table -> rows -> size, ") doesn't match the number of events (", my events -> size, ")."); autoERPTier thee = Thing_new (ERPTier); Function_init (thee.peek(), my xmin, my xmax); thy numberOfChannels = my numberOfChannels; thy channelNames = NUMvector <wchar_t *> (1, thy numberOfChannels); for (long ichan = 1; ichan <= thy numberOfChannels; ichan ++) { thy channelNames [ichan] = Melder_wcsdup (my channelNames [ichan]); } thy events = SortedSetOfDouble_create (); for (long ievent = 1; ievent <= my events -> size; ievent ++) { ERPPoint oldEvent = my event (ievent); TableRow row = table -> row (ievent); if (Melder_stringMatchesCriterion (row -> cells [columnNumber]. string, which_Melder_STRING, criterion)) { autoERPPoint newEvent = Data_copy (oldEvent); Collection_addItem (thy events, newEvent.transfer()); } } if (thy events -> size == 0) { Melder_warning ("No event matches criterion."); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": events not extracted."); } }
autoERPTier ERPTier_extractEventsWhereColumn_number (ERPTier me, Table table, long columnNumber, int which_Melder_NUMBER, double criterion) { try { Table_checkSpecifiedColumnNumberWithinRange (table, columnNumber); Table_numericize_Assert (table, columnNumber); // extraction should work even if cells are not defined if (my events -> size != table -> rows -> size) Melder_throw (me, U" & ", table, U": the number of rows in the table (", table -> rows -> size, U") doesn't match the number of events (", my events -> size, U")."); autoERPTier thee = Thing_new (ERPTier); Function_init (thee.peek(), my xmin, my xmax); thy numberOfChannels = my numberOfChannels; thy channelNames = NUMvector <char32 *> (1, thy numberOfChannels); for (long ichan = 1; ichan <= thy numberOfChannels; ichan ++) { thy channelNames [ichan] = Melder_dup (my channelNames [ichan]); } thy events = SortedSetOfDouble_create (); for (long ievent = 1; ievent <= my events -> size; ievent ++) { ERPPoint oldEvent = my event (ievent); TableRow row = table -> row (ievent); if (Melder_numberMatchesCriterion (row -> cells [columnNumber]. number, which_Melder_NUMBER, criterion)) { autoERPPoint newEvent = Data_copy (oldEvent); Collection_addItem_move (thy events.get(), newEvent.move()); } } if (thy events -> size == 0) { Melder_warning (U"No event matches criterion."); } return thee; } catch (MelderError) { Melder_throw (me, U": events not extracted."); } }
autoERPTier ERPTier_extractEventsWhereColumn_string (ERPTier me, Table table, long columnNumber, int which_Melder_STRING, const char32 *criterion) { try { Table_checkSpecifiedColumnNumberWithinRange (table, columnNumber); if (my points.size != table -> rows.size) Melder_throw (me, U" & ", table, U": the number of rows in the table (", table -> rows.size, U") doesn't match the number of events (", my points.size, U")."); autoERPTier thee = Thing_new (ERPTier); Function_init (thee.get(), my xmin, my xmax); thy numberOfChannels = my numberOfChannels; thy channelNames = NUMvector <char32 *> (1, thy numberOfChannels); for (long ichan = 1; ichan <= thy numberOfChannels; ichan ++) { thy channelNames [ichan] = Melder_dup (my channelNames [ichan]); } for (long ievent = 1; ievent <= my points.size; ievent ++) { ERPPoint oldEvent = my points.at [ievent]; TableRow row = table -> rows.at [ievent]; if (Melder_stringMatchesCriterion (row -> cells [columnNumber]. string, which_Melder_STRING, criterion)) { autoERPPoint newEvent = Data_copy (oldEvent); thy points. addItem_move (newEvent.move()); } } if (thy points.size == 0) { Melder_warning (U"No event matches criterion."); } return thee; } catch (MelderError) { Melder_throw (me, U": events not extracted."); } }
void PointProcess_init (PointProcess me, double tmin, double tmax, long initialMaxnt) { Function_init (me, tmin, tmax); if (initialMaxnt < 1) initialMaxnt = 1; my maxnt = initialMaxnt; my nt = 0; my t = NUMvector <double> (1, my maxnt); }
autoVocalTractTier VocalTractTier_create (double fromTime, double toTime) { try { autoVocalTractTier me = Thing_new (VocalTractTier); Function_init (me.get(), fromTime, toTime); return me; } catch (MelderError) { Melder_throw (U": VocalTractTier not created."); } }
autoFujisakiCommand FujisakiCommand_create (double tmin, double tmax, double amplitude) { try { autoFujisakiCommand me = Thing_new (FujisakiCommand); Function_init (me.get(), tmin, tmax); my amplitude = amplitude; return me; } catch (MelderError) { Melder_throw (U"Fujisaki command not created."); } }
autoAutosegment Autosegment_create (double tmin, double tmax, const char32 *label) { try { autoAutosegment me = Thing_new (Autosegment); Function_init (me.peek(), tmin, tmax); if (label) { Thing_setName (me.peek(), label); } return me; } catch (MelderError) { Melder_throw (U"Autosegment not created."); } }
static Function Function_create(PG_FUNCTION_ARGS) { ParseResultData info; Function self = (Function)PgObjectClass_allocInstance(s_FunctionClass, TopMemoryContext); HeapTuple procTup = PgObject_getValidTuple(PROCOID, fcinfo->flinfo->fn_oid, "function"); memset(&info, 0, sizeof(ParseResultData)); parseFunction(&info, procTup); Function_init(self, &info, (Form_pg_proc)GETSTRUCT(procTup), fcinfo); pfree(info.buffer); ReleaseSysCache(procTup); return self; }
autoFujisakiPitch FujisakiPitch_create (double tmin, double tmax, double baseFrequency, double alpha, double beta, double gamma) { try { autoFujisakiPitch me = Thing_new (FujisakiPitch); Function_init (me.get(), tmin, tmax); my baseFrequency = baseFrequency; my alpha = alpha; my beta = beta; my gamma = gamma; return me; } catch (MelderError) { Melder_throw (U"FujisakiPitch not created."); } }
FujisakiPitch FujisakiPitch_create (double tmin, double tmax, double baseFrequency, double alpha, double beta, double gamma) { try { autoFujisakiPitch me = Thing_new (FujisakiPitch); Function_init (me.peek(), tmin, tmax); my baseFrequency = baseFrequency; my alpha = alpha; my beta = beta; my gamma = gamma; my phraseCommands = SortedSetOfDouble_create (); my accentCommands = SortedSetOfDouble_create (); return me.transfer(); } catch (MelderError) { Melder_throw ("FujisakiPitch not created."); } }
static ERPTier EEG_PointProcess_to_ERPTier (EEG me, PointProcess events, double fromTime, double toTime) { try { autoERPTier thee = Thing_new (ERPTier); Function_init (thee.peek(), fromTime, toTime); thy numberOfChannels = my numberOfChannels - EEG_getNumberOfExtraSensors (me); Melder_assert (thy numberOfChannels > 0); thy channelNames = NUMvector <wchar_t *> (1, thy numberOfChannels); for (long ichan = 1; ichan <= thy numberOfChannels; ichan ++) { thy channelNames [ichan] = Melder_wcsdup (my channelNames [ichan]); } long numberOfEvents = events -> nt; thy events = SortedSetOfDouble_create (); double soundDuration = toTime - fromTime; double samplingPeriod = my sound -> dx; long numberOfSamples = floor (soundDuration / samplingPeriod) + 1; if (numberOfSamples < 1) Melder_throw (L"Time window too short."); double midTime = 0.5 * (fromTime + toTime); double soundPhysicalDuration = numberOfSamples * samplingPeriod; double firstTime = midTime - 0.5 * soundPhysicalDuration + 0.5 * samplingPeriod; // distribute the samples evenly over the time domain for (long ievent = 1; ievent <= numberOfEvents; ievent ++) { double eegEventTime = events -> t [ievent]; autoERPPoint event = Thing_new (ERPPoint); event -> number = eegEventTime; event -> erp = Sound_create (thy numberOfChannels, fromTime, toTime, numberOfSamples, samplingPeriod, firstTime); double erpEventTime = 0.0; double eegSample = 1 + (eegEventTime - my sound -> x1) / samplingPeriod; double erpSample = 1 + (erpEventTime - firstTime) / samplingPeriod; long sampleDifference = round (eegSample - erpSample); for (long ichannel = 1; ichannel <= thy numberOfChannels; ichannel ++) { for (long isample = 1; isample <= numberOfSamples; isample ++) { long jsample = isample + sampleDifference; event -> erp -> z [ichannel] [isample] = jsample < 1 || jsample > my sound -> nx ? 0.0 : my sound -> z [ichannel] [jsample]; } } Collection_addItem (thy events, event.transfer()); } return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": ERP analysis not performed."); } }