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
20 lines
281 B
Go
20 lines
281 B
Go
package opus
|
|
|
|
type Buffer struct {
|
|
Data []int16
|
|
idx int
|
|
}
|
|
|
|
func (b *Buffer) Write(samples []int16) (written int) {
|
|
w := copy(b.Data[b.idx:], samples)
|
|
b.idx += w
|
|
return w
|
|
}
|
|
|
|
func (b *Buffer) Full() bool {
|
|
full := b.idx == len(b.Data)
|
|
if full {
|
|
b.idx = 0
|
|
}
|
|
return full
|
|
}
|