Skip to content
Open
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
17 changes: 17 additions & 0 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ bridge_decoder_get_last_packet_duration(OpusDecoder *st, opus_int32 *samples)
{
return opus_decoder_ctl(st, OPUS_GET_LAST_PACKET_DURATION(samples));
}

int
bridge_decoder_set_complexity(OpusDecoder *st, opus_int32 complexity)
{
return opus_decoder_ctl(st, OPUS_SET_COMPLEXITY(complexity));
}
*/
import "C"

Expand Down Expand Up @@ -260,3 +266,14 @@ func (dec *Decoder) LastPacketDuration() (int, error) {
}
return int(samples), nil
}

// SetComplexity sets the decoders's computational complexity
// Note that this feature is only available if using libopus >= 1.5
// This function will return ErrUnimplemented if the feature is not available
func (enc *Decoder) SetComplexity(complexity int) error {
res := C.bridge_decoder_set_complexity(enc.p, C.opus_int32(complexity))
if res != C.OPUS_OK {
return Error(res)
}
return nil
}
28 changes: 28 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package opus

import (
"fmt"
"testing"
)

Expand Down Expand Up @@ -66,3 +67,30 @@ func TestDecoder_GetLastPacketDuration(t *testing.T) {
t.Fatalf("Wrong duration length. Expected %d. Got %d", n, samples)
}
}

func TestDecoder_SetComplexity(t *testing.T) {
const SAMPLE_RATE = 48000

dec, err := NewDecoder(SAMPLE_RATE, 1)
if err != nil || dec == nil {
t.Fatalf("Error creating new decoder: %v", err)
}

t.Run("Complexity 0 to 10", func(t *testing.T) {
for i := 0; i <= 10; i++ {
err = dec.SetComplexity(i)
if err != nil {
t.Fatalf("Expected nil got %v", err)
}
}
})

for _, tt := range []int{-1, 11, 99} {
t.Run(fmt.Sprintf("Complexity %d", tt), func(t *testing.T) {
err = dec.SetComplexity(tt)
if err != ErrBadArg {
t.Fatalf("Expected %v got %v", ErrBadArg, err)
}
})
}
}
Loading