[SOLVED]: click when reproducing audio
-
Hello,
following the documentation I use this code to play a wave file:@
m_sourceFile.setFileName(filename);
m_sourceFile.open(QIODevice::ReadOnly);QAudioFormat format; format.setSampleRate(44100); format.setChannelCount(2); format.setSampleSize(16); format.setCodec("audio/pcm"); format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(format)) { qWarning() << "Raw audio format not supported by backend, cannot play audio."; return; } m_audio = new QAudioOutput(format, this); m_audio->start(&m_sourceFile);
@
But when the audio start I hear a "click" noise.
Playing the some file with another player (aplay for example) there is no such a noise.My platform is Raspberry Pi, Qt5.2, custom buildroot image.
-
It's a standard PCM Wave, 44100 Hz, 16-bit Stereo.
Do you mean Qt doesn't take care of the header section!?
So, how to correctly play a standard wave file?I tried with QMediaPlayer but I get the following warning and no audio:
@
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
@ -
You'll have to read the header yourself and set the output format accordingly. You can find the header definition here: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ or take a look at http://qt-project.org/doc/qt-4.8/demos-spectrum-app-wavfile-cpp.html