Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]: click when reproducing audio

[SOLVED]: click when reproducing audio

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Mark_
    wrote on 1 Mar 2014, 06:32 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vidar
      wrote on 1 Mar 2014, 06:52 last edited by
      #2

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

      1 Reply Last reply
      0
      • _ Offline
        _ Offline
        _Mark_
        wrote on 1 Mar 2014, 06:56 last edited by
        #3

        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"
        @

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vidar
          wrote on 1 Mar 2014, 07:25 last edited by
          #4

          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

          1 Reply Last reply
          0
          • _ Offline
            _ Offline
            _Mark_
            wrote on 1 Mar 2014, 07:33 last edited by
            #5

            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

            1 Reply Last reply
            0
            • _ Offline
              _ Offline
              _Mark_
              wrote on 1 Mar 2014, 07:40 last edited by
              #6

              Solved using the class you linked. Thanks again

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vidar
                wrote on 1 Mar 2014, 09:27 last edited by
                #7

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

                1 Reply Last reply
                0

                1/7

                1 Mar 2014, 06:32

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved