tweak the adaptive frame dropping a little further

This commit is contained in:
2025-11-11 16:16:37 +01:00
parent a6e4ff9df9
commit e9e5a190f6

View File

@@ -65,11 +65,8 @@ class ModSoundDeviceAudioInput(audio_io.SoundDeviceAudioInput):
hostapis = sd.query_hostapis()
api_index = dev_info.get('hostapi')
api_name = hostapis[api_index]['name'] if isinstance(api_index, int) and 0 <= api_index < len(hostapis) else 'unknown'
pa_ver = None
try:
pa_ver = sd.get_portaudio_version()
except Exception:
pass
pa_ver = sd.get_portaudio_version()
logging.info(
"SoundDevice backend=%s device='%s' (id=%s) ch=%s default_low_input_latency=%.4f default_high_input_latency=%.4f portaudio=%s",
api_name,
@@ -697,7 +694,7 @@ class Streamer():
drift_threshold_ms = 2.0 if enable_drift_compensation else 0.0
static_drop_ms = 2 if enable_drift_compensation else 0.0
# Guard interval measured in LC3 frames (10 ms each)
discard_guard_frames = int(sample_rate / 1000) // 2 if enable_drift_compensation else 0
discard_guard_frames = 10 if enable_drift_compensation else 0
# Derived sample counts
drop_threshold_samples = int(sample_rate * drift_threshold_ms / 1000.0)
static_drop_samples = int(sample_rate * static_drop_ms / 1000.0)
@@ -1040,18 +1037,18 @@ if __name__ == "__main__":
raise ValueError(f"Invalid AUDIO_BACKEND: {AUDIO_BACKEND}")
# Select audio input device based on backend
shure_device_idx = None
audio_dev = None
if AUDIO_BACKEND == 'ALSA':
search_str='ch1'
# Use ALSA devices
from auracast.utils.sounddevice_utils import get_alsa_usb_inputs
devices = get_alsa_usb_inputs()
logging.info("Searching ALSA devices for Shure MVX2U...")
logging.info(f"Searching ALSA devices for first device with string {search_str}...")
for idx, dev in devices:
logging.info(f" ALSA device [{idx}]: {dev['name']} ({dev['max_input_channels']} ch)")
if 'shure' in dev['name'].lower() and 'mvx2u' in dev['name'].lower():
shure_device_idx = idx
if search_str in dev['name'].lower():
audio_dev = idx
logging.info(f"✓ Selected ALSA device {idx}: {dev['name']}")
break
@@ -1077,8 +1074,8 @@ if __name__ == "__main__":
logging.info(f"✓ Selected PulseAudio device {idx}: {dev['name']} → routes to PipeWire")
break
if shure_device_idx is None:
logging.error(f"Shure MVX2U not found in {AUDIO_BACKEND} devices!")
if audio_dev is None:
logging.error(f"Audio device {audio_dev} not found in {AUDIO_BACKEND} devices!")
raise RuntimeError(f"Audio device not found for {AUDIO_BACKEND} backend")
config = auracast_config.AuracastConfigGroup(
@@ -1112,10 +1109,10 @@ if __name__ == "__main__":
#big.audio_source = read_lc3_file(big.audio_source) # load files in advance
# --- Configure Shure MVX2U USB Audio Interface (ALSA backend) ---
if shure_device_idx is not None:
big.audio_source = f'device:{shure_device_idx}' # Shure MVX2U USB mono interface
if audio_dev is not None:
big.audio_source = f'device:{audio_dev}' # Shure MVX2U USB mono interface
big.input_format = 'int16le,48000,1' # int16, 48kHz, mono
logging.info(f"Configured BIG '{big.name}' with Shure MVX2U (device:{shure_device_idx}, 48kHz mono)")
logging.info(f"Configured BIG '{big.name}' with Shure MVX2U (device:{audio_dev}, 48kHz mono)")
else:
logging.warning(f"Shure device not found, BIG '{big.name}' will use default audio_source: {big.audio_source}")
@@ -1128,12 +1125,13 @@ if __name__ == "__main__":
# 24kHz is only working with 2 streams - probably airtime constraint
# TODO: with more than three broadcasters (16kHz) no advertising (no primary channels is present anymore)
# TODO: find the bottleneck - probably airtime
# TODO: test encrypted streams
config.auracast_sampling_rate_hz = 16000
config.octets_per_frame = 40 # 32kbps@16kHz
#config.debug = True
config.enable_adaptive_frame_dropping=True
# Enable clock drift compensation to prevent latency accumulation
run_async(