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

Author Topic: Seamless music looping  (Read 13877 times)

0 Members and 1 Guest are viewing this topic.

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« on: February 19, 2009, 07:40:41 pm »
Hello,

I've been using SDL_mixer for sound, and am looking for a replacement due to the fact that SDL_mixer is unable to loop streamed .ogg files seamlessly.

My understanding is that it's more or less impossible to loop .mp3 files seamlessly due to the way they're encoded, but as far as I can tell, .ogg files don't have this limitation (BASS and FMOD are both able to loop .ogg files with no problem).

I've tried SFML's basic music playback functions (and looked through the forums here for relevant information), and it appears that SFML has the same problem as SDL_mixer in this regard. However, I also see that SFML has a 'stream' base class, which I'm guessing might allow the looping behavior to be customized.

So, I have a couple of questions:

1. Would it be possible to implement seamless streamed .ogg looping using the 'stream' class? Has anyone had any luck doing this?

2. Can SDL and SFML run concurrently? That is, would there be any problem with using SDL for video and input, while using SFML for audio?

Thanks,
Jesse

(SFML looks like a great library, by the way :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #1 on: February 19, 2009, 11:10:47 pm »
1. It depends on the origin of the lag. It might be stb_vorbis, my streaming algorithm or the way looping is implemented. I'll have to investigate to find the source of this issue, and see what I can do about it.

2. No problem ;)
Laurent Gomila - SFML developer

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« Reply #2 on: February 20, 2009, 12:24:06 am »
Cool, thanks for the info.

I've tested a variety of .ogg files with several different sound libraries - BASS, FMOD, and IrrKlang are all able to loop the files seamlessly, while SDL_mixer and SFML introduce a gap or audio glitch at the loop point. I know SFML uses OpenAL under the hood - I haven't tried looping streamed audio directly using OpenAL, but Unity uses OpenAL as well and as far as I can tell it's able to loop .ogg files seamlessly.

Anyway, I just thought I'd share that info, in case it's useful. I have my own open-source project, so I know it's not easy to meet everyone's needs or fulfill every feature request :) For what it's worth though, I'd switch to SFML without a second thought if it were able to loop streamed audio seamlessly (not everyone needs this feature, I don't think, but with rhythmic or electronic music it's hard to do without).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #3 on: February 20, 2009, 07:46:48 am »
Quote
Anyway, I just thought I'd share that info, in case it's useful

It is :)
In fact I didn't know about this issue before, and whatever the source of the problem is, I think it can be fixed easily.

I'll let you know as soon as I have some results.
Laurent Gomila - SFML developer

SamuraiCrow

  • Newbie
  • *
  • Posts: 40
    • Yahoo Instant Messenger - samuraileumas
    • View Profile
Seamless music looping
« Reply #4 on: February 20, 2009, 08:25:59 pm »
I think the trick to seamless looping is to open a second Ogg file handle pointing to the beginning of the same file and start playing the second Ogg handle when the first reaches the end and switching back and forth between the handles.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #5 on: February 20, 2009, 08:37:21 pm »
Quote
I think the trick to seamless looping is to open a second Ogg file handle pointing to the beginning of the same file and start playing the second Ogg handle when the first reaches the end and switching back and forth between the handles.

I think I can do without such a trick ;)

Currently, my stream implementation waits for the music to finish and all buffers to be empty, before restarting the whole streaming process. That probably explains the lag.
Restarting the file while the last buffer is still playing should be enough to fix this issue, and shouldn't be too hard to implement.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #6 on: February 20, 2009, 10:42:13 pm »
I fixed the algorithm, it now loops perfectly seamlessly :)
You can get the latest sources from SVN if you want to test.

Thanks for your feedback.
Laurent Gomila - SFML developer

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« Reply #7 on: February 20, 2009, 10:54:53 pm »
I'll try it out and let you know how it goes :)

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« Reply #8 on: February 21, 2009, 01:07:11 am »
I tried it out with a number of different .ogg files, and they all looped perfectly! :)

So far I've only tried it in OS X. The looping works great, but stopping the music generates the following error:

Code: [Select]
An internal OpenAL call failed in SoundStream.cpp (276) : AL_INVALID_OPERATION, the specified operation is not allowed in the current state

Which refers to this line of code:

Code: [Select]
ALCheck(alDeleteBuffers(BuffersCount, myBuffers));

On one occasion it dropped into the debugger instead, but I haven't been able to reproduce that.

Previously I was using the last official SDK release. It didn't have this problem, so I'm assuming it's been introduced since then.

I'm running OS X 10.5.6 on a PowerPC Mac. Please let me know if there's any other info I can provide that would be useful :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #9 on: February 21, 2009, 11:34:46 am »
Is it happening in a particular context, or is it everytime you stop a music?
Laurent Gomila - SFML developer

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« Reply #10 on: February 21, 2009, 03:37:26 pm »
Every time.

I'll investigate further over the weekend and try to post back with some more useful information (if you haven't solved the problem by then, that is :).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #11 on: February 21, 2009, 03:44:02 pm »
Unfortunately, I can't reproduce this problem on Windows.
Laurent Gomila - SFML developer

Jesse

  • Newbie
  • *
  • Posts: 16
    • View Profile
Seamless music looping
« Reply #12 on: February 21, 2009, 10:58:55 pm »
Quote from: "Laurent"
Unfortunately, I can't reproduce this problem on Windows.

Do you have an OS X system that you can test SFML on as you make changes? Or are you currently Windows-only?

If you can test it on a Mac, I'd be interested to know if you get the same results (and if not, what versions of OS X and OpenAL you're using, and whether your Mac is PowerPC or Intel).

Whether or not you can test it in OS X, I'll keep investigating - if I manage to figure out what's causing the bug, I'll let you know :)

Thanks,
Jesse

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Seamless music looping
« Reply #13 on: February 22, 2009, 09:11:46 am »
I only have Windows and Linux systems, the OSX port is maintained by someone else. I'm going to contact him to let him know about this bug.
Laurent Gomila - SFML developer

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Seamless music looping
« Reply #14 on: February 22, 2009, 01:40:24 pm »
Could you give a minimal example that produces this error ?
Want to play movies in your SFML application? Check out sfeMovie!