From be26455f736eadb4258155a2990b814111b25409 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 28 Feb 2015 13:24:35 -0800 Subject: [PATCH] Fix size of first bg audio read. Otherwise we get static at the start. --- UI/BackgroundAudio.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index a6608067a3..558e5901f5 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -125,6 +125,7 @@ public: bool Read(int *buffer, int len) { if (!raw_data_) return false; + while (bgQueue.size() < (size_t)(len * 2)) { int outBytes; decoder_->Decode(raw_data_ + raw_offset_, raw_bytes_per_frame_, (uint8_t *)buffer_, &outBytes); @@ -225,14 +226,16 @@ int PlayBackgroundAudio() { double now = time_now(); if (at3Reader) { - const int sz = (now - lastPlaybackTime) * 44100; - if (sz >= 16 && sz < (int)ARRAY_SIZE(buffer) / 2) { + int sz = lastPlaybackTime <= 0.0 ? 44100 / 60 : (int)((now - lastPlaybackTime) * 44100); + sz = std::min((int)ARRAY_SIZE(buffer) / 2, sz); + if (sz >= 16) { if (at3Reader->Read(buffer, sz)) __PushExternalAudio(buffer, sz); + lastPlaybackTime = now; } - lastPlaybackTime = now; } else { __PushExternalAudio(0, 0); + lastPlaybackTime = now; } return 0;