[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.



  • What is the file Format of the audio file? That click is probably the header of the wave file?



  • 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



  • Skipping the header file leads to no click at all.
    I'm going to parse the header to extract the actual audio format - anyway it's a pity Qt doesn't handle this by itself!

    Thanks



  • Solved using the class you linked. Thanks again



  • I agree, I also think that Qt should provide the reading/writing of Audio files, at least for some basic formats ...


Log in to reply
 

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