Hi, I have posted this problem in two other places but found no solution. So I am posting it here.

How can I implement full duplex audio communication in Qt? That is, I want to record sound from the microphone and at the same time I want to play the sound
on the headphone/speaker.

The code that I have tried so far is as below -

Qt Code:
  1. void AudioRecorder::on_btnStart_clicked()
  2. {
  3. // Get audio format and search for nearest matching format of the device
  4. QAudioFormat format = this->getFormat();
  5.  
  6. // Star recording using the specified format
  7. this->audioInput = new QAudioInput(format, this);
  8. connect(this->audioInput,SIGNAL(stateChanged(QAudio::State)),
  9. SLOT(inputStateChanged(QAudio::State)));
  10. QIODevice *myBuffer = this->audioInput->start();
  11.  
  12. this->audioOutput = new QAudioOutput(format, this);
  13. connect(this->audioOutput,SIGNAL(stateChanged(QAudio::State)),
  14. SLOT(outputStateChanged(QAudio::State)));
  15. this->audioOutput->start(myBuffer);
  16. }
  17.  
  18. QAudioFormat AudioRecorder::getFormat()
  19. {
  20. QAudioFormat format;
  21. format.setFrequency(8000);
  22. format.setChannels(1);
  23. format.setSampleSize(8);
  24. format.setCodec("audio/pcm");
  25. format.setByteOrder(QAudioFormat::LittleEndian);
  26. format.setSampleType(QAudioFormat::UnSignedInt);
  27.  
  28. QAudioDeviceInfo info = QAudioDeviceInfo::defaultInputDevice();
  29. if (!info.isFormatSupported(format))
  30. {
  31. this->log("Default format not supported. Trying to use the nearest format.....");
  32. format = info.nearestFormat(format);
  33. }
  34.  
  35. return format;
  36. }
To copy to clipboard, switch view to plain text mode 

The only problem is that in linux this code runs for some time but after that the output device faces an Underrun Error (I have checked that in the stateChanged slot) and in windows this program crashes just after it's run.

How can I solve this problem? Is there any other method for full duplex audio communication?