How to load sounds without route them directly to hardware?
-
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/ :(
-
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 :) -
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(); }
@
-
defaultServiceProvider::requestService(): no service found for – “org.qt-project.qt.audiodecode”
have you any answer now ???
I meet this problem too,