Git commit bdae4e5eca0945a96b7012007dbf56ba848d98ca by Laszlo Papp. Committed on 06/12/2011 at 00:53. Pushed by lpapp into branch 'master'. Better support for things, like sample rate, channels getters, error manage= ment M +2 -0 src/CMakeLists.txt M +18 -12 src/qalvorbisfileaudiodecoder.cpp http://commits.kde.org/qtopenal/bdae4e5eca0945a96b7012007dbf56ba848d98ca diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 138c104..480c278 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ set(QtOpenAL_SRCS qalcontext.cpp qalsndaudiodecoder.cpp qalsource.cpp + qalvorbisfileaudiodecoder.cpp ) = set(QtOpenAL_HEADERS @@ -61,6 +62,7 @@ set(QtOpenAL_HEADERS qalcontext.h qalsndaudiodecoder.h qalsource.h + qalvorbisfileaudiodecoder.h ${CMAKE_CURRENT_BINARY_DIR}/qtopenal_global.h ) = diff --git a/src/qalvorbisfileaudiodecoder.cpp b/src/qalvorbisfileaudiodeco= der.cpp index 8930eab..5c9c104 100644 --- a/src/qalvorbisfileaudiodecoder.cpp +++ b/src/qalvorbisfileaudiodecoder.cpp @@ -46,13 +46,15 @@ class QALVorbisFileAudioDecoder::Private QFile file; = QByteArray encodedData; - OggVorbis_File* oggVorbisFile; + OggVorbis_File *oggVorbisFile; + vorbis_info vorbisInfo; }; = int QALVorbisFileAudioDecoder::Private::closeCallback(void *datasource) { reinterpret_cast(datasource)->fil= e.close(); + return 0; } = @@ -129,17 +131,19 @@ QALVorbisFileAudioDecoder::open(const QString &fileNa= me) d->file.setFileName(fileName); = ov_callbacks oggVorbisCallbacks; - oggVorbisCallbacks.close_func =3D &d->fileLengthCallback; - oggVorbisCallbacks.seek_func =3D &d->seekCallback; + oggVorbisCallbacks.close_func =3D &d->closeCallback; oggVorbisCallbacks.read_func =3D &d->readCallback; + oggVorbisCallbacks.seek_func =3D &d->seekCallback; oggVorbisCallbacks.tell_func =3D &d->tellCallback; = - int error =3D 0; - if ((error =3D ov_open_callbacks(d, d->oggVorbisFile, 0, 0, &oggVofbis= Callback) < 0)) { + int error; + if ((error =3D ov_open_callbacks(d, d->oggVorbisFile, 0, 0, oggVorbisC= allbacks) < 0)) { qWarning() << Q_FUNC_INFO << "Failed to open the file" << fileName= .toUtf8().constData() << "for decoding:" << error; return false; } = + d->vorbisInfo =3D *ov_info(d->oggVorbisFile, -1); + return true; } = @@ -157,8 +161,9 @@ QALVorbisFileAudioDecoder::pos() bool QALVorbisFileAudioDecoder::seek(qint64 pos) { - if (sf_seek(d->sndFile, pos, SEEK_SET) =3D=3D -1) { - qWarning() << Q_FUNC_INFO << "Failed to seek in the file:" << sf_s= trerror(d->sndFile); + int error; + if ((error =3D sf_seek(d->sndFile, pos, SEEK_SET) =3D=3D -1)) { + qWarning() << Q_FUNC_INFO << "Failed to seek in the file:" << erro= r; return false; } = @@ -168,8 +173,9 @@ QALVorbisFileAudioDecoder::seek(qint64 pos) bool QALVorbisFileAudioDecoder::close() { - if (ov_clear(d->oggVorbisFile)) { - qWarning() << Q_FUNC_INFO << "Failed to close the file:" << sf_st= rerror(d->sndFile); + int error; + if ((error =3D ov_clear(d->oggVorbisFile))) { + qWarning() << Q_FUNC_INFO << "Failed to close the file:" << error; return false; } = @@ -185,19 +191,19 @@ QALVorbisFileAudioDecoder::setEncodedData(const QByte= Array &encodedData) int QALVorbisFileAudioDecoder::channels() const { - return d->sfInfo.channels; + return d->vorbisInfo.channels; } = int QALVorbisFileAudioDecoder::sampleRate() const { - return d->sfInfo.samplerate; + return d->vorbisInfo.rate; } = int QALVorbisFileAudioDecoder::sampleSize() const { - return 16; + return d->vorbisInfo.bitrate_nominal; } = QByteArray