mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 18:46:11 +00:00
* Refactor OPUS encoder for quality and speed. Use OPUS low delay mode (https://www.opus-codec.org/docs/opus_api-1.1.3/group__opus__ctlvalues.html#ga592232fb39db60c1369989c5c5d19a07) * Slightly tweak linear resample function and disable it on 48kHz input * Rewrite OPUS encoder as a struct with some internal buffer * Use OPUS 192Kbps preset by default * Add encoder callback function on a full buffer * Reuse OPUS output buffer * Add write limiter for samples
27 lines
468 B
Go
27 lines
468 B
Go
package opus
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var resampleData []int16
|
|
|
|
func init() {
|
|
rand.Seed(time.Now().Unix())
|
|
l := rand.Perm(getBufferLength(44000))
|
|
for _, n := range l {
|
|
resampleData = append(resampleData, int16(n))
|
|
}
|
|
}
|
|
|
|
func BenchmarkResample(b *testing.B) {
|
|
sr := 48000
|
|
bs := getBufferLength(sr)
|
|
for i := 0; i < b.N; i++ {
|
|
resampleFn(resampleData, bs)
|
|
}
|
|
}
|
|
|
|
func getBufferLength(sampleRate int) int { return sampleRate * 20 / 1000 * 2 }
|