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
codec/adpcm

View File

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