static int lua_alDistanceModel(lua_State* lua_state) { ALenum enum_parameter; enum_parameter = lua_tointeger(lua_state, 1); alDistanceModel(enum_parameter); return 0; }
bool ALSound::Create() { CleanUp(); if (m_enabled) return true; GetLogger()->Info("Opening audio device...\n"); m_device = alcOpenDevice(nullptr); if (!m_device) { GetLogger()->Error("Could not open audio device!\n"); return false; } m_context = alcCreateContext(m_device, nullptr); if (!m_context) { GetLogger()->Error("Could not create audio context!\n"); return false; } alcMakeContextCurrent(m_context); alListenerf(AL_GAIN, m_audioVolume); alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); GetLogger()->Info("Done.\n"); m_enabled = true; return true; }
COpenALSound::COpenALSound() { maxSounds = configHandler.GetInt("MaxSounds",16); noSound = false; cur = 0; if (!noSound) { ALCdevice *device = alcOpenDevice(NULL); if (device != NULL) { ALCcontext *context = alcCreateContext(device, NULL); if (context != NULL) alcMakeContextCurrent(context); else { handleerror(0, "Could not create audio context","OpenAL error",MBF_OK); noSound = true; alcCloseDevice(device); return; } } else { handleerror(0,"Could not create audio device","OpenAL error",MBF_OK); noSound = true; return; } } // Generate sound sources Sources = new ALuint[maxSounds]; for (int a=0;a<maxSounds;a++) Sources[a]=0; // Set distance model (sound attenuation) alDistanceModel (AL_INVERSE_DISTANCE); posScale.x = 0.02f; posScale.y = 0.02f; posScale.z = 0.0005f; }
void sound_init () { if (have_al) return; if ((dev = alcOpenDevice (NULL)) == NULL) return; if ((context_id = alcCreateContext (dev, NULL)) == NULL) { alcCloseDevice (dev); have_al = 0; return; } alcMakeContextCurrent (context_id); alGenSources (1, &source); alGenBuffers (2, wave); sound_load (wave[SOUND_BOINK], "/boink.wav"); sound_load (wave[SOUND_NNGNGNG], "/lose.wav"); alDistanceModel (AL_DISTANCE_MODEL); alSourcef (source, AL_REFERENCE_DISTANCE, 22.0); have_al = 1; return; }
GAudio::GAudio() : mDevice(NULL), mContext(NULL), mChannels(NULL) { // open the device mDevice = alcOpenDevice(NULL); if(mDevice==NULL) GAssert("GAudio: could not open the al device!."); // create a context ALCint caps[] = { ALC_FREQUENCY, 44100, ALC_STEREO_SOURCES, 4, 0, 0 }; mContext = alcCreateContext(mDevice, caps); if(mContext==NULL) GAssert("GAudio: could not create a al context."); CHECK(alcMakeContextCurrent(mContext)); // initialize channels. mChannels = GNEW(GAudioSource[MAX_AUDIO_CHANNELS]); CHECK(mChannels); for(U32 i = 0; i < MAX_AUDIO_CHANNELS; i++) { mFrees.push_back(&mChannels[i]); } // use our own distance model. alDistanceModel(AL_NONE); }
void cOAL_Device::SetDistanceModel(eOAL_DistanceModel aModel) { DEF_FUNC_NAME("OAL_SetDistanceModel"); FUNC_USES_AL; ALenum distModel; switch(aModel) { case eOAL_DistanceModel_Inverse: distModel = AL_INVERSE_DISTANCE; break; case eOAL_DistanceModel_Inverse_Clamped: distModel = AL_INVERSE_DISTANCE_CLAMPED; break; case eOAL_DistanceModel_Linear: distModel = AL_LINEAR_DISTANCE; break; case eOAL_DistanceModel_Linear_Clamped: distModel = AL_LINEAR_DISTANCE_CLAMPED; break; case eOAL_DistanceModel_Exponent: distModel = AL_EXPONENT_DISTANCE; break; case eOAL_DistanceModel_Exponent_Clamped: distModel = AL_EXPONENT_DISTANCE_CLAMPED; break; case eOAL_DistanceModel_None: distModel = AL_NONE; default: break; } RUN_AL_FUNC(alDistanceModel(distModel)); }
// Thread: Any. Must be locked: AudioMutex. bool CreatePlaybackDevice() { if (AudioDevice) return true; AudioDevice = alcOpenDevice(nullptr); if (!AudioDevice) { LOG(("Audio Error: Could not create default playback device, enumerating..")); EnumeratePlaybackDevices(); return false; } ALCint attributes[] = { ALC_STEREO_SOURCES, 128, ALC_FREQUENCY, Media::Player::kDefaultFrequency, 0 }; AudioContext = alcCreateContext(AudioDevice, attributes); alcMakeContextCurrent(AudioContext); if (ContextErrorHappened()) { DestroyPlaybackDevice(); return false; } ALfloat v[] = { 0.f, 0.f, -1.f, 0.f, 1.f, 0.f }; alListener3f(AL_POSITION, 0.f, 0.f, 0.f); alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f); alListenerfv(AL_ORIENTATION, v); alDistanceModel(AL_NONE); return true; }
int DS_Init(void) { // Already initialized? if(initOk) return true; // Open the default playback device. device = alcOpenDevice(NULL); if(!device) { Con_Message("OpenAL init failed (default playback device)."); return false; } // Create and make current a new context. alcMakeContextCurrent(context = alcCreateContext(device, NULL)); DSOPENAL_ERRCHECK(alGetError()); // Attempt to load and configure the EAX extensions. loadExtensions(); // Configure the listener and global OpenAL properties/state. alListenerf(AL_GAIN, 1); alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); headYaw = headPitch = 0; unitsPerMeter = 36; // Everything is OK. DSOPENAL_TRACE("DS_Init: OpenAL initialized%s." << (hasEAX? " (EAX 2.0 available)" : "")); initOk = true; return true; }
AudioWorld::AudioWorld(Engine::BaseEngine& engine, AudioEngine& audio_engine, const VDFS::FileIndex& vdfidx) : m_Engine(engine) , m_VDFSIndex(vdfidx) , m_exiting(false) { #ifdef RE_USE_SOUND if (!audio_engine.getDevice()) return; m_Context = alcCreateContext(audio_engine.getDevice(), nullptr); if (!m_Context) { LogWarn() << "Could not create OpenAL context: " << AudioEngine::getErrorString(alcGetError(audio_engine.getDevice())); return; } alcMakeContextCurrent(m_Context); alListener3f(AL_POSITION, 0, 0, 0.0f); // check for errors alListener3f(AL_VELOCITY, 0, 0, 0); // check for errors ALfloat listenerOri[] = {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f}; alListenerfv(AL_ORIENTATION, listenerOri); // Need this for AL_MAX_DISTANCE to work alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); createSounds(); initializeMusic(); #endif }
OpenALSoundManager(OnDemandSoundFetcher *fetcher): m_fetcher(fetcher), m_device(NULL), m_context(NULL), m_can_vorbis(false), m_next_id(1), m_is_initialized(false) { ALCenum error = ALC_NO_ERROR; infostream<<"Audio: Initializing..."<<std::endl; m_device = alcOpenDevice(NULL); if(!m_device){ infostream<<"Audio: No audio device available, audio system " <<"not initialized"<<std::endl; return; } if(alcIsExtensionPresent(m_device, "EXT_vorbis")){ infostream<<"Audio: Vorbis extension present"<<std::endl; m_can_vorbis = true; } else{ infostream<<"Audio: Vorbis extension NOT present"<<std::endl; m_can_vorbis = false; } m_context = alcCreateContext(m_device, NULL); if(!m_context){ error = alcGetError(m_device); infostream<<"Audio: Unable to initialize audio context, " <<"aborting audio initialization ("<<alcErrorString(error) <<")"<<std::endl; alcCloseDevice(m_device); m_device = NULL; return; } if(!alcMakeContextCurrent(m_context) || (error = alcGetError(m_device) != ALC_NO_ERROR)) { infostream<<"Audio: Error setting audio context, aborting audio " <<"initialization ("<<alcErrorString(error)<<")"<<std::endl; alcDestroyContext(m_context); m_context = NULL; alcCloseDevice(m_device); m_device = NULL; return; } alDistanceModel(AL_EXPONENT_DISTANCE); infostream<<"Audio: Initialized: OpenAL "<<alGetString(AL_VERSION) <<", using "<<alcGetString(m_device, ALC_DEVICE_SPECIFIER) <<std::endl; m_is_initialized = true; }
void OpenALDevice::setDistanceModel(DistanceModel model) { std::lock_guard<std::recursive_mutex> lock(m_mutex); switch(model) { case DISTANCE_MODEL_INVERSE: alDistanceModel(AL_INVERSE_DISTANCE); break; case DISTANCE_MODEL_INVERSE_CLAMPED: alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); break; case DISTANCE_MODEL_LINEAR: alDistanceModel(AL_LINEAR_DISTANCE); break; case DISTANCE_MODEL_LINEAR_CLAMPED: alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); break; case DISTANCE_MODEL_EXPONENT: alDistanceModel(AL_EXPONENT_DISTANCE); break; case DISTANCE_MODEL_EXPONENT_CLAMPED: alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED); break; default: alDistanceModel(AL_NONE); } }
void AUD_OpenALDevice::setDistanceModel(AUD_DistanceModel model) { switch(model) { case AUD_DISTANCE_MODEL_INVERSE: alDistanceModel(AL_INVERSE_DISTANCE); break; case AUD_DISTANCE_MODEL_INVERSE_CLAMPED: alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); break; case AUD_DISTANCE_MODEL_LINEAR: alDistanceModel(AL_LINEAR_DISTANCE); break; case AUD_DISTANCE_MODEL_LINEAR_CLAMPED: alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); break; case AUD_DISTANCE_MODEL_EXPONENT: alDistanceModel(AL_EXPONENT_DISTANCE); break; case AUD_DISTANCE_MODEL_EXPONENT_CLAMPED: alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED); break; default: alDistanceModel(AL_NONE); } }
Audio::Audio(){ dev = alcOpenDevice(NULL); ctx = alcCreateContext(dev, NULL); alcMakeContextCurrent(ctx); // alDistanceModel(AL_INVERSE_DISTANCE); alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); //alListenerf(AL_GAIN, 0.0f); }
optional<string> AudioDevice::initialize() { if ((device = alcOpenDevice(nullptr))) { if ((context = alcCreateContext((ALCdevice*)device, nullptr))) { alcMakeContextCurrent((ALCcontext*)context); alDistanceModel(AL_NONE); initialized = true; return none; } } return "Error code: " + toString(alGetError()); }
void CSoundManager::InitListener() { ALfloat listenerPos[] = {0.0, 0.0, 0.0}; ALfloat listenerVel[] = {0.0, 0.0, 0.0}; ALfloat listenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; alListenerfv(AL_POSITION, listenerPos); alListenerfv(AL_VELOCITY, listenerVel); alListenerfv(AL_ORIENTATION, listenerOri); alDistanceModel(AL_LINEAR_DISTANCE); }
void CSound::StartThread(int maxSounds) { #if BOOST_VERSION >= 103500 try { #endif { boost::mutex::scoped_lock lck(soundMutex); // Generate sound sources for (int i = 0; i < maxSounds; i++) { SoundSource* thenewone = new SoundSource(); if (thenewone->IsValid()) { sources.push_back(thenewone); } else { maxSounds = std::max(i-1,0); LogObject(LOG_SOUND) << "Your hardware/driver can not handle more than " << maxSounds << " soundsources"; delete thenewone; break; } } // Set distance model (sound attenuation) alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); //alDopplerFactor(1.0); alListenerf(AL_GAIN, masterVolume); } configHandler->Set("MaxSounds", maxSounds); soundThreadRunning = true; while (soundThreadRunning) { #if BOOST_VERSION >= 103500 boost::this_thread::sleep(boost::posix_time::millisec(50)); // sleep #else SDL_Delay(50); #endif boost::mutex::scoped_lock lck(soundMutex); // lock Update(); // call update } #if BOOST_VERSION >= 103500 } catch(boost::thread_interrupted const&) { // do cleanup here } #endif }
Handle<Value> ALDistanceModelCallback(const Arguments& args) { //if less that nbr of formal parameters then do nothing if (args.Length() < 1) return v8::Undefined(); //get arguments int arg0 = args[0]->IntegerValue(); //make call alDistanceModel((ALenum)arg0); return v8::Undefined(); }
// Thread: Any. Must be locked: AudioMutex. bool CreatePlaybackDevice() { if (AudioDevice) return true; AudioDevice = alcOpenDevice(nullptr); if (!AudioDevice) { LOG(("Audio Error: Could not create default playback device, enumerating..")); EnumeratePlaybackDevices(); return false; } ALCint attributes[] = { ALC_STEREO_SOURCES, 128, ALC_FREQUENCY, Media::Player::kDefaultFrequency, 0 }; AudioContext = alcCreateContext(AudioDevice, attributes); alcMakeContextCurrent(AudioContext); if (ContextErrorHappened()) { DestroyPlaybackDevice(); return false; } ALfloat v[] = { 0.f, 0.f, -1.f, 0.f, 1.f, 0.f }; alListener3f(AL_POSITION, 0.f, 0.f, 0.f); alListener3f(AL_VELOCITY, 0.f, 0.f, 0.f); alListenerfv(AL_ORIENTATION, v); #ifndef TDESKTOP_DISABLE_OPENAL_EFFECTS // playback speed related init // generate an effect slot and an effect alGenAuxiliaryEffectSlots(1, &_playbackSpeedData.uiEffectSlot); alGenEffects(1, &_playbackSpeedData.uiEffect); // initialize the pitch shifter effect alEffecti(_playbackSpeedData.uiEffect, AL_EFFECT_TYPE, AL_EFFECT_PITCH_SHIFTER); // 12 semitones = 1 octave alEffecti(_playbackSpeedData.uiEffect, AL_PITCH_SHIFTER_COARSE_TUNE, kPlaybackSpeedTune); // connect the effect with the effect slot alAuxiliaryEffectSloti(_playbackSpeedData.uiEffectSlot, AL_EFFECTSLOT_EFFECT, _playbackSpeedData.uiEffect); // initialize a filter to disable the direct (dry) path alGenFilters(1, &_playbackSpeedData.uiFilter); alFilteri(_playbackSpeedData.uiFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS); // disable all frequencies alFilterf(_playbackSpeedData.uiFilter, AL_LOWPASS_GAIN, 0.f); // to use the modified playback speed: // connect both the effect slot and filter with the stream source and set AL_PITCH #endif // TDESKTOP_DISABLE_OPENAL_EFFECTS alDistanceModel(AL_NONE); return true; }
/* The open method starts up the driver and should lock the device, using the previously set paramters, or defaults. It shouldn't need to start sending audio data to the device yet, however. */ static int _openal_open(void) { ALenum openal_err; ALCenum alc_err; ALLEGRO_INFO("Starting OpenAL\n"); /* clear the error state */ openal_err = alGetError(); /* pick default device. always a good choice */ openal_dev = alcOpenDevice(NULL); alc_err = ALC_NO_ERROR; if (!openal_dev || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) { ALLEGRO_ERROR("Could not open audio device: %s\n", alc_get_err_str(alc_err)); return 1; } openal_context = alcCreateContext(openal_dev, NULL); alc_err = ALC_NO_ERROR; if (!openal_context || (alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) { ALLEGRO_ERROR("Could not create current device context: %s\n", alc_get_err_str(alc_err)); return 1; } alcMakeContextCurrent(openal_context); #if !defined ALLEGRO_IPHONE if ((alc_err = alcGetError(openal_dev)) != ALC_NO_ERROR) { ALLEGRO_ERROR("Could not make context current: %s\n", alc_get_err_str(alc_err)); return 1; } alDistanceModel(AL_NONE); if ((openal_err = alGetError()) != AL_NO_ERROR) { ALLEGRO_ERROR("Could not set distance model: %s\n", openal_get_err_str(openal_err)); return 1; } #endif ALLEGRO_DEBUG("Vendor: %s\n", alGetString(AL_VENDOR)); ALLEGRO_DEBUG("Version: %s\n", alGetString(AL_VERSION)); ALLEGRO_DEBUG("Renderer: %s\n", alGetString(AL_RENDERER)); ALLEGRO_DEBUG("Extensions: %s\n", alGetString(AL_EXTENSIONS)); return 0; }
void ConfigurarEntorno ( ALsizei identificador, ALenum modelo, ALfloat doppler_factor, ALfloat doppler_vel, ALint room, ALint room_high_frequency, ALfloat rolloff_factor, ALfloat decay_time, ALfloat decay_high_frequency_ratio, ALint reflections, ALfloat reflections_delay, ALint reverb, ALfloat reverb_delay, ALfloat diffusion, ALfloat density, ALfloat high_frequency_reference ){ /* Configuramos la atenuacion y el efecto doppler */ alEnable ( AL_DISTANCE_MODEL ); alDistanceModel ( modelo ); alDopplerFactor ( doppler_factor ); alDopplerVelocity ( doppler_vel ); /* Recordad que en metros la velocidad del sonido es 343 */ #ifdef _LINUX /* Generamos el entorno y comprobamos errores */ alGenEnvironmentIASIG ( identificador, &entornos[identificador] ); if ( !alIsEnvironmentIASIG ( entornos[identificador] )){ fprintf ( logs, "No se puede configurar parte del entorno\n"); } /* Configuramos las propiedades del entorno */ alEnvironmentiIASIG ( entornos[identificador], AL_ENV_ROOM_IASIG, room ); alEnvironmentiIASIG ( entornos[identificador], AL_ENV_ROOM_HIGH_FREQUENCY_IASIG, room_high_frequency); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_ROOM_ROLLOFF_FACTOR_IASIG, rolloff_factor ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DECAY_TIME_IASIG, decay_time ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DECAY_HIGH_FREQUENCY_RATIO_IASIG, decay_high_frequency_ratio ); alEnvironmentiIASIG ( entornos[identificador], AL_ENV_REFLECTIONS_IASIG, reflections ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_REFLECTIONS_DELAY_IASIG, reflections_delay ); alEnvironmentiIASIG ( entornos[identificador], AL_ENV_REVERB_IASIG, reverb ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_REVERB_DELAY_IASIG, reverb_delay ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DIFFUSION_IASIG, diffusion ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_DENSITY_IASIG, density ); alEnvironmentfIASIG ( entornos[identificador], AL_ENV_HIGH_FREQUENCY_REFERENCE_IASIG, high_frequency_reference ); #endif #ifdef _WIN32 /* Para windows se pueden crear y configurar entornos utilizando las extensiones EAX que admiten algunas tarjetas Soundblaster. Pero como no sé si es gratuito la utilizacion de dichas extensiones, de momento para windows no se generaran entornos */ #endif }
void Contexte::setDistanceModel(ALenum modele) { alGetError(); alDistanceModel(modele); ALenum error = alCheckError(); if (error == AL_INVALID_VALUE) { std::cerr << "The specified distance model is not valid." << std::endl; } else if (error == AL_INVALID_OPERATION) { std::cerr << "There is no current context." << std::endl; } }
static int _context_setdistancemodel (PyObject* self, PyObject *value, void *closure) { int model; ASSERT_CONTEXT_IS_CURRENT (self, -1); if (!IntFromObj (value, &model)) return -1; CLEAR_ALERROR_STATE (); alDistanceModel ((ALenum)model); if (SetALErrorException (alGetError (), 0)) return -1; return 0; }
OALAudioEngine::OALAudioEngine() { ALCdevice* device = alcOpenDevice(nullptr); ALCcontext* context = alcCreateContext(device, 0); alcMakeContextCurrent(context); this->SetListenerPos(float3(0, 0, 0)); this->SetListenerVel(float3(0, 0, 0)); this->SetListenerOri(float3(0, 0, 1), float3(0, 1, 0)); alDistanceModel(AL_INVERSE_DISTANCE); alDopplerFactor(1); alDopplerVelocity(343); // m/s }
Engine::Audio::AudioRenderer::AudioRenderer(void) { _device = alcOpenDevice(NULL); if (!_device) { throw std::exception("Error init OpenAL device"); } _context = alcCreateContext(_device, NULL); if (!alcMakeContextCurrent(_context)) { throw std::exception("Error init OpenAL context"); } alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); }
void init() { s_al_device = alcOpenDevice(NULL); CE_ASSERT(s_al_device, "Cannot open OpenAL audio device"); s_al_context = alcCreateContext(s_al_device, NULL); CE_ASSERT(s_al_context, "Cannot create OpenAL context"); AL_CHECK(alcMakeContextCurrent(s_al_context)); CE_LOGD("OpenAL Vendor : %s", alGetString(AL_VENDOR)); CE_LOGD("OpenAL Version : %s", alGetString(AL_VERSION)); CE_LOGD("OpenAL Renderer : %s", alGetString(AL_RENDERER)); AL_CHECK(alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED)); AL_CHECK(alDopplerFactor(1.0f)); AL_CHECK(alDopplerVelocity(343.0f)); }
static int Initialize(void *hnd) { ALCdevice *dev; ALCcontext *ctxt; ALCint attrs[3]; // TODO: Check for failures (generally, not just in this file). dev = alcOpenDevice(NULL); attrs[0] = ALC_FREQUENCY; attrs[1] = RLX.Audio.SR_to_Khz[RLX.Audio.SamplingRate]; attrs[2] = 0; ctxt = alcCreateContext(dev, (ALCint *)&attrs); alcMakeContextCurrent(ctxt); alDistanceModel(AL_INVERSE_DISTANCE); alDopplerFactor(0.f); // No doppler alDopplerVelocity(0.f); // No velocity RLX.Audio.Config|=RLXAUDIO_Use3D; return 0; }
COpenALSound::COpenALSound() { Sources = NULL; maxSounds = configHandler.GetInt("MaxSounds", 16); if (maxSounds <= 0) { throw content_error("Internal error, (maxSounds <= 0) in COpenALSound"); } globalVolume = 1.0f; cur = 0; ALCdevice *device = alcOpenDevice(NULL); if (device == NULL) { throw content_error("Could not create OpenAL audio device"); } else { ALCcontext *context = alcCreateContext(device, NULL); if (context != NULL) { alcMakeContextCurrent(context); } else { alcCloseDevice(device); throw content_error("Could not create OpenAL audio context"); } } logOutput.Print("OpenAL: %s\n", (const char*)alGetString(AL_VERSION)); logOutput.Print("OpenAL: %s", (const char*)alGetString(AL_EXTENSIONS)); // Generate sound sources Sources = SAFE_NEW ALuint[maxSounds]; for (int a=0;a<maxSounds;a++) { Sources[a]=0; } // Set distance model (sound attenuation) alDistanceModel (AL_INVERSE_DISTANCE); posScale.x = 0.02f; posScale.y = 0.0005f; posScale.z = 0.02f; }
void SetupAndPlayAudio() { g_MyState.source_pos[0] = 1.0f; g_MyState.source_pos[1] = 1.0f; g_MyState.source_pos[2] = 1.0f; g_MyState.source_vel[0] = 0.0f; g_MyState.source_vel[1] = 0.0f; g_MyState.source_vel[2] = 0.0f; g_MyState.listener_pos[0] = 0.0f; g_MyState.listener_pos[1] = 0.0f; g_MyState.listener_pos[2] = 0.0f; g_MyState.listener_vel[0] = 0.0f; g_MyState.listener_vel[1] = 0.0f; g_MyState.listener_vel[2] = 0.0f; g_MyState.pitch = 1.0f; g_MyState.gain = 1.0f; alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED); assert(alGetError() == AL_NO_ERROR); alSourcei(g_MyState.source, AL_LOOPING, AL_TRUE); assert(alGetError() == AL_NO_ERROR); alSourcefv(g_MyState.source, AL_POSITION, g_MyState.source_pos); assert(alGetError() == AL_NO_ERROR); alSourcef(g_MyState.source, AL_REFERENCE_DISTANCE, 1.0f); assert(alGetError() == AL_NO_ERROR); alSourcef(g_MyState.source, AL_MAX_DISTANCE, 70.0f); assert(alGetError() == AL_NO_ERROR); alSourcef(g_MyState.source, AL_GAIN, 1.0f); assert(alGetError() == AL_NO_ERROR); alSourcei(g_MyState.source, AL_BUFFER, g_MyState.buffer); assert(alGetError() == AL_NO_ERROR); alSourcef(g_MyState.source, AL_PITCH, g_MyState.pitch); assert(alGetError() == AL_NO_ERROR); alSourcef(g_MyState.source, AL_GAIN, g_MyState.gain); assert(alGetError() == AL_NO_ERROR); alSourcePlay(g_MyState.source); assert(alGetError() == AL_NO_ERROR); }
void sound_init() { ALCdevice* pDevice; ALCcontext* pContext; // Get handle to device. pDevice = alcOpenDevice(NULL); // Create audio context. pContext = alcCreateContext(pDevice, NULL); // Set active context. alcMakeContextCurrent(pContext); // Check for an error. if (alcGetError(pDevice) != ALC_NO_ERROR) fprintf(stderr, "Warning: cannot initialize sound environment."); alDistanceModel(AL_LINEAR_DISTANCE); }
void Init(int frequency, int resolution, int sources) { (void)resolution; --sources; // one spare source for music ALCint attribs[] = { ALC_FREQUENCY, frequency, /*ALC_MONO_SOURCES, sources, ALC_STEREO_SOURCES, 1,*/ 0 }; alureInitDevice(NULL, attribs); soundSources = new ALuint[sources]; alGenSources(sources, soundSources); alGenSources(1, &musicSource); //alGenBuffers(2, musicBufs); soundSourceCount = sources; alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); alSpeedOfSound(1400.0); alDopplerFactor(0.7); alureUpdateInterval(0.03333f); }