adpcm: updated BytesOutput function to account for padding

This commit is contained in:
Trek H 2019-05-05 18:46:03 +09:30
parent 60d789e697
commit c27a726831
1 changed files with 8 additions and 3 deletions

View File

@ -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
}