I am using Qt 4.8 with Qt Creator 2.4.1 on Windows 7 Ultimate x64.
I take audio input using the QAudioInput class and play it using QAudioOutput . There is a 2 second timeout after which I stop accepting input, and then I configure the output as follows:
class MainWindow { // ... QByteArray output_data; QBuffer output_data_buffer; QAudioOutput *audio_out; // ... }; MainWindow::MainWindow(QWidget *parent) { // ... output_data_buffer.setBuffer(&output_data); // ... } void MainWindow::audioInputStopped(QByteArray data) { output_data = data; output_data_buffer.open(QIODevice::ReadOnly); audio_out = new QAudioOutput(audio_format, this); connect(audio_out, SIGNAL(stateChanged(QAudio::State)), SLOT(audioOutputStateChanged(QAudio::State))); audio_out->start(&output_data_buffer); }
The audio format used is supported by both input devices and outputs. I checked them using QAudioDeviceInfo::isFormatSupported() . A sound of 2 seconds ( data in audioInputStopped() ) always plays normally.
In the audioOutputStateChanged slot audioOutputStateChanged I always encounter the QAudio::UnderrunError from audio_out->error() after the buffer has finished playing. After calling audio_out->start() state (passed as a parameter to audioOutputStateChanged() ) and the error occurs as follows:
- Error. Active state.
- Error. The state is stopped.
- Overflow error. Idle state.
Note that I am stopping audio_out in the standby state according to this example . Why does the code encounter an underload error? This is normal?
source share