- // Initialize the sound sub-system.
- // Use ALURE to ease the use of OpenAL.
- void SFXObject::init()
- {
- // Initialize the sound device
- if(!alureInitDevice(NULL, NULL))
- {
- logprintf(LogConsumer::LogError, "Failed to open OpenAL device: %s\n", alureGetErrorString());
- return;
- }
- // Create free (empty) sound sources
- alGenSources(NumSources, gSources);
- if(alGetError() != AL_NO_ERROR)
- {
- logprintf(LogConsumer::LogError, "Failed to create OpenAL sources!\n");
- return;
- }
- // Create sound buffers for the sound effect pool
- alGenBuffers(NumSFXBuffers, gBuffers);
- if(alGetError() != AL_NO_ERROR)
- {
- logprintf(LogConsumer::LogError, "Failed to create OpenAL buffers!\n");
- return;
- }
- // Choose the sound set
- if(gIniSettings.sfxSet == sfxClassicSet)
- gSFXProfiles = sfxProfilesClassic;
- else
- gSFXProfiles = sfxProfilesModern;
- // Iterate through all sounds
- for(U32 i = 0; i < NumSFXBuffers; i++)
- {
- // End when we find a sound sans filename
- if(!gSFXProfiles[i].fileName)
- break;
- // Grab sound file location
- string fileBuffer = joindir(gConfigDirs.sfxDir, gSFXProfiles[i].fileName);
- // Stick sound into a buffer
- alureBufferDataFromFile(fileBuffer.c_str(), gBuffers[i]);
- // gBuffers[i] = alureCreateBufferFromFile(fileBuffer.c_str());
- if(alGetError() != AL_NO_ERROR)
- {
- logprintf(LogConsumer::LogError, "Failure (1) loading sound file '%s': Game will proceed without sound.", fileBuffer.c_str());
- return;
- }
- }
- ALuint src;
- alGenSources(1, &src);
- for(U32 i = 0; i < NumSFXBuffers; i++)
- {
- alSourcei(src, AL_BUFFER, gBuffers[i]);
- if(alurePlaySource(src, eos_callback, NULL) == AL_FALSE)
- {
- logprintf(LogConsumer::LogError, "Failed to start source!\n");
- }
- while(!isdone)
- {
- alureSleep(0.125);
- alureUpdate();
- }
- }
- gSFXValid = true;
- }