Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 2.01 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Initialize the sound sub-system.
  2. // Use ALURE to ease the use of OpenAL.
  3. void SFXObject::init()
  4. {
  5.    // Initialize the sound device
  6.    if(!alureInitDevice(NULL, NULL))
  7.    {
  8.       logprintf(LogConsumer::LogError, "Failed to open OpenAL device: %s\n", alureGetErrorString());
  9.       return;
  10.    }
  11.  
  12.    // Create free (empty) sound sources
  13.    alGenSources(NumSources, gSources);
  14.    if(alGetError() != AL_NO_ERROR)
  15.    {
  16.       logprintf(LogConsumer::LogError, "Failed to create OpenAL sources!\n");
  17.       return;
  18.    }
  19.  
  20.    // Create sound buffers for the sound effect pool
  21.    alGenBuffers(NumSFXBuffers, gBuffers);
  22.    if(alGetError() != AL_NO_ERROR)
  23.    {
  24.       logprintf(LogConsumer::LogError, "Failed to create OpenAL buffers!\n");
  25.       return;
  26.    }
  27.  
  28.    // Choose the sound set
  29.    if(gIniSettings.sfxSet == sfxClassicSet)
  30.       gSFXProfiles = sfxProfilesClassic;
  31.    else
  32.       gSFXProfiles = sfxProfilesModern;
  33.  
  34.    // Iterate through all sounds
  35.    for(U32 i = 0; i < NumSFXBuffers; i++)
  36.    {
  37.       // End when we find a sound sans filename
  38.       if(!gSFXProfiles[i].fileName)
  39.          break;
  40.  
  41.       // Grab sound file location
  42.       string fileBuffer = joindir(gConfigDirs.sfxDir, gSFXProfiles[i].fileName);
  43.  
  44.       // Stick sound into a buffer
  45.       alureBufferDataFromFile(fileBuffer.c_str(), gBuffers[i]);
  46. //      gBuffers[i] = alureCreateBufferFromFile(fileBuffer.c_str());
  47.       if(alGetError() != AL_NO_ERROR)
  48.       {
  49.          logprintf(LogConsumer::LogError, "Failure (1) loading sound file '%s': Game will proceed without sound.", fileBuffer.c_str());
  50.          return;
  51.       }
  52.    }
  53.  
  54.    ALuint src;
  55.    alGenSources(1, &src);
  56.    for(U32 i = 0; i < NumSFXBuffers; i++)
  57.    {
  58.       alSourcei(src, AL_BUFFER, gBuffers[i]);
  59.       if(alurePlaySource(src, eos_callback, NULL) == AL_FALSE)
  60.       {
  61.          logprintf(LogConsumer::LogError, "Failed to start source!\n");
  62.       }
  63.  
  64.       while(!isdone)
  65.       {
  66.          alureSleep(0.125);
  67.          alureUpdate();
  68.       }
  69.    }
  70.  
  71.    gSFXValid = true;
  72. }