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. Why does QSoundEffect play sounds poorly unlike QMediaPlayer?

Why does QSoundEffect play sounds poorly unlike QMediaPlayer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.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.
  • N Offline
    N Offline
    NightShadeI
    wrote on 2 Apr 2023, 07:13 last edited by
    #1

    I'm trying to play a very short sound (definitely less than a second , maybe 0.2 seconds)

    I notice the sound is clear and crisp from QMediaPlayer, but not from QSoundEffect in Qt6 using C++

    The start or end of the sound gets cutoff in QSoundEffect which sounds counter-intuitive given its optimised for things like this

    I notice many applications to play audio files have this issue, but some play it really smoothly just like QMediaPlayer

    My operating system is Windows 10

    C 1 Reply Last reply 2 Apr 2023, 07:50
    0
    • N NightShadeI
      2 Apr 2023, 07:13

      I'm trying to play a very short sound (definitely less than a second , maybe 0.2 seconds)

      I notice the sound is clear and crisp from QMediaPlayer, but not from QSoundEffect in Qt6 using C++

      The start or end of the sound gets cutoff in QSoundEffect which sounds counter-intuitive given its optimised for things like this

      I notice many applications to play audio files have this issue, but some play it really smoothly just like QMediaPlayer

      My operating system is Windows 10

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 2 Apr 2023, 07:50 last edited by
      #2

      Please show your code.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      N 1 Reply Last reply 2 Apr 2023, 12:04
      0
      • C Christian Ehrlicher
        2 Apr 2023, 07:50

        Please show your code.

        N Offline
        N Offline
        NightShadeI
        wrote on 2 Apr 2023, 12:04 last edited by
        #3

        Alright will share the code here, hadn't initially intended to provide it because I don't think it will be useful , and more fishing for an answer as to why the two are giving different results. Also I cannot provide the wav file by law, nonetheless, here is the relavent code:

        int main(int aArgc, char *aArgv[]) {
            QApplication myApplication{aArgc, aArgv};
        
            QMediaPlayer* myMediaPlayer = new QMediaPlayer;
            myMediaPlayer->setSource(QUrl::fromLocalFile("path/to/file.wav"));
            
            QAudioOutput* myMediaAudioOutput = new QAudioOutput;
            myMediaAudioOutput->setVolume(1.f);
            myMediaPlayer->setAudioOutput(myMediaAudioOutput);
            
            QSoundEffect* myEffectPlayer = new QSoundEffect{};
            myEffectPlayer->setSource(QUrl::fromLocalFile("path/to/file.wav"));
            myEffectPlayer->setVolume(1.f);
            myEffectPlayer->setLoopCount(1);
        
            // myEffectPlayer->play();
            myMediaPlayer->play();
        
            return myApplication.exec();
        }
        
        C 1 Reply Last reply 2 Apr 2023, 13:29
        0
        • N NightShadeI
          2 Apr 2023, 12:04

          Alright will share the code here, hadn't initially intended to provide it because I don't think it will be useful , and more fishing for an answer as to why the two are giving different results. Also I cannot provide the wav file by law, nonetheless, here is the relavent code:

          int main(int aArgc, char *aArgv[]) {
              QApplication myApplication{aArgc, aArgv};
          
              QMediaPlayer* myMediaPlayer = new QMediaPlayer;
              myMediaPlayer->setSource(QUrl::fromLocalFile("path/to/file.wav"));
              
              QAudioOutput* myMediaAudioOutput = new QAudioOutput;
              myMediaAudioOutput->setVolume(1.f);
              myMediaPlayer->setAudioOutput(myMediaAudioOutput);
              
              QSoundEffect* myEffectPlayer = new QSoundEffect{};
              myEffectPlayer->setSource(QUrl::fromLocalFile("path/to/file.wav"));
              myEffectPlayer->setVolume(1.f);
              myEffectPlayer->setLoopCount(1);
          
              // myEffectPlayer->play();
              myMediaPlayer->play();
          
              return myApplication.exec();
          }
          
          C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 2 Apr 2023, 13:29 last edited by
          #4

          @NightShadeI Ok, th code looks good and I don't see an obvious error. Please create a bug report and post the bug number here.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          N 1 Reply Last reply 2 Apr 2023, 21:56
          0
          • C Christian Ehrlicher
            2 Apr 2023, 13:29

            @NightShadeI Ok, th code looks good and I don't see an obvious error. Please create a bug report and post the bug number here.

            N Offline
            N Offline
            NightShadeI
            wrote on 2 Apr 2023, 21:56 last edited by NightShadeI 4 Feb 2023, 22:03
            #5

            @Christian-Ehrlicher Hi Chris, appreciate it. Unfortunately the provided link looks broken and provides me with a 404 not found

            edit: Just created one manually, please find here : QTBUG-112512

            C 1 Reply Last reply 3 Apr 2023, 05:42
            0
            • N NightShadeI
              2 Apr 2023, 21:56

              @Christian-Ehrlicher Hi Chris, appreciate it. Unfortunately the provided link looks broken and provides me with a 404 not found

              edit: Just created one manually, please find here : QTBUG-112512

              C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 3 Apr 2023, 05:42 last edited by
              #6

              @NightShadeI bugreports.qt.io

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              N 1 Reply Last reply 3 Apr 2023, 09:35
              0
              • C Christian Ehrlicher
                3 Apr 2023, 05:42

                @NightShadeI bugreports.qt.io

                N Offline
                N Offline
                NightShadeI
                wrote on 3 Apr 2023, 09:35 last edited by
                #7

                Yup can confirm this one is created here 🙂

                1 Reply Last reply
                0

                7/7

                3 Apr 2023, 09:35

                • Login

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