Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. How to stream audio to QAudioSink in a separate thread
Forum Update on Monday, May 27th 2025

How to stream audio to QAudioSink in a separate thread

Scheduled Pinned Locked Moved Unsolved Qt 6
23 Posts 4 Posters 4.5k 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.
  • P paulmasri
    1 Feb 2022, 21:58

    Yeah :-(
    I included logging and included time elapsed. This showed that typically the time between calls to readData() for a long buffer (10ms) is typically 1-2ms, with occasional gaps 3-5ms. However every real/simulated GUI interaction results in a gap of 10-30ms.

    Nevertheless I do like the QtMultimedia library for its cross-platform support, so unless someone has a great idea how to solve this situation, I'm going to fork the library and see if I can make QAudioSink and related classes thread-safe, so that I can put them in a high priority thread.

    I've not tried building any part of Qt from source before, so I'm already seeking support in the forums. Hopefully I'll be able to get somewhere with it, and who knows, maybe even contribute something back.

    K Offline
    K Offline
    kshegunov
    Moderators
    wrote on 1 Feb 2022, 23:12 last edited by
    #21

    @paulmasri said in How to stream audio to QAudioSink in a separate thread:

    Nevertheless I do like the QtMultimedia library for its cross-platform support, so unless someone has a great idea how to solve this situation, I'm going to fork the library and see if I can make QAudioSink and related classes thread-safe, so that I can put them in a high priority thread.

    What I was thinking of initially (hence the million questions game) was to drive the event loop manually with some timeout that should be okay for your application, so you control how long events are processed. I know sounds like an abomination, but should approximate what you want. Although from what you'd observed I'm utterly unconvinced this is going to truly work. It's probably worth a shot still, but a long one.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    0
    • P Offline
      P Offline
      paulmasri
      wrote on 2 Feb 2022, 13:48 last edited by
      #22

      @kshegunov said in How to stream audio to QAudioSink in a separate thread:

      What I was thinking of initially (hence the million questions game) was to drive the event loop manually with some timeout that should be okay for your application, so you control how long events are processed. I know sounds like an abomination, but should approximate what you want. Although from what you'd observed I'm utterly unconvinced this is going to truly work. It's probably worth a shot still, but a long one.

      I agree it does sound an abomination! Aside of feeling wrong — messing with something unrelated to audio streaming in order to solve audio streaming issues — I'm doubtful it would work. As it says in the documentation, any time I would call processEvents(), it will process all queued events "however long it takes." This seems guaranteed to perpetuate the current issues.

      I'm currently working through the audio streaming classes to understand them and see if I can work with them in some way, ideally to improve QtMultimedia and submit a pull request, but otherwise to pull them out of QtMultimedia and make use of them somehow myself.

      T 1 Reply Last reply 15 Dec 2023, 07:56
      1
      • P paulmasri
        2 Feb 2022, 13:48

        @kshegunov said in How to stream audio to QAudioSink in a separate thread:

        What I was thinking of initially (hence the million questions game) was to drive the event loop manually with some timeout that should be okay for your application, so you control how long events are processed. I know sounds like an abomination, but should approximate what you want. Although from what you'd observed I'm utterly unconvinced this is going to truly work. It's probably worth a shot still, but a long one.

        I agree it does sound an abomination! Aside of feeling wrong — messing with something unrelated to audio streaming in order to solve audio streaming issues — I'm doubtful it would work. As it says in the documentation, any time I would call processEvents(), it will process all queued events "however long it takes." This seems guaranteed to perpetuate the current issues.

        I'm currently working through the audio streaming classes to understand them and see if I can work with them in some way, ideally to improve QtMultimedia and submit a pull request, but otherwise to pull them out of QtMultimedia and make use of them somehow myself.

        T Offline
        T Offline
        tomtomtomtomtomtom
        wrote on 15 Dec 2023, 07:56 last edited by
        #23

        @paulmasri
        Hi, I'm encountering the exact same issue with Qt 6.5.1. Have you found a solution yet?

        1 Reply Last reply
        0

        • Login

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