Advertisement Jump to content
Sign in to follow this  
Silent Angel

ogg vorbis with openal doesn't repeat :-(

This topic is 4879 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there I'm trying to make an ogg music repeat several times while I'm playing my game... but I can't get it to work... My play function is like this: bool Oggvorbis::play() { if (playing()) return true; if (!stream(buffers[0])) return false; if (!stream(buffers[1])) return false; alSourceQueueBuffers(source, 2, buffers); alSourcePlay(source); return true; } I put this function in my main loop and it isn't reloading the initial music data into the buffer... I tried to use alSourcei (source, AL_LOOPING, AL_TRUE ); but it only repeats the actual info in the buffer Does anyone know what can I do to solve this?

Share this post

Link to post
Share on other sites
Yes, the idea is this:

  • Have a loop variable that tells you if you want the song to loop.
  • If you reach the end of the song, then check to see if that loop variable is set.
  • If it is set, then you will need to do the OGG seeking function to go to the beginning again.

    Now to comment on your code, it looks almost right, but there's a little problem that you are failing to address that will come back and bite you in the rear.

    Let's say you buffer that first segment, so the stream works fine. You have valid data that needs to be played right? Now what if you try to buffer more, and you are out? With that code from a tutorial a presume (I've seen it before somewhere), you will ignore that last part of the song, so it's not played. So what you need to do is something like this logivally (I'll let you make your own code for it)

    Stream Buffer 0
    if failed, return false

    Stream Buffer 1
    if failed, just stream 1 in alSourceQueueBuffers, Play, and return true

    alSourceQueueBuffers(source, 2, buffers);

    return true;

    As you can see what I am telling you, it will make it work correctly now in the end. If you need a visual illustration of what is happening right now with that code, here it is:

    buffer size => 4096 KB
    Song = 4096 * 5 KB
    [ ]|[ ]|[ ]|[ ]|[ ]
    1 2 3 4 5

    Now you buffer 1, then 2 and are fine. You buffer 3 and then 4 and you are fine. You buffer 5, and WHOOPS, no 6, so 5 is not played and you lose that ending. If you use the algorithm that I've mentioned above, you will not have to worry about that condition.

    Share this post

    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement

    Important Information

    By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

    Sign me up!