ALSA: fix thinko in sample time calc.
This commit is contained in:
parent
0446ff64f4
commit
52e99750a0
@ -51,7 +51,6 @@ AlsaAudioBackend::AlsaAudioBackend (AudioEngine& e, AudioBackendInfo& info)
|
||||
, _freewheeling (false)
|
||||
, _measure_latency (false)
|
||||
, _last_process_start (0)
|
||||
, _process_speed_samples_per_ms (0)
|
||||
, _audio_device("")
|
||||
, _midi_driver_option(_("None"))
|
||||
, _device_reservation(0)
|
||||
@ -510,7 +509,6 @@ AlsaAudioBackend::_start (bool for_latency_measurement)
|
||||
_freewheeling = false;
|
||||
_freewheel = false;
|
||||
_last_process_start = 0;
|
||||
_process_speed_samples_per_ms = 0;
|
||||
|
||||
release_device();
|
||||
|
||||
@ -711,21 +709,12 @@ AlsaAudioBackend::samples_since_cycle_start ()
|
||||
if (!_active || !_run || _freewheeling || _freewheel) {
|
||||
return 0;
|
||||
}
|
||||
if (_last_process_start == 0 || _process_speed_samples_per_ms) {
|
||||
if (_last_process_start == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const int64_t elapsed_time_us = _last_process_start - g_get_monotonic_time();
|
||||
|
||||
assert(elapsed_time_us >=0);
|
||||
|
||||
/* linear extrapolation, using [low pass] filtered process-speed. */
|
||||
const pframes_t processed_samples = elapsed_time_us * _process_speed_samples_per_ms * 1e-3;
|
||||
|
||||
if (processed_samples >= _samples_per_period) {
|
||||
return _samples_per_period;
|
||||
}
|
||||
return processed_samples;
|
||||
const int64_t elapsed_time_us = g_get_monotonic_time() - _last_process_start;
|
||||
return std::max((pframes_t)0, (pframes_t)rint(1e-6 * elapsed_time_us * _samplerate));
|
||||
}
|
||||
|
||||
|
||||
@ -1551,12 +1540,6 @@ AlsaAudioBackend::main_process_thread ()
|
||||
clock2 = g_get_monotonic_time();
|
||||
const int64_t elapsed_time = clock2 - clock1;
|
||||
_dsp_load = elapsed_time / (float) nomial_time;
|
||||
|
||||
const double ps = 1e3 * _samples_per_period / elapsed_time;
|
||||
// low pass filter, The time-constant should really be
|
||||
// 1.0 - e^(-2.0 * π * v / SR);
|
||||
// with v = _samples_per_period / N, and SR = _samples_per_period;
|
||||
_process_speed_samples_per_ms = _process_speed_samples_per_ms + .05 * (ps - _process_speed_samples_per_ms) + 1e-12;
|
||||
}
|
||||
|
||||
if (xrun && (_pcmi->capt_xrun() > 0 || _pcmi->play_xrun() > 0)) {
|
||||
|
@ -306,7 +306,6 @@ class AlsaAudioBackend : public AudioBackend {
|
||||
bool _measure_latency;
|
||||
|
||||
uint64_t _last_process_start;
|
||||
double _process_speed_samples_per_ms;
|
||||
|
||||
static std::vector<std::string> _midi_options;
|
||||
static std::vector<AudioBackend::DeviceStatus> _audio_device_status;
|
||||
|
Loading…
Reference in New Issue
Block a user