From 4cadf38e5aa39c7c7f1db626e3cd1a6facfb6fb5 Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 25 Nov 2025 10:29:57 +0200 Subject: [PATCH] Remove unused sample rate and frame size parameters Hardware sample rate is auto-negotiated by ALSA, and frame size is derived from it. These parameters were being passed but ignored - remove them from update_audio_constants() and update_audio_decoder_constants() signatures. --- internal/audio/c/audio.c | 14 ++++---------- internal/audio/cgo_source.go | 8 -------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/internal/audio/c/audio.c b/internal/audio/c/audio.c index 2693b497..1fd8c814 100644 --- a/internal/audio/c/audio.c +++ b/internal/audio/c/audio.c @@ -119,16 +119,16 @@ void jetkvm_audio_playback_close(); int jetkvm_audio_decode_write(void *opus_buf, int opus_size); void update_audio_constants(uint32_t bitrate, uint8_t complexity, - uint32_t sr, uint8_t ch, uint16_t fs, uint16_t max_pkt, + uint8_t ch, uint16_t max_pkt, uint32_t sleep_us, uint8_t max_attempts, uint32_t max_backoff, uint8_t dtx_enabled, uint8_t fec_enabled, uint8_t buf_periods, uint8_t pkt_loss_perc); -void update_audio_decoder_constants(uint32_t sr, uint8_t ch, uint16_t fs, uint16_t max_pkt, +void update_audio_decoder_constants(uint8_t ch, uint16_t max_pkt, uint32_t sleep_us, uint8_t max_attempts, uint32_t max_backoff, uint8_t buf_periods); void update_audio_constants(uint32_t bitrate, uint8_t complexity, - uint32_t sr, uint8_t ch, uint16_t fs, uint16_t max_pkt, + uint8_t ch, uint16_t max_pkt, uint32_t sleep_us, uint8_t max_attempts, uint32_t max_backoff, uint8_t dtx_enabled, uint8_t fec_enabled, uint8_t buf_periods, uint8_t pkt_loss_perc) { opus_bitrate = (bitrate >= 64000 && bitrate <= 256000) ? bitrate : 192000; @@ -143,12 +143,9 @@ void update_audio_constants(uint32_t bitrate, uint8_t complexity, opus_fec_enabled = fec_enabled ? 1 : 0; buffer_period_count = (buf_periods >= 2 && buf_periods <= 24) ? buf_periods : 12; opus_packet_loss_perc = (pkt_loss_perc <= 100) ? pkt_loss_perc : 20; - - // Note: sr and fs parameters ignored - RFC 7587 requires fixed 48kHz RTP clock rate - // Hardware sample rate conversion is handled by SpeexDSP resampler } -void update_audio_decoder_constants(uint32_t sr, uint8_t ch, uint16_t fs, uint16_t max_pkt, +void update_audio_decoder_constants(uint8_t ch, uint16_t max_pkt, uint32_t sleep_us, uint8_t max_attempts, uint32_t max_backoff, uint8_t buf_periods) { playback_channels = (ch == 1 || ch == 2) ? ch : 2; @@ -158,9 +155,6 @@ void update_audio_decoder_constants(uint32_t sr, uint8_t ch, uint16_t fs, uint16 max_attempts_global = max_attempts > 0 ? max_attempts : 5; max_backoff_us_global = max_backoff > 0 ? max_backoff : 500000; buffer_period_count = (buf_periods >= 2 && buf_periods <= 24) ? buf_periods : 12; - - // Note: sr and fs parameters ignored - decoder uses hardware-negotiated rate - // USB Audio Gadget typically negotiates 48kHz, matching Opus RTP clock (RFC 7587) } /** diff --git a/internal/audio/cgo_source.go b/internal/audio/cgo_source.go index bd047b2c..b8de5731 100644 --- a/internal/audio/cgo_source.go +++ b/internal/audio/cgo_source.go @@ -102,9 +102,7 @@ func (c *CgoSource) connectOutput() error { C.update_audio_constants( C.uint(uint32(c.config.Bitrate)*1000), C.uchar(c.config.Complexity), - C.uint(sampleRate), C.uchar(2), - C.ushort(frameSize), C.ushort(1500), C.uint(1000), C.uchar(5), @@ -130,14 +128,8 @@ func (c *CgoSource) connectInput() error { c.logger.Warn().Err(err).Str("device", c.alsaDevice).Msg("Failed to set ALSA_PLAYBACK_DEVICE") } - // USB Audio Gadget uses fixed 48kHz sample rate - const inputSampleRate = 48000 - const frameSize = uint16(inputSampleRate * 20 / 1000) // 20ms frames - C.update_audio_decoder_constants( - C.uint(inputSampleRate), C.uchar(1), // Mono for USB audio gadget - C.ushort(uint16(frameSize)), C.ushort(1500), C.uint(1000), C.uchar(5),