Skip to content

Commit

Permalink
Fixed issue zaf#1
Browse files Browse the repository at this point in the history
The encoder would omit one PCM frame in cases where the length of the
input in EncodeUlaw() or EncodeAlaw() was 2
  • Loading branch information
zaf committed Aug 14, 2019
1 parent c92d33e commit 76a4a53
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion alaw.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func EncodeAlaw(lpcm []byte) []byte {
return []byte{}
}
alaw := make([]byte, len(lpcm)/2)
for i, j := 0, 0; j < len(lpcm)-2; i, j = i+1, j+2 {
for i, j := 0, 0; j <= len(lpcm)-2; i, j = i+1, j+2 {
alaw[i] = EncodeAlawFrame(int16(lpcm[j]) | int16(lpcm[j+1])<<8)
}
return alaw
Expand Down
3 changes: 3 additions & 0 deletions g711_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var EncoderTest = []struct {
expected int
}{
{[]byte{}, 0},
{[]byte{0x01, 0x00}, 2},
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 12},
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 12},
}
Expand All @@ -33,6 +34,7 @@ var DecoderTest = []struct {
expected int
}{
{[]byte{}, 0},
{[]byte{0x01, 0x00}, 4},
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 24},
{[]byte{0x01, 0x00, 0xdc, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 26},
}
Expand All @@ -42,6 +44,7 @@ var TranscoderTest = []struct {
expected int
}{
{[]byte{}, 0},
{[]byte{0x01, 0x00}, 2},
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde}, 12},
{[]byte{0x01, 0x00, 0x7c, 0x7f, 0xd1, 0xd0, 0xd3, 0xd2, 0xdd, 0xdc, 0xdf, 0xde, 0xd9}, 13},
}
Expand Down
2 changes: 1 addition & 1 deletion ulaw.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func EncodeUlaw(lpcm []byte) []byte {
return []byte{}
}
ulaw := make([]byte, len(lpcm)/2)
for i, j := 0, 0; j < len(lpcm)-2; i, j = i+1, j+2 {
for i, j := 0, 0; j <= len(lpcm)-2; i, j = i+1, j+2 {
ulaw[i] = EncodeUlawFrame(int16(lpcm[j]) | int16(lpcm[j+1])<<8)
}
return ulaw
Expand Down

0 comments on commit 76a4a53

Please sign in to comment.