diff --git a/cmd/adpcm/decode-pcm/decode-pcm.go b/cmd/adpcm/decode-pcm/decode-pcm.go index 3c375de1..81b2d969 100644 --- a/cmd/adpcm/decode-pcm/decode-pcm.go +++ b/cmd/adpcm/decode-pcm/decode-pcm.go @@ -4,7 +4,7 @@ import ( "flag" "io/ioutil" - "bitbucket.org/ausocean/av/cmd/adpcm" + "bitbucket.org/ausocean/av/stream/adpcm" ) // This program accepts an input file encoded in adpcm and outputs a decoded pcm file. @@ -29,7 +29,6 @@ func main() { block := comp[start : i+1] decBlock, err := adpcm.DecodeBlock(block) if err != nil { - //todo: use correct logging of error panic(err) } decoded = append(decoded, decBlock...) @@ -41,5 +40,4 @@ func main() { if err != nil { panic(err) } - } diff --git a/cmd/adpcm/encode-pcm/encode-pcm.go b/cmd/adpcm/encode-pcm/encode-pcm.go index 57c9fd22..f8812dd3 100644 --- a/cmd/adpcm/encode-pcm/encode-pcm.go +++ b/cmd/adpcm/encode-pcm/encode-pcm.go @@ -4,7 +4,7 @@ import ( "flag" "io/ioutil" - "bitbucket.org/ausocean/av/cmd/adpcm" + "bitbucket.org/ausocean/av/stream/adpcm" ) func main() { @@ -22,13 +22,13 @@ func main() { //encode adpcm var comp []byte start := 0 + bSize := 1010 for i := 0; i < len(pcm); i++ { - if i%1010 == 1009 { + if i%bSize == bSize-1 { block := pcm[start : i+1] encBlock, err := adpcm.EncodeBlock(block) if err != nil { - //todo: use correct logging of error panic(err) } comp = append(comp, encBlock...) diff --git a/stream/adpcm/adpcm_test.go b/stream/adpcm/adpcm_test.go new file mode 100644 index 00000000..96c4a556 --- /dev/null +++ b/stream/adpcm/adpcm_test.go @@ -0,0 +1,42 @@ +package adpcm + +import ( + "bytes" + "io/ioutil" + "testing" +) + +func TestEncodeBlock(t *testing.T) { + //read input pcm + pcm, err := ioutil.ReadFile("../../../test/test-data/av/input/raw-voice.pcm") + if err != nil { + t.Errorf("Unable to read input PCM file: %v", err) + } + + //encode adpcm + var comp []byte + start := 0 + for i := 0; i < len(pcm); i++ { + if i%1010 == 1009 { + block := pcm[start : i+1] + + encBlock, err := EncodeBlock(block) + if err != nil { + //todo: use correct logging of error + t.Errorf("Unable to encode block: %v", err) + } + comp = append(comp, encBlock...) + start = i + 1 + } + } + + //read expected adpcm file + exp, err := ioutil.ReadFile("../../../test/test-data/av/output/encoded-voice.adpcm") + if err != nil { + t.Errorf("Unable to read expected ADPCM file: %v", err) + } + + if !bytes.Equal(comp, exp) { + t.Error("ADPCM generated does not match expected ADPCM") + } +}