mirror of https://bitbucket.org/ausocean/av.git
ADPCM: removed unneccessary code for commands and updated their file names
This commit is contained in:
parent
5a2129f00f
commit
eabea6ce26
|
@ -0,0 +1,45 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
|
||||
"bitbucket.org/ausocean/av/cmd/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 {
|
||||
//todo: use correct logging of error
|
||||
panic(err)
|
||||
}
|
||||
decoded = append(decoded, decBlock...)
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
// save pcm to file
|
||||
err = ioutil.WriteFile(outPath, decoded, 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue