mirror of https://bitbucket.org/ausocean/av.git
adpcm: naming and documentation
This commit is contained in:
parent
0570d7823d
commit
9fadb47902
|
@ -315,12 +315,12 @@ func (e *encoder) Write(inPcm []byte) (int, error) {
|
||||||
// Write takes a slice of bytes of arbitrary length representing adpcm and decodes it into pcm.
|
// Write takes a slice of bytes of arbitrary length representing adpcm and decodes it into pcm.
|
||||||
// It writes its output to the decoder's dst.
|
// It writes its output to the decoder's dst.
|
||||||
// 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 (d *decoder) Write(inAdpcm []byte) (int, error) {
|
func (d *decoder) Write(chunk []byte) (int, error) {
|
||||||
// Initialize decoder with first 4 bytes of the inAdpcm.
|
// Initialize decoder with first 4 bytes of the chunk.
|
||||||
d.est = int16(binary.LittleEndian.Uint16(inAdpcm[:byteDepth]))
|
d.est = int16(binary.LittleEndian.Uint16(chunk[:byteDepth]))
|
||||||
d.index = int16(inAdpcm[byteDepth])
|
d.index = int16(chunk[byteDepth])
|
||||||
d.step = stepTable[d.index]
|
d.step = stepTable[d.index]
|
||||||
n, err := d.dst.Write(inAdpcm[:byteDepth])
|
n, err := d.dst.Write(chunk[:byteDepth])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
@ -328,8 +328,8 @@ 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.
|
||||||
// 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 := headBytes; i < len(inAdpcm)-int(inAdpcm[3]); i++ {
|
for i := headBytes; i < len(chunk)-int(chunk[3]); i++ {
|
||||||
twoNibs := inAdpcm[i]
|
twoNibs := chunk[i]
|
||||||
nib2 := byte(twoNibs >> 4)
|
nib2 := byte(twoNibs >> 4)
|
||||||
nib1 := byte((nib2 << 4) ^ twoNibs)
|
nib1 := byte((nib2 << 4) ^ twoNibs)
|
||||||
|
|
||||||
|
@ -349,8 +349,8 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inAdpcm[3] == 0x01 {
|
if chunk[3] == 0x01 {
|
||||||
padNib := inAdpcm[len(inAdpcm)-1]
|
padNib := chunk[len(chunk)-1]
|
||||||
samp := make([]byte, byteDepth)
|
samp := make([]byte, byteDepth)
|
||||||
binary.LittleEndian.PutUint16(samp, uint16(d.decodeSample(padNib)))
|
binary.LittleEndian.PutUint16(samp, uint16(d.decodeSample(padNib)))
|
||||||
_n, err := d.dst.Write(samp)
|
_n, err := d.dst.Write(samp)
|
||||||
|
@ -364,7 +364,7 @@ func (d *decoder) Write(inAdpcm []byte) (int, error) {
|
||||||
|
|
||||||
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data byte size.
|
// BytesOutput will return the number of adpcm bytes that will be generated for the given pcm data byte size.
|
||||||
func BytesOutput(pcm int) int {
|
func BytesOutput(pcm int) int {
|
||||||
// for X pcm bytes, byteDepth (eg. 2 bytes) are left uncompressed, the rest is compressed by a factor of 4
|
// For X pcm bytes, 1 sample is left uncompressed, the rest is compressed by a factor of 4
|
||||||
// and a start index and padding-flag byte are added.
|
// and a start index and padding-flag byte are added.
|
||||||
// Also if there are an even number of samples, there will be half a byte of padding added to the last byte.
|
// Also if there are an even number of samples, there will be half a byte of padding added to the last byte.
|
||||||
if pcm%bytesPerEnc == 0 {
|
if pcm%bytesPerEnc == 0 {
|
||||||
|
|
Loading…
Reference in New Issue