radio: add activation controls, live VAD meters and signal diagnostics
This commit is contained in:
1 parent
fddbba217d
commit
7f3247bfcc
23 files changed
+818
-182
No files matched your search
@@ -214,7 +214,8 @@ object NativeLib {
|
||||
fun radioAudioStop() { nativeRadioAudioStop() }
|
||||
fun radioCaptureStart(groupId: Long, channels: Int, mode: Int): Boolean = nativeRadioCaptureStart(groupId, channels, mode)
|
||||
fun radioConfigure(requestId: Long, settings: RadioAutoSettings): Boolean = nativeRadioConfigure(requestId, settings.nativeValues())
|
||||
fun radioInputStatus(): FloatArray = nativeRadioInputStatus() // уровень dBFS, valid, RX-блокировка
|
||||
// dBFS, valid, RX-блокировка, вероятность речи 0..1, vadValid, усиление VAD в dB, компрессор VAD включён.
|
||||
fun radioInputStatus(): FloatArray = nativeRadioInputStatus()
|
||||
fun radioCaptureStop() { nativeRadioCaptureStop() }
|
||||
fun radioTransmitting(): Boolean = nativeRadioTransmitting()
|
||||
fun radioAutoMode(): Int = nativeRadioAutoMode()
|
||||
|
||||
+35
-14
@@ -584,7 +584,7 @@ private fun DeveloperSettingsTab(vm: ChatViewModel, onDirty: (Boolean) -> Unit,
|
||||
dismissButton = { TextButton(onClick = { showClearDb = false }) { Text(stringResource(R.string.cancel)) } })
|
||||
}
|
||||
|
||||
/* Настройка детектора использует тот же native RMS, что и фактическая передача. */
|
||||
/* Измерители показывают фактические RMS и вероятность речи из native-детекторов. */
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
internal fun RadioAutomaticSettings(provider: ConfigProvider, compact: Boolean = false) {
|
||||
@@ -596,6 +596,9 @@ internal fun RadioAutomaticSettings(provider: ConfigProvider, compact: Boolean =
|
||||
var saveError by remember { mutableStateOf(false) }
|
||||
var resumed by remember { mutableStateOf(false) }
|
||||
var level by remember { mutableStateOf<Float?>(null) }
|
||||
var vadProbability by remember { mutableStateOf<Float?>(null) }
|
||||
var vadGain by remember { mutableStateOf<Float?>(null) }
|
||||
var vadCompressorEnabled by remember { mutableStateOf(false) }
|
||||
var blocked by remember { mutableStateOf(false) }
|
||||
var active by remember { mutableStateOf(engine.isActive()) }
|
||||
var micPermission by remember { mutableStateOf(MicrophonePermission.granted()) }
|
||||
@@ -607,12 +610,15 @@ internal fun RadioAutomaticSettings(provider: ConfigProvider, compact: Boolean =
|
||||
onPauseOrDispose { resumed = false; engine.setLevelMonitoring(false) }
|
||||
}
|
||||
LaunchedEffect(resumed) {
|
||||
if (!resumed) { level = null; return@LaunchedEffect }
|
||||
if (!resumed) { level = null; vadProbability = null; vadGain = null; return@LaunchedEffect }
|
||||
while (true) {
|
||||
val status = NativeLib.radioInputStatus()
|
||||
active = engine.isActive()
|
||||
micPermission = MicrophonePermission.granted()
|
||||
level = if (active && status[1] != 0f) status[0] else null
|
||||
vadProbability = if (active && status[4] != 0f) status[3] else null
|
||||
vadGain = if (active && status[4] != 0f) status[5] else null
|
||||
vadCompressorEnabled = status[6] != 0f
|
||||
blocked = status[2] != 0f
|
||||
delay(100)
|
||||
}
|
||||
@@ -661,19 +667,34 @@ internal fun RadioAutomaticSettings(provider: ConfigProvider, compact: Boolean =
|
||||
Text("−90 dBFS", style = MaterialTheme.typography.bodySmall)
|
||||
Text("0", style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
if (draft.mode == RadioAutoSettings.LEVEL) {
|
||||
LabeledSlider(stringResource(R.string.radio_level_on), draft.levelOn.toFloat(), -90f..0f, 89, "${draft.levelOn} dBFS",
|
||||
{ if (!saving) draft = draft.copy(levelOn = it.toInt()) })
|
||||
LabeledSlider(stringResource(R.string.radio_level_off), draft.levelOff.toFloat(), -90f..0f, 89, "${draft.levelOff} dBFS",
|
||||
{ if (!saving) draft = draft.copy(levelOff = it.toInt()) })
|
||||
} else {
|
||||
LabeledSlider(stringResource(R.string.speech_threshold), draft.vadThreshold.toFloat(), 10f..95f, 84, "${draft.vadThreshold}%",
|
||||
{ if (!saving) draft = draft.copy(vadThreshold = it.toInt()) })
|
||||
if (!compact) LabeledSlider(stringResource(R.string.vad_max_gain), draft.vadGain.toFloat(), 1f..60f, 58, "${draft.vadGain} dB",
|
||||
{ if (!saving) draft = draft.copy(vadGain = it.toInt()) })
|
||||
if (!compact) Text(stringResource(R.string.vad_compressor_hint), style = MaterialTheme.typography.bodySmall)
|
||||
LabeledSlider(stringResource(R.string.radio_level_on), draft.levelOn.toFloat(), -90f..0f, 89, "${draft.levelOn} dBFS",
|
||||
{ if (!saving) draft = draft.copy(levelOn = it.toInt()) })
|
||||
LabeledSlider(stringResource(R.string.radio_level_off), draft.levelOff.toFloat(), -90f..0f, 89, "${draft.levelOff} dBFS",
|
||||
{ if (!saving) draft = draft.copy(levelOff = it.toInt()) })
|
||||
HorizontalDivider()
|
||||
Text(stringResource(R.string.vad_button), style = MaterialTheme.typography.titleSmall)
|
||||
Text(vadProbability?.let { stringResource(R.string.radio_vad_current, it * 100f) } ?: stringResource(when {
|
||||
!saved.enabled || saved.mode != RadioAutoSettings.VAD -> R.string.radio_vad_enable
|
||||
blocked -> R.string.radio_vad_busy
|
||||
else -> R.string.radio_vad_unavailable
|
||||
}), style = MaterialTheme.typography.bodySmall)
|
||||
Canvas(Modifier.fillMaxWidth().height(20.dp)) {
|
||||
drawRect(background)
|
||||
vadProbability?.let { drawRect(Color(0xFF27AE60), size = Size(it.coerceIn(0f, 1f) * size.width, size.height)) }
|
||||
val thresholdX = draft.vadThreshold / 100f * size.width
|
||||
drawLine(Color(0xFFE67E22), Offset(thresholdX, 0f), Offset(thresholdX, size.height), 3.dp.toPx())
|
||||
}
|
||||
if (!compact) LabeledSlider(stringResource(R.string.silence_delay), draft.hangoverMs.toFloat(), 50f..2000f, 38,
|
||||
LabeledSlider(stringResource(R.string.speech_threshold), draft.vadThreshold.toFloat(), 10f..95f, 84, "${draft.vadThreshold}%",
|
||||
{ if (!saving) draft = draft.copy(vadThreshold = it.toInt()) })
|
||||
Text(when {
|
||||
vadGain == null -> stringResource(R.string.radio_vad_gain_unavailable)
|
||||
!vadCompressorEnabled -> stringResource(R.string.radio_vad_compressor_off)
|
||||
else -> stringResource(R.string.radio_vad_gain_current, vadGain!!)
|
||||
}, style = MaterialTheme.typography.bodySmall)
|
||||
LabeledSlider(stringResource(R.string.vad_max_gain), draft.vadGain.toFloat(), 1f..60f, 58, "${draft.vadGain} dB",
|
||||
{ if (!saving) draft = draft.copy(vadGain = it.toInt()) })
|
||||
if (!compact) Text(stringResource(R.string.vad_compressor_hint), style = MaterialTheme.typography.bodySmall)
|
||||
LabeledSlider(stringResource(R.string.silence_delay), draft.hangoverMs.toFloat(), 50f..2000f, 38,
|
||||
stringResource(R.string.milliseconds, draft.hangoverMs), { if (!saving) draft = draft.copy(hangoverMs = it.toInt()) })
|
||||
if (draft.levelOff >= draft.levelOn) Text(stringResource(R.string.radio_level_invalid), color = MaterialTheme.colorScheme.error)
|
||||
if (saveError) Text(stringResource(R.string.radio_auto_save_failed), color = MaterialTheme.colorScheme.error)
|
||||
|
||||
@@ -407,6 +407,13 @@
|
||||
<string name="radio_level_allow_mic">"Разрешить доступ к микрофону"</string>
|
||||
<string name="radio_level_unavailable">"Уровень микрофона недоступен"</string>
|
||||
<string name="radio_level_current">"Текущий уровень: %1$.1f dBFS"</string>
|
||||
<string name="radio_vad_current">"Вероятность речи VAD: %1$.1f%%"</string>
|
||||
<string name="radio_vad_enable">"Включите автопередачу в режиме VAD для оценки вероятности речи"</string>
|
||||
<string name="radio_vad_busy">"Оценка VAD приостановлена: эфир занят"</string>
|
||||
<string name="radio_vad_unavailable">"Оценка вероятности речи VAD недоступна"</string>
|
||||
<string name="radio_vad_gain_current">"Текущее усиление компрессора VAD: %1$+.1f dB"</string>
|
||||
<string name="radio_vad_gain_unavailable">"Текущее усиление компрессора VAD: —"</string>
|
||||
<string name="radio_vad_compressor_off">"Компрессор VAD выключен (0 dB)"</string>
|
||||
<string name="radio_level_on">"Порог включения (оранжевый):"</string>
|
||||
<string name="radio_level_off">"Порог отключения (синий):"</string>
|
||||
<string name="radio_level_invalid">"Порог отключения должен быть ниже порога включения"</string>
|
||||
|
||||
@@ -406,6 +406,13 @@
|
||||
<string name="radio_level_allow_mic">"Allow microphone access"</string>
|
||||
<string name="radio_level_unavailable">"Microphone level unavailable"</string>
|
||||
<string name="radio_level_current">"Current level: %1$.1f dBFS"</string>
|
||||
<string name="radio_vad_current">"VAD speech probability: %1$.1f%%"</string>
|
||||
<string name="radio_vad_enable">"Enable automatic transmission in VAD mode to see speech probability"</string>
|
||||
<string name="radio_vad_busy">"VAD measurement paused: channel busy"</string>
|
||||
<string name="radio_vad_unavailable">"VAD speech probability unavailable"</string>
|
||||
<string name="radio_vad_gain_current">"Current VAD compressor gain: %1$+.1f dB"</string>
|
||||
<string name="radio_vad_gain_unavailable">"Current VAD compressor gain: —"</string>
|
||||
<string name="radio_vad_compressor_off">"VAD compressor off (0 dB)"</string>
|
||||
<string name="radio_level_on">"Start threshold (orange):"</string>
|
||||
<string name="radio_level_off">"Stop threshold (blue):"</string>
|
||||
<string name="radio_level_invalid">"The stop threshold must be lower than the start threshold"</string>
|
||||
|
||||
@@ -2784,10 +2784,11 @@ JNIEXPORT jboolean JNICALL Java_com_utun_chat_data_NativeLib_nativeRadioConfigur
|
||||
JNIEXPORT jfloatArray JNICALL Java_com_utun_chat_data_NativeLib_nativeRadioInputStatus(JNIEnv* env, jobject thiz) {
|
||||
(void)thiz;
|
||||
struct radio_audio_input_status status = radio_audio_get_input_status();
|
||||
jfloat values[] = {status.level_dbfs, (float)status.valid, (float)status.blocked};
|
||||
jfloatArray result = (*env)->NewFloatArray(env, 3);
|
||||
jfloat values[] = {status.level_dbfs, (float)status.valid, (float)status.blocked, status.vad_probability, (float)status.vad_valid,
|
||||
status.vad_gain_db, (float)status.vad_compressor_enabled};
|
||||
jfloatArray result = (*env)->NewFloatArray(env, 7);
|
||||
if (!result) { DEBUG_ERROR(DEBUG_CATEGORY_RADIO, "Android radio input status allocation failed"); return NULL; }
|
||||
(*env)->SetFloatArrayRegion(env, result, 0, 3, values);
|
||||
(*env)->SetFloatArrayRegion(env, result, 0, 7, values);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -444,6 +444,12 @@ add_executable(test_voice_audio_io tests/test_voice_audio_io.cpp src/voice_audio
|
||||
target_include_directories(test_voice_audio_io PRIVATE ${UTUN_INCLUDE_DIRS})
|
||||
target_link_libraries(test_voice_audio_io PRIVATE utun pthread)
|
||||
add_test(NAME test_voice_audio_io COMMAND test_voice_audio_io)
|
||||
if(ONNXRUNTIME_INCLUDE_DIR AND ONNXRUNTIME_LIB)
|
||||
add_executable(test_silero_vad ../../tests/test_silero_vad.c)
|
||||
target_compile_definitions(test_silero_vad PRIVATE TEST_SILERO_SPEECH_PATH="${CMAKE_CURRENT_SOURCE_DIR}/../../tests/data/silero_speech.pcm")
|
||||
target_link_libraries(test_silero_vad PRIVATE utun)
|
||||
add_test(NAME test_silero_vad COMMAND test_silero_vad "${CMAKE_CURRENT_SOURCE_DIR}/../../lib/silero_vad.onnx")
|
||||
endif()
|
||||
set_tests_properties(test_audio_event_queue test_voice_audio_io PROPERTIES TIMEOUT 15)
|
||||
if(UNIX AND NOT APPLE)
|
||||
add_executable(test_audio_timing tests/test_audio_timing.c transport/audio_diagnostics.cpp)
|
||||
|
||||
@@ -271,8 +271,12 @@ void RadioAudioEngine::updateState() {
|
||||
bool capture = m_active && m_capture.initialized() && m_voice.captureRunning() && ma_device_is_started(m_capture.device());
|
||||
auto input = radio_audio_get_input_status();
|
||||
bool valid = capture && input.valid;
|
||||
if (m_inputLevel != input.level_dbfs || m_inputLevelValid != valid) {
|
||||
bool vadValid = capture && input.vad_valid;
|
||||
if (m_inputLevel != input.level_dbfs || m_inputLevelValid != valid || m_vadProbability != input.vad_probability ||
|
||||
m_vadValid != vadValid || m_vadGain != input.vad_gain_db || m_vadCompressorEnabled != bool(input.vad_compressor_enabled)) {
|
||||
m_inputLevel = input.level_dbfs; m_inputLevelValid = valid;
|
||||
m_vadProbability = input.vad_probability; m_vadValid = vadValid;
|
||||
m_vadGain = input.vad_gain_db; m_vadCompressorEnabled = input.vad_compressor_enabled;
|
||||
emit inputLevelChanged();
|
||||
}
|
||||
bool automatic = capture && radio_audio_auto_mode() != RADIO_AUTO_OFF;
|
||||
|
||||
@@ -44,6 +44,10 @@ public:
|
||||
int autoMode() const { return m_settings[6]; }
|
||||
float inputLevel() const { return m_inputLevel; }
|
||||
bool inputLevelValid() const { return m_inputLevelValid; }
|
||||
float vadProbability() const { return m_vadProbability; }
|
||||
bool vadValid() const { return m_vadValid; }
|
||||
float vadGain() const { return m_vadGain; }
|
||||
bool vadCompressorEnabled() const { return m_vadCompressorEnabled; }
|
||||
bool autoBlocked() const { return m_autoBlocked; }
|
||||
bool autoAvailable() const { return m_autoAvailable; }
|
||||
bool captureAvailable() const { return m_captureAvailable; }
|
||||
@@ -80,6 +84,8 @@ private:
|
||||
|
||||
float m_inputLevel = -120;
|
||||
bool m_inputLevelValid = false, m_autoBlocked = false;
|
||||
float m_vadProbability = 0, m_vadGain = 0;
|
||||
bool m_vadValid = false, m_vadCompressorEnabled = false;
|
||||
|
||||
std::atomic<bool> m_active{false};
|
||||
std::atomic<bool> m_talking{false};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include "radiopanel.h"
|
||||
#include "radio_audio_engine.h"
|
||||
#include "radiosettingspage.h"
|
||||
#include "sound_manager.h"
|
||||
#include "../transport/gui_bridge.h"
|
||||
extern "C" {
|
||||
@@ -17,7 +18,32 @@ extern "C" {
|
||||
#include <QSignalBlocker>
|
||||
#include <QStyle>
|
||||
#include <QMouseEvent>
|
||||
#include <QWidgetAction>
|
||||
#include <QScrollArea>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QScreen>
|
||||
#include <QGuiApplication>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
/* Полоса показывает текущую вероятность речи, не установленный порог срабатывания. */
|
||||
class RadioAutoButton final : public QPushButton {
|
||||
public:
|
||||
explicit RadioAutoButton(QWidget* parent) : QPushButton(QStringLiteral("VAD"), parent) {}
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override {
|
||||
QPushButton::paintEvent(event);
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
if (engine->autoMode() != 1) return;
|
||||
QPainter painter(this);
|
||||
QRectF track(6, height() - 7, width() - 12, 3);
|
||||
painter.fillRect(track, isChecked() ? QColor(0, 0, 0, 65) : palette().color(QPalette::Mid));
|
||||
if (!engine->vadValid()) return;
|
||||
track.setWidth(track.width() * std::clamp(engine->vadProbability(), 0.0f, 1.0f));
|
||||
painter.fillRect(track, QColor("#4cdb88"));
|
||||
}
|
||||
};
|
||||
|
||||
RadioPanel::RadioPanel(QWidget* parent) : QWidget(parent) {
|
||||
setObjectName(QStringLiteral("radioPanel"));
|
||||
@@ -43,12 +69,21 @@ RadioPanel::RadioPanel(QWidget* parent) : QWidget(parent) {
|
||||
m_status->setMinimumWidth(0);
|
||||
m_status->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
|
||||
row->addWidget(m_status, 1);
|
||||
m_auto = new QPushButton(QStringLiteral("VAD"), this);
|
||||
m_auto = new RadioAutoButton(this);
|
||||
m_auto->setObjectName(QStringLiteral("radioAutoButton"));
|
||||
m_auto->setAccessibleName(QCoreApplication::translate("ChatGui", "Automatic voice transmission"));
|
||||
m_auto->setCheckable(true);
|
||||
m_auto->setMinimumWidth(72);
|
||||
m_auto->setFixedHeight(34);
|
||||
m_auto->installEventFilter(this);
|
||||
m_auto->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(m_auto, &QWidget::customContextMenuRequested, this, [this]() { showActivationSettings(); });
|
||||
m_autoHold.setSingleShot(true); m_autoHold.setInterval(500);
|
||||
connect(&m_autoHold, &QTimer::timeout, this, [this]() {
|
||||
if (!m_auto->isDown() || !m_auto->isEnabled()) return;
|
||||
m_autoLongPressed = true; m_auto->setDown(false);
|
||||
showActivationSettings();
|
||||
});
|
||||
m_auto->setStyleSheet("QPushButton:checked { background: #3390EC; color: white; }");
|
||||
row->addWidget(m_auto);
|
||||
m_ptt = new QPushButton(QStringLiteral("PTT"), this);
|
||||
@@ -67,10 +102,13 @@ RadioPanel::RadioPanel(QWidget* parent) : QWidget(parent) {
|
||||
if (!m_pttLatched) engine->talkEnd();
|
||||
});
|
||||
connect(m_auto, &QPushButton::clicked, this, [this](bool checked) {
|
||||
if (m_autoLongPressed) { updateState(); return; }
|
||||
RadioAudioEngine::instance()->applySettings({{QStringLiteral("radio_auto_enabled"), checked ? 1 : 0}});
|
||||
updateState();
|
||||
});
|
||||
connect(engine, &RadioAudioEngine::stateChanged, this, &RadioPanel::updateState);
|
||||
connect(engine, &RadioAudioEngine::inputLevelChanged, m_auto, [this]() { m_auto->update(); });
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_RADIO, "RadioPanel: VAD button meter uses live speech probability (0..100%%), refresh <=10Hz");
|
||||
connect(SoundManager::instance(), &SoundManager::devicesChanged, this, &RadioPanel::updateDevices);
|
||||
updateState();
|
||||
updateDevices();
|
||||
@@ -82,6 +120,16 @@ RadioPanel::~RadioPanel() {
|
||||
|
||||
/* Второе нажатие Qt приходит как DoubleClick: не отдаём его обычному переключателю pressed. */
|
||||
bool RadioPanel::eventFilter(QObject* watched, QEvent* event) {
|
||||
if (watched == m_auto) {
|
||||
if (event->type() == QEvent::MouseButtonPress && static_cast<QMouseEvent*>(event)->button() == Qt::LeftButton) {
|
||||
m_autoLongPressed = false; m_autoHold.start();
|
||||
} else if (event->type() == QEvent::MouseButtonRelease && static_cast<QMouseEvent*>(event)->button() == Qt::LeftButton) {
|
||||
m_autoHold.stop();
|
||||
if (m_autoLongPressed) { m_autoLongPressed = false; m_auto->setDown(false); return true; }
|
||||
} else if (event->type() == QEvent::Leave || event->type() == QEvent::Hide || event->type() == QEvent::WindowDeactivate) {
|
||||
m_autoHold.stop();
|
||||
} else if (event->type() == QEvent::KeyPress) m_autoLongPressed = false;
|
||||
}
|
||||
if (watched == m_ptt && event->type() == QEvent::MouseButtonDblClick && m_ptt->isEnabled()) {
|
||||
auto* mouse = static_cast<QMouseEvent*>(event);
|
||||
if (mouse->button() == Qt::LeftButton && m_ptt->rect().contains(mouse->pos())) {
|
||||
@@ -93,6 +141,42 @@ bool RadioPanel::eventFilter(QObject* watched, QEvent* event) {
|
||||
return QWidget::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
void RadioPanel::showActivationSettings() {
|
||||
if (!m_auto->isEnabled()) return;
|
||||
m_autoHold.stop(); m_auto->setDown(false);
|
||||
if (!m_activationMenu) {
|
||||
m_activationMenu = new QMenu(this);
|
||||
m_activationMenu->setObjectName(QStringLiteral("radioActivationPopup"));
|
||||
auto* action = new QWidgetAction(m_activationMenu);
|
||||
auto* contents = new QWidget(m_activationMenu);
|
||||
auto* layout = new QVBoxLayout(contents);
|
||||
auto* scroll = new QScrollArea(contents);
|
||||
scroll->setFrameShape(QFrame::NoFrame); scroll->setWidgetResizable(true);
|
||||
m_activationSettings = new RadioActivationSettings(true);
|
||||
scroll->setWidget(m_activationSettings);
|
||||
int height = QGuiApplication::primaryScreen()->availableGeometry().height();
|
||||
int contentHeight = m_activationSettings->heightForWidth(420);
|
||||
if (contentHeight < 0) contentHeight = m_activationSettings->sizeHint().height();
|
||||
scroll->setFixedSize(420, std::min(contentHeight + 24, std::min(480, std::max(160, height - 120))));
|
||||
layout->addWidget(scroll);
|
||||
auto* apply = new QPushButton(QCoreApplication::translate("ChatGui", "Apply"), contents);
|
||||
apply->setObjectName(QStringLiteral("radioActivationApply"));
|
||||
layout->addWidget(apply);
|
||||
connect(apply, &QPushButton::clicked, m_activationSettings, &RadioActivationSettings::apply);
|
||||
connect(m_activationSettings, &RadioActivationSettings::changed, apply, [this, apply]() {
|
||||
apply->setEnabled(m_activationSettings->canApply());
|
||||
});
|
||||
action->setDefaultWidget(contents); m_activationMenu->addAction(action);
|
||||
connect(m_activationMenu, &QMenu::aboutToHide, this, [this]() {
|
||||
m_autoLongPressed = false;
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_RADIO, "RadioPanel: close activation quick settings");
|
||||
});
|
||||
}
|
||||
m_activationSettings->loadSettings();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_RADIO, "RadioPanel: open activation quick settings mode=%d", RadioAudioEngine::instance()->autoMode());
|
||||
m_activationMenu->popup(m_auto->mapToGlobal(QPoint(0, m_auto->height())));
|
||||
}
|
||||
|
||||
/* Фиксация владеет только кнопочным PTT; хоткей и автоматическая передача остаются независимыми. */
|
||||
void RadioPanel::setPttLatched(bool latched, const char* reason) {
|
||||
if (m_pttLatched == latched) return;
|
||||
@@ -109,9 +193,19 @@ void RadioPanel::updateState() {
|
||||
if (m_pttLatched && (!engine->isActive() || !engine->captureAvailable()))
|
||||
setPttLatched(false, engine->isActive() ? "microphone-unavailable" : "radio-stopped");
|
||||
QSignalBlocker blocker(m_auto);
|
||||
m_auto->setText(engine->autoMode() == 2 ? QCoreApplication::translate("ChatGui", "Level") : QStringLiteral("VAD"));
|
||||
m_auto->setText(engine->autoMode() == 2 ? QString() : QStringLiteral("VAD"));
|
||||
QIcon levelIcon;
|
||||
if (engine->autoMode() == 2) {
|
||||
QPixmap pixmap(24, 24); pixmap.fill(Qt::transparent);
|
||||
QPainter painter(&pixmap);
|
||||
painter.setPen(QPen(engine->autoEnabled() ? Qt::white : palette().color(QPalette::ButtonText), 3, Qt::SolidLine, Qt::RoundCap));
|
||||
painter.drawLine(5, 10, 5, 19); painter.drawLine(12, 4, 12, 19); painter.drawLine(19, 7, 19, 19);
|
||||
painter.end(); levelIcon = QIcon(pixmap);
|
||||
}
|
||||
m_auto->setIcon(levelIcon); m_auto->setIconSize(QSize(24, 24));
|
||||
m_auto->setChecked(engine->autoEnabled());
|
||||
m_auto->setEnabled(engine->isActive() && engine->settingsReady() && !engine->settingsBusy());
|
||||
if (!engine->isActive() && m_activationMenu) m_activationMenu->hide();
|
||||
m_ptt->setEnabled(engine->isActive() && engine->captureAvailable());
|
||||
m_ptt->setText(m_pttLatched ? QStringLiteral("PTT \U0001F512") : QStringLiteral("PTT"));
|
||||
m_ptt->setToolTip(m_pttLatched ? QCoreApplication::translate("ChatGui", "PTT locked. Click to release.")
|
||||
@@ -137,8 +231,13 @@ void RadioPanel::updateState() {
|
||||
: QCoreApplication::translate("ChatGui", "VAD listening");
|
||||
m_status->setText(state);
|
||||
m_status->setToolTip(engine->settingsError().isEmpty() ? state : engine->settingsError());
|
||||
m_auto->setToolTip(engine->autoEnabled() ? QCoreApplication::translate("ChatGui", "Disable automatic voice transmission")
|
||||
: QCoreApplication::translate("ChatGui", "Enable automatic voice transmission"));
|
||||
const QString toggle = engine->autoEnabled() ? QCoreApplication::translate("ChatGui", "Disable automatic voice transmission")
|
||||
: QCoreApplication::translate("ChatGui", "Enable automatic voice transmission");
|
||||
const QString mode = engine->autoMode() == 2 ? QCoreApplication::translate("ChatGui", "By signal level") : QStringLiteral("VAD");
|
||||
const QString hint = QCoreApplication::translate("ChatGui", "Hold or right-click to adjust activation mode and thresholds");
|
||||
m_auto->setToolTip(mode + "\n" + toggle + "\n" + hint);
|
||||
m_auto->setAccessibleName(mode + ". " + toggle); m_auto->setAccessibleDescription(hint);
|
||||
m_auto->update();
|
||||
}
|
||||
|
||||
/* Список перечитывается при открытии меню: подключённые устройства видны без перезапуска. */
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
class QToolButton;
|
||||
class QPushButton;
|
||||
class QLabel;
|
||||
class QMenu;
|
||||
class RadioActivationSettings;
|
||||
|
||||
/* Верхняя панель активной рации: общие устройства SoundManager, VAD и удерживаемая PTT.
|
||||
* Состояние передачи берётся из ядра; включение VAD хранится в конфигурации приложения. */
|
||||
@@ -17,6 +20,7 @@ private:
|
||||
bool eventFilter(QObject* watched, QEvent* event) override;
|
||||
void setPttLatched(bool latched, const char* reason);
|
||||
void updateState();
|
||||
void showActivationSettings();
|
||||
void updateDevices();
|
||||
void populateDevices(QToolButton* button, bool capture);
|
||||
void selectDevice(const QString& id, bool capture);
|
||||
@@ -24,4 +28,8 @@ private:
|
||||
QPushButton *m_auto, *m_ptt;
|
||||
QLabel* m_status;
|
||||
bool m_pttLatched = false;
|
||||
QTimer m_autoHold;
|
||||
bool m_autoLongPressed = false;
|
||||
QMenu* m_activationMenu = nullptr;
|
||||
RadioActivationSettings* m_activationSettings = nullptr;
|
||||
};
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <QFormLayout>
|
||||
#include <QSpinBox>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QButtonGroup>
|
||||
#include <QPainter>
|
||||
#include <algorithm>
|
||||
#include <QKeyEvent>
|
||||
@@ -29,89 +29,181 @@ public:
|
||||
explicit RadioLevelMeter(QWidget* parent) : QWidget(parent) { setMinimumSize(200, 34); }
|
||||
float level = -120;
|
||||
int on = -35, off = -45;
|
||||
bool valid = false;
|
||||
bool valid = false, vad = false;
|
||||
protected:
|
||||
void paintEvent(QPaintEvent*) override {
|
||||
QPainter painter(this);
|
||||
QRect bar(1, 1, width() - 2, 16);
|
||||
painter.fillRect(bar, palette().color(QPalette::Mid));
|
||||
auto x = [&](float db) { return bar.left() + int(std::clamp((db + 90) / 90, 0.0f, 1.0f) * bar.width()); };
|
||||
auto x = [&](float value) { return bar.left() + int(std::clamp(vad ? value / 100 : (value + 90) / 90, 0.0f, 1.0f) * bar.width()); };
|
||||
if (valid) painter.fillRect(QRect(bar.left(), bar.top(), x(level) - bar.left(), bar.height()), QColor("#27ae60"));
|
||||
painter.setPen(palette().color(QPalette::Text));
|
||||
painter.drawText(QRect(0, 18, width(), 16), Qt::AlignLeft, QStringLiteral("−90 dBFS"));
|
||||
painter.drawText(QRect(0, 18, width(), 16), Qt::AlignRight, QStringLiteral("0"));
|
||||
painter.drawText(QRect(0, 18, width(), 16), Qt::AlignLeft, vad ? QStringLiteral("0%") : QStringLiteral("−90 dBFS"));
|
||||
painter.drawText(QRect(0, 18, width(), 16), Qt::AlignRight, vad ? QStringLiteral("100%") : QStringLiteral("0"));
|
||||
for (int threshold : {off, on}) {
|
||||
if (vad && threshold == off) continue;
|
||||
painter.setPen(QPen(threshold == on ? QColor("#e67e22") : QColor("#3390ec"), 2));
|
||||
painter.drawLine(x(threshold), 0, x(threshold), 18);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
RadioActivationSettings::RadioActivationSettings(bool compact, QWidget* parent) : QWidget(parent), m_compact(compact) {
|
||||
auto* form = new QFormLayout(this);
|
||||
form->setContentsMargins(0, 0, 0, 8);
|
||||
form->setRowWrapPolicy(QFormLayout::WrapLongRows);
|
||||
form->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
|
||||
auto add = [&](const QString& label, const char* name, int min, int max, const QString& suffix) {
|
||||
auto* spin = new QSpinBox(this);
|
||||
spin->setObjectName(QLatin1String(name)); spin->setRange(min, max); spin->setSuffix(suffix);
|
||||
auto* text = new QLabel(label, this); text->setWordWrap(true);
|
||||
form->addRow(text, spin);
|
||||
connect(spin, QOverload<int>::of(&QSpinBox::valueChanged), this, &RadioActivationSettings::updateControls);
|
||||
return spin;
|
||||
};
|
||||
auto label = [&](const char* name) {
|
||||
auto* text = new QLabel(this); text->setObjectName(QLatin1String(name)); text->setWordWrap(true);
|
||||
form->addRow(text); return text;
|
||||
};
|
||||
auto* modes = new QWidget(this);
|
||||
auto* row = new QHBoxLayout(modes); row->setContentsMargins(0, 0, 0, 0); row->setSpacing(0);
|
||||
m_mode = new QButtonGroup(this);
|
||||
for (int mode : {1, 2}) {
|
||||
auto* button = new QPushButton(mode == 1 ? QStringLiteral("VAD") : QCoreApplication::translate("ChatGui", "By signal level"), modes);
|
||||
button->setObjectName(mode == 1 ? QStringLiteral("radioModeVad") : QStringLiteral("radioModeLevel"));
|
||||
button->setCheckable(true); button->setMinimumHeight(36);
|
||||
button->setStyleSheet("QPushButton:checked { background: #3390EC; color: white; }");
|
||||
m_mode->addButton(button, mode); row->addWidget(button, 1);
|
||||
connect(button, &QPushButton::clicked, this, [this, mode]() {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_RADIO, "Radio settings: select mode=%d compact=%d (pending Apply)", mode, m_compact);
|
||||
updateControls();
|
||||
});
|
||||
}
|
||||
m_mode->button(1)->setChecked(true);
|
||||
form->addRow(QCoreApplication::translate("ChatGui", "Automatic transmission:"), modes);
|
||||
m_levelText = label("radioLevelText");
|
||||
m_levelMeter = new RadioLevelMeter(this); m_levelMeter->setObjectName(QStringLiteral("radioLevelMeter"));
|
||||
form->addRow(m_levelMeter);
|
||||
m_levelOn = add(QCoreApplication::translate("ChatGui", "Start threshold (orange):"), "radioLevelOn", -90, 0, QStringLiteral(" dBFS"));
|
||||
m_levelOff = add(QCoreApplication::translate("ChatGui", "Stop threshold (blue):"), "radioLevelOff", -90, 0, QStringLiteral(" dBFS"));
|
||||
m_vadText = label("radioVadText");
|
||||
m_vadMeter = new RadioLevelMeter(this); m_vadMeter->vad = true; m_vadMeter->setObjectName(QStringLiteral("radioVadMeter"));
|
||||
form->addRow(m_vadMeter);
|
||||
m_threshold = add(QCoreApplication::translate("ChatGui", "VAD speech threshold:"), "radioVadThreshold", 10, 95, QStringLiteral(" %"));
|
||||
m_threshold->setToolTip(QCoreApplication::translate("ChatGui",
|
||||
"Speech probability threshold: lower is more sensitive. This is not a volume threshold."));
|
||||
m_gainText = label("radioVadGainText");
|
||||
m_vadGain = add(QCoreApplication::translate("ChatGui", "VAD max gain:"), "radioVadGain", 1, 60, QCoreApplication::translate("ChatGui", " dB"));
|
||||
m_hangover = add(QCoreApplication::translate("ChatGui", "Silence before ending transmission:"), "radioHangover", 50, 2000,
|
||||
QCoreApplication::translate("ChatGui", " ms"));
|
||||
if (!compact) {
|
||||
m_compressor = new QCheckBox(QCoreApplication::translate("ChatGui", "Transmission and VAD compressor"), this);
|
||||
form->addRow(m_compressor);
|
||||
connect(m_compressor, &QCheckBox::toggled, this, &RadioActivationSettings::updateControls);
|
||||
m_txGain = add(QCoreApplication::translate("ChatGui", "Transmission max gain:"), "radioTxGain", 1, 60,
|
||||
QCoreApplication::translate("ChatGui", " dB"));
|
||||
label("radioActivationHint")->setText(QCoreApplication::translate("ChatGui",
|
||||
"Enable automatic transmission using the radio panel button. Both modes include 0.6 s of prebuffer. "
|
||||
"Signal level is measured after echo cancellation, before compression. Start requires 40 ms above the start threshold; "
|
||||
"transmission ends after the configured silence below the stop threshold. The VAD compressor has a separate maximum gain."));
|
||||
}
|
||||
m_error = label("radioActivationError"); m_error->setStyleSheet(QStringLiteral("color: #e74c3c;"));
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
connect(engine, &RadioAudioEngine::stateChanged, this, [this, engine]() {
|
||||
setEnabled(engine->settingsReady() && !engine->settingsBusy());
|
||||
if (!m_loaded && engine->settingsReady()) loadSettings();
|
||||
else updateControls();
|
||||
});
|
||||
connect(engine, &RadioAudioEngine::inputLevelChanged, this, &RadioActivationSettings::updateMeters);
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
QMap<QString, int> RadioActivationSettings::values() const {
|
||||
QMap<QString, int> result{{"radio_auto_mode", m_mode->checkedId()}, {"radio_level_on_dbfs", m_levelOn->value()},
|
||||
{"radio_level_off_dbfs", m_levelOff->value()}, {"radio_vad_threshold", m_threshold->value()},
|
||||
{"radio_auto_hangover_ms", m_hangover->value()}, {"radio_vad_compressor_max_gain_db", m_vadGain->value()}};
|
||||
if (!m_compact) {
|
||||
result.insert(QStringLiteral("radio_compressor_enabled"), m_compressor->isChecked() ? 1 : 0);
|
||||
result.insert(QStringLiteral("radio_compressor_max_gain_db"), m_txGain->value());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RadioActivationSettings::canApply() const {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
if (!m_loaded || !engine->settingsReady() || engine->settingsBusy() || m_levelOff->value() >= m_levelOn->value()) return false;
|
||||
const auto draft = values();
|
||||
for (auto it = draft.cbegin(); it != draft.cend(); ++it) if (engine->setting(it.key()) != it.value()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RadioActivationSettings::apply() {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_RADIO, "Radio settings: apply compact=%d mode=%d on=%d off=%d vad=%d gain=%d hangover=%d",
|
||||
m_compact, m_mode->checkedId(), m_levelOn->value(), m_levelOff->value(), m_threshold->value(),
|
||||
m_vadGain->value(), m_hangover->value());
|
||||
return RadioAudioEngine::instance()->applySettings(values());
|
||||
}
|
||||
|
||||
void RadioActivationSettings::loadSettings() {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
setEnabled(engine->settingsReady() && !engine->settingsBusy());
|
||||
if (!engine->settingsReady()) return;
|
||||
m_loaded = false;
|
||||
m_mode->button(engine->autoMode())->setChecked(true);
|
||||
m_levelOn->setValue(engine->setting(QStringLiteral("radio_level_on_dbfs")));
|
||||
m_levelOff->setValue(engine->setting(QStringLiteral("radio_level_off_dbfs")));
|
||||
m_threshold->setValue(engine->setting(QStringLiteral("radio_vad_threshold")));
|
||||
m_hangover->setValue(engine->setting(QStringLiteral("radio_auto_hangover_ms")));
|
||||
m_vadGain->setValue(engine->setting(QStringLiteral("radio_vad_compressor_max_gain_db")));
|
||||
if (!m_compact) {
|
||||
m_compressor->setChecked(engine->setting(QStringLiteral("radio_compressor_enabled")) != 0);
|
||||
m_txGain->setValue(engine->setting(QStringLiteral("radio_compressor_max_gain_db")));
|
||||
}
|
||||
m_loaded = true;
|
||||
updateControls();
|
||||
}
|
||||
|
||||
void RadioActivationSettings::updateControls() {
|
||||
if (!m_loaded) return;
|
||||
QString error = m_levelOff->value() >= m_levelOn->value()
|
||||
? QCoreApplication::translate("ChatGui", "The stop threshold must be lower than the start threshold")
|
||||
: RadioAudioEngine::instance()->settingsError();
|
||||
m_error->setText(error); m_error->setVisible(!error.isEmpty());
|
||||
m_levelMeter->on = m_levelOn->value(); m_levelMeter->off = m_levelOff->value();
|
||||
m_vadMeter->on = m_threshold->value();
|
||||
updateMeters();
|
||||
emit changed();
|
||||
}
|
||||
|
||||
void RadioActivationSettings::updateMeters() {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
m_levelMeter->valid = engine->inputLevelValid(); m_levelMeter->level = engine->inputLevel(); m_levelMeter->update();
|
||||
QString text;
|
||||
if (!engine->isActive()) text = QCoreApplication::translate("ChatGui", "Enable radio to measure the microphone level");
|
||||
else if (!engine->inputLevelValid()) text = QCoreApplication::translate("ChatGui", "Microphone level unavailable");
|
||||
else text = QCoreApplication::translate("ChatGui", "Current level: %1 dBFS").arg(engine->inputLevel(), 0, 'f', 1);
|
||||
m_levelText->setText(text); m_levelMeter->setAccessibleName(text);
|
||||
m_vadMeter->valid = engine->vadValid(); m_vadMeter->level = engine->vadProbability() * 100; m_vadMeter->update();
|
||||
if (engine->vadValid()) text = QCoreApplication::translate("ChatGui", "VAD speech probability: %1%").arg(engine->vadProbability() * 100, 0, 'f', 1);
|
||||
else if (!engine->autoEnabled() || engine->autoMode() != 1)
|
||||
text = QCoreApplication::translate("ChatGui", "Enable automatic transmission in VAD mode to see speech probability");
|
||||
else if (engine->autoBlocked()) text = QCoreApplication::translate("ChatGui", "VAD measurement paused: channel busy");
|
||||
else text = QCoreApplication::translate("ChatGui", "VAD speech probability unavailable");
|
||||
m_vadText->setText(text); m_vadMeter->setAccessibleName(text);
|
||||
if (!engine->vadValid()) text = QCoreApplication::translate("ChatGui", "Current VAD compressor gain: —");
|
||||
else if (!engine->vadCompressorEnabled()) text = QCoreApplication::translate("ChatGui", "VAD compressor off (0 dB)");
|
||||
else text = QCoreApplication::translate("ChatGui", "Current VAD compressor gain: %1 dB")
|
||||
.arg((engine->vadGain() >= 0 ? QStringLiteral("+") : QString()) + QString::number(engine->vadGain(), 'f', 1));
|
||||
m_gainText->setText(text);
|
||||
}
|
||||
|
||||
RadioSettingsPage::RadioSettingsPage(DbManager* db, QWidget* parent) : QWidget(parent), m_db(db) {
|
||||
auto* layout = new QVBoxLayout(this);
|
||||
auto* title = new QLabel(QCoreApplication::translate("ChatGui", "Radio (PTT)"), this);
|
||||
title->setStyleSheet("font-weight: bold; font-size: 13px;");
|
||||
layout->addWidget(title);
|
||||
m_audioSettings = new QWidget(this);
|
||||
auto* form = new QFormLayout(m_audioSettings);
|
||||
form->setContentsMargins(0, 0, 0, 12);
|
||||
auto add = [&](const QString& label, int min, int max, const QString& suffix) {
|
||||
auto* spin = new QSpinBox(m_audioSettings);
|
||||
spin->setRange(min, max);
|
||||
spin->setSuffix(suffix);
|
||||
form->addRow(label, spin);
|
||||
return spin;
|
||||
};
|
||||
m_mode = new QComboBox(m_audioSettings);
|
||||
m_mode->setObjectName(QStringLiteral("radioAutoMode"));
|
||||
m_mode->addItem(QStringLiteral("VAD"), 1);
|
||||
m_mode->addItem(QCoreApplication::translate("ChatGui", "By signal level"), 2);
|
||||
form->addRow(QCoreApplication::translate("ChatGui", "Automatic transmission:"), m_mode);
|
||||
m_levelMeter = new RadioLevelMeter(m_audioSettings);
|
||||
m_levelMeter->setObjectName(QStringLiteral("radioLevelMeter"));
|
||||
form->addRow(QCoreApplication::translate("ChatGui", "Microphone level:"), m_levelMeter);
|
||||
m_levelText = new QLabel(m_audioSettings);
|
||||
m_levelText->setObjectName(QStringLiteral("radioLevelText"));
|
||||
m_levelText->setWordWrap(true);
|
||||
form->addRow(m_levelText);
|
||||
m_levelOn = add(QCoreApplication::translate("ChatGui", "Start threshold (orange):"), -90, 0, QStringLiteral(" dBFS"));
|
||||
m_levelOff = add(QCoreApplication::translate("ChatGui", "Stop threshold (blue):"), -90, 0, QStringLiteral(" dBFS"));
|
||||
m_levelOn->setObjectName(QStringLiteral("radioLevelOn"));
|
||||
m_levelOff->setObjectName(QStringLiteral("radioLevelOff"));
|
||||
m_thresholdError = new QLabel(m_audioSettings);
|
||||
m_thresholdError->setWordWrap(true);
|
||||
m_thresholdError->setStyleSheet(QStringLiteral("color: #e74c3c;"));
|
||||
m_thresholdError->setText(QCoreApplication::translate("ChatGui", "The stop threshold must be lower than the start threshold"));
|
||||
form->addRow(m_thresholdError);
|
||||
m_threshold = add(QCoreApplication::translate("ChatGui", "VAD speech threshold:"), 10, 95, QStringLiteral(" %"));
|
||||
m_threshold->setToolTip(QCoreApplication::translate("ChatGui",
|
||||
"Speech probability threshold: lower is more sensitive. This is not a volume threshold."));
|
||||
m_hangover = add(QCoreApplication::translate("ChatGui",
|
||||
"Silence before ending transmission:"), 50, 2000, QCoreApplication::translate("ChatGui",
|
||||
" ms"));
|
||||
m_compressor = new QCheckBox(QCoreApplication::translate("ChatGui", "Transmission and VAD compressor"), m_audioSettings);
|
||||
form->addRow(m_compressor);
|
||||
m_txGain = add(QCoreApplication::translate("ChatGui", "Transmission max gain:"), 1, 60, QCoreApplication::translate("ChatGui", " dB"));
|
||||
m_vadGain = add(QCoreApplication::translate("ChatGui", "VAD max gain:"), 1, 60, QCoreApplication::translate("ChatGui", " dB"));
|
||||
auto* explanation = new QLabel(QCoreApplication::translate("ChatGui",
|
||||
"Enable automatic transmission using the radio panel button. Both modes include 0.6 s of prebuffer. "
|
||||
"Signal level is measured after echo cancellation, before compression. Start requires 40 ms above the start threshold; "
|
||||
"transmission ends after the configured silence below the stop threshold. The VAD compressor has a separate maximum gain."), m_audioSettings);
|
||||
explanation->setWordWrap(true);
|
||||
form->addRow(explanation);
|
||||
layout->addWidget(m_audioSettings);
|
||||
connect(RadioAudioEngine::instance(), &RadioAudioEngine::stateChanged, this, [this]() {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
m_audioSettings->setEnabled(engine->settingsReady() && !engine->settingsBusy());
|
||||
if (!m_audioSettingsLoaded && engine->settingsReady()) loadAudioSettings();
|
||||
});
|
||||
connect(m_mode, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this]() { updateAudioControls(); });
|
||||
for (auto* spin : {m_levelOn, m_levelOff})
|
||||
connect(spin, QOverload<int>::of(&QSpinBox::valueChanged), this, [this]() { updateAudioControls(); });
|
||||
connect(RadioAudioEngine::instance(), &RadioAudioEngine::inputLevelChanged, this, &RadioSettingsPage::updateLevel);
|
||||
connect(RadioAudioEngine::instance(), &RadioAudioEngine::stateChanged, this, &RadioSettingsPage::updateLevel);
|
||||
loadAudioSettings();
|
||||
updateAudioControls();
|
||||
m_activation = new RadioActivationSettings(false, this);
|
||||
layout->addWidget(m_activation);
|
||||
if (PttHotkeyManager::usesPortal()) {
|
||||
auto* hint = new QLabel(QCoreApplication::translate("ChatGui",
|
||||
"Global shortcuts work from any application. Assign a regular key with Ctrl, Shift, Alt or "
|
||||
@@ -267,7 +359,7 @@ void RadioSettingsPage::updateLabel(int index) {
|
||||
}
|
||||
|
||||
void RadioSettingsPage::loadFromDb() {
|
||||
loadAudioSettings();
|
||||
m_activation->loadSettings();
|
||||
if (m_portalStatus) { updatePortalLabels(); return; }
|
||||
finishCapture(false);
|
||||
QStringList values;
|
||||
@@ -286,37 +378,13 @@ QStringList RadioSettingsPage::hotkeys() const {
|
||||
}
|
||||
|
||||
bool RadioSettingsPage::apply() {
|
||||
if (!RadioAudioEngine::instance()->applySettings({
|
||||
{QStringLiteral("radio_auto_mode"), m_mode->currentData().toInt()},
|
||||
{QStringLiteral("radio_level_on_dbfs"), m_levelOn->value()},
|
||||
{QStringLiteral("radio_level_off_dbfs"), m_levelOff->value()},
|
||||
{QStringLiteral("radio_vad_threshold"), m_threshold->value()},
|
||||
{QStringLiteral("radio_auto_hangover_ms"), m_hangover->value()},
|
||||
{QStringLiteral("radio_compressor_enabled"), m_compressor->isChecked() ? 1 : 0},
|
||||
{QStringLiteral("radio_compressor_max_gain_db"), m_txGain->value()},
|
||||
{QStringLiteral("radio_vad_compressor_max_gain_db"), m_vadGain->value()}})) return false;
|
||||
if (!m_activation->apply()) return false;
|
||||
if (m_portalStatus) return true;
|
||||
finishCapture(false);
|
||||
PttHotkeyManager::instance()->setHotkeys(hotkeys());
|
||||
return true;
|
||||
}
|
||||
|
||||
void RadioSettingsPage::loadAudioSettings() {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
m_audioSettings->setEnabled(engine->settingsReady() && !engine->settingsBusy());
|
||||
if (!engine->settingsReady()) return;
|
||||
m_mode->setCurrentIndex(m_mode->findData(engine->autoMode()));
|
||||
m_levelOn->setValue(engine->setting(QStringLiteral("radio_level_on_dbfs")));
|
||||
m_levelOff->setValue(engine->setting(QStringLiteral("radio_level_off_dbfs")));
|
||||
m_threshold->setValue(engine->setting(QStringLiteral("radio_vad_threshold")));
|
||||
m_hangover->setValue(engine->setting(QStringLiteral("radio_auto_hangover_ms")));
|
||||
m_compressor->setChecked(engine->setting(QStringLiteral("radio_compressor_enabled")) != 0);
|
||||
m_txGain->setValue(engine->setting(QStringLiteral("radio_compressor_max_gain_db")));
|
||||
m_vadGain->setValue(engine->setting(QStringLiteral("radio_vad_compressor_max_gain_db")));
|
||||
m_audioSettingsLoaded = true;
|
||||
updateAudioControls();
|
||||
}
|
||||
|
||||
void RadioSettingsPage::updatePortalLabels() {
|
||||
auto* manager = PttHotkeyManager::instance();
|
||||
const auto descriptions = manager->portalDescriptions();
|
||||
@@ -329,25 +397,3 @@ void RadioSettingsPage::updatePortalLabels() {
|
||||
m_portalStatus->setText(manager->portalStatus());
|
||||
m_buttons[0]->setEnabled(!manager->portalBusy());
|
||||
}
|
||||
|
||||
void RadioSettingsPage::updateAudioControls() {
|
||||
bool level = m_mode->currentData().toInt() == 2;
|
||||
m_levelOn->setEnabled(level); m_levelOff->setEnabled(level);
|
||||
m_threshold->setEnabled(!level); m_vadGain->setEnabled(!level);
|
||||
m_thresholdError->setVisible(m_levelOff->value() >= m_levelOn->value());
|
||||
m_levelMeter->on = m_levelOn->value(); m_levelMeter->off = m_levelOff->value();
|
||||
updateLevel();
|
||||
}
|
||||
|
||||
void RadioSettingsPage::updateLevel() {
|
||||
auto* engine = RadioAudioEngine::instance();
|
||||
m_levelMeter->valid = engine->inputLevelValid();
|
||||
m_levelMeter->level = engine->inputLevel();
|
||||
m_levelMeter->update();
|
||||
QString text;
|
||||
if (!engine->isActive()) text = QCoreApplication::translate("ChatGui", "Enable radio to measure the microphone level");
|
||||
else if (!engine->inputLevelValid()) text = QCoreApplication::translate("ChatGui", "Microphone level unavailable");
|
||||
else text = QCoreApplication::translate("ChatGui", "Current level: %1 dBFS").arg(engine->inputLevel(), 0, 'f', 1);
|
||||
m_levelText->setText(text);
|
||||
m_levelMeter->setAccessibleName(text);
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "ptt_key_chord.h"
|
||||
#include <QWidget>
|
||||
#include <QVector>
|
||||
#include <QMap>
|
||||
|
||||
class DbManager;
|
||||
class QPushButton;
|
||||
@@ -11,9 +12,31 @@ class QHideEvent;
|
||||
class QShowEvent;
|
||||
class QSpinBox;
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QButtonGroup;
|
||||
class RadioLevelMeter;
|
||||
|
||||
/* Общий редактор вкладки и мини-блока; метрики не перезаписывают редактируемые настройки. */
|
||||
class RadioActivationSettings : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RadioActivationSettings(bool compact, QWidget* parent = nullptr);
|
||||
void loadSettings();
|
||||
bool apply();
|
||||
bool canApply() const;
|
||||
signals:
|
||||
void changed();
|
||||
private:
|
||||
QMap<QString, int> values() const;
|
||||
void updateControls();
|
||||
void updateMeters();
|
||||
bool m_compact, m_loaded = false;
|
||||
QButtonGroup* m_mode;
|
||||
QSpinBox *m_threshold, *m_hangover, *m_txGain = nullptr, *m_vadGain, *m_levelOn, *m_levelOff;
|
||||
QCheckBox* m_compressor = nullptr;
|
||||
RadioLevelMeter *m_levelMeter, *m_vadMeter;
|
||||
QLabel *m_levelText, *m_vadText, *m_gainText, *m_error;
|
||||
};
|
||||
|
||||
// Запись глобальных сочетаний PTT, включая отдельные левые/правые модификаторы.
|
||||
class RadioSettingsPage : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -31,17 +54,7 @@ protected:
|
||||
|
||||
private:
|
||||
void updatePortalLabels();
|
||||
void loadAudioSettings();
|
||||
void updateAudioControls();
|
||||
void updateLevel();
|
||||
QWidget* m_audioSettings = nullptr;
|
||||
QSpinBox *m_threshold, *m_hangover, *m_txGain, *m_vadGain;
|
||||
QCheckBox* m_compressor;
|
||||
QComboBox* m_mode;
|
||||
QSpinBox *m_levelOn, *m_levelOff;
|
||||
RadioLevelMeter* m_levelMeter;
|
||||
QLabel *m_levelText, *m_thresholdError;
|
||||
bool m_audioSettingsLoaded = false;
|
||||
RadioActivationSettings* m_activation;
|
||||
QLabel* m_portalStatus = nullptr;
|
||||
void startCapture(int index);
|
||||
void finishCapture(bool save);
|
||||
|
||||
@@ -34,6 +34,7 @@ extern "C" {
|
||||
#include <QTextStream>
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
#include <QScrollArea>
|
||||
|
||||
SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, UtunNode* node,
|
||||
AudioRecorder* recorder, QWidget* parent)
|
||||
@@ -210,8 +211,12 @@ SettingsDialog::SettingsDialog(const QString& configPath, DbManager* db, UtunNod
|
||||
m_audioDevicePage->loadFromDb();
|
||||
m_pages->addWidget(m_audioDevicePage);
|
||||
|
||||
m_radioPage = new RadioSettingsPage(db, m_pages);
|
||||
m_pages->addWidget(m_radioPage);
|
||||
auto* radioScroll = new QScrollArea(m_pages);
|
||||
radioScroll->setWidgetResizable(true);
|
||||
radioScroll->setFrameShape(QFrame::NoFrame);
|
||||
m_radioPage = new RadioSettingsPage(db, radioScroll);
|
||||
radioScroll->setWidget(m_radioPage);
|
||||
m_pages->addWidget(radioScroll);
|
||||
rightLayout->addWidget(m_pages, 1);
|
||||
|
||||
// --- Bottom buttons ---
|
||||
|
||||
@@ -205,10 +205,15 @@ void VoiceAudioIo::captureLoop() {
|
||||
int16_t raw[1920]{}, cleaned[1920]{}, referencePcm[1920]{};
|
||||
uint8_t muteMask[960]{};
|
||||
unsigned filled = 0;
|
||||
int64_t frameTime = 0, lastReport = voice_time_us();
|
||||
int64_t frameTime = 0, lastReport = voice_time_us(), lastCapture = lastReport, maxQueueAge = 0;
|
||||
uint64_t expectedSequence = 0, missingReference = 0, reportedReferenceDrops = referenceDrops, captureRoute = 0;
|
||||
int64_t expectedCaptureTime = 0;
|
||||
bool referenceAvailable = false;
|
||||
const char* referenceReason = "empty_history";
|
||||
double referenceGapUs = 0;
|
||||
double rawEnergy = 0, cleanEnergy = 0, referenceEnergy = 0;
|
||||
float rawPeak = 0, cleanPeak = 0, referencePeak = 0;
|
||||
unsigned signalFrames = 0, aecFrames = 0;
|
||||
bool muted = false;
|
||||
auto applyMarker = [&](EventKind kind, bool value) {
|
||||
if (kind == EventKind::Mute) muted = value;
|
||||
@@ -238,6 +243,7 @@ void VoiceAudioIo::captureLoop() {
|
||||
}
|
||||
};
|
||||
auto alignReference = [&]() {
|
||||
referenceReason = "empty_history"; referenceGapUs = 0;
|
||||
if (!historyCount) return false;
|
||||
size_t index = 0;
|
||||
for (unsigned i = 0; i < 960; ++i) {
|
||||
@@ -251,7 +257,11 @@ void VoiceAudioIo::captureLoop() {
|
||||
if (measured > interval * 0.95 && measured < interval * 1.05) interval = measured;
|
||||
}
|
||||
double position = (time - block.time) / interval;
|
||||
if (position < 0 || position >= block.frames) return false;
|
||||
if (position < 0 || position >= block.frames) {
|
||||
referenceReason = position < 0 ? "history_too_new" : index + 1 == historyCount ? "render_not_ready" : "render_gap";
|
||||
referenceGapUs = position < 0 ? -position * interval : (position - block.frames) * interval;
|
||||
return false;
|
||||
}
|
||||
unsigned sample = (unsigned)position;
|
||||
double fraction = position - sample;
|
||||
for (unsigned channel = 0; channel < 2; ++channel) {
|
||||
@@ -260,6 +270,7 @@ void VoiceAudioIo::captureLoop() {
|
||||
referencePcm[2*i+channel] = (int16_t)(first + (second - first) * fraction);
|
||||
}
|
||||
}
|
||||
referenceReason = "aligned";
|
||||
return true;
|
||||
};
|
||||
auto deliver = [&](unsigned frames) {
|
||||
@@ -274,8 +285,42 @@ void VoiceAudioIo::captureLoop() {
|
||||
if (m_kind == Kind::Call && frames == 960) call_audio_feed_prepared_pcm(m_session, cleaned, muteMask);
|
||||
filled = 0; markerCount = 0;
|
||||
};
|
||||
// Отчёт работает и при отсутствии PCM, иначе длительный провал захвата невидим.
|
||||
auto report = [&]() {
|
||||
int64_t now = voice_time_us();
|
||||
if (now - lastReport >= 1000000) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_AEC, "voice-io: capture health session=%llu span=%.1fms pcm_age=%.1fms "
|
||||
"queue_age_max=%.1fms queue=%zu pending=%u sequence=%llu",
|
||||
(unsigned long long)m_session, (now - lastReport) / 1000.0, (now - lastCapture) / 1000.0,
|
||||
maxQueueAge / 1000.0, m_captureEvents.size(), filled, (unsigned long long)expectedSequence);
|
||||
if (now - lastCapture >= 1000000)
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CALL, "voice-io: capture stalled session=%llu no_pcm=%.1fms queue=%zu",
|
||||
(unsigned long long)m_session, (now - lastCapture) / 1000.0, m_captureEvents.size());
|
||||
maxQueueAge = 0;
|
||||
if (signalFrames) {
|
||||
auto db = [](double power) { return 10 * std::log10(std::max(power, 1e-12)); };
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_AEC, "voice-io: signal session=%llu frames=%u aec_frames=%u raw=%.1fdBFS clean=%.1fdBFS "
|
||||
"reference=%.1fdBFS peaks=%.4f/%.4f/%.4f reference_state=%s gap=%.1fus",
|
||||
(unsigned long long)m_session, signalFrames, aecFrames, db(rawEnergy / (signalFrames * 960 * m_channels)),
|
||||
db(cleanEnergy / (signalFrames * 960 * m_channels)), db(aecFrames ? referenceEnergy / (aecFrames * 1920) : 0),
|
||||
rawPeak, cleanPeak, referencePeak, referenceReason, referenceGapUs);
|
||||
signalFrames = aecFrames = 0; rawEnergy = cleanEnergy = referenceEnergy = 0;
|
||||
rawPeak = cleanPeak = referencePeak = 0;
|
||||
}
|
||||
uint64_t captureDrops = m_captureDropped.exchange(0), refDrops = m_referenceDropped.load();
|
||||
uint64_t underruns = m_playbackUnderruns.exchange(0);
|
||||
if (captureDrops || refDrops != reportedReferenceDrops || missingReference || underruns)
|
||||
DEBUG_WARN(DEBUG_CATEGORY_AEC, "voice-io: session=%llu capture_drop=%llu reference_drop=%llu missing_ref=%llu output_missing=%llu",
|
||||
(unsigned long long)m_session, (unsigned long long)captureDrops, (unsigned long long)refDrops,
|
||||
(unsigned long long)missingReference, (unsigned long long)underruns);
|
||||
else DEBUG_DEBUG(DEBUG_CATEGORY_AEC, "voice-io: session=%llu reference history=%zu capture_queue=%zu",
|
||||
(unsigned long long)m_session, historyCount, m_captureEvents.size());
|
||||
missingReference = 0; reportedReferenceDrops = refDrops; lastReport = now;
|
||||
}
|
||||
};
|
||||
bool stopping = false;
|
||||
while (m_capturing && !stopping) {
|
||||
report();
|
||||
consumeReference();
|
||||
Event event{};
|
||||
if (!m_captureEvents.pop(event)) {
|
||||
@@ -289,9 +334,12 @@ void VoiceAudioIo::captureLoop() {
|
||||
else { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "voice-io: too many controls within one capture frame"); stopping = true; }
|
||||
continue;
|
||||
}
|
||||
if (voice_time_us() - event.enqueued > 100000) {
|
||||
int64_t received = voice_time_us();
|
||||
maxQueueAge = std::max(maxQueueAge, received - event.enqueued);
|
||||
if (received - event.enqueued > 100000) {
|
||||
m_captureDropped.fetch_add(event.frames); continue;
|
||||
}
|
||||
lastCapture = received;
|
||||
bool clockJump = expectedCaptureTime && std::abs(event.time - expectedCaptureTime) > 20000;
|
||||
if (event.sequence != expectedSequence || (captureRoute && event.route != captureRoute) || clockJump) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CALL, "voice-io: capture discontinuity expected=%llu actual=%llu pending=%u route=%016llx->%016llx",
|
||||
@@ -315,28 +363,34 @@ void VoiceAudioIo::captureLoop() {
|
||||
memcpy(cleaned, raw, 960 * m_channels * sizeof(int16_t));
|
||||
consumeReference();
|
||||
bool available = aec && alignReference();
|
||||
if (!aec) referenceReason = "disabled";
|
||||
if (available) {
|
||||
speex_aec_feed_playback(aec, referencePcm, 1920);
|
||||
speex_aec_process_capture(aec, raw, 960 * m_channels, cleaned);
|
||||
} else if (aec) {
|
||||
++missingReference;
|
||||
if (referenceAvailable) speex_aec_reset(aec);
|
||||
if (referenceAvailable) {
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_AEC, "voice-io: AEC bypass/reset session=%llu reason=%s gap=%.1fus history=%zu capture_time=%lld",
|
||||
(unsigned long long)m_session, referenceReason, referenceGapUs, historyCount, (long long)frameTime);
|
||||
speex_aec_reset(aec);
|
||||
}
|
||||
}
|
||||
if (debug_should_output(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_AEC)) {
|
||||
++signalFrames; if (available) ++aecFrames;
|
||||
for (int i = 0; i < 960 * m_channels; ++i) {
|
||||
float in = raw[i] / 32768.0f, out = cleaned[i] / 32768.0f;
|
||||
rawEnergy += in * in; cleanEnergy += out * out;
|
||||
rawPeak = std::max(rawPeak, std::abs(in)); cleanPeak = std::max(cleanPeak, std::abs(out));
|
||||
}
|
||||
if (available) for (int i = 0; i < 1920; ++i) {
|
||||
float ref = referencePcm[i] / 32768.0f;
|
||||
referenceEnergy += ref * ref; referencePeak = std::max(referencePeak, std::abs(ref));
|
||||
}
|
||||
}
|
||||
referenceAvailable = available;
|
||||
deliver(960);
|
||||
}
|
||||
int64_t now = voice_time_us();
|
||||
if (now - lastReport >= 1000000) {
|
||||
uint64_t captureDrops = m_captureDropped.exchange(0), refDrops = m_referenceDropped.load();
|
||||
uint64_t underruns = m_playbackUnderruns.exchange(0);
|
||||
if (captureDrops || refDrops != reportedReferenceDrops || missingReference || underruns)
|
||||
DEBUG_WARN(DEBUG_CATEGORY_AEC, "voice-io: session=%llu capture_drop=%llu reference_drop=%llu missing_ref=%llu output_missing=%llu",
|
||||
(unsigned long long)m_session, (unsigned long long)captureDrops, (unsigned long long)refDrops,
|
||||
(unsigned long long)missingReference, (unsigned long long)underruns);
|
||||
else DEBUG_DEBUG(DEBUG_CATEGORY_AEC, "voice-io: session=%llu aligned history=%zu capture_queue=%zu",
|
||||
(unsigned long long)m_session, historyCount, m_captureEvents.size());
|
||||
missingReference = 0; reportedReferenceDrops = refDrops; lastReport = now;
|
||||
}
|
||||
|
||||
}
|
||||
if (filled) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CALL, "voice-io: capture tail=%u frames bypasses AEC; call tail discarded, radio tail preserved", filled);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* Настоящие Qt-кнопки, null audio backend и общий radio_audio; подменяем только вероятность VAD и сетевой выход. */
|
||||
#include "../src/radiopanel.h"
|
||||
#include "../src/radiosettingspage.h"
|
||||
#include <QComboBox>
|
||||
#include <QSpinBox>
|
||||
#include "../src/radio_audio_engine.h"
|
||||
#include "../src/sound_manager.h"
|
||||
@@ -124,12 +123,42 @@ int main(int argc, char** argv) {
|
||||
REQUIRE(engine->settingsBusy() && !vad->isEnabled());
|
||||
await([&]() { return !engine->settingsBusy() && engine->autoAvailable(); });
|
||||
REQUIRE(vad->isChecked() && outputs == oldOutputs && inputs == oldInputs + 1);
|
||||
// Удержание открывает редактор без переключения автоматики и перезапуска захвата.
|
||||
oldInputs = inputs;
|
||||
QTest::mousePress(vad, Qt::LeftButton); pump(550);
|
||||
auto* popup = panel.findChild<QMenu*>("radioActivationPopup");
|
||||
REQUIRE(popup && popup->isVisible() && engine->autoEnabled() && inputs == oldInputs);
|
||||
QTest::mouseRelease(vad, Qt::LeftButton);
|
||||
REQUIRE(popup->isVisible() && engine->autoEnabled() && !engine->settingsBusy());
|
||||
auto* quickVad = popup->findChild<QPushButton*>("radioModeVad");
|
||||
auto* quickLevel = popup->findChild<QPushButton*>("radioModeLevel");
|
||||
auto* quickThreshold = popup->findChild<QSpinBox*>("radioVadThreshold");
|
||||
auto* quickOn = popup->findChild<QSpinBox*>("radioLevelOn");
|
||||
auto* quickApply = popup->findChild<QPushButton*>("radioActivationApply");
|
||||
auto* quickProbability = popup->findChild<QLabel*>("radioVadText");
|
||||
auto* quickGain = popup->findChild<QLabel*>("radioVadGainText");
|
||||
REQUIRE(quickVad && quickLevel && quickThreshold && quickOn && quickApply && quickProbability && quickGain);
|
||||
quickLevel->click(); REQUIRE(quickOn->isEnabled() && quickThreshold->isEnabled() && engine->autoMode() == 1);
|
||||
quickVad->click(); quickThreshold->setValue(60); REQUIRE(quickApply->isEnabled());
|
||||
quickApply->click(); await([&] { return !engine->settingsBusy() && engine->vadValid(); });
|
||||
REQUIRE(engine->setting("radio_vad_threshold") == 60 && engine->autoEnabled() && !quickApply->isEnabled());
|
||||
probability = 0.25f;
|
||||
await([&] { return quickProbability->text().contains("25.0%") && quickGain->text().contains("dB"); });
|
||||
REQUIRE(engine->vadCompressorEnabled() && engine->vadGain() > 0);
|
||||
REQUIRE(popup->grab().save("/tmp/desktop-radio-activation-popup.png"));
|
||||
quickThreshold->setValue(70);
|
||||
QTest::keyClick(popup, Qt::Key_Escape); REQUIRE(!popup->isVisible());
|
||||
QMetaObject::invokeMethod(vad, "customContextMenuRequested", Q_ARG(QPoint, QPoint()));
|
||||
REQUIRE(popup->isVisible() && quickThreshold->value() == 60);
|
||||
popup->hide(); probability = 0;
|
||||
qInfo("radio panel: hold/context popup, no toggle, direct modes, both thresholds, apply/cancel, live probability/gain PASS");
|
||||
pump(750); // Полное кольцо prefetch до начала речи.
|
||||
int previousPackets = packets;
|
||||
probability = 0.9f;
|
||||
await([&]() { return engine->isTransmitting() && begins == 1 && packets >= previousPackets + 30; });
|
||||
REQUIRE(!engine->isTalking() && ptt->property("transmitting").toBool() && begins == 1);
|
||||
REQUIRE(selfSpeaking()); // VAD включает собственный динамик без нажатой PTT.
|
||||
REQUIRE(panel.grab().save("/tmp/desktop-radio-vad-meter.png"));
|
||||
REQUIRE(packets >= previousPackets + 30);
|
||||
int beforeManual = begins;
|
||||
QTest::mousePress(ptt, Qt::LeftButton);
|
||||
@@ -210,17 +239,18 @@ int main(int argc, char** argv) {
|
||||
|
||||
RadioSettingsPage settings(nullptr);
|
||||
settings.resize(620, 780); settings.show();
|
||||
auto* mode = settings.findChild<QComboBox*>("radioAutoMode");
|
||||
auto* mode = settings.findChild<QPushButton*>("radioModeLevel");
|
||||
auto* on = settings.findChild<QSpinBox*>("radioLevelOn");
|
||||
auto* off = settings.findChild<QSpinBox*>("radioLevelOff");
|
||||
auto* levelText = settings.findChild<QLabel*>("radioLevelText");
|
||||
REQUIRE(mode && on && off && levelText);
|
||||
mode->setCurrentIndex(1); on->setValue(-50); off->setValue(-40);
|
||||
mode->click(); on->setValue(-50); off->setValue(-40);
|
||||
REQUIRE(!settings.apply() && !engine->settingsBusy() && engine->autoMode() == 1);
|
||||
off->setValue(-60);
|
||||
REQUIRE(settings.apply());
|
||||
await([&]() { return !engine->settingsBusy() && engine->autoAvailable() && engine->inputLevelValid(); });
|
||||
REQUIRE(engine->autoMode() == 2 && vad->text() == "Level" && radio_audio_auto_mode() == RADIO_AUTO_LEVEL);
|
||||
REQUIRE(engine->autoMode() == 2 && !vad->icon().isNull() && vad->text().isEmpty() && radio_audio_auto_mode() == RADIO_AUTO_LEVEL);
|
||||
REQUIRE(settings.findChild<QSpinBox*>("radioVadThreshold")->isEnabled() && on->isEnabled());
|
||||
REQUIRE(!engine->isTransmitting() && status->text() == "Waiting for signal");
|
||||
REQUIRE(levelText->text().contains("dBFS") && engine->inputLevel() == -120);
|
||||
// Silero недоступен; уровень работает и сохраняется вместе с парой порогов.
|
||||
|
||||
@@ -14,6 +14,7 @@ extern "C" {
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#define REQUIRE(x) do { if (!(x)) { fprintf(stderr, "voice-io:%d %s\n", __LINE__, #x); abort(); } } while (0)
|
||||
static std::mutex mutex;
|
||||
static std::vector<int16_t> capture, transmitted;
|
||||
@@ -21,6 +22,10 @@ static std::vector<uint8_t> masks;
|
||||
static bool talking;
|
||||
static std::atomic<int> pulls{0}, blocks{0};
|
||||
static std::atomic<bool> stall{false}, stalled{false};
|
||||
static std::atomic<bool> idleReported{false};
|
||||
static void capture_diagnostic(int, const char*, const char* message) {
|
||||
if (std::strstr(message, "voice-io: capture stalled")) idleReported = true;
|
||||
}
|
||||
static std::atomic<uint64_t> output_position{0}, output_delay{0};
|
||||
extern "C" void radio_audio_playback_progress(uint64_t, uint64_t position, uint64_t delay) {
|
||||
output_delay = delay; output_position = position;
|
||||
@@ -58,6 +63,15 @@ int main() {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN);
|
||||
VoiceAudioIo voice;
|
||||
std::array<int16_t, 960> pcm{}; pcm.fill(1234);
|
||||
// Отсутствие PCM должно попадать в лог без необходимости ждать следующего кадра.
|
||||
debug_set_log_hook(capture_diagnostic);
|
||||
REQUIRE(voice.start(VoiceAudioIo::Kind::Radio, 7) && voice.startCapture(1, false));
|
||||
await([] { return idleReported.load(); });
|
||||
voice.capture(pcm.data(), 960, 0);
|
||||
await([] { return blocks.load() == 1; });
|
||||
voice.stop(); debug_set_log_hook(nullptr);
|
||||
REQUIRE(capture.size() == 960 && capture.front() == 1234 && capture.back() == 1234);
|
||||
reset(); pulls = 0; output_position = 0;
|
||||
// Выдача RX worker не подтверждает вывод; частичный callback сохраняет позицию и backend delay.
|
||||
REQUIRE(voice.start(VoiceAudioIo::Kind::Radio, 7));
|
||||
await([] { return pulls.load() >= 2; });
|
||||
|
||||
@@ -26,6 +26,7 @@ static std::vector<char> events;
|
||||
static std::vector<std::vector<uint8_t>> packets;
|
||||
static float probability;
|
||||
static int vad_windows;
|
||||
static int vad_result;
|
||||
static int radio_compressor_enabled;
|
||||
static int auto_hangover_ms;
|
||||
static bool observe_vad;
|
||||
@@ -40,7 +41,7 @@ extern "C" void __wrap_silero_vad_reset(silero_vad_t*) {}
|
||||
extern "C" int __wrap_silero_vad_process(silero_vad_t*, const float* samples, float* result) {
|
||||
if (stall_vad) { vad_stalled = true; while (stall_vad) std::this_thread::sleep_for(std::chrono::milliseconds(1)); }
|
||||
if (observe_vad) vad_input.insert(vad_input.end(), samples, samples + SILERO_VAD_WINDOW_SAMPLES);
|
||||
++vad_windows; *result = probability; return 0;
|
||||
++vad_windows; *result = probability; return vad_result;
|
||||
}
|
||||
extern "C" int __wrap_radio_talk_begin(UTUN_INSTANCE*, uint64_t) { events.push_back('B'); return 0; }
|
||||
extern "C" int __wrap_radio_talk_end(UTUN_INSTANCE*, uint64_t) { events.push_back('F'); return 0; }
|
||||
@@ -97,6 +98,8 @@ static void check_vad_pcm(const int16_t* pcm, int frames, int channels, int max_
|
||||
expected.resize(expected.size() / 512 * 512);
|
||||
REQUIRE(vad_input == expected);
|
||||
REQUIRE(audio_compressor_gain_db(ac) <= max_gain + 0.001f);
|
||||
auto status = radio_audio_get_input_status();
|
||||
REQUIRE(status.vad_compressor_enabled && std::abs(status.vad_gain_db - audio_compressor_gain_db(ac)) < 0.0001f);
|
||||
audio_compressor_destroy(ac);
|
||||
}
|
||||
|
||||
@@ -275,6 +278,7 @@ static void test_vad_diagnostics(UTUN_INSTANCE* instance) {
|
||||
REQUIRE(!radio_audio_transmitting()); uasync_poll(instance->ua, 0);
|
||||
REQUIRE(!packets.empty());
|
||||
radio_audio_on_frame(instance, 7, 0x1234, 1, 0, 0, packets.front().data(), packets.front().size(), nullptr);
|
||||
REQUIRE(radio_audio_get_input_status().blocked && !radio_audio_get_input_status().vad_valid);
|
||||
probability = 0.9f;
|
||||
for (int i = 0; i < 2; ++i) REQUIRE(radio_audio_feed_pcm(7, pcm.data(), pcm.size()) == 0);
|
||||
REQUIRE(!radio_audio_transmitting());
|
||||
@@ -289,6 +293,16 @@ static void test_vad_diagnostics(UTUN_INSTANCE* instance) {
|
||||
for (const char* text : {"VAD config", "reason=confirming", "reason=confirm_reset", "reason=confirmed",
|
||||
"reason=silence_timeout", "reason=rx_busy", "rx_node=0000000000001234", "manual=1",
|
||||
"BEGIN dispatched", "capture discontinuity", "VAD capture stop", "model_rms="}) REQUIRE(contains(text));
|
||||
// Клиппинг должен быть явно виден в диагностике ветки VAD, отдельно от компрессора передачи.
|
||||
radio_compressor_enabled = 1; probability = 0; test_time = 100000;
|
||||
REQUIRE(radio_audio_start(7, 0) == 0 && radio_audio_capture_start(7, 1, RADIO_AUTO_VAD) == 0);
|
||||
pcm.fill(0);
|
||||
for (int i = 0; i < 2; ++i) REQUIRE(radio_audio_feed_pcm(7, pcm.data(), pcm.size()) == 0);
|
||||
REQUIRE(contains("dc=0.000000 zeros=512/512"));
|
||||
test_time += 10001; pcm.fill(30000);
|
||||
for (int i = 0; i < 2; ++i) REQUIRE(radio_audio_feed_pcm(7, pcm.data(), pcm.size()) == 0);
|
||||
REQUIRE(contains("VAD compressor clipping") && contains("input_peak="));
|
||||
radio_audio_stop(); uasync_poll(instance->ua, 0); test_time = 0; radio_compressor_enabled = 0;
|
||||
debug_set_log_hook(nullptr);
|
||||
debug_set_category_level(DEBUG_CATEGORY_VAD, DEBUG_LEVEL_NONE);
|
||||
debug_set_category_level(DEBUG_CATEGORY_RADIO, DEBUG_LEVEL_NONE);
|
||||
@@ -432,6 +446,36 @@ static void test_level_detector(UTUN_INSTANCE* instance, int channels, int compr
|
||||
channels, compressor);
|
||||
}
|
||||
|
||||
/* UI получает именно результат Silero; устаревшее значение не выглядит свежей тишиной. */
|
||||
static void test_vad_input_status(UTUN_INSTANCE* instance) {
|
||||
radio_compressor_enabled = 0; test_time = 100000;
|
||||
REQUIRE(radio_audio_start(7, 0) == 0 && radio_audio_capture_start(7, 1, RADIO_AUTO_VAD) == 0);
|
||||
REQUIRE(!radio_audio_get_input_status().vad_valid);
|
||||
std::array<int16_t, 1536> pcm{};
|
||||
auto feed = [&] { REQUIRE(radio_audio_feed_pcm(7, pcm.data(), pcm.size()) == 0); };
|
||||
probability = 0.25f; feed();
|
||||
auto status = radio_audio_get_input_status();
|
||||
REQUIRE(status.valid && status.vad_valid && status.vad_probability == probability);
|
||||
REQUIRE(!status.vad_compressor_enabled && status.vad_gain_db == 0);
|
||||
test_time += 2000; REQUIRE(radio_audio_get_input_status().vad_valid);
|
||||
test_time += 1; REQUIRE(!radio_audio_get_input_status().vad_valid);
|
||||
probability = 0; feed();
|
||||
status = radio_audio_get_input_status(); REQUIRE(status.vad_valid && status.vad_probability == 0);
|
||||
radio_audio_capture_discontinuity(7); REQUIRE(!radio_audio_get_input_status().vad_valid);
|
||||
probability = 0.4f; feed(); REQUIRE(radio_audio_get_input_status().vad_valid);
|
||||
vad_result = -1; feed(); REQUIRE(!radio_audio_get_input_status().vad_valid);
|
||||
vad_result = 0; feed();
|
||||
status = radio_audio_get_input_status(); REQUIRE(status.vad_valid && status.vad_probability == probability);
|
||||
radio_audio_capture_stop(); REQUIRE(!radio_audio_get_input_status().vad_valid);
|
||||
for (int mode : {RADIO_AUTO_OFF, RADIO_AUTO_LEVEL, RADIO_AUTO_VAD}) {
|
||||
REQUIRE(radio_audio_capture_start(7, 1, mode) == 0 && !radio_audio_get_input_status().vad_valid);
|
||||
feed(); REQUIRE(!!radio_audio_get_input_status().vad_valid == (mode == RADIO_AUTO_VAD));
|
||||
radio_audio_capture_stop();
|
||||
}
|
||||
radio_audio_stop(); uasync_poll(instance->ua, 0); test_time = 0;
|
||||
puts("voice TX: VAD probability snapshot, zero, freshness, inference failure, discontinuity, stop and mode switch PASS");
|
||||
}
|
||||
|
||||
int main() {
|
||||
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN);
|
||||
UTUN_INSTANCE instance{}; instance.ua = uasync_create(); REQUIRE(instance.ua);
|
||||
@@ -513,6 +557,7 @@ int main() {
|
||||
}
|
||||
test_prefetch_deferred(&instance);
|
||||
test_vad_diagnostics(&instance);
|
||||
test_vad_input_status(&instance);
|
||||
test_vad_receive_guard(&instance);
|
||||
test_vad_receive_guard(&instance, RADIO_AUTO_LEVEL);
|
||||
for (int channels : {1, 2}) for (int gain : {6, 30}) test_vad_compressor(&instance, channels, gain);
|
||||
|
||||
@@ -2215,5 +2215,37 @@ Directories: %5</translation>
|
||||
<source>Enable automatic transmission using the radio panel button. Both modes include 0.6 s of prebuffer. Signal level is measured after echo cancellation, before compression. Start requires 40 ms above the start threshold; transmission ends after the configured silence below the stop threshold. The VAD compressor has a separate maximum gain.</source>
|
||||
<translation>Enable automatic transmission using the radio panel button. Both modes include 0.6 s of prebuffer. Signal level is measured after echo cancellation, before compression. Start requires 40 ms above the start threshold; transmission ends after the configured silence below the stop threshold. The VAD compressor has a separate maximum gain.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD speech probability: %1%</source>
|
||||
<translation>VAD speech probability: %1%</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Enable automatic transmission in VAD mode to see speech probability</source>
|
||||
<translation>Enable automatic transmission in VAD mode to see speech probability</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD measurement paused: channel busy</source>
|
||||
<translation>VAD measurement paused: channel busy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD speech probability unavailable</source>
|
||||
<translation>VAD speech probability unavailable</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Current VAD compressor gain: —</source>
|
||||
<translation>Current VAD compressor gain: —</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD compressor off (0 dB)</source>
|
||||
<translation>VAD compressor off (0 dB)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Current VAD compressor gain: %1 dB</source>
|
||||
<translation>Current VAD compressor gain: %1 dB</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hold or right-click to adjust activation mode and thresholds</source>
|
||||
<translation>Hold or right-click to adjust activation mode and thresholds</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
@@ -2221,5 +2221,37 @@ Directories: %5</source>
|
||||
<source>Enable automatic transmission using the radio panel button. Both modes include 0.6 s of prebuffer. Signal level is measured after echo cancellation, before compression. Start requires 40 ms above the start threshold; transmission ends after the configured silence below the stop threshold. The VAD compressor has a separate maximum gain.</source>
|
||||
<translation>Включайте автоматическую передачу кнопкой на панели рации. В обоих режимах передаётся до 0,6 с звука перед срабатыванием. Уровень измеряется после эхоподавления, до компрессора. Для включения нужны 40 мс на пороге включения или выше; передача заканчивается после заданной паузы ниже порога отключения. У компрессора VAD отдельный предел усиления.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD speech probability: %1%</source>
|
||||
<translation>Вероятность речи VAD: %1%</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Enable automatic transmission in VAD mode to see speech probability</source>
|
||||
<translation>Включите автопередачу в режиме VAD для оценки вероятности речи</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD measurement paused: channel busy</source>
|
||||
<translation>Оценка VAD приостановлена: эфир занят</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD speech probability unavailable</source>
|
||||
<translation>Оценка вероятности речи VAD недоступна</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Current VAD compressor gain: —</source>
|
||||
<translation>Текущее усиление компрессора VAD: —</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>VAD compressor off (0 dB)</source>
|
||||
<translation>Компрессор VAD выключен (0 dB)</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Current VAD compressor gain: %1 dB</source>
|
||||
<translation>Текущее усиление компрессора VAD: %1 dB</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Hold or right-click to adjust activation mode and thresholds</source>
|
||||
<translation>Удерживайте или нажмите правой кнопкой для настройки режима и порогов</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
Reference in new issue
Block a user