From 03a4c5a4053a144b60ba0277df87d35a3b693aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Garramu=C3=B1o?= Date: Wed, 13 Mar 2024 19:08:10 -0300 Subject: [PATCH] Fixed audio playback at different speed. --- lib/tlTimeline/Player.cpp | 1 - lib/tlTimeline/PlayerPrivate.cpp | 10 ++++------ lib/tlTimeline/PlayerPrivate.h | 1 - 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/tlTimeline/Player.cpp b/lib/tlTimeline/Player.cpp index c3470cad..3b52d482 100644 --- a/lib/tlTimeline/Player.cpp +++ b/lib/tlTimeline/Player.cpp @@ -127,7 +127,6 @@ namespace tl p.mutex.cacheOptions = p.cacheOptions->get(); p.mutex.cacheInfo = p.cacheInfo->get(); p.audioMutex.speed = p.speed->get(); - p.audioMutex.defaultSpeed = p.speed->get(); #if defined(TLRENDER_AUDIO) try { diff --git a/lib/tlTimeline/PlayerPrivate.cpp b/lib/tlTimeline/PlayerPrivate.cpp index 8dc5e149..79fde7b7 100644 --- a/lib/tlTimeline/PlayerPrivate.cpp +++ b/lib/tlTimeline/PlayerPrivate.cpp @@ -570,7 +570,7 @@ namespace tl { std::unique_lock lock(p->audioMutex.mutex); speed = p->audioMutex.speed; - defaultSpeed = p->audioMutex.defaultSpeed; + defaultSpeed = p->timeline->getTimeRange().duration().rate(); speedMultiplier = defaultSpeed / speed; volume = p->audioMutex.volume; mute = p->audioMutex.mute; @@ -580,7 +580,6 @@ namespace tl } //std::cout << "playback: " << playback << std::endl; //std::cout << "playbackStartTime: " << playbackStartTime << std::endl; - //std::cout << "reset: " << reset << std::endl; // Zero output audio data. std::memset(outputBuffer, 0, nFrames * p->audioThread.info.getByteCount()); @@ -665,7 +664,7 @@ namespace tl int64_t offset = frame - seconds * infoSampleRate; - + // std::cout << "frame: " << frame << std::endl; // std::cout << "seconds: " << seconds << std::endl; // std::cout << "offset: " << offset << std::endl; @@ -761,7 +760,6 @@ namespace tl audios.push_back(audio); } audioDataP.push_back(audio->getData() + dataOffset); - // std::cerr << "volume=" << volumeMultiplier << std::endl; volumeScale.push_back(volumeMultiplier); } } @@ -774,7 +772,7 @@ namespace tl size_t size = std::min( p->playerOptions.audioBufferFrameCount, static_cast(maxOffset - offset)); - + if (backwards) { if ( p->audioThread.backwardsSize < size ) @@ -839,7 +837,7 @@ namespace tl // Send audio data to RtAudio. const auto now = std::chrono::steady_clock::now(); - if (speed == p->timeline->getTimeRange().duration().rate() && + if (defaultSpeed == p->timeline->getTimeRange().duration().rate() && !mute && now >= muteTimeout && nFrames <= getSampleCount(p->audioThread.buffer)) diff --git a/lib/tlTimeline/PlayerPrivate.h b/lib/tlTimeline/PlayerPrivate.h index 283dcdc5..cfa868c7 100644 --- a/lib/tlTimeline/PlayerPrivate.h +++ b/lib/tlTimeline/PlayerPrivate.h @@ -97,7 +97,6 @@ namespace tl struct AudioMutex { double speed = 0.0; - double defaultSpeed = 0.0; float volume = 1.F; bool mute = false; std::chrono::steady_clock::time_point muteTimeout;