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. How to load sounds without route them directly to hardware?
Forum Updated to NodeBB v4.3 + New Features

How to load sounds without route them directly to hardware?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k Views 1 Watching
  • 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.
  • Z Offline
    Z Offline
    Zylann
    wrote on last edited by
    #1

    Hi,
    I am searching for a way to load sound files (WAV, OGG/Vorbis, MP3...) for accessing their samples, without send them to the hardware for playing (like would do a QSound) and to access raw samples data.

    The QAudioDecoder seems to suit my needs, both for full or stream loading.
    However, when I include it to my source code the compiler says "QAudioDecoder: No such file or directory". By the way, the documentation says that "This class is under development and is subject to change.". It is finally useable or not?

    If not, what are the alternatives? I tried libsndfile but "had some issues with it":http://qt-project.org/forums/viewthread/25837/ :(

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      QAudioDecoder is part of the multimedia module, so you need to add this to your .pro file:
      @
      Qt += multimedia
      @
      As for whether or not it is usable - I don't know, check. If it works it works :)

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zylann
        wrote on last edited by
        #3

        Oh, thanks I forgot to write this line... so QAudioDecoder can be used now :)
        But when I try to load a sound (kinda... I'm not even following a tutorial for this) I get an error in the console :

        defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.audiodecode"

        Am I doing something wrong?
        I found "another post":http://qt-project.org/forums/viewthread/25059 mentionning this problem, but it wasn't solved...

        @ QAudioFormat format;
        format.setSampleType(QAudioFormat::SignedInt);
        format.setSampleSize(16);

        QAudioDecoder decoder;
        decoder.setAudioFormat(format);
        decoder.setSourceFilename(filepath.c_str());
        
        decoder.start(); // << Problem here... I think
        
        if(!decoder.bufferAvailable())
        {
            std::cout << "ERROR: SoundEngine::loadSound:"
                << "No sample available" << std::endl;
            decoder.stop();
            return false; // No buffers to read
        }
        
        // Extract all samples
        std::vector<short> samples;
        unsigned int sampleCount = 0;
        while(decoder.bufferAvailable())
        {
            // Get next buffer
            QAudioBuffer qbuf = decoder.read();
        
            // Increase container size
            // Note : a sample is ONE number of the waveform.
            // For example, there is two samples per stereo frame (left and right).
            const unsigned int i = samples.size();
            samples.resize(samples.size() + qbuf.sampleCount(), 0);
        
            // Copy samples from the buffer to the container
            memcpy(&samples[i], qbuf.constData(), qbuf.byteCount());
        
            sampleCount += qbuf.sampleCount();
        }
        

        @

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chenmo20074639
          wrote on last edited by
          #4

          defaultServiceProvider::requestService(): no service found for – “org.qt-project.qt.audiodecode”

          have you any answer now ???
          I meet this problem too,

          1 Reply Last reply
          0

          • Login

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