package main import ( "flag" "io/ioutil" "bitbucket.org/ausocean/av/cmd/adpcm" ) func main() { var inPath string var adpcmPath string flag.StringVar(&inPath, "in", "data.pcm", "file path of input data") flag.StringVar(&adpcmPath, "out", "encoded.adpcm", "file path of output") flag.Parse() //read pcm pcm, err := ioutil.ReadFile(inPath) if err != nil { panic(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 := adpcm.EncodeBlock(block) if err != nil { //todo: use correct logging of error panic(err) } comp = append(comp, encBlock...) start = i + 1 } } // save adpcm to file err = ioutil.WriteFile(adpcmPath, comp, 0644) if err != nil { panic(err) } }