Sign in to follow this  

ov_read() and streaming sound

This topic is 3775 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've been able to decode an OGG all at once and then play it, but that takes about 50 megabytes of ram. So, I'm trying to stream it now. I basically took the code and made it so that it loads during the game loop instead of all at once before, but it is loading the beginning of the OGG constantly. Here is my code:
bool Sound::play()
{
	int state;
	alGetSourcei(sourceID, AL_SOURCE_STATE, &state);
	if (state != AL_STOPPED)
	{
		return false;
	}

	stream();

	return true;
}

bool Sound::stream()
{
	char array[32768];
	int bytes;

	bytes = ov_read(&ogg, array, sizeof(array), 0, 2, 1, &bitStream);

	alBufferData(bufferID, format, &array[0], bytes, freq);

	alSourcei(sourceID, AL_BUFFER, bufferID);

	alSourcePlay(sourceID);

	return true;
}
I call the play() function during the loop. I check to make sure it isn't already playing. If it isn't then I call stream() that decodes the OGG with ov_read() and puts it in the source and plays it. Everything looks like it should be working, but for some reason I always hear the same sound from the beginning of the song. Can anyone tell me what I'm doing wrong? Sorry for all the questions lately. And thank you all for your help.

Share this post


Link to post
Share on other sites
In case anyone needs to stream oggs, I found this tutorial.

http://www.devmaster.net/articles/openal-tutorials/lesson8.php

The only problem is there are a lot of errors in the page. But the source has all the errors fixed. So, I'd recommend just downloading the source.

[Edited by - yahn on August 12, 2007 2:08:15 PM]

Share this post


Link to post
Share on other sites

This topic is 3775 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this