Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ linters-settings:
recommendations:
- errors
forbidigo:
analyze-types: true
forbid:
- ^fmt.Print(f|ln)?$
- ^log.(Panic|Fatal|Print)(f|ln)?$
- ^os.Exit$
- ^panic$
- ^print(ln)?$
- p: ^testing.T.(Error|Errorf|Fatal|Fatalf|Fail|FailNow)$
pkg: ^testing$
msg: "use testify/assert instead"
varnamelen:
max-distance: 12
min-name-length: 2
Expand Down Expand Up @@ -127,9 +131,12 @@ issues:
exclude-dirs-use-default: false
exclude-rules:
# Allow complex tests and examples, better to be self contained
- path: (examples|main\.go|_test\.go)
- path: (examples|main\.go)
linters:
- gocognit
- forbidigo
- path: _test\.go
linters:
- gocognit

# Allow forbidden identifiers in CLI commands
Expand Down
9 changes: 3 additions & 6 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"testing"

"github.com/pion/opus/pkg/oggreader"
"github.com/stretchr/testify/assert"
)

// nolint: gochecknoglobals
Expand Down Expand Up @@ -89,9 +90,7 @@ func TestTinyOgg(t *testing.T) {
var out [1920]byte

ogg, _, err := oggreader.NewWith(bytes.NewReader(tinyogg))
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)

decoder := NewDecoder()
for {
Expand All @@ -101,9 +100,7 @@ func TestTinyOgg(t *testing.T) {
} else if bytes.HasPrefix(segments[0], []byte("OpusTags")) {
continue
}
if err != nil {
t.Fatal(err)
}
assert.NoError(t, err)

for i := range segments {
if _, _, err = decoder.Decode(segments[i], out[:]); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/pion/opus

go 1.20

require github.com/stretchr/testify v1.10.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
13 changes: 4 additions & 9 deletions internal/bitdepth/bitdepth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
package bitdepth

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
)

func TestConvertFloat32LittleEndianToSigned16LittleEndian(t *testing.T) {
in := []float32{0.3, 0, .55, .72, -.05}
out := make([]byte, len(in)*2)

err := ConvertFloat32LittleEndianToSigned16LittleEndian(in, out, 1)
if err != nil {
t.Fatal(err)
}

if !bytes.Equal([]byte{0x66, 0x26, 0x00, 0x00, 0x65, 0x46, 0x28, 0x5c, 0x99, 0xf9}, out) {
t.Fatal("buffer mismatch")
}
assert.NoError(t, ConvertFloat32LittleEndianToSigned16LittleEndian(in, out, 1))
assert.Equal(t, []byte{0x66, 0x26, 0x00, 0x00, 0x65, 0x46, 0x28, 0x5c, 0x99, 0xf9}, out)
}
204 changes: 60 additions & 144 deletions internal/rangecoding/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package rangecoding

import (
"testing"

"github.com/stretchr/testify/assert"
)

// nolint: gochecknoglobals
Expand Down Expand Up @@ -132,148 +134,62 @@ func TestDecoder(t *testing.T) { // nolint:cyclop,gocyclo
decoder := &Decoder{}
decoder.Init([]byte{0x0b, 0xe4, 0xc1, 0x36, 0xec, 0xc5, 0x80})

if result := decoder.DecodeSymbolLogP(0x1); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolLogP(0x1); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelFrameTypeInactive); result != 1 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelGainHighbits[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelGainLowbits); result != 6 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelGainDelta); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelGainDelta); result != 3 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelGainDelta); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS1[1][0]); result != 9 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[10]); result != 5 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[9]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLsfInterpolationOffset); result != 4 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelLcgSeed); result != 2 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelExcRate[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
if result := decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]); result != 0 {
t.Fatal("")
}
assert.Equal(t, uint32(0), decoder.DecodeSymbolLogP(0x1))
assert.Equal(t, uint32(0), decoder.DecodeSymbolLogP(0x1))

assert.Equal(t, uint32(1), decoder.DecodeSymbolWithICDF(silkModelFrameTypeInactive))

assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelGainHighbits[0]))

assert.Equal(t, uint32(6), decoder.DecodeSymbolWithICDF(silkModelGainLowbits))

assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelGainDelta))
assert.Equal(t, uint32(3), decoder.DecodeSymbolWithICDF(silkModelGainDelta))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelGainDelta))

assert.Equal(t, uint32(9), decoder.DecodeSymbolWithICDF(silkModelLsfS1[1][0]))
assert.Equal(t, uint32(5), decoder.DecodeSymbolWithICDF(silkModelLsfS2[10]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[9]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))

assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))
assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfS2[8]))

assert.Equal(t, uint32(4), decoder.DecodeSymbolWithICDF(silkModelLsfInterpolationOffset))

assert.Equal(t, uint32(2), decoder.DecodeSymbolWithICDF(silkModelLcgSeed))

assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelExcRate[0]))

assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
assert.Equal(t, uint32(0), decoder.DecodeSymbolWithICDF(silkModelPulseCount[0]))
}
Loading
Loading