creating a dummy QAudioDevice
-
On Qt 6.x, is there a way of creating a custom QAudioDevice. I looked into the guts of how QT creates a list of supported input and output audio devices using the static functions QMediaDevices::defaultAudioInput() & QMediaDevices::defaultAudioOutput(). These functions use platform specific APIs and a QAudioDevicePrivate which I think would be really useful if exposed. I found this private class implementation in qtmultimedia\include\QtMultimedia\6.6.0\QtMultimedia\private\qaudiodevice_p.h using the latest dev release.
The QAudioDevice is a descriptive wrapper that describes the capability of various audio input or output devices. I have a GUI with combo boxes allowing the user to select from these inputs and outputs that are prepopulated from these static functions, but I do not have a clean way of adding a custom input and output ones to these.
The input one (which currently shows the available microphone sources) would in my case describe a signal generator class, while the output one would describe a UDP type of RTP audio device. These classes would be useful in that they can describe the various supported formats etc.
Any pointers on how to do this would be greatly appreciated.
-
Hi,
Following the big refactoring that happened, I would say no.
You should check the bug report system to see if there's not something about virtual devices and if not, open a feature request.
-
@SGaist Thanks for following up on this. I'm kind of making some small progress in this area by looking at the whole pimpl technique used in QT - I was able to make a generic QAudioDevice (just a descriptor for now containing supported formats and channel details) by adding the QT += multimedia-private to the pro file. This allows me to #include "private/qaudiodevice_h" which in turn allows code like this:
auto* infop = new QAudioDevicePrivate( "deviceID", QAudioDevice::Mode::Input); auto inputDevice = infop->create();
This creates a really dumb qaudiodevice - I will need to fill the default values for my input device by directly updating the contents of the QAudioDevicePrivate (aka infop) before calling its create() method (which returns the QAudioDevice).
Going a little further with this approach using QAlsaAudioDeviceInfo for inspiration from the Qt source, I subclassed QAudioDevicePrivate.
Header file AudioDevice.h
#pragma once #include "private/qaudiodevice_p.h" class AudioDeviceInfo : public QAudioDevicePrivate { public: AudioDeviceInfo( const QByteArray& dev, const QString& description, QAudioDevice::Mode mode); ~AudioDeviceInfo() override = default; private: };
& AudioDevice.cpp
AudioDeviceInfo::AudioDeviceInfo( const QByteArray& dev, const QString& desc, QAudioDevice::Mode mode) : QAudioDevicePrivate(dev, mode) { description = desc; minimumChannelCount = 1; maximumChannelCount = 4; minimumSampleRate = 8000; maximumSampleRate = 48000; supportedSampleFormats = { QAudioFormat::UInt8, QAudioFormat::Int16, QAudioFormat::Int32, QAudioFormat::Float }; preferredFormat.setChannelCount(mode == QAudioDevice::Input ? 1 : 2); preferredFormat.setSampleFormat(QAudioFormat::Int16); preferredFormat.setSampleRate(48000); }
This gets me to a place where I can create this device and add it to the current list of input devices.
// this is a pseudo input device const auto info1 = new AudioDeviceInfo( "deviceID1", "Generator Input Device", QAudioDevice::Mode::Input); const auto inputAudioDevice = info1->create(); stringList.emplaceBack(inputAudioDevice.description());
Ideally, I would like to be able to somehow hook these audio descriptor classes to work with QAudioSource & QAudioSink. if you have any guidelines on how I could do that - it would be great. Thanks again.
-
I would check the internals of the other platform plugins to see how they are used by these classes.