From 3b6723e6f2b700e2c9a5ab0d3dc73f12edc1062e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 2 Oct 2022 06:53:44 -0700 Subject: [PATCH] Better report the number of Smacker audio tracks --- .../libsmackerdec/include/SmackerDecoder.h | 1 + .../libsmackerdec/src/SmackerDecoder.cpp | 20 ++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common/thirdparty/libsmackerdec/include/SmackerDecoder.h b/src/common/thirdparty/libsmackerdec/include/SmackerDecoder.h index 5e7e43641..42cc6fc76 100644 --- a/src/common/thirdparty/libsmackerdec/include/SmackerDecoder.h +++ b/src/common/thirdparty/libsmackerdec/include/SmackerDecoder.h @@ -125,6 +125,7 @@ class SmackerDecoder void GetPalette(uint8_t *palette); void GetFrame(uint8_t *frame); + uint32_t GetNumAudioTracks(); SmackerAudioInfo GetAudioTrackDetails(uint32_t trackIndex); uint32_t GetAudioData(uint32_t trackIndex, int16_t *audioBuffer); void DisableAudioTrack(uint32_t trackIndex); diff --git a/src/common/thirdparty/libsmackerdec/src/SmackerDecoder.cpp b/src/common/thirdparty/libsmackerdec/src/SmackerDecoder.cpp index 5539181d4..cc14a85ca 100644 --- a/src/common/thirdparty/libsmackerdec/src/SmackerDecoder.cpp +++ b/src/common/thirdparty/libsmackerdec/src/SmackerDecoder.cpp @@ -94,10 +94,9 @@ void Smacker_Close(SmackerHandle &handle) handle.isValid = false; } -uint32_t Smacker_GetNumAudioTracks(SmackerHandle &) +uint32_t Smacker_GetNumAudioTracks(SmackerHandle &handle) { - // TODO: fixme - return 1; + return classInstances[handle.instanceIndex]->GetNumAudioTracks(); } SmackerAudioInfo Smacker_GetAudioTrackDetails(SmackerHandle &handle, uint32_t trackIndex) @@ -398,8 +397,9 @@ bool SmackerDecoder::Open(const char *fileName) audioTracks[i].bufferSize = 0; audioTracks[i].bytesReadThisFrame = 0; - // FIXME: Only disable non-consecutive enabled tracks - if (i > 0 /*&& !(audioTracks[i-1].flags & SMK_AUD_PRESENT)*/) + // Disable non-consecutive enabled tracks. Not sure how to otherwise report + // them properly for Smacker_GetNumAudioTracks. + if (i > 0 && !(audioTracks[i-1].flags & SMK_AUD_PRESENT)) audioTracks[i].flags &= ~SMK_AUD_PRESENT; if (audioTracks[i].flags & 0xFFFFFF) @@ -1184,6 +1184,16 @@ void SmackerDecoder::GotoFrame(uint32_t frameNum) GetNextFrame(); } +uint32_t SmackerDecoder::GetNumAudioTracks() +{ + for(uint32_t i = 0;i < kMaxAudioTracks;++i) + { + if (!(audioTracks[i].flags & SMK_AUD_PRESENT)) + return i; + } + return kMaxAudioTracks; +} + SmackerAudioInfo SmackerDecoder::GetAudioTrackDetails(uint32_t trackIndex) { SmackerAudioInfo info;