Jump to content
  • Advertisement
Sign in to follow this  
codemastermm

OpenAL Streaming and OpenGL

This topic is 4882 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

I recently have setup OpenAL to load an Ogg Vorbis file and stream it (since with the audio uncompressed and not streamed, it'd take around 40-50 MB of RAM and that'd be quite wasteful). Anyway, my problem occurs here. In my standard code without any OpenGL and just a sample OpenAL program, my main code is this:
int main(int argc, char** argv)
{
    alutInit(&argc, argv);
    ogg_stream *ogg = new ogg_stream("music.ogg");

    if(!ogg->play())
        printf("Ogg refused to play\n");
    while(ogg->update())
    {
        if(!ogg->playing())
        {
            if(!ogg->play())
                printf("Ogg abruptly stopped\n");
            else
                printf("Ogg stream was interrupted\n");
        }
    }
    
	delete ogg;
	alutExit();
	return 0;
}

I am attempting, now, to have music play along with a display of graphics via OpenGL. From the code above, it easily can create and load the Ogg file, but when it comes to the while(ogg->update()) function, I have attempted to modify it to an if(ogg->update()) and placed it inside my drawing function. To my avail, this failed horribly. I am not sure how to modify this original code into working with an OpenGL project. I am currently presuming I may have to make another thread (although I am doing my best not to). Any assistance is greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
A good way to do it would be to fill the source with buffers loaded from the file every game loop, depending on how many are missing (keep about 2-3 seconds in memory all the time, and you should be OK). It's not too hard to figure out how many buffers are required for a full second of time when you know the format of the data.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net 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!