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

Author Topic: SetPlayingOffset: interesting bug!  (Read 4710 times)

0 Members and 2 Guests are viewing this topic.

Mr. Yes

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SetPlayingOffset: interesting bug!
« 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!

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SetPlayingOffset: interesting bug!
« Reply #1 on: December 07, 2011, 06:43:39 am »
What happens if you call SetPlayingOffset() before Play() ?
Want to play movies in your SFML application? Check out sfeMovie!

Mr. Yes

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SetPlayingOffset: interesting bug!
« Reply #2 on: December 07, 2011, 07:12:56 am »
Unfortunately, the same thing. Changing the order doesn't seem to make a difference.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetPlayingOffset: interesting bug!
« Reply #3 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:
Laurent Gomila - SFML developer

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
SetPlayingOffset: interesting bug!
« Reply #4 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.. !
Want to play movies in your SFML application? Check out sfeMovie!

Mr. Yes

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SetPlayingOffset: interesting bug!
« Reply #5 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetPlayingOffset: interesting bug!
« Reply #6 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?
Laurent Gomila - SFML developer

Mr. Yes

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SetPlayingOffset: interesting bug!
« Reply #7 on: December 07, 2011, 10:22:12 pm »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SetPlayingOffset: interesting bug!
« Reply #8 on: December 09, 2011, 08:57:56 pm »
There was another bug. It's fixed now.

Thanks for your feedback :)
Laurent Gomila - SFML developer

Mr. Yes

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Email
SetPlayingOffset: interesting bug!
« Reply #9 on: December 10, 2011, 02:06:24 am »
Beautiful! Works perfectly.