Merge branch 'adpcm-nonblock' of https://bitbucket.org/ausocean/av into adpcm-nonblock

This commit is contained in:
Trek H 2019-04-26 20:01:48 +09:30
commit 2fd8d8de1b
1 changed files with 19 additions and 0 deletions

View File

@ -304,6 +304,7 @@ func (d *decoder) decodeBlock(block []byte) (int, error) {
// It writes its output to the encoder's dest.
// The number of bytes written out is returned along with any error that occured.
func (e *encoder) Write(inPcm []byte) (int, error) {
<<<<<<< HEAD:codec/adpcm/adpcm.go
// Determine if there will be a byte that won't contain two full nibbles and will need padding.
pcmLen := len(inPcm)
pad := false
@ -312,10 +313,15 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
}
n, err := e.calcHead(inPcm[0:2], pad)
=======
n, err := e.calcHead(inPcm[0:2])
>>>>>>> 2600fa884f6d71d325dfad995cc1d053106a88d6:audio/adpcm/adpcm.go
if err != nil {
return n, err
}
<<<<<<< HEAD:codec/adpcm/adpcm.go
for i := 3; i < pcmLen; i += 4 {
nib1 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i-1 : i+1])))
nib2 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i+1 : i+3])))
@ -330,6 +336,12 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
if pad {
nib := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[pcmLen-2 : pcmLen])))
err = e.dest.WriteByte(nib)
=======
for i := 3; i < len(inPcm); i += 4 {
nib1 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i-1 : i+1])))
nib2 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i+1 : i+3])))
err = e.dest.WriteByte(byte((nib2 << 4) | nib1))
>>>>>>> 2600fa884f6d71d325dfad995cc1d053106a88d6:audio/adpcm/adpcm.go
if err != nil {
return n, err
}
@ -355,8 +367,12 @@ func (d *decoder) Write(inAdpcm []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.
<<<<<<< HEAD:codec/adpcm/adpcm.go
// If padding flag is true (Adpcm[3]), only decode up until the last byte, then decode that separately.
for i := 4; i < len(inAdpcm)-int(inAdpcm[3]); i++ {
=======
for i := 4; i < len(inAdpcm); i++ {
>>>>>>> 2600fa884f6d71d325dfad995cc1d053106a88d6:audio/adpcm/adpcm.go
twoNibs := inAdpcm[i]
nib2 := byte(twoNibs >> 4)
nib1 := byte((nib2 << 4) ^ twoNibs)
@ -372,6 +388,7 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) {
secondBytes := make([]byte, 2)
binary.LittleEndian.PutUint16(secondBytes, uint16(d.decodeSample(nib2)))
_n, err = d.dest.Write(secondBytes)
<<<<<<< HEAD:codec/adpcm/adpcm.go
n += _n
if err != nil {
return n, err
@ -382,6 +399,8 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) {
samp := make([]byte, 2)
binary.LittleEndian.PutUint16(samp, uint16(d.decodeSample(padNib)))
_n, err := d.dest.Write(samp)
=======
>>>>>>> 2600fa884f6d71d325dfad995cc1d053106a88d6:audio/adpcm/adpcm.go
n += _n
if err != nil {
return n, err