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

Author Topic: Looping a music from a certain point  (Read 20684 times)

0 Members and 1 Guest are viewing this topic.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« on: February 11, 2009, 01:15:15 am »
A lot of songs have some kind of intro sequence in the beginning but then start to loop from another point of the song.  Is there a way to do this in SFML? If not, would the best alternative way be to just manually split the song, play the intro piece, then time it, play the other part then loop?  The only problem with the latter is I seem to have some kind of lag when I play musics, (it's not a loading issue, I load at a different part of the program much before execution begins.

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Looping a music from a certain point
« Reply #1 on: February 11, 2009, 04:21:30 am »
One thing that might interfere with your attempts is the MP3 format, which cannot be looped seamlessly. MP3s work with some kind of block structure or whatnot, and can't loop perfectly.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #2 on: February 11, 2009, 05:15:02 am »
i thought that SFML can't support mp3?

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Looping a music from a certain point
« Reply #3 on: February 11, 2009, 06:30:06 am »
Well in fact, I don't know. I just wanted to point that out, in case you ever have problems :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Looping a music from a certain point
« Reply #4 on: February 11, 2009, 07:57:34 am »
Quote
would the best alternative way be to just manually split the song

Probably. Or using another audio library which allows more advanced control (FMod, Bass, Audiere, ...).

Quote
The only problem with the latter is I seem to have some kind of lag when I play musics

Could you show a minimal and complete piece of code which reproduces this problem (with the audio file you're using), so that I can test it?

Quote
i thought that SFML can't support mp3?

Correct. But Ogg files, which are supported by SFML, use a block structure too.
Laurent Gomila - SFML developer

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Looping a music from a certain point
« Reply #5 on: February 11, 2009, 10:32:26 am »
Quote from: "Laurent"

Correct. But Ogg files, which are supported by SFML, use a block structure too.


Really? They loop perfectly though.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Looping a music from a certain point
« Reply #6 on: February 11, 2009, 10:45:44 am »
Yeah, the seeking function of stb_vorbis (the library I use for loading ogg) is pretty good ;)

But it still might be a little bit unaccurate sometimes, this is explained in the documentation of stb_vorbis.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #7 on: February 14, 2009, 11:01:11 pm »
i just do a simple:
Code: [Select]

sf::Music music;
music.OpenFromFile("SolarisPhase2Theme.aif");
music.SetLoop(true);
music.Play();

there seems to be like a half a second lag.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #8 on: February 15, 2009, 07:01:46 am »
I think the problem might just be with the Music files themselves.  (two files seemed to lag though one started right away).  I guess I'll just have to look into that some more.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #9 on: February 25, 2009, 08:53:23 pm »
Would a way to loop the music from a certain point work by waiting until the song finishes (or gets to a certain point) then restarting from the desired part? (seeking with the GetPlayingOffset )?
This would use threads a lot woudn't it; could the sleep function be used to sleep until the music is over (time it) and then restart from a point? how much of a lag would there be?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Looping a music from a certain point
« Reply #10 on: February 25, 2009, 08:54:59 pm »
SetPlayingPosition is not implemented for sound streams, it works only for sounds.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #11 on: February 25, 2009, 10:54:59 pm »
hmm, can this be implemented for sound streams later? (like in sfml 2)? I don't know about other people, but I find this feature useful.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Looping a music from a certain point
« Reply #12 on: February 25, 2009, 11:04:12 pm »
I really wish I could do that ;)

But this would require seeking into audio files (as they're not decoded in memory), which is very hard to do for ogg-vorbis files. In particular, the library I'm using to decode ogg-vorbis files (stb_vorbis) is currently not able to do it.
Laurent Gomila - SFML developer

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Looping a music from a certain point
« Reply #13 on: February 25, 2009, 11:13:11 pm »
darn...so i'm back to my either split files or use a different library approach.  I really do not want to use a different library (one reason why I chose SFML was because it did the graphics, audio, (joystick if I wanted to do that) and networking all together.  

If possible it would be really cool if this feature could be added to SFML in the future, though I do realize your limitations on this issue with stb_vorbis.  Are ogg files the only problem? Could a different ogg library be used? I do not know what is required of a library to be added to the framework; I realize you chose sdb_vorbis over other libs.  

On another note, this issue isn't too big of a deal, as I'm more worried about getting gameplay working first.  But I'll definitely have to come back to this later.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Looping a music from a certain point
« Reply #14 on: February 25, 2009, 11:29:57 pm »
There is the official libvorbis library, which is open source and has a nice license, but it requires 4 external dependencies. stb_vorbis is only one file and can be embedded directly into SFML. Moreover, I can rely on the author to fix any bug I find :)
Laurent Gomila - SFML developer