mirror of https://bitbucket.org/ausocean/av.git
adpcm: added ability to read consecutive chunks to adpcm decoder.
This commit is contained in:
parent
137b47b56c
commit
d23ae1a290
|
@ -209,7 +209,7 @@ func (e *Encoder) Write(b []byte) (int, error) {
|
|||
}
|
||||
|
||||
// Write the first 4 bytes of the adpcm chunk, which represent its length, ie. the number of bytes following the chunk length.
|
||||
chunkLen := EncBytes(pcmLen) - chunkLenSize
|
||||
chunkLen := EncBytes(pcmLen)
|
||||
chunkLenBytes := make([]byte, chunkLenSize)
|
||||
binary.LittleEndian.PutUint32(chunkLenBytes, uint32(chunkLen))
|
||||
n, err := e.dst.Write(chunkLenBytes)
|
||||
|
@ -298,10 +298,10 @@ func (d *Decoder) Write(b []byte) (int, error) {
|
|||
// Iterate over each chunk and decode it.
|
||||
var n int
|
||||
var chunkLen int
|
||||
for off := 0; off+headSize <= len(b); off += chunkLenSize + chunkLen {
|
||||
for off := 0; off+headSize <= len(b); off += chunkLen {
|
||||
// Read length of chunk and check if whole chunk exists.
|
||||
chunkLen = int(binary.LittleEndian.Uint32(b[off : off+chunkLenSize]))
|
||||
if off+chunkLenSize+chunkLen > len(b) {
|
||||
if off+chunkLen > len(b) {
|
||||
break
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,7 @@ func (d *Decoder) Write(b []byte) (int, error) {
|
|||
// For each byte, seperate it into two nibbles (each nibble is a compressed sample),
|
||||
// then decode each nibble and output the resulting 16-bit samples.
|
||||
// If padding flag is true only decode up until the last byte, then decode that separately.
|
||||
for i := off + headSize; i < off+chunkLenSize+chunkLen-int(b[off+chunkLenSize+3]); i++ {
|
||||
for i := off + headSize; i < off+chunkLen-int(b[off+chunkLenSize+3]); i++ {
|
||||
twoNibs := b[i]
|
||||
nib2 := byte(twoNibs >> 4)
|
||||
nib1 := byte((nib2 << 4) ^ twoNibs)
|
||||
|
@ -340,7 +340,7 @@ func (d *Decoder) Write(b []byte) (int, error) {
|
|||
}
|
||||
}
|
||||
if b[off+chunkLenSize+3] == 0x01 {
|
||||
padNib := b[off+chunkLenSize+chunkLen-1]
|
||||
padNib := b[off+chunkLen-1]
|
||||
samp := make([]byte, byteDepth)
|
||||
binary.LittleEndian.PutUint16(samp, uint16(d.decodeSample(padNib)))
|
||||
_n, err := d.dst.Write(samp)
|
||||
|
|
Loading…
Reference in New Issue