Jump to content
  • Advertisement
Sign in to follow this  
yahn

ov_read() and streaming sound

This topic is 4059 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!