SoundManager::SoundManager()
  : device(0), context(0), sound_enabled(false), music_source(0),
    music_enabled(true)
{
  try {
    device = alcOpenDevice(0);
    if(device == 0) {
      print_openal_version();
      throw std::runtime_error("Couldn't open audio device.");
    }

    int attributes[] = { 0 };
    context = alcCreateContext(device, attributes);
    check_alc_error("Couldn't create audio context: ");
    alcMakeContextCurrent(context);
    check_alc_error("Couldn't select audio context: ");

    check_al_error("Audio error after init: ");
    sound_enabled = true;
  } catch(std::exception& e) {
    device = 0;
    context = 0;
    log_warning << "Couldn't initialize audio device:" << e.what() << std::endl;
    print_openal_version();
    throw e;
  }
}
Beispiel #2
0
SoundManager::SoundManager() :
  device(0), 
  context(0), 
  sound_enabled(false), 
  buffers(),
  sources(),
  update_list(),
  music_source(0),
  music_enabled(false),
  current_music()
{
  try {
    device = alcOpenDevice(0);
    if (device == NULL) {
      throw std::runtime_error("Couldn't open audio device.");
    }

    int attributes[] = { 0 };
    context = alcCreateContext(device, attributes);
    check_alc_error("Couldn't create audio context: ");
    alcMakeContextCurrent(context);
    check_alc_error("Couldn't select audio context: ");

    check_al_error("Audio error after init: ");
    sound_enabled = true;
    music_enabled = true;
  } catch(std::exception& e) {
    if(context != NULL) {
      alcDestroyContext(context);
      context = NULL; 
    }
    if(device != NULL) {
      alcCloseDevice(device);
      device = NULL;
    }
    log_warning << "Couldn't initialize audio device: " << e.what() << std::endl;
    print_openal_version();
  }
}