CSound::CSound() : prevVelocity(0.0, 0.0, 0.0), numEmptyPlayRequests(0), updateCounter(0) { mute = false; appIsIconified = false; int maxSounds = configHandler->Get("MaxSounds", 64) - 1; // 1 source is occupied by eventual music (handled by OggStream) pitchAdjust = configHandler->Get("PitchAdjust", true); masterVolume = configHandler->Get("snd_volmaster", 60) * 0.01f; Channels::General.SetVolume(configHandler->Get("snd_volgeneral", 100 ) * 0.01f); Channels::UnitReply.SetVolume(configHandler->Get("snd_volunitreply", 100 ) * 0.01f); Channels::UnitReply.SetMaxEmmits(1); Channels::Battle.SetVolume(configHandler->Get("snd_volbattle", 100 ) * 0.01f); Channels::UserInterface.SetVolume(configHandler->Get("snd_volui", 100 ) * 0.01f); if (maxSounds <= 0) { LogObject(LOG_SOUND) << "MaxSounds set to 0, sound is disabled"; } else { //TODO: device choosing, like this: //const ALchar* deviceName = "ALSA Software on SB Live 5.1 [SB0220] [Multichannel Playback]"; const char* deviceName = NULL; ALCdevice *device = alcOpenDevice((ALCubyte*)deviceName); if (device == NULL) { LogObject(LOG_SOUND) << "Could not open a sounddevice, disabling sounds"; CheckError("CSound::InitAL"); return; } else { ALCcontext *context = alcCreateContext(device, NULL); if (context != NULL) { alcMakeContextCurrent(context); CheckError("CSound::CreateContext"); } else { alcCloseDevice(device); LogObject(LOG_SOUND) << "Could not create OpenAL audio context"; return; } } LogObject(LOG_SOUND) << "OpenAL info:\n"; LogObject(LOG_SOUND) << " Vendor: " << (const char*)alGetString(AL_VENDOR ); LogObject(LOG_SOUND) << " Version: " << (const char*)alGetString(AL_VERSION); LogObject(LOG_SOUND) << " Renderer: " << (const char*)alGetString(AL_RENDERER); LogObject(LOG_SOUND) << " AL Extensions: " << (const char*)alGetString(AL_EXTENSIONS); LogObject(LOG_SOUND) << " ALC Extensions: " << (const char*)alcGetString(device, ALC_EXTENSIONS); if(alcIsExtensionPresent(NULL, (ALCubyte*)"ALC_ENUMERATION_EXT")) { LogObject(LOG_SOUND) << " Device: " << alcGetString(device, ALC_DEVICE_SPECIFIER); const char *s = (const char*)alcGetString(NULL, ALC_DEVICE_SPECIFIER); LogObject(LOG_SOUND) << " Available Devices: "; while (*s != '\0') { LogObject(LOG_SOUND) << " " << s; while (*s++ != '\0') ; } } // Generate sound sources for (int i = 0; i < maxSounds; i++) { sources.push_back(new SoundSource()); if (!sources[i].IsValid()) { sources.pop_back(); maxSounds = i-1; LogObject(LOG_SOUND) << "Your hardware/driver can not handle more than " << maxSounds << " soundsources"; break; } } // Set distance model (sound attenuation) alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); //alDopplerFactor(1.0); alListenerf(AL_GAIN, masterVolume); } SoundBuffer::Initialise(); soundItemDef temp; temp["name"] = "EmptySource"; SoundItem* empty = new SoundItem(SoundBuffer::GetById(0), temp); sounds.push_back(empty); LoadSoundDefs("gamedata/sounds.lua"); configHandler->NotifyOnChange(this); }
CSound::CSound() : prevVelocity(0.0, 0.0, 0.0), numEmptyPlayRequests(0), soundThread(NULL) { mute = false; appIsIconified = false; int maxSounds = configHandler->Get("MaxSounds", 128); pitchAdjust = configHandler->Get("PitchAdjust", true); masterVolume = configHandler->Get("snd_volmaster", 60) * 0.01f; Channels::General.SetVolume(configHandler->Get("snd_volgeneral", 100 ) * 0.01f); Channels::UnitReply.SetVolume(configHandler->Get("snd_volunitreply", 100 ) * 0.01f); Channels::UnitReply.SetMaxEmmits(1); Channels::Battle.SetVolume(configHandler->Get("snd_volbattle", 100 ) * 0.01f); Channels::UserInterface.SetVolume(configHandler->Get("snd_volui", 100 ) * 0.01f); Channels::UserInterface.SetVolume(configHandler->Get("snd_volmusic", 100 ) * 0.01f); if (maxSounds <= 0) { LogObject(LOG_SOUND) << "MaxSounds set to 0, sound is disabled"; } else { //TODO: device choosing, like this: //const ALchar* deviceName = "ALSA Software on SB Live 5.1 [SB0220] [Multichannel Playback]"; const ALchar* deviceName = NULL; ALCdevice *device = alcOpenDevice(deviceName); if (device == NULL) { LogObject(LOG_SOUND) << "Could not open a sounddevice, disabling sounds"; CheckError("CSound::InitAL"); return; } else { ALCcontext *context = alcCreateContext(device, NULL); if (context != NULL) { alcMakeContextCurrent(context); CheckError("CSound::CreateContext"); } else { alcCloseDevice(device); LogObject(LOG_SOUND) << "Could not create OpenAL audio context"; return; } } LogObject(LOG_SOUND) << "OpenAL info:\n"; LogObject(LOG_SOUND) << " Vendor: " << (const char*)alGetString(AL_VENDOR ); LogObject(LOG_SOUND) << " Version: " << (const char*)alGetString(AL_VERSION); LogObject(LOG_SOUND) << " Renderer: " << (const char*)alGetString(AL_RENDERER); LogObject(LOG_SOUND) << " AL Extensions: " << (const char*)alGetString(AL_EXTENSIONS); LogObject(LOG_SOUND) << " ALC Extensions: " << (const char*)alcGetString(device, ALC_EXTENSIONS); if(alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT")) { LogObject(LOG_SOUND) << " Device: " << alcGetString(device, ALC_DEVICE_SPECIFIER); const char *s = alcGetString(NULL, ALC_DEVICE_SPECIFIER); LogObject(LOG_SOUND) << " Available Devices: "; while (*s != '\0') { LogObject(LOG_SOUND) << " " << s; while (*s++ != '\0') ; } } } SoundBuffer::Initialise(); soundItemDef temp; temp["name"] = "EmptySource"; SoundItem* empty = new SoundItem(SoundBuffer::GetById(0), temp); sounds.push_back(empty); LoadSoundDefs("gamedata/sounds.lua"); if (maxSounds > 0) soundThread = new boost::thread(boost::bind(&CSound::StartThread, this, maxSounds)); configHandler->NotifyOnChange(this); }