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. Can't get QAudioInput from qtaudio_windows to work
Forum Updated to NodeBB v4.3 + New Features

Can't get QAudioInput from qtaudio_windows to work

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 729 Views 3 Watching
  • 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.
  • P Offline
    P Offline
    pderocco
    wrote on last edited by pderocco
    #1

    I'm using the qtaudio_windows plugin because I'm running on Win7, and the standard multimedia stuff assumes Win8 or higher.

    I create a QAudioInput, successfully set its format to 48KHz 16-bit stereo, give it a 4K buffer, and set its notify interval to 6ms (a little over 1/4 of the buffer). Out of curiosity, I read back the buffer size and interval to make sure the driver didn't change them, and it didn't.

    In my notify handler, I use readAll() on the QIODevice, and I always get a QByteArray whose size is 0, 1638, 2457, or occasionally 3276, all multiples of 819 (0x333) bytes. Out of curiosity, I called bytesAvailable() on the device before the readAll(), and I always get zero!

    The data I'm getting looks like valid audio samples (I know what kind of waveforms I'm listening to), but of course the data should be a multiple of four bytes, so there are partial samples at the beginning and/or end. When I add up the number of bytes I get over time, it comes out to about a 47.1KHz sample rate, so it is dropping data, or the 6ms notify interval is averaging out to something less than 6ms.

    What could be wrong? You'd think that readAll() would "read all", not almost all. Or does anyone know where the source is for this plugin?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I might be wrong but I think the notify interval is too small. You are asking to get data at about 167 Herz.

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

      P 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I might be wrong but I think the notify interval is too small. You are asking to get data at about 167 Herz.

        P Offline
        P Offline
        pderocco
        wrote on last edited by
        #3

        @sgaist 6ms isn't unusual for low latency audio, and it's a fast machine. But I changed the buffer size from 4K to 64K, and computed the interval using QAudioFormat::durationForBytes, which came out to 86, and now it's giving me either 13107 or 26214 bytes on every notification. (Note that those are powers of two divided by 10.)

        This suggests that the sound card driver is returning blocks of data every 68.266ms, and so the notification interval sometimes finds one block in the buffer, sometimes two. I don't know what the significance of that number is--it's not related to some other standard rate like 44100Hz, or 60Hz, or 59.94Hz NTSC.

        But it shouldn't matter, except that my program is getting non-integral numbers of samples. I've never heard of an audio device delivering or accepting numbers of bytes that weren't integral multiples of the frame size.

        So I don't know if this is a Qt issue or if my sound card has a buggy driver. I'd really like to find the source code for this version of QAudioInput, but the Qt source library looks like a huge jungle to me.

        mrjjM 1 Reply Last reply
        0
        • P pderocco

          @sgaist 6ms isn't unusual for low latency audio, and it's a fast machine. But I changed the buffer size from 4K to 64K, and computed the interval using QAudioFormat::durationForBytes, which came out to 86, and now it's giving me either 13107 or 26214 bytes on every notification. (Note that those are powers of two divided by 10.)

          This suggests that the sound card driver is returning blocks of data every 68.266ms, and so the notification interval sometimes finds one block in the buffer, sometimes two. I don't know what the significance of that number is--it's not related to some other standard rate like 44100Hz, or 60Hz, or 59.94Hz NTSC.

          But it shouldn't matter, except that my program is getting non-integral numbers of samples. I've never heard of an audio device delivering or accepting numbers of bytes that weren't integral multiples of the frame size.

          So I don't know if this is a Qt issue or if my sound card has a buggy driver. I'd really like to find the source code for this version of QAudioInput, but the Qt source library looks like a huge jungle to me.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi

          • I'd really like to find the source code for this version of QAudioInput
            You can browse around at
            https://code.woboq.org/qt5/qtmultimedia/src/multimedia/audio/qaudioinput.cpp.html
            its hot linked and makes the code easier to navigate (IMHO)
          P 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi

            • I'd really like to find the source code for this version of QAudioInput
              You can browse around at
              https://code.woboq.org/qt5/qtmultimedia/src/multimedia/audio/qaudioinput.cpp.html
              its hot linked and makes the code easier to navigate (IMHO)
            P Offline
            P Offline
            pderocco
            wrote on last edited by
            #5

            @mrjj That's all the abstract stuff. I need to find the source for the Windows plugin that's pulled in by QTPLUGIN.audio = qtaudio_windows in my project file. I searched for files with "qtaudio_windows" in the name and came up empty.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It's in the plugins sub folder under windowsaudio.

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

              P 1 Reply Last reply
              2
              • SGaistS SGaist

                It's in the plugins sub folder under windowsaudio.

                P Offline
                P Offline
                pderocco
                wrote on last edited by
                #7

                @sgaist The problem is in qtmultimedia/src/plugins/windowsaudio/qwindowsaudioinput.cpp, in the open() function. It supplies a default buffer size of 200ms, and assigns a period size (the size of the individual blocks to be returned to the application) to be 1/5 of the buffer size, so you only get complete samples if you explicitly set a buffer size that is a multiple of five frames, whatever that turns out to be (20 bytes for 16-bit stereo). I've filed this bug report. In the meantime, you just have to set an explicit buffer size, instead of letting it choose a default.

                1 Reply Last reply
                2

                • Login

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