Results 1 to 10 of 10

Thread: Qt Audio in Linux and Windows: different behaviour

Hybrid 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 Re: Qt Audio in Linux and Windows: different behaviour

    Quote Originally Posted by janK View Post
    That is true, but that does not explain why the Audiosink opens without error and then goes into state Idle. especially when the QIODevice reports that opening is fine, The result is that in the end no bytes are read.
    If I understand the documentation, then the Audiosink goes into state Idle if there is no input, but I ensured that a buffer is filled, and then no element of the buffer is read
    And again, using Linux, it works fine, so either the Windows version should have worked, or the Linux version works while it should not

    I think the basic quesiton is
    if the creation of a QIODevice and the creation of an QAudioSink is also without errors,
    under what conditions changes the AudioSink the state to "Idle"

    I checked again btw that while sthe "start" of the QIODevice is - according to the QIODevice = without problems, the "readData" function
    is not called at all. So, it seems that the AudioSink does not see that the readData function can be called

    Anyway, in the documentation I do not find any clue of why this behavious happens under Windows

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

    Default Re: Qt Audio in Linux and Windows: different behaviour

    Implementing the (virtual) bytesAvailable function for the derives QUIDevice class did the trick. It remains a mystery why the Linux implementation apaprently does not require that and rhe windows ine does
    (Both are 6.8.1)

  3. The following user says thank you to janK for this useful post:

    d_stranz (10th January 2025)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,327
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt Audio in Linux and Windows: different behaviour

    Implementing the (virtual) bytesAvailable function for the derives QUIDevice class did the trick.
    I assume you meant QIODevice. It would be nice if you could post your code for that to help others who might experience the same problem in the future and come across this thread looking for an answer.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #4
    Join Date
    Mar 2008
    Posts
    51
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Qt Audio in Linux and Windows: different behaviour

    Quote Originally Posted by d_stranz View Post
    I assume you meant QIODevice. It would be nice if you could post your code for that to help others who might experience the same problem in the future and come across this thread looking for an answer.
    The siruation was roughly as sketched below, a derived class from QIODevice was used and sound was output under Linux and silence was output under Windows
    Under windows, the AudioSink that was use to embed the derived QIODevice class gave state Idle under Window and Active under Linux
    The read function implemented in the derived QIOdevice class always gives the required amount of bytes back, taken from abuffer and a shortage, if appearing, filled with o bytes.
    The original version differs from the one given below by not having impmented the "bytesAvailable" function and the "sze" function.
    After implementing the bytesAvailable function itworked fine. Appparently the Windows version of AudioSink - when started- first looks at the bytesAvailable function, while the
    same class in the Linux version does not.

    The amount returned by the bytesAvailable function did not matter, as long as the (virtual) function is reimplemented and returns a value > 0 it works fine (again, given that the read function always returns the
    requested amount

    In both cases it was version 6.8.1.

    Qt Code:
    1. Qt_AudioDevice::~Qt_AudioDevice () {
    2. close ();
    3. }
    4.  
    5. void Qt_AudioDevice::start () {
    6. bool b = open (QIODevice::ReadOnly);
    7. }
    8.  
    9. // we always return "maxSize" bytes
    10. qint64 Qt_AudioDevice::readData (char* buffer, qint64 maxSize) {
    11. // "maxSize" is the requested size in bytes
    12. // "amount" is in uint8_t's
    13. amount = Buffer -> getDataFromBuffer (buffer, maxSize);
    14. if (amount < maxSize) {
    15. for (int i = amount; i < maxSize; i ++)
    16. buffer [i] = (char)(0);
    17. }
    18. }
    19.  
    20. // usused here
    21. qint64 Qt_AudioDevice::writeData (const char* data, qint64 len) {
    22. Q_UNUSED (data);
    23. Q_UNUSED (len);
    24. return 0;
    25. }
    26.  
    27.  
    28. qint64 Qt_AudioDevice::bytesAvailable () const {
    29. return 32768;
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by d_stranz; 16th January 2025 at 16:42. Reason: missing [code] tags

  6. The following user says thank you to janK for this useful post:

    d_stranz (16th January 2025)

Similar Threads

  1. Left audio channel intermittently drops out (QAudioOutput, Linux)
    By QtDrivesMeCrazy in forum Qt Programming
    Replies: 0
    Last Post: 1st March 2016, 23:09
  2. Replies: 5
    Last Post: 10th June 2014, 11:26
  3. Replies: 0
    Last Post: 8th December 2011, 12: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, 05:17
  5. Replies: 2
    Last Post: 4th June 2009, 16: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.