From f937afaf180f3eda6ce504bcea81828847fb8682 Mon Sep 17 00:00:00 2001 From: Stephen Booth Date: Mon, 25 May 2026 09:59:01 -0600 Subject: [PATCH] Fix WavPack sample shift --- Sources/CSFBAudioEngine/Decoders/SFBWavPackDecoder.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/CSFBAudioEngine/Decoders/SFBWavPackDecoder.m b/Sources/CSFBAudioEngine/Decoders/SFBWavPackDecoder.m index e10337df..f926edd3 100644 --- a/Sources/CSFBAudioEngine/Decoders/SFBWavPackDecoder.m +++ b/Sources/CSFBAudioEngine/Decoders/SFBWavPackDecoder.m @@ -470,11 +470,11 @@ - (BOOL)decodeIntoBuffer:(AVAudioPCMBuffer *)buffer frameLength:(AVAudioFrameCou buffer.audioBufferList->mBuffers[0].mDataByteSize, _buffer, samplesRead * WavpackGetNumChannels(_wpc) * sizeof(float)); } else if (mode & MODE_LOSSLESS) { - // For lossless files WavPack produces 32-bit signed integers with the samples low-aligned - int bitsPerSample = WavpackGetBitsPerSample(_wpc); - if (bitsPerSample != 32) { + // For lossless files WavPack produces 32-bit signed integers with the samples low-aligned in each + // four byte buffer entry but high-aligned within the number of bytes used for the original data + if (WavpackGetBitsPerSample(_wpc) != 32) { // Shift the samples to high alignment - int shift = 32 - bitsPerSample; + int shift = 32 - (8 * WavpackGetBytesPerSample(_wpc)); uint32_t count = WavpackGetNumChannels(_wpc) * samplesRead; uint32_t *dst = (uint32_t *)((unsigned char *)buffer.audioBufferList->mBuffers[0].mData +