From 00a453f18c1b1222a44070468e00bd76837a1680 Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Sun, 1 Mar 2026 10:42:00 +0100 Subject: [PATCH] [perf](trx-server): set opus complexity to 5 and raise default bitrate to 256k Set opus encoder complexity from default (9-10) to 5 for both cpal and SDR audio paths, significantly reducing encoding CPU usage with minimal quality impact at these bitrates. Raise default bitrate from 192 kbps to 256 kbps for higher fidelity stereo audio. Co-Authored-By: Claude Opus 4.6 Signed-off-by: Stan Grams --- src/trx-server/src/audio.rs | 1 + src/trx-server/src/config.rs | 2 +- src/trx-server/src/main.rs | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/trx-server/src/audio.rs b/src/trx-server/src/audio.rs index 1771305..142ab1f 100644 --- a/src/trx-server/src/audio.rs +++ b/src/trx-server/src/audio.rs @@ -295,6 +295,7 @@ fn run_capture( let mut encoder = opus::Encoder::new(sample_rate, opus_channels, opus::Application::Audio)?; encoder.set_bitrate(opus::Bitrate::Bits(bitrate_bps as i32))?; + encoder.set_complexity(5)?; // Start paused — only capture when clients are connected info!( diff --git a/src/trx-server/src/config.rs b/src/trx-server/src/config.rs index d99dc3f..ce5cd1c 100644 --- a/src/trx-server/src/config.rs +++ b/src/trx-server/src/config.rs @@ -267,7 +267,7 @@ impl Default for AudioConfig { sample_rate: 48000, channels: 2, frame_duration_ms: 20, - bitrate_bps: 192000, + bitrate_bps: 256000, } } } diff --git a/src/trx-server/src/main.rs b/src/trx-server/src/main.rs index 74f5b94..7b3439a 100644 --- a/src/trx-server/src/main.rs +++ b/src/trx-server/src/main.rs @@ -519,6 +519,9 @@ fn spawn_rig_audio_stack( if let Err(e) = encoder.set_bitrate(opus::Bitrate::Bits(sdr_bitrate_bps as i32)) { tracing::warn!("SDR audio: set_bitrate failed: {}", e); } + if let Err(e) = encoder.set_complexity(5) { + tracing::warn!("SDR audio: set_complexity failed: {}", e); + } let mut opus_buf = vec![0u8; 4096]; loop { match sdr_rx.recv().await {