ADPCM: fixed conversions and calculations for block variables

This commit is contained in:
Trek H 2019-02-25 14:43:26 +10:30
parent 48e848b7c4
commit 1ad2195938
3 changed files with 6 additions and 6 deletions

View File

@ -54,7 +54,7 @@ func main() {
// decode adpcm // decode adpcm
inBSize := 256 inBSize := 256
numBlocks := int(len(comp) / inBSize) numBlocks := len(comp) / inBSize
outBSize := 2 + (inBSize-4)*4 // 2 bytes are copied, 2 are used as block header info, the remaining bytes are decompressed 1:4 outBSize := 2 + (inBSize-4)*4 // 2 bytes are copied, 2 are used as block header info, the remaining bytes are decompressed 1:4
decoded := make([]byte, 0, outBSize*numBlocks) decoded := make([]byte, 0, outBSize*numBlocks)
for i := 0; i < numBlocks; i++ { for i := 0; i < numBlocks; i++ {

View File

@ -54,8 +54,8 @@ func main() {
//encode adpcm //encode adpcm
inBSize := 1010 inBSize := 1010
numBlocks := int(len(pcm) / inBSize) numBlocks := len(pcm) / inBSize
outBSize := int(float32(inBSize/4) + float32(3.5)) // compression is 4:1 and 3.5 bytes of info are added to each block outBSize := int(float64(inBSize)/4 + 3.5) // compression is 4:1 and 3.5 bytes of info are added to each block
comp := make([]byte, 0, outBSize*numBlocks) comp := make([]byte, 0, outBSize*numBlocks)
for i := 0; i < numBlocks; i++ { for i := 0; i < numBlocks; i++ {
block := pcm[inBSize*i : inBSize*(i+1)] block := pcm[inBSize*i : inBSize*(i+1)]

View File

@ -45,8 +45,8 @@ func TestEncodeBlock(t *testing.T) {
//encode adpcm //encode adpcm
inBSize := 1010 inBSize := 1010
numBlocks := int(len(pcm) / inBSize) numBlocks := len(pcm) / inBSize
outBSize := int(float32(inBSize/4) + float32(3.5)) // compression is 4:1 and 3.5 bytes of info are added to each block outBSize := int(float64(inBSize)/4 + 3.5) // compression is 4:1 and 3.5 bytes of info are added to each block
comp := make([]byte, 0, outBSize*numBlocks) comp := make([]byte, 0, outBSize*numBlocks)
for i := 0; i < numBlocks; i++ { for i := 0; i < numBlocks; i++ {
block := pcm[inBSize*i : inBSize*(i+1)] block := pcm[inBSize*i : inBSize*(i+1)]
@ -79,7 +79,7 @@ func TestDecodeBlock(t *testing.T) {
//decode adpcm //decode adpcm
inBSize := 256 inBSize := 256
numBlocks := int(len(comp) / inBSize) numBlocks := len(comp) / inBSize
outBSize := 2 + (inBSize-4)*4 // 2 bytes are copied, 2 are used as block header info, the remaining bytes are decompressed 1:4 outBSize := 2 + (inBSize-4)*4 // 2 bytes are copied, 2 are used as block header info, the remaining bytes are decompressed 1:4
decoded := make([]byte, 0, outBSize*numBlocks) decoded := make([]byte, 0, outBSize*numBlocks)
for i := 0; i < numBlocks; i++ { for i := 0; i < numBlocks; i++ {