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

Author Topic: Playing sound at precise timing.  (Read 3208 times)

0 Members and 1 Guest are viewing this topic.

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
Playing sound at precise timing.
« on: November 21, 2015, 06:22:44 am »
Because of my game's framerate, playing a sound at a certain time will only trigger at a frame after that time, so i cannot get it precise. I've had the idea of adding some empty sound to the start of the sound (50ms or so) and playing it 50ms before and taking away the offset when it actually gets called to play, however, i have many small sounds which would cause my program to have an even greater RAM usage (even if it's only 50ms, it may still end up being a lot when i have 731 small sounds)
So my question is, can i make a sound play at a precise time independent of the game's framerate? (Possibly seeking negatively before the sound?)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Playing sound at precise timing.
« Reply #1 on: November 29, 2015, 08:41:26 pm »
What kind of application are you writing that you notice if a sound plays 1 frame sooner or later? Is your framerate that extremely low?

I don't see how the delay between calling sf::Sound::play() and the sound actually playing is related to the framerate -- sounds are played in their own independent threads.

You could do some operations earlier (buffer allocation, sound instantiation), maybe even experiment with play + pause + later play.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Playing sound at precise timing.
« Reply #2 on: November 29, 2015, 08:56:34 pm »
Maybe he's recording it and can then step through frame by frame.

Also keep in mind that SFML uses some buffers which are sent to OpenAL, so there's no 0 delay playback.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Playing sound at precise timing.
« Reply #3 on: November 30, 2015, 12:15:14 am »
I've had times when sounds have been rather delayed too but it's not all the time. Sometimes, just closing everything and restarting/rebuilding can fix it (temporarily).
I'd suggest making sure your audio drivers are correct, up-to-date, and set up properly. Pay attention also to the latency setting if you have one.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything