SFML community forums

Help => Audio => Topic started by: Mr. Yes on December 07, 2011, 03:46:06 am

Title: SetPlayingOffset: interesting bug!
Post by: Mr. Yes on December 07, 2011, 03:46:06 am
Hello!

I've come upon what I believe to be somewhat of a glitch, here. Please correct me if I'm doing something wrong, but there appears to be a point wherein SetPlayingOffset causes SFML to stream an incorrect part of the audio file.

Code: [Select]

#include <SFML/Audio.hpp>

int main()
{
    sf::Music music;
    music.OpenFromFile("song.ogg");
    music.Play();
    music.SetPlayingOffset(97392);
    while (music.GetStatus() == sf::Music::Playing){}
   
    return 0;
}


I tested this short snippet with a file that contains one second of white noise at the very beginning and 199 seconds of silence. When run (for me), this program will immediately play the white noise.

That number, 97392, is interesting - any lower and it sets the offset correctly and the white noise does not play. I believe there are several other points later in the file that cause this odd behavior as well.

Again, I may be doing something stupid here. Let me know!
Title: SetPlayingOffset: interesting bug!
Post by: Ceylo on December 07, 2011, 06:43:39 am
What happens if you call SetPlayingOffset() before Play() ?
Title: SetPlayingOffset: interesting bug!
Post by: Mr. Yes on December 07, 2011, 07:12:56 am
Unfortunately, the same thing. Changing the order doesn't seem to make a difference.
Title: SetPlayingOffset: interesting bug!
Post by: Laurent on December 07, 2011, 07:42:55 am
If your music parameters are either 22050 Hz sample rate with 2 channels, or 44100 Hz sample rate with 1 channel, then the internal calcucations in sf::SoundStream::SetPlayingOffset produce approximately 2^32 with a position of 97392. Which is stored in a 32-bits integer -- so it overflows.

This bug is already fixed in SFML 2.

Ceylo should have known that :lol:
Title: SetPlayingOffset: interesting bug!
Post by: Ceylo on December 07, 2011, 04:44:31 pm
Well I just couldn't remember exactly that bug so... and from what I remember it was about GetPlayingOffset(), not SetPlayingOffset(). Anyway.. !
Title: SetPlayingOffset: interesting bug!
Post by: Mr. Yes on December 07, 2011, 07:24:59 pm
It definitely isn't a GetPlayingOffset problem - that still works fine. This only occurs after using SetPlayingOffset.

Anyway, thanks for the speedy reply! However, I've been using the latest SFML 2.0 snapshot as of November 6th. How recently was this fixed?
Title: SetPlayingOffset: interesting bug!
Post by: Laurent on December 07, 2011, 10:04:40 pm
It was fixed the 8th of august.

Can you upload your music file, so that I can test it?
Title: SetPlayingOffset: interesting bug!
Post by: Mr. Yes on December 07, 2011, 10:22:12 pm
Yeah, here you go:

http://dl.dropbox.com/u/507182/song.ogg
Title: SetPlayingOffset: interesting bug!
Post by: Laurent on December 09, 2011, 08:57:56 pm
There was another bug. It's fixed now.

Thanks for your feedback :)
Title: SetPlayingOffset: interesting bug!
Post by: Mr. Yes on December 10, 2011, 02:06:24 am
Beautiful! Works perfectly.