Linux audio stops reading



  • I’ve got a desktop application that allows you test your audio configuration by sending and receiving audio between your local devices (typically a headset mic and headset speaker of some sort).

    It works fine on Windows but on Linux (Ubuntu 14.04 32-bit in particular) it stops reading from the output device. I created a simple stripped down program which seems to work using my stripped down subclass of QIODevice but stops reading when using QBuffer as the device. I’d like to know why it doesn’t work when using QBuffer because my real (non-stripped down) subclass of QIODevice has similar behavior (audio stops reading from output device).
    At first I thought it was because I wasn’t emitting readyRead signals but adding them didn’t help and my stripped down subclasss of QIODevice appears to work fine without them.

    Here is the method that starts playing audio. The entire application can be found here

    void MainWindow::start() {
       QAudioDeviceInfo inputDevinfo = QAudioDeviceInfo::defaultInputDevice();
       QAudioFormat audioFormat;
       audioFormat.setCodec("audio/pcm");
       audioFormat.setSampleRate(44100);
       audioFormat.setChannelCount(2);
       audioFormat.setSampleSize(16);
       audioFormat.setSampleType(QAudioFormat::SignedInt);
       audioFormat.setByteOrder(QAudioFormat::LittleEndian);
    
       if (!inputDevinfo.isFormatSupported(audioFormat)) {
          //Default format not supported - trying to use nearest
          audioFormat = inputDevinfo.nearestFormat(audioFormat);
       }
    
       QAudioDeviceInfo outputDevinfo = QAudioDeviceInfo::defaultOutputDevice();
       if (!outputDevinfo.isFormatSupported(audioFormat)) {
           //Default format not supported - trying to use nearest
           audioFormat = outputDevinfo.nearestFormat(audioFormat);
       }
       qInfo() << "Input:" << inputDevinfo.deviceName()
               << " Output:" << outputDevinfo.deviceName();
       qInfo() << "audioInput format: " << audioFormatToString(audioFormat);
       qInfo() << "audioOutput format:" << audioFormatToString(audioFormat);
    
       audioInput = new QAudioInput(inputDevinfo, audioFormat, this);
       connect(audioInput, SIGNAL(stateChanged(QAudio::State)),
               this, SLOT(onAudioInputStateChanged(QAudio::State)));
       connect(audioInput, SIGNAL(notify()), this, SLOT(onAudioInputNotify()));
    
       audioOutput = new QAudioOutput(outputDevinfo, audioFormat, this);
       connect(audioOutput, SIGNAL(stateChanged(QAudio::State)),
               this, SLOT(onAudioOutputStateChanged(QAudio::State)));
       connect(audioOutput, SIGNAL(notify()), this, SLOT(onAudioOutputNotify()));
    
       // Using MyDevice on both CentOs 7 x64 and Ubuntu 14.04 x32 seems to work.
       // Although, I don't hear anything, reads and writes from/to the device
       // continue until stopped by the UI.
       //
       // However using QBuffer, on both CentOs 7 x64 and Ubuntu 14.04 x32 the
       // program promptly stops reading while the writes continue eventually
       // exhausting memory.
       //
       // Why does the program stop reading from QBuffer ?
       //
       // I need to know because the behavior of my real application is similar
       // to the behavior being exhibited by QBuffer and I'm not sure how to fix it.
       // I've tried emit(readyRead()) but that didn't help.
    
    //   buffer = new MyDevice(this);     // seems to work although I don't hear anything.
       buffer = new QBuffer();          // stops reading.  Why ?
    
       buffer->open(QIODevice::ReadWrite);
    
       audioInput->start(buffer);
       audioOutput->start(buffer);
    
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.