PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop, float volume, v3f pos, float pitch) { infostream<<"OpenALSoundManager: Creating positional playing sound" <<std::endl; assert(buf); PlayingSound *sound = new PlayingSound; assert(sound); warn_if_error(alGetError(), "before createPlayingSoundAt"); alGenSources(1, &sound->source_id); alSourcei(sound->source_id, AL_BUFFER, buf->buffer_id); alSourcei(sound->source_id, AL_SOURCE_RELATIVE, false); alSource3f(sound->source_id, AL_POSITION, pos.X, pos.Y, pos.Z); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); // Use alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED) and set reference // distance to clamp gain at <1 node distance, to avoid excessive // volume when closer alSourcef(sound->source_id, AL_REFERENCE_DISTANCE, 10.0f); alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); // Multiply by 3 to compensate for reducing AL_REFERENCE_DISTANCE from // the previous value of 30 to the new value of 10 volume = std::fmax(0.0f, volume * 3.0f); alSourcef(sound->source_id, AL_GAIN, volume); alSourcef(sound->source_id, AL_PITCH, pitch); alSourcePlay(sound->source_id); warn_if_error(alGetError(), "createPlayingSoundAt"); return sound; }
void updateListener(v3f pos, v3f vel, v3f at, v3f up) { m_listener_pos = pos; alListener3f(AL_POSITION, pos.X, pos.Y, pos.Z); alListener3f(AL_VELOCITY, vel.X, vel.Y, vel.Z); ALfloat f[6]; f3_set(f, at); f3_set(f+3, -up); alListenerfv(AL_ORIENTATION, f); warn_if_error(alGetError(), "updateListener"); }
PlayingSound* createPlayingSound(SoundBuffer *buf, bool loop, float volume) { infostream<<"OpenALSoundManager: Creating playing sound"<<std::endl; assert(buf); PlayingSound *sound = new PlayingSound; assert(sound); warn_if_error(alGetError(), "before createPlayingSound"); alGenSources(1, &sound->source_id); alSourcei(sound->source_id, AL_BUFFER, buf->buffer_id); alSourcei(sound->source_id, AL_SOURCE_RELATIVE, true); alSource3f(sound->source_id, AL_POSITION, 0, 0, 0); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); volume = MYMAX(0.0, volume); alSourcef(sound->source_id, AL_GAIN, volume); alSourcePlay(sound->source_id); warn_if_error(alGetError(), "createPlayingSound"); return sound; }
PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop, float volume, v3f pos) { infostream<<"OpenALSoundManager: Creating positional playing sound" <<std::endl; assert(buf); PlayingSound *sound = new PlayingSound; assert(sound); warn_if_error(alGetError(), "before createPlayingSoundAt"); alGenSources(1, &sound->source_id); alSourcei(sound->source_id, AL_BUFFER, buf->buffer_id); alSourcei(sound->source_id, AL_SOURCE_RELATIVE, false); alSource3f(sound->source_id, AL_POSITION, pos.X, pos.Y, pos.Z); alSource3f(sound->source_id, AL_VELOCITY, 0, 0, 0); //alSourcef(sound->source_id, AL_ROLLOFF_FACTOR, 0.7); alSourcef(sound->source_id, AL_REFERENCE_DISTANCE, 30.0); alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE); volume = MYMAX(0.0, volume); alSourcef(sound->source_id, AL_GAIN, volume); alSourcePlay(sound->source_id); warn_if_error(alGetError(), "createPlayingSoundAt"); return sound; }