SFML community forums

Help => Audio => Topic started by: kr3nshaw on April 30, 2019, 05:50:38 pm

Title: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: kr3nshaw on April 30, 2019, 05:50:38 pm
It played correctly before I asked it to loop, but now it just loops the first second of the track. Watching the stream's position reveals that some part of the library is making the stream seek back to the beginning of the file, and I don't understand why. getSize correctly reports the size of the OGG file, so it's not as if the library doesn't know how long it is. I do get a message telling me that the loop points are invalid, so the library definitely isn't seeing the rest of the file, even though it's there.

What's even weirder is that if I convert the OGG file to a WAV file, it loops correctly. Does anyone know what I might be doing wrong?

Int64 Archive::read(void* data, Int64 size)
{
   ifs.read(reinterpret_cast<char*>(data), size);
   seek(position + size);

   return size;
}

Int64 Archive::seek(Int64 position)
{
   ifs.seekg(sectorTable[0] + position);

   return this->position = position;
}
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 01, 2019, 09:38:09 am
Is the behavior the same without your custom Archive stream (ie. using a true OGG file on the disk)?
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 01, 2019, 07:02:34 pm
So there might be something wrong with your Archive class. Try to debug calls to read / seek, log the arguments and returned values and try to see what's wrong when it loops.
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 02, 2019, 01:27:21 pm
Because the OGG reader and the WAV reader have nothing in common, and use the source stream in a different way. If you log the sequence of calls to your Archive stream, you'll most likely see a very different output for OGG and WAV. This might help you figuring which particular sequence triggers the bug.
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 02, 2019, 04:03:44 pm
Quote
I really have no idea where to go from here
Log the calls to your stream class made by ov_pcm_total. You can post them, maybe we'll see something.
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 02, 2019, 04:19:05 pm
Add some logging to your functions.

Int64 Archive::read(void* data, Int64 size)
{
   std::cout << "read " << size << " bytes at position " << position << std::endl;
   ...
}

Int64 Archive::seek(Int64 position)
{
   std::cout << "seek from " << this->position << " to " << position << std::endl;

   ...
}

Maybe log return values as well.

Also add a log just before and after the call to ov_pcm_total, so that you can focus on the relevant part.

By the way, I see that you never check the result of your standard stream calls, and blindly return as if everything were always ok. Maybe that's something that you could improve, to make your code more robust.
Title: Re: OGG file loops first second repeatedly, but WAV file loops correctly
Post by: Laurent on May 02, 2019, 04:53:33 pm
I'm glad you made it work, even if you don't understand why ;D