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

Author Topic: Seamless transition for a looping section  (Read 4496 times)

0 Members and 1 Guest are viewing this topic.

metafurionx

  • Newbie
  • *
  • Posts: 13
    • View Profile
Seamless transition for a looping section
« on: October 11, 2017, 01:34:34 pm »
Using VS2015, C++, SFML 2.4.1, sf::Music class.
I have a .ogg music file with an intro-body-outro structure. I play its intro once, then loop the body indefinitely.

I achieved this by adding
if (my_music.getPlayingOffset().asMilliseconds() > end_of_body)
my_music.setPlayingOffset(sf::milliseconds(beginning_of_body);
inside of
while(my_render_window.isOpen())

However, when the transition occurs, the song hiccups. What should I do there to make it seamless?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Seamless transition for a looping section
« Reply #1 on: October 11, 2017, 01:39:17 pm »
The next version of SFML (and thus the current revision on git) has built-in support for loop points in sf::Music, chances are that it works better than your workaround ;)
Laurent Gomila - SFML developer

metafurionx

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Seamless transition for a looping section
« Reply #2 on: October 11, 2017, 06:46:40 pm »
Sure; did it.

my_music.setLoopPoints(sf::Music::TimeSpan(sf::milliseconds(beginning_of_body), sf::milliseconds(end_of_body - beginning_of_body)));

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Seamless transition for a looping section
« Reply #3 on: October 12, 2017, 06:37:56 am »
No more hiccups?
Laurent Gomila - SFML developer

metafurionx

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Seamless transition for a looping section
« Reply #4 on: October 12, 2017, 02:30:33 pm »
No more hiccups?
Nope, it loops smoothly now. Thank you very much. :)

BTW I only compiled the Audio library (statically for my project) and swapped it and the new OpenAL .dll with the old ones.
Will switch everything when you guys release the stable version.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Seamless transition for a looping section
« Reply #5 on: October 16, 2017, 11:57:45 am »
I came up with a similar solution as it is sometimes necessary to loop long sounds (sf::Sound) rather than musics (sf::Music).
The trick here, as you found, is to remove the length of the loop from the current position so that it is back inside the loop. However, it can skips the first part of the loop because it has played past the loop's end; therefore, the beginning part of the loop should be present again in the sound to allow for the overlap.

Now, if SFML could set loop points for sf::Sound, I would be much happier :P
(I tried multiple ways to do this but it seems that it requires the direct access to OpenAL stuff to achieve it properly)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

metafurionx

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Seamless transition for a looping section
« Reply #6 on: December 11, 2017, 07:29:14 pm »
BTW I only compiled the Audio library (statically for my project) and swapped it and the new OpenAL .dll with the old ones.
The new OpenAL.dll (616 KB) had issues in WinXP, sounds were choppy. Reverted to previous (414 KB). Loop points still ok.

 

anything