int gettimeofday( struct timeval *tp, struct timezone *tzp ) { MMTIME mmtime; // clock() returns time in miliseconds if( !startseconds ) startseconds = time( 0 ); timeGetSystemTime( &mmtime, sizeof( mmtime ) ); tp->tv_sec = ( mmtime.u.ms / 1000 ) + startseconds; tp->tv_usec = ( mmtime.u.ms % 1000 ) * 1000; return 0; };
/** * Returns the current system time in milliseconds. The value is only useful * to measure the elapsed time between subsequent calls of the function. The * absolute time value depends on the system. * * @return The system time in milliseconds. */ UINT64 dlp_time() { time_t nTime; time(&nTime); nTime*=1000; { #if defined __GNUC__ || defined __TMS nTime += (time_t)(clock()/(time_t)((FLOAT64)CLOCKS_PER_SEC/1000.)); #else MMTIME rNow; timeGetSystemTime(&rNow,sizeof(MMTIME)); nTime += (time_t)rNow.u.ms%1000; #endif } return (UINT64)nTime; }
// ---------------------------------------------------------------------------- // Name: TrueRandNum // // Desc: Statistically, the C++ standard library rand() function does not // return a truly random number. This function uses a different // procedure to generate a truly random number (or as close as it can // possibly get). // ---------------------------------------------------------------------------- DWORD TrueRandNum( int nLowBound, int nHighBound ) { MMTIME now; int i; DWORD seed = 0; PUCHAR p; // Get the system time. timeGetSystemTime( &now, sizeof(MMTIME) ); p = (PUCHAR)&now.u.ms; // Create a hash of the system time for the random seed. for( i = 0; i < sizeof(now.u.ms); i++ ) seed = seed * (UCHAR_MAX + 2U) + p[i]; // Seed the random number generator. srand( seed ); // This fixes the lower/upper bound issue with rand(). return nLowBound + (rand() * (1.0 / (RAND_MAX + 1.0))) * nHighBound; }
/* midiInputHandler - Low-level callback function to handle MIDI input. * Installed by midiInOpen(). The input handler takes incoming * MIDI events and places them in the circular input buffer. It then * notifies the application by posting a MM_MIDIINPUT message. * * This function is accessed at interrupt time, so it should be as * fast and efficient as possible. You can't make any * Windows calls here, except PostMessage(). The only Multimedia * Windows call you can make are timeGetSystemTime(), midiOutShortMsg(). * * * Param: hMidiIn - Handle for the associated input device. * wMsg - One of the MIM_***** messages. * dwInstance - Points to CALLBACKINSTANCEDATA structure. * dwParam1 - MIDI data. * dwParam2 - Timestamp (in milliseconds) * * Return: void */ void FAR PASCAL midiInputHandler( HMIDIIN hMidiIn, WORD wMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) { EVENT event; switch(wMsg) { case MIM_OPEN: break; /* The only error possible is invalid MIDI data, so just pass * the invalid data on so we'll see it. */ case MIM_ERROR: case MIM_DATA: event.fdwEvent = (wMsg == MIM_ERROR) ? EVNT_F_ERROR : 0; event.dwDevice = ((LPCALLBACKINSTANCEDATA)dwInstance)->dwDevice; event.data = dwParam1; #ifdef MIDI_TIMESTAMP event.timestamp = timeGetSystemTime(); #endif /* Put the MIDI event in the circular input buffer. */ PutEvent(((LPCALLBACKINSTANCEDATA)dwInstance)->lpBuf, (LPEVENT) &event); break; default: break; } }