vtime_t to_utc(vtime_t _time) { __int64 local = (__int64)(_time * 10000000 + epoch_adj); __int64 utc; LocalFileTimeToFileTime((FILETIME*)&local, (FILETIME*)&utc); return vtime_t(utc - epoch_adj) / 10000000; }
vtime_t to_local(vtime_t _time) { __int64 utc = (__int64)(_time * 10000000 + epoch_adj); __int64 local; FileTimeToLocalFileTime((FILETIME*)&utc, (FILETIME*)&local); return vtime_t(local - epoch_adj) / 10000000; }
vtime_t utc_time() { __int64 ft; SYSTEMTIME st; GetSystemTime(&st); SystemTimeToFileTime(&st,(FILETIME*)&ft); return vtime_t(ft - epoch_adj) / 10000000; // 10Mhz clock }
vtime_t local_time() { __int64 ft; SYSTEMTIME st; GetLocalTime(&st); SystemTimeToFileTime(&st,(FILETIME*)&ft); vtime_t result = vtime_t(ft - epoch_adj) / 10000000; // 10Mhz clock return result; }
bool Levels::on_process() { size_t n = size; if (sync) continuous_time = time; ///////////////////////////////////////////////////////// // Find peak-levels sample_t max; sample_t *sptr; sample_t *send; int nch = spk.nch(); sample_t spk_level = 1.0 / spk.level; const int *spk_order = spk.order(); while (n) { size_t block_size = MIN(n, nsamples - sample); n -= block_size; sample += block_size; for (int ch = 0; ch < nch; ch++) { max = 0; sptr = samples[ch]; send = sptr + block_size - 7; while (sptr < send) { if (fabs(sptr[0]) > max) max = fabs(sptr[0]); if (fabs(sptr[1]) > max) max = fabs(sptr[1]); if (fabs(sptr[2]) > max) max = fabs(sptr[2]); if (fabs(sptr[3]) > max) max = fabs(sptr[3]); if (fabs(sptr[4]) > max) max = fabs(sptr[4]); if (fabs(sptr[5]) > max) max = fabs(sptr[5]); if (fabs(sptr[6]) > max) max = fabs(sptr[6]); if (fabs(sptr[7]) > max) max = fabs(sptr[7]); sptr += 8; } send += 7; while (sptr < send) { if (fabs(sptr[0]) > max) max = fabs(sptr[0]); sptr++; } max *= spk_level; if (max > levels[spk_order[ch]]) levels[spk_order[ch]] = max; } if (sample >= nsamples) { add_levels(continuous_time, levels); memset(levels, 0, sizeof(sample_t) * NCHANNELS); sample = 0; } continuous_time += vtime_t(block_size) / spk.sample_rate; } return true; }
bool Converter::convert_pcm2linear(Chunk &in, Chunk &out) { const size_t sample_size = spk.sample_size() * spk.nch(); uint8_t *rawdata = in.rawdata; size_t size = in.size; size_t out_size = 0; ///////////////////////////////////////////////////////// // If we have some data buffered, we have to adjust // the resulting timestamp to avoid jitter if (in.sync && part_size && spk.sample_rate) in.time -= vtime_t(part_size) / double(sample_size * spk.sample_rate); ///////////////////////////////////////////////////////// // Process part of a sample if (part_size) { assert(part_size < sample_size); size_t delta = sample_size - part_size; if (size < delta) { // not enough data to fill sample buffer memcpy(part_buf + part_size, rawdata, size); part_size += size; in.clear(); return false; } else { // fill the buffer & convert incomplete sample memcpy(part_buf + part_size, rawdata, delta); part_size = 0; rawdata += delta; size -= delta; convert(part_buf, out_samples, 1); out_size++; if (is_lpcm(spk.format)) out_size++; } } ///////////////////////////////////////////////////////// // Determine the number of samples to convert and // the size of raw data required for conversion // Note: LPCM sample size is doubled because one block // contains 2 samples. Also, decoding is done in 2 sample // blocks, thus we have to specify less cycles. size_t n = nsamples - out_size; if (is_lpcm(spk.format)) n /= 2; size_t n_size = n * sample_size; if (n_size > size) { n = size / sample_size; n_size = n * sample_size; } ///////////////////////////////////////////////////////// // Convert convert(rawdata, out_samples + out_size, n); out_size += n; if (is_lpcm(spk.format)) out_size += n; rawdata += n_size; size -= n_size; ///////////////////////////////////////////////////////// // Remember the remaining part of a sample if (size && size < sample_size) { memcpy(part_buf, rawdata, size); part_size = size; rawdata += size; size = 0; } ///////////////////////////////////////////////////////// // Make output chunk and update input out.set_linear(out_samples, out_size, in.sync, in.time); out.samples.reorder_to_std(spk, order); in.set_rawdata(rawdata, size); return !out.is_dummy(); }