From 682472c5b59f8cc3e4bafff9e0b4f5dc1a2d4edd Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sat, 3 Oct 2015 23:18:54 +0200 Subject: [PATCH] Allow mono atrac3 for "game menu backgrund audio". Fix possible data race. --- UI/BackgroundAudio.cpp | 8 +++++++- UI/GameInfoCache.cpp | 2 +- UI/GameInfoCache.h | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/UI/BackgroundAudio.cpp b/UI/BackgroundAudio.cpp index b99fd5e854eb..986da3ea377b 100644 --- a/UI/BackgroundAudio.cpp +++ b/UI/BackgroundAudio.cpp @@ -80,7 +80,7 @@ class AT3PlusReader { raw_data_ = (uint8_t *)malloc(numBytes); raw_data_size_ = numBytes; - if (/*raw_bytes_per_frame_ == 280 && */ num_channels == 2) { + if (/*raw_bytes_per_frame_ == 280 && */ num_channels == 1 || num_channels == 2) { file_.readData(raw_data_, numBytes); } else { ELOG("Error - bad blockalign or channels"); @@ -174,6 +174,7 @@ static void ClearBackgroundAudio() { at3Reader = 0; } playbackOffset = 0; + gameLastChanged = 0; } void SetBackgroundAudioGame(const std::string &path) { @@ -210,6 +211,11 @@ int PlayBackgroundAudio() { if (!gameInfo) return 0; + if (gameInfo->pending) { + // Should try again shortly.. + return 0; + } + if (gameInfo->sndFileData.size()) { const std::string &data = gameInfo->sndFileData; at3Reader = new AT3PlusReader(data); diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 73333e53b7bb..3faed1559b1d 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -563,7 +563,7 @@ class GameInfoWorkItem : public PrioritizedWorkQueueItem { info_->saveDataSize = info_->GetSaveDataSizeInBytes(); info_->installDataSize = info_->GetInstallDataSizeInBytes(); } - + info_->pending = false; info_->DisposeFileLoader(); } diff --git a/UI/GameInfoCache.h b/UI/GameInfoCache.h index a744fe0371f4..334981b8ab10 100644 --- a/UI/GameInfoCache.h +++ b/UI/GameInfoCache.h @@ -98,7 +98,7 @@ class GameInfo { : disc_total(0), disc_number(0), region(-1), fileType(FILETYPE_UNKNOWN), paramSFOLoaded(false), hasConfig(false), iconTexture(nullptr), pic0Texture(nullptr), pic1Texture(nullptr), wantFlags(0), lastAccessedTime(0.0), timeIconWasLoaded(0.0), timePic0WasLoaded(0.0), timePic1WasLoaded(0.0), - gameSize(0), saveDataSize(0), installDataSize(0), fileLoader(nullptr) {} + gameSize(0), saveDataSize(0), installDataSize(0), pending(true), fileLoader(nullptr) {} ~GameInfo(); bool Delete(); // Better be sure what you're doing when calling this. @@ -163,6 +163,7 @@ class GameInfo { u64 gameSize; u64 saveDataSize; u64 installDataSize; + bool pending; protected: FileLoader *fileLoader;