From c27a726831695b6f86e8614211ec04944a4c1a87 Mon Sep 17 00:00:00 2001 From: Trek H Date: Sun, 5 May 2019 18:46:03 +0930 Subject: [PATCH] adpcm: updated BytesOutput function to account for padding --- codec/adpcm/adpcm.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/codec/adpcm/adpcm.go b/codec/adpcm/adpcm.go index e152ede7..d4f08ddf 100644 --- a/codec/adpcm/adpcm.go +++ b/codec/adpcm/adpcm.go @@ -352,7 +352,12 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) { // BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data byte size. func BytesOutput(pcm int) int { - // for X pcm bytes, 2 bytes are left uncompressed, the rest is compressed by a factor of 4 - // and a start index and padding byte are added. - return (pcm-2)/4 + 2 + 1 + 1 + // for X pcm bytes, byteDepth (eg. 2 bytes) are left uncompressed, the rest is compressed by a factor of 4 + // and a start index and padding-flag byte are added. + // Also if there are an even number of samples, there will be half a byte of padding added to the last byte. + byteDepth := 2 + if pcm%2*byteDepth == 0 { // %2 because samples are encoded 2 at a time. + return (pcm-byteDepth)/4 + byteDepth + 1 + 1 + 1 + } + return (pcm-byteDepth)/4 + byteDepth + 1 + 1 }