av/cmd/adpcm/decode-pcm/decode-pcm.go

44 lines
924 B
Go
Raw Normal View History

package main
import (
"flag"
"io/ioutil"
2019-02-11 07:55:10 +03:00
"bitbucket.org/ausocean/av/stream/adpcm"
)
// This program accepts an input file encoded in adpcm and outputs a decoded pcm file.
// Input and output file names can be specified as arguments.
func main() {
var inPath string
var outPath string
flag.StringVar(&inPath, "in", "encoded.adpcm", "file path of input")
flag.StringVar(&outPath, "out", "decoded.pcm", "file path of output data")
flag.Parse()
//read adpcm
comp, err := ioutil.ReadFile(inPath)
if err != nil {
panic(err)
}
//decode adpcm
var decoded []byte
start := 0
for i := 0; i < len(comp); i++ {
if i%256 == 255 {
block := comp[start : i+1]
decBlock, err := adpcm.DecodeBlock(block)
if err != nil {
panic(err)
}
decoded = append(decoded, decBlock...)
start = i + 1
}
}
// save pcm to file
err = ioutil.WriteFile(outPath, decoded, 0644)
if err != nil {
panic(err)
}
}