Jump to content
  • Advertisement
Sign in to follow this  
bballmitch

OpenAL sound devices

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

Will someone please tell me how to change the following code so that it will work on the majority of computers? For some reason, that code works 100% like its supposed to on my computer, but it hasn't worked on anyone elses computer. I THINK it has something to do with alcOpenDevice(), but I can't figure it out. All the lines that I have tried below have worked 100% on my computer, but for some reason, none of them work on anyone elses. PLEASE help. Its very important! Thanks.
ALCcontext *Context;
	ALCdevice *Device;

//Open device
	Device = alcOpenDevice((ALCchar*)"MMSYSTEM");
	//Device = alcOpenDevice(NULL); ... didn't work either
//Device=alcCreateContext( (ALchar*) "DirectSound3D"); ...also didn't work

	//Create context(s)
	Context=alcCreateContext(Device,NULL);

	//Set active context
	alcMakeContextCurrent(Context);

	// Clear Error Code
	alGetError();

Share this post


Link to post
Share on other sites
Advertisement
At what point does it not work? Are you sure that these other computers have OpenAL installed on them, or are the DLLs packaged with the execuable?

Share this post


Link to post
Share on other sites
Here's my code for initializing the best device available. This code may still have some bugs in it but hey it worked for me - so here it goes:


ALCint highest_version = 0; // Highest version number found
const ALCchar * best_device = NULL; // Name of the 'best' device

// Find the highest-version device available
const ALCchar * device_name = alcGetString(NULL, ALC_DEVICE_SPECIFIER); // Get list of all devices (terminated with two '0')
while (*device_name != NULL) // Loop until two terminating zeroes has been read
{
ALCint major_v=0, minor_v=0;
ALCdevice * _temp_device = alcOpenDevice(device_name); // Open a temporary device for reading in its version number
if (_temp_device == NULL) // Just keep looping if we couldn't open the device
{
cerr << "AUDIO: Couldn't open a temporary device: " << device_name << endl;
device_name += strlen(device_name) + 1;
continue;
}
ALCcontext * temp_context = alcCreateContext(_temp_device, NULL); // Create a temporary context
if (temp_context == NULL) // Keep looping again if no context was created
{
cerr << "AUDIO: Couldn't create a temporary context for device: " << device_name << endl;
alcCloseDevice(_temp_device);
device_name += strlen(device_name) + 1;
continue;
}
alcMakeContextCurrent(temp_context);
alGetError();
alcGetIntegerv(_temp_device, ALC_MAJOR_VERSION, sizeof(ALCint), &major_v); // Get the version number
alcGetIntegerv(_temp_device, ALC_MINOR_VERSION, sizeof(ALCint), &minor_v);
alcMakeContextCurrent(NULL); // Disable the temporary context
alcDestroyContext(temp_context); // Destroy the temporary context
alcCloseDevice(_temp_device); // Close the temporary device
if (highest_version < (major_v * 10 + minor_v)) // Check if we found a higher version
{
highest_version = (major_v * 10 + minor_v);
best_device = device_name;
}
device_name += strlen(device_name) + 1; // Go to the next device name in the list
}

// Open the 'best' device we found above
_device = alcOpenDevice(best_device);
if (_device == NULL) {
cerr << "AUDIO ERROR: Failed to initialize OpenAL and open a default device." << endl;
return false;
}

ALCcontext * context = alcCreateContext(best_device, NULL);
alcMakeContextCurrent(context);
alGetError();



I'd still suggest to check hh10k's advice

Share this post


Link to post
Share on other sites
Quote:
Original post by hh10k
At what point does it not work? Are you sure that these other computers have OpenAL installed on them, or are the DLLs packaged with the execuable?



The DLLs are packaged with the executable. In addition, on one computer I installed OpenAL and i packaged the executable and it still didnt work. :(

I'm not 100% sure its the device, but I can't think of what other thing would make it so that it would work on my computer, but on no one elses.

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!