--- soundsourceoggvorbis.h 2005-08-11 12:44:04.000000000 -0500 +++ soundsourceoggvorbis.patched.h 2008-06-09 12:40:21.000000000 -0500 @@ -41,6 +41,7 @@ int current_section; unsigned long ret, needed, index; SAMPLE* dest; + char* pRead; }; #endif --- soundsourceoggvorbis.cpp 2008-05-11 10:27:38.000000000 -0500 +++ soundsourceoggvorbis.patched.v1.cpp 2008-06-09 13:21:53.000000000 -0500 @@ -41,7 +41,10 @@ Class for reading Ogg Vorbis */ -SoundSourceOggVorbis::SoundSourceOggVorbis(QString qFilename) : SoundSource(qFilename) +SoundSourceOggVorbis::SoundSourceOggVorbis(QString qFilename) +: SoundSource(qFilename) +, dest (0) +, pRead(0) { QByteArray qBAFilename = qFilename.toUtf8(); vorbisfile = fopen(qBAFilename.data(), "r"); @@ -112,28 +115,23 @@ unsigned SoundSourceOggVorbis::read(volatile unsigned long size, const SAMPLE * destination) { - dest = (SAMPLE *) destination; - index = 0; + pRead = (char*) destination; + dest = (SAMPLE*) destination; + + index = ret = 0; needed = size*channels; // loop until requested number of samples has been retrieved - while (needed > 0) + do { - // read samples into buffer - ret = ov_read(&vf,(char *) dest+index,needed, OV_ENDIAN_ARG, 2, 1, ¤t_section); - // if eof we fill the rest with zero - if (ret == 0) - { - while (needed > 0) - { - dest[index] = 0; - index++; - needed--; - } - } - index += ret; + index += ret; needed -= ret; - } + + // read samples into buffer + ret = ov_read(&vf, pRead+index, needed, OV_ENDIAN_ARG, 2, 1, ¤t_section); + + // stop loop if requested amount was read (needed==0) or end of file was reached (ret==0) or an error occured (ret<0) + } while (needed > 0 && ret > 0); // convert into stereo if file is mono if (channels == 1)