summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Eric Vidal <ericvids@gmail.com>2019-07-14 19:41:20 +0800
committer Eric Vidal <ericvids@gmail.com>2019-07-14 19:41:20 +0800
commit1ccdfb873a480c0306ac0553cf9298036f79d2d7 (patch)
tree94d6b250bdf1d8eb20e5f82ad31148b0e7e5d24f
parenta5fdcb40f838a16008dc1251c344b9f6ad1f0f7e (diff)
Suggestion for very-low-latency mode on portaudio
- Needed to keep audio in sync when playing rhythm game machines such as konami system 573. This is because the lowest audio_latency currently supported (audio_latency 1) introduces at least 10 ms of variable latency. I am unsure how to go about this without breaking backward compatibility so I set it to work only when audio_latency is 0 (which was previously ignored by mame itself and was treated equivalent to audio_latency 1). I am aware that setting audio_latency to 0 is not supported by many mame frontends, but this change seems natural. Otherwise, would it be better to add a new mame.ini option, or to automatically enable this low-latency mode when pa_latency is set lower than, say, 0.01 (10ms), which would break people's configurations if they already rely on the old behavior?
-rw-r--r--src/osd/modules/sound/pa_sound.cpp35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/osd/modules/sound/pa_sound.cpp b/src/osd/modules/sound/pa_sound.cpp
index ffa6d6bf6f5..41645318672 100644
--- a/src/osd/modules/sound/pa_sound.cpp
+++ b/src/osd/modules/sound/pa_sound.cpp
@@ -132,7 +132,7 @@ private:
enum
{
- LATENCY_MIN = 1,
+ LATENCY_MIN = 0,
LATENCY_MAX = 5,
};
@@ -261,8 +261,16 @@ int sound_pa::init(osd_options const &options)
// clamp to a probable figure
callback_interval = std::min<double>(callback_interval, 20.0);
- // set the best guess callback interval to allowed count, each audio_latency step > 1 adds 20 ms
- m_skip_threshold = ((std::max<double>(callback_interval, 10.0) + (m_audio_latency - 1) * 20.0) / 1000.0) * m_sample_rate * 2 + 0.5f;
+ if (m_audio_latency == 0)
+ {
+ // very-low-latency mode (set audio_latency to 0); pa_latency controls allowable audio jitter
+ m_skip_threshold = (options.pa_latency() ? options.pa_latency() : device_info->defaultLowOutputLatency) * m_sample_rate * 2 + 0.5f;
+ }
+ else
+ {
+ // set the best guess callback interval to allowed count, each audio_latency step > 1 adds 20 ms
+ m_skip_threshold = ((std::max<double>(callback_interval, 10.0) + (m_audio_latency - 1) * 20.0) / 1000.0) * m_sample_rate * 2 + 0.5f;
+ }
osd_printf_verbose("PortAudio: Using device \"%s\" on API \"%s\"\n", device_info->name, api_info->name);
osd_printf_verbose("PortAudio: Sample rate is %0.0f Hz, device output latency is %0.2f ms\n",
@@ -343,13 +351,24 @@ int sound_pa::callback(s16* output_buffer, size_t number_of_samples)
// if we have been above the set threshold for ~1 second, skip forward
if (m_osd_ticks - m_skip_threshold_ticks > m_osd_tps)
{
- int adjust = m_buffer_min_ct - m_skip_threshold / 2;
-
- // if adjustment is less than two milliseconds, don't bother
- if (adjust / 2 > sample_rate() / 500) {
- m_ab->increment_playpos(adjust);
+ if (m_audio_latency == 0)
+ {
+ // in very-low-latency mode, always skip forward the whole way
+ // to prevent input from appearing delayed (due to sound cues getting delayed)
+ m_ab->increment_playpos(m_buffer_min_ct);
+ //osd_printf_verbose("PortAudio: skip ahead %d samples\n", m_buffer_min_ct);
m_has_overflowed = true;
}
+ else
+ {
+ int adjust = m_buffer_min_ct - m_skip_threshold / 2;
+
+ // if adjustment is less than two milliseconds, don't bother
+ if (adjust / 2 > sample_rate() / 500) {
+ m_ab->increment_playpos(adjust);
+ m_has_overflowed = true;
+ }
+ }
m_skip_threshold_ticks = m_osd_ticks;
m_buffer_min_ct = INT_MAX;