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 071b16ccf6
commit 408a952c9a
1 changed files with 10 additions and 6 deletions
stream/adpcm

View File

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