Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. creating a dummy QAudioDevice
Forum Update on Monday, May 27th 2025

creating a dummy QAudioDevice

Scheduled Pinned Locked Moved Unsolved General and Desktop
multimediaaudio devicewidgetqt6
4 Posts 2 Posters 712 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnco3
    wrote on 10 Jan 2023, 22:44 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 11 Jan 2023, 20:53 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 13 Jan 2023, 06:09
      0
      • S SGaist
        11 Jan 2023, 20:53

        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.

        J Offline
        J Offline
        johnco3
        wrote on 13 Jan 2023, 06:09 last edited by johnco3
        #3

        @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.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Jan 2023, 20:50 last edited by
          #4

          I would check the internals of the other platform plugins to see how they are used by these classes.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          4/4

          13 Jan 2023, 20:50

          • Login

          • Login or register to search.
          4 out of 4
          • First post
            4/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved