# [solved] Having some OpenAL/Ogg problems

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

## Recommended Posts

Just to get the specs out of the way..I'm using OpenAL 1.1, the newest Ogg and Vorbis libraries, and Visual Studio 2005/2008 depending on which computer I'm using. I've had no issues with getting OpenAL to work with .wav files, but I've recently decided to go to .ogg. I'm not trying to stream from the hard drive, since this is for a game, so I'm just trying to load the .ogg into a buffer. I'm having issues when I run the ov_open() function and I was told to try using ov_open_callbacks() instead. I can't, however, find any good references on how these callbacks work. Here is my code:
FILE* theFile;
OggVorbis_File oggFile;
vorbis_info* vorbisInfo;
ALenum format;
int result;

if (!(theFile = fopen(_szFileName, "rb")))
return 0;

if ((result = ov_open(theFile, &oggFile, NULL, 0)) < 0)
{
fclose(theFile);
return 0;
}

vorbisInfo = ov_info(&oggFile, -1);

if (vorbisInfo->channels == 1)
format = AL_FORMAT_MONO16;
else
format = AL_FORMAT_STEREO16;

int length = ov_pcm_total(&oggFile, -1) * vorbisInfo->channels * 2;
char *data = new char[length];
int size = 0;
int section;
while (size < length)
{
result = ov_read(&oggFile, data + size, length - size, 0, 2, 1, §ion);
if (result > 0)
size += result;
else if (result < 0);
//handle error
else break;
}

if (size == 0)
return 0;

ov_clear(&oggFile);

alBufferData(buffer, format, data, size, vorbisInfo->rate);

I'm not sure what exactly the ov_open_callbacks will replace. I'm assuming it will replace the ov_open function but the parameters are a bit different and that last callback param isn't cooperating. any help at all would be greatly appreciated! [Edited by - Holland on November 19, 2008 11:04:50 PM]

##### Share on other sites
Quote:
 Original post by HollandI can't, however, find any good references on how these callbacks work.

There's tons of vorbis decoding examples on the internet! I can't believe you didn't find anything...

For instance there's the official Vorbis documentation (vorbisfile). There's an example showing the use of ov_open_callbacks. It uses the standard input, but it's pretty similar for files.

You only have to provide the callback functions as described here. Your FILE pointer (or whatever object you use to open files...) will be the datasource variable.

##### Share on other sites
Yeah..I have found these tutorials on the Vorbis site but for whatever reason those callback defines did not exist for me. I finally realized that the OggVorbis SDK I got wasn't the latest version. I downloaded the stuff from the vorbis site and now I'm having issues making the .lib and .dll files. :(

edit
Does anyone have any input on how I can go about creating all of my necessary .dll and .lib files using Visual Studio? This is the first time I've reached outside of DirectX, so I'm very used to all of the appropriate files being supplied already. The Ogg/Vorbis SDK I downloaded first already had the lib and dll supplied, but it was an old version so these tutorials aren't helping. :(

[Edited by - Holland on November 16, 2008 6:42:12 PM]

##### Share on other sites
Somewhere in the ogg source zip folder you downloaded should be a Visual Studio Project(.sln).
-open it
-Build it.
-That will make all the files needed (.dll and .lib)
-Now you need to setup Visual Studio to see those .lib files
Tools->Options->Projects and Solutions->VC++ Directories

-Also in that Ogg zip there will be a folder called include, these are the headers you should include to use the Ogg library. So you will need to setup Visual Studio to see them as well.

Once you have that done, you can repeat the process with the Vorbis lib.

##### Share on other sites
Are you kidding me?
"%OpenAL 1.1 SDK%\samples\playoggvorbis"

There's a nice sample showing how to dynamically load Ogg Vorbis DLL (although, you can change this with a couple of lines, to make the compiler do that for you)

That sample shows how to stream.
In order to load the FULL buffer, the following trick will work:
[source lang=c++]frequency = ov_pcm_total(&sOggVorbisFile, -1); //!!!Here we tell Ogg to load everything that's in the buffer. A trick that mathematically works (with the rest of the code unchanged).channels = psVorbisInfo->channels;//This is code similar to what it's in that sampleif( psVorbisInfo->channels == 1 ){	Format = AL_FORMAT_MONO16;	// Set BufferSize (Frequency * 2 (16bit))	size = oggData.m_Frequency*2;	// IMPORTANT : The Buffer Size must be an exact multiple of the BlockAlignment ...	size -= (oggData.m_size % 2);}else if( psVorbisInfo->channels == 2 ){	Format = AL_FORMAT_STEREO16;	// Set BufferSize (Frequency * 4 (16bit stereo))	size = oggData.m_Frequency * 4;	// IMPORTANT : The Buffer Size must be an exact multiple of the BlockAlignment ...	size -= (oggData.m_size % 4);}else if (psVorbisInfo->channels == 4){	Format = alGetEnumValue("AL_FORMAT_QUAD16");	// Set BufferSize (Frequency * 8 (16bit 4-channel))	size = oggData.m_Frequency * 8;	// IMPORTANT : The Buffer Size must be an exact multiple of the BlockAlignment ...	size -= (oggData.m_size % 8);}else if (psVorbisInfo->channels == 6){	Format = alGetEnumValue("AL_FORMAT_51CHN16");	// Set BufferSize to 250ms (Frequency * 12 (16bit 6-channel) )	size = oggData.m_Frequency * 12;	// IMPORTANT : The Buffer Size must be an exact multiple of the BlockAlignment ...	size -= (oggData.m_size % 12);}//!!!Frequency = psVorbisInfo->rate; //We change back the frequency before loading the sound into OpenAL to the value it should, if we want to hear the sound being played at the right speed.//The rest isn't changed

Be aware though, that you WANT to stream in-game music.
Be aware that a 6MB encoded clip can easily become 60MB in RAM. You don't want to spend 60MB of RAM just for one music piece.

Cheers
Dark Sylinc

##### Share on other sites
Thanks for all the help in pointing out things I didn't have. Again, since I couldn't get the .dll and .lib to compile I had to find some premade SDK..and as a result It had the bare essentials and nothing else. inc, lib, dll, nothing more...so I had no samples. I wasn't aware there were samples.

I got it all figured out though. Finally found all the right parts of the vorbis sdk to make it functional. And yes, I understand I need to stream the music...just because I couldn't find an example on it doesn't mean I don't know that ogg is a compressed file format. :)

case closed.

##### Share on other sites

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

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628721
• Total Posts
2984394

• 25
• 11
• 10
• 16
• 14