2019-02-13 04:23:06 +03:00
|
|
|
/*
|
|
|
|
NAME
|
|
|
|
encode-pcm.go
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHOR
|
|
|
|
Trek Hopton <trek@ausocean.org>
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
encode-pcm.go is Copyright (C) 2018 the Australian Ocean Lab (AusOcean)
|
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
|
|
|
|
*/
|
|
|
|
|
2019-02-11 04:41:26 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
|
2019-02-11 07:55:10 +03:00
|
|
|
"bitbucket.org/ausocean/av/stream/adpcm"
|
2019-02-11 04:41:26 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
2019-02-13 04:23:06 +03:00
|
|
|
|
2019-02-11 04:41:26 +03:00
|
|
|
//read pcm
|
|
|
|
pcm, err := ioutil.ReadFile(inPath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
//encode adpcm
|
|
|
|
var comp []byte
|
|
|
|
start := 0
|
2019-02-11 07:55:10 +03:00
|
|
|
bSize := 1010
|
2019-02-11 04:41:26 +03:00
|
|
|
for i := 0; i < len(pcm); i++ {
|
2019-02-11 07:55:10 +03:00
|
|
|
if i%bSize == bSize-1 {
|
2019-02-11 04:41:26 +03:00
|
|
|
block := pcm[start : i+1]
|
|
|
|
|
|
|
|
encBlock, err := adpcm.EncodeBlock(block)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
comp = append(comp, encBlock...)
|
|
|
|
start = i + 1
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 04:23:06 +03:00
|
|
|
|
2019-02-11 04:41:26 +03:00
|
|
|
// save adpcm to file
|
|
|
|
err = ioutil.WriteFile(adpcmPath, comp, 0644)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|