fix: add minimum Opus bitrate floor in encoder
Add a defensive floor of 8000 bps in the Encode method, preventing the encoder from being configured with an invalidly low bitrate even if AudioDataBytes is somehow set to a very small value.
This commit is contained in:
1 parent
64a3ea6c32
commit
181b325c2d
1 file changed
+3
@@ -68,6 +68,9 @@ func (e *Encoder) Encode(pcm []int16, _, maxDataBytes int) ([]byte, error) {
|
|||||||
// Opus encodes best when the bitrate target is set properly rather than
|
// Opus encodes best when the bitrate target is set properly rather than
|
||||||
// relying on truncation, which can produce incomplete or corrupt frames.
|
// relying on truncation, which can produce incomplete or corrupt frames.
|
||||||
bitrate := maxDataBytes * 8 * 100
|
bitrate := maxDataBytes * 8 * 100
|
||||||
|
if bitrate < 8000 {
|
||||||
|
bitrate = 8000 // Opus minimum viable bitrate for voice
|
||||||
|
}
|
||||||
_ = e.Encoder.SetBitrate(bitrate)
|
_ = e.Encoder.SetBitrate(bitrate)
|
||||||
|
|
||||||
buf := make([]byte, maxDataBytes)
|
buf := make([]byte, maxDataBytes)
|
||||||
|
|||||||
Reference in new issue
Block a user