mirror of https://bitbucket.org/ausocean/av.git
adpcm: fixing offset error
This commit is contained in:
parent
c089980175
commit
b412b75fc6
|
@ -315,10 +315,11 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
|
|||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
||||
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])))
|
||||
// Skip the first sample and start at the end of the first two samples, then every two samples encode them into a byte of adpcm.
|
||||
// TODO: make all hard coded numbers variables so that other bitrates and compression ratios can be used.
|
||||
for i := 5; i < pcmLen; i += 4 {
|
||||
nib1 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i-3 : i-1])))
|
||||
nib2 := e.encodeSample(int16(binary.LittleEndian.Uint16(inPcm[i-1 : i+1])))
|
||||
err = e.dest.WriteByte(byte((nib2 << 4) | nib1))
|
||||
if err != nil {
|
||||
return n, err
|
||||
|
@ -335,7 +336,6 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
|
|||
}
|
||||
n++
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,6 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
|
|||
// It writes its output to the decoder's dest.
|
||||
// The number of bytes written out is returned along with any error that occured.
|
||||
func (d *decoder) Write(inAdpcm []byte) (int, error) {
|
||||
|
||||
// Initialize decoder with first 4 bytes of the inAdpcm.
|
||||
d.pred = int16(binary.LittleEndian.Uint16(inAdpcm[0:2]))
|
||||
d.index = int16(inAdpcm[2])
|
||||
|
@ -387,11 +386,10 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) {
|
|||
return n, err
|
||||
}
|
||||
}
|
||||
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data
|
||||
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data byte size.
|
||||
func BytesOutput(pcm int) int {
|
||||
// for X pcm bytes, 2 bytes are left uncompressed, the rest is compressed by a factor of 4
|
||||
// and a start index and padding byte are added.
|
||||
|
|
Loading…
Reference in New Issue