Skip to content

Commit 76a4a53

Browse files
committed
Fixed issue #1
The encoder would omit one PCM frame in cases where the length of the input in EncodeUlaw() or EncodeAlaw() was 2
1 parent c92d33e commit 76a4a53

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

alaw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func EncodeAlaw(lpcm []byte) []byte {
9595
return []byte{}
9696
}
9797
alaw := make([]byte, len(lpcm)/2)
98-
for i, j := 0, 0; j < len(lpcm)-2; i, j = i+1, j+2 {
98+
for i, j := 0, 0; j <= len(lpcm)-2; i, j = i+1, j+2 {
9999
alaw[i] = EncodeAlawFrame(int16(lpcm[j]) | int16(lpcm[j+1])<<8)
100100
}
101101
return alaw

g711_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var EncoderTest = []struct {
2424
expected int
2525
}{
2626
{[]byte{}, 0},
27+
{[]byte{0x01, 0x00}, 2},
2728
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 12},
2829
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 12},
2930
}
@@ -33,6 +34,7 @@ var DecoderTest = []struct {
3334
expected int
3435
}{
3536
{[]byte{}, 0},
37+
{[]byte{0x01, 0x00}, 4},
3638
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 24},
3739
{[]byte{0x01, 0x00, 0xdc, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 26},
3840
}
@@ -42,6 +44,7 @@ var TranscoderTest = []struct {
4244
expected int
4345
}{
4446
{[]byte{}, 0},
47+
{[]byte{0x01, 0x00}, 2},
4548
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 12},
4649
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 13},
4750
}

ulaw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func EncodeUlaw(lpcm []byte) []byte {
9898
return []byte{}
9999
}
100100
ulaw := make([]byte, len(lpcm)/2)
101-
for i, j := 0, 0; j < len(lpcm)-2; i, j = i+1, j+2 {
101+
for i, j := 0, 0; j <= len(lpcm)-2; i, j = i+1, j+2 {
102102
ulaw[i] = EncodeUlawFrame(int16(lpcm[j]) | int16(lpcm[j+1])<<8)
103103
}
104104
return ulaw

0 commit comments

Comments
 (0)