mirror of https://bitbucket.org/ausocean/av.git
adpcm: updated BytesOutput function to account for padding
This commit is contained in:
parent
60d789e697
commit
c27a726831
|
@ -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.
|
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data byte size.
|
||||||
func BytesOutput(pcm int) int {
|
func BytesOutput(pcm int) int {
|
||||||
// for X pcm bytes, 2 bytes are left uncompressed, the rest is compressed by a factor of 4
|
// 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 byte are added.
|
// and a start index and padding-flag byte are added.
|
||||||
return (pcm-2)/4 + 2 + 1 + 1
|
// 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue