long RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate) { if (time < zeroTime) return -realTime2Frame(-time, sampleRate); double s = time.sec + double(time.nsec + 1) / 1000000000.0; return long(s * sampleRate); }
long long RealTime::realTime2Frame(const RealTime &time, unsigned int sr) { if (time < zeroTime) return -realTime2Frame(-time, sr); long long sampleRate = sr; // We like integers. The last term is always zero unless the // sample rate is greater than 1MHz, but hell, you never know... long frame = time.sec * sampleRate + (time.msec() * sampleRate) / 1000 + ((time.usec() - 1000 * time.msec()) * sampleRate) / 1000000 + ((time.nsec - 1000 * time.usec()) * sampleRate) / 1000000000; return frame; }