Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: OGG file loops first second repeatedly, but WAV file loops correctly  (Read 4017 times)

0 Members and 1 Guest are viewing this topic.

kr3nshaw

  • Guest
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;
}
« Last Edit: April 30, 2019, 05:59:58 pm by kr3nshaw »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Is the behavior the same without your custom Archive stream (ie. using a true OGG file on the disk)?
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
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.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
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.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
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.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
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.
« Last Edit: May 02, 2019, 04:21:46 pm by Laurent »
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
I'm glad you made it work, even if you don't understand why ;D
Laurent Gomila - SFML developer

 

anything