mirror of https://bitbucket.org/ausocean/av.git
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
/*
|
|
NAME
|
|
decode-pcm.go
|
|
|
|
DESCRIPTION
|
|
decode-pcm.go is a program for decoding/decompressing an adpcm file to a pcm file.
|
|
|
|
AUTHOR
|
|
Trek Hopton <trek@ausocean.org>
|
|
|
|
LICENSE
|
|
decode-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 in gpl.txt.
|
|
If not, see [GNU licenses](http://www.gnu.org/licenses).
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"flag"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"log"
|
|
|
|
"bitbucket.org/ausocean/av/audio/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 {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println("Read", len(comp), "bytes from file", inPath)
|
|
|
|
// Decode adpcm.
|
|
numBlocks := len(comp) / adpcm.AdpcmBS
|
|
decoded := bytes.NewBuffer(make([]byte, 0, adpcm.PcmBS*numBlocks))
|
|
dec := adpcm.NewDecoder(decoded)
|
|
for i := 0; i < numBlocks; i++ {
|
|
block := comp[adpcm.AdpcmBS*i : adpcm.AdpcmBS*(i+1)]
|
|
err := dec.DecodeBlock(block)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// Save pcm to file.
|
|
err = ioutil.WriteFile(outPath, decoded.Bytes(), 0644)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
fmt.Println("Decoded and wrote", len(decoded.Bytes()), "bytes to file", outPath)
|
|
}
|