ADPCM: changed adpcm_test.go to use pre-allocation of byte slices

This commit is contained in:
Trek H 2019-02-13 16:58:21 +10:30
parent 7d3829d19f
commit 78a3127632
1 changed files with 10 additions and 6 deletions

View File

@ -43,9 +43,11 @@ func TestEncodeBlock(t *testing.T) {
} }
//encode adpcm //encode adpcm
var comp []byte inBSize := 1010
bSize := 1010 numBlocks := int(len(pcm) / inBSize)
for i, start := bSize-1, 0; i < len(pcm); i += bSize { outBSize := int(float32(inBSize/4) + float32(3.5)) // compression is 4:1 and 3.5 bytes of info are added to each block
comp := make([]byte, 0, outBSize*numBlocks)
for i, start := inBSize-1, 0; i < len(pcm); i += inBSize {
block := pcm[start : i+1] block := pcm[start : i+1]
encBlock, err := EncodeBlock(block) encBlock, err := EncodeBlock(block)
@ -77,9 +79,11 @@ func TestDecodeBlock(t *testing.T) {
} }
//decode adpcm //decode adpcm
var decoded []byte inBSize := 256
bSize := 256 numBlocks := int(len(comp) / inBSize)
for i, start := bSize-1, 0; i < len(comp); i += bSize { 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)
for i, start := inBSize-1, 0; i < len(comp); i += inBSize {
block := comp[start : i+1] block := comp[start : i+1]
decBlock, err := DecodeBlock(block) decBlock, err := DecodeBlock(block)
if err != nil { if err != nil {