From 0e2a706ec81950b42b69a7596f8b93b998dcc7d2 Mon Sep 17 00:00:00 2001 From: rdb Date: Wed, 27 Mar 2024 12:02:12 +0100 Subject: [PATCH] audio: Fix changing sound time not working on macOS Fixes #1607 --- panda/src/audiotraits/openalAudioSound.cxx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/panda/src/audiotraits/openalAudioSound.cxx b/panda/src/audiotraits/openalAudioSound.cxx index bb4b9f9ae4..155d6211fb 100644 --- a/panda/src/audiotraits/openalAudioSound.cxx +++ b/panda/src/audiotraits/openalAudioSound.cxx @@ -172,9 +172,20 @@ play() { if (_sd->_sample) { push_fresh_buffers(); + // The macOS implementation of alSourcePlay resets the offset, so we call + // it before and avoid calling restart_stalled_audio() afterwards (#1607) +#ifdef HAVE_OPENAL_FRAMEWORK + ALenum status; + alGetSourcei(_source, AL_SOURCE_STATE, &status); + if (status != AL_PLAYING) { + alSourcePlay(_source); + } +#endif alSourcef(_source, AL_SEC_OFFSET, _start_time); _stream_queued[0]._time_offset = _start_time; +#ifndef HAVE_OPENAL_FRAMEWORK restart_stalled_audio(); +#endif } else { audio_debug("Play: stream tell = " << _sd->_stream->tell() << " seeking " << _start_time); if (_sd->_stream->tell() != _start_time) {