AudioMaximumFrameSize (5760) already accounts for stereo by including
the AudioChannels factor. The Decode method was multiplying by
AudioChannels again, allocating 11520 int16s per decode call instead
of the needed 5760. This wasted ~21KB per audio packet (2MB/s at
100 pps). Use frameSize directly and derive total sample count from
the decoder's configured channel count.
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.
Replace SetBitrateToMax() with dynamic bitrate configuration based on
the per-frame byte budget (AudioDataBytes). Previously, the encoder
always targeted maximum bitrate (~510 kbps) and relied on output
truncation when frames exceeded the available bandwidth. This could
produce truncated/invalid Opus frames when the server's max bandwidth
is lower than the encoder's target.
The bitrate is now recalculated on every Encode() call as:
maxDataBytes * 8 * 100 (bits per second for 10ms frames)
This ensures the encoder produces frames that fit within the byte
budget without truncation.