Results 1 to 10 of 10

Thread: Qt Audio in Linux and Windows: different behaviour

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Platforms
    Unix/X11 Windows

    Default Qt Audio in Linux and Windows: different behaviour

    I have an application (SDR type) where the software generates a nice stream of PCM audiosamples and the output is made audible using QAudio to the soundcard of the PC
    The current version runs with Qt5, and I am in the transition from Qt5 to Qt

    I have a version that runs fine under Linux, but - it is cross compiled - under Windows it does not generate sound and does not give error messages either
    It should be possible to have it run under Windows, the audioOutput example from the Qt sourcetree runs both under Linux and Windows fine

    The structure of the class, driving the output, is basic, it is a class in which an AudioSink and a IODevice are created and the incoming samples are stored in a large ringbuffer
    Part of the code that is executed on a (re)start, where newDeviceIndex is just in index is the vector ith device descriptions. the format is stored in m_settings:

    Qt Code:
    1. if (newDeviceIndex < 0)
    2. return;
    3. QAudioDevice currentDevice
    4. = outputDevices. at (newDeviceIndex);
    5. fprintf (stderr, "going for %s\n",
    6. currentDevice. description (). toLatin1 (). data ());
    7. m_audioSink = new QAudioSink (currentDevice, m_settings);
    8.  
    9. m_audioSink -> setBufferSize (8 * 32768);
    10. connect (m_audioSink, &QAudioSink::stateChanged,
    11. this, &Qt_Audio::state_changed);
    12. //
    13. // and run off
    14. theIODevice -> close ();
    15. delete theIODevice;
    16. theIODevice = new Qt_AudioDevice (mr, &tempBuffer);
    17. theIODevice -> start ();
    18. m_audioSink -> start (theIODevice);
    19.  
    20. QtAudio::Error err = m_audioSink -> error ();
    21. fprintf (stderr, "Errorcode %d\n", (int)(err));
    To copy to clipboard, switch view to plain text mode 
    And the IODevice is the most simple one one can imagine

    Qt Code:
    1. void Qt_AudioDevice::start () {
    2. if (running. load ())
    3. return;
    4. bool b = open (QIODevice::ReadOnly);
    5. fprintf (stderr, "Opening QIODevice %s\n", b ? "ok" : "error");
    6. running. store (true);
    7. }
    8.  
    9. // we always return "maxSize" bytes
    10. qint64 Qt_AudioDevice::readData (char* buffer, qint64 maxSize) {
    11. qint64 amount = 0;
    12. // "maxSize" is the requested size in bytes
    13. // "amount" is in uint8_t's
    14. amount = Buffer -> getDataFromBuffer (buffer, maxSize);
    15.  
    16. if (amount < maxSize) {
    17. for (int i = amount; i < maxSize; i ++)
    18. buffer [i] = (char)(0);
    19. }
    20.  
    21. totalBytes_l += amount;
    22. missedBytes_l += maxSize - amount;
    23. return maxSize;
    24. }
    To copy to clipboard, switch view to plain text mode 


    On a state change I print the state,
    On Linux, the message is - after opening the device "activeState"
    On windows, the message with opening is that opening was successfull and the state is "Idle"

    Format is 48000, 2 channels and floats (bit I tried Int16 as well with the same result)

    Any help would really be appreciated

    Jan
    Last edited by d_stranz; 26th December 2024 at 01:48. Reason: missing [code] tags

Similar Threads

  1. Left audio channel intermittently drops out (QAudioOutput, Linux)
    By QtDrivesMeCrazy in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2016, 00:09
  2. Replies: 5
    Last Post: 10th June 2014, 12:26
  3. Replies: 0
    Last Post: 8th December 2011, 13:21
  4. executing a audio player code on Embedded linux
    By sureshlohith in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 21st April 2010, 06:17
  5. Replies: 2
    Last Post: 4th June 2009, 17:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.