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

Author Topic: Increasing Sound::GetPlayingOffset() precision  (Read 3587 times)

0 Members and 1 Guest are viewing this topic.

Notnasiul

  • Newbie
  • *
  • Posts: 10
    • View Profile
Increasing Sound::GetPlayingOffset() precision
« on: July 23, 2011, 05:00:04 pm »
Hi! First post in these forums : ) First of all, congratulations for this great library.

I'm working with sound in a project that is closely related to a karaoke. Therefore, I need access to sound buffers. At some point,  sound/music is playing and I must get the raw values from the buffer from the exact playing offset.

It's easy by knowing its sample rate and the playing offset. However, sound.GetPlayingOffset() returns floats with just two decimals (e.g. 2.23) so the resolution is pretty low.

If I use Clock.GetElapsedTime() the precision is higher (e.g. 2.23154), which is more discriminative. Just see this example:

2.22 x 44100 -> 97902
2.23 x 44100 -> 98343

There are like 1000 samples lost in just 1/100 seconds. But it's even worse: many consecutive calls return the same playing offset, so I get the same sample even when time has obviously advanced (a few milliseconds, but it's not the same)

If I do something like this (just imagine that Sound is already playing):

Code: [Select]
std::cout << Clock.GetElapsedTime() << " " << Sound.GetPlayingOffset() << std::endl

see how Clock is much more precise than GetPlayingOffset in this few samples:

0.060948 0.06
0.0629533 0.06
0.0649569 0.06
0.0667986 0.06
0.0687719 0.06
0.0704301 0.07
0.072469 0.07
0.074509 0.07
0.0758784 0.07
0.0778292 0.07

I hope I managed to explain myself... Is it possible to increase GetPlayingOffset somehow?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Increasing Sound::GetPlayingOffset() precision
« Reply #1 on: July 23, 2011, 06:49:07 pm »
This is the value which is directly returned by OpenAL, I can't make it more precise.

But you should try SFML 2, maybe it's already fixed ;) And if not, then we'll be able to test and see if it can somehow be improved.
Laurent Gomila - SFML developer

Notnasiul

  • Newbie
  • *
  • Posts: 10
    • View Profile
Increasing Sound::GetPlayingOffset() precision
« Reply #2 on: July 24, 2011, 12:11:42 am »
What a pity... Well, is SFML2 reliable enough for a relatively big project? :D I know I can download it from sourceforge but, when is it expected to be released?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Increasing Sound::GetPlayingOffset() precision
« Reply #3 on: July 24, 2011, 12:18:27 am »
Quote from: "Notnasiul"
Well, is SFML2 reliable enough for a relatively big project? :D
I think so, and it is especially more reliable than SFML 1.6. There are some API modifications to expect until the final release, but you can already make use of many new features and bugfixes since SFML 1.

Quote from: "Notnasiul"
I know I can download it from sourceforge but, when is it expected to be released?
You can download it from GitHub, not Sourceforge anymore ;)

And there is no fixed release date.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Notnasiul

  • Newbie
  • *
  • Posts: 10
    • View Profile
Increasing Sound::GetPlayingOffset() precision
« Reply #4 on: July 24, 2011, 12:36:51 am »
Um... I may consider adopting SFML 2 for this project. Thanks!

Mecha the Slag

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • http://mechatheslag.net
Increasing Sound::GetPlayingOffset() precision
« Reply #5 on: March 10, 2012, 11:55:54 am »
Hi. Would just like to say that this is still an issue in SFML 2.0. Since I am making a game that requires precision in the audio, this is an issue for me.

It may not be SFML's fault, but I'm just notifying anyone else who may get here through Google that SFML 2.0 does not fix the issue :P

For the record, this is the issue:

Quote

Audio time: 6.80309
Audio time: 6.80309

Audio time: 6.82631
Audio time: 6.82631
Audio time: 6.82631
Audio time: 6.82631

Audio time: 6.84953
Audio time: 6.84953
Audio time: 6.84953
Audio time: 6.84953
Audio time: 6.84953
Audio time: 6.84953

Audio time: 6.87275
Audio time: 6.87275
Audio time: 6.87275
Audio time: 6.87275
Audio time: 6.87275

Audio time: 6.89597
Audio time: 6.89597
Audio time: 6.89597

Audio time: 6.91919
Audio time: 6.91919
Audio time: 6.91919



it's "jumpy"

Tex Killer

  • Full Member
  • ***
  • Posts: 242
    • View Profile
Increasing Sound::GetPlayingOffset() precision
« Reply #6 on: March 10, 2012, 03:12:49 pm »
As far as I know, the current playing offset is updated at each audio buffer fill.

The buffer is refilled each time it runs out, so it is not constant, and that should be why the playing offset is jumping like that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Increasing Sound::GetPlayingOffset() precision
« Reply #7 on: March 10, 2012, 05:43:39 pm »
Can you do this test for a sf::Sound and a sf::Music, and compare the results?
Laurent Gomila - SFML developer