diff options
| author | Anton <anton@picapica.im> | 2026-08-24 05:06:23 +0400 |
|---|---|---|
| committer | Anton <anton@picapica.im> | 2026-08-24 05:06:23 +0400 |
| commit | a4ddbc49c82e31ee980ea1096cc737db438c012e (patch) | |
| tree | 045ae5a4031f928dedb772a8998b220f0d5aa3e2 /pica-client/dialogs/settingsdialog.h | |
| parent | 5c5fe2b41da2f4f1da32b12909a9b982e5dec70a (diff) | |
| download | pica-pica-a4ddbc49c82e31ee980ea1096cc737db438c012e.tar.gz pica-pica-a4ddbc49c82e31ee980ea1096cc737db438c012e.zip | |
pica-client: echo cancellation, and native audio on Windows and macOS
PlatformDriverName() now takes a direction, and answers with one of two kinds
of name. A bare one - "alsa", "pulse", "oss" - is an FFmpeg libavdevice driver
opened the way everything else here is opened. One prefixed "platform-" is not
an FFmpeg driver at all: what follows names a platform audio API the caller
drives itself through NativeAudioBackend.
Windows and macOS take the second route, because both provide acoustic echo
cancellation but only to streams that declare themselves part of a voice call
- AudioCategory_Communications on WASAPI, the VoiceProcessingIO audio unit on
CoreAudio - and libavdevice's wrappers have no way to ask for either. Doing our
own cancelling on platforms that would have done it better below us is not a
trade worth making.
Where the platform will not do it, speexdsp does: one EchoCanceller per call,
shared by both directions through a QSharedPointer, since the call is torn down
without joining either audio thread. Playback feeds it the far end as it hands
it to the device; capture subtracts before encoding. Alignment is left to the
FIFO - in steady state its backlog settles at the sound card's buffer depth,
which is also how far ahead of the speaker the playback side runs, leaving only
the room for the filter tail to model. Measured 27 dB ERLE on a 60 ms echo with
1.6 dB of loss on speech when nothing is playing.
On macOS the canceller is a single audio unit that renders and captures at
once, so both directions share one refcounted instance. Ringtones deliberately
get a plain HALOutput unit instead - opening a voice unit to play a bell would
switch the microphone on and prompt for permission.
Linux gains a choice of alsa or pulse, with PulseAudio device enumeration
through libpulse when configure finds it.
Info.plist gains NSMicrophoneUsageDescription and NSCameraUsageDescription.
Without them macOS 10.14 and later kills the process on first use of the
microphone or camera rather than asking, so calls did not merely fail, they
took the application with them.
Two things fixed along the way that were not about echo at all: the settings
dialog's microphone test paced playback by counting timer ticks, which on
Windows meant a 20 ms packet every ~31 ms because the system timer granularity
is 15.6 ms - the recording came out slowed down and chopped up. It now paces
against a QElapsedTimer. And chooseEncoderSampleFmt() uses
avcodec_get_supported_config() where available, the AVCodec format arrays it
replaced having been removed in FFmpeg 9.
Only the Linux paths are verified here; the Windows and macOS backends compile
to nothing on this machine and have been reviewed by hand.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CBqDgvq3Ty6C6BjLFH16bw
Diffstat (limited to 'pica-client/dialogs/settingsdialog.h')
| -rw-r--r-- | pica-client/dialogs/settingsdialog.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pica-client/dialogs/settingsdialog.h b/pica-client/dialogs/settingsdialog.h index e9ad558..424d43f 100644 --- a/pica-client/dialogs/settingsdialog.h +++ b/pica-client/dialogs/settingsdialog.h @@ -29,6 +29,7 @@ #include <QImage> #include <QList> #include <QTimer> +#include <QElapsedTimer> #include "../mediadevice.h" #include "../audiodevice.h" #include "../videodevice.h" @@ -68,6 +69,19 @@ private: QComboBox *audioCaptureDev; QComboBox *audioPlaybackDev; QComboBox *audioRingDev; + + // Which audio API to go through. Only Linux has a choice worth offering + // (ALSA or PulseAudio, the latter covering PipeWire's PulseAudio + // interface too), so elsewhere this stays null and no widget is built. + // The member and its slot are declared unconditionally all the same: + // moc runs its own preprocessor and would not see a platform #ifdef, so + // a slot hidden behind one ends up declared but never generated. + QComboBox *audioDriver; + + // Whether to run our own acoustic echo cancellation. Ignored when the + // platform provides one - see AudioDevice::PlatformDriverName(). + QCheckBox *cbEchoCancel; + QComboBox *videoDev; QPushButton *videoDevRefresh; @@ -92,6 +106,9 @@ private: }; AudioTestState audioTestState; + // What the microphone and playback devices reported negotiating, shown + // with the result. Same idea as videoTestPathReport. + QString audioTestPathReport; // The recording, as encoded packets, and how far playback has fed it. QList<QByteArray> audioTestPackets; int audioTestPlaybackPos; @@ -100,6 +117,9 @@ private: // fire into the next one. QTimer *audioTestRecordTimer; QTimer *audioTestPlaybackTimer; + // Playback is paced against this rather than against the number of times + // the timer has fired - see audioTestFeedPacket(). + QElapsedTimer audioTestPlaybackClock; QTimer *audioTestDrainTimer; void stopAudioTest(); @@ -161,6 +181,9 @@ private slots: void toggleIncomingConnections(bool checked); void toggleMultipleLogins(bool checked); void fillVideoDevices(); + // Device names are driver specific, so all three lists have to be filled + // again when the driver changes. Only ever connected on Linux. + void audioDriverChanged(int index); void fillAudioCaptureDevices(); void fillAudioPlaybackDevices(); void fillAudioRingDevices(); @@ -175,6 +198,7 @@ private slots: void audioTestFeedPacket(); void audioTestPlaybackFinished(); void audioTestError(QString message); + void audioTestPath(QString description); void toggleVideoTest(); void videoTestCaptureStarted(QString codec, int width, int height); |
