2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "audio/openal_sound_source.hpp"
18 #include "audio/sound_manager.hpp"
20 OpenALSoundSource::OpenALSoundSource() :
23 alGenSources(1, &source);
24 SoundManager::check_al_error("Couldn't create audio source: ");
25 set_reference_distance(128);
28 OpenALSoundSource::~OpenALSoundSource()
31 alDeleteSources(1, &source);
35 OpenALSoundSource::stop()
38 alSourcei(source, AL_BUFFER, AL_NONE);
39 SoundManager::check_al_error("Problem stopping audio source: ");
43 OpenALSoundSource::play()
46 SoundManager::check_al_error("Couldn't start audio source: ");
50 OpenALSoundSource::playing()
52 ALint state = AL_PLAYING;
53 alGetSourcei(source, AL_SOURCE_STATE, &state);
54 return state != AL_STOPPED;
58 OpenALSoundSource::update()
63 OpenALSoundSource::set_looping(bool looping)
65 alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
69 OpenALSoundSource::set_position(const Vector& position)
71 alSource3f(source, AL_POSITION, position.x, position.y, 0);
75 OpenALSoundSource::set_velocity(const Vector& velocity)
77 alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
81 OpenALSoundSource::set_gain(float gain)
83 alSourcef(source, AL_GAIN, gain);
87 OpenALSoundSource::set_pitch(float pitch)
89 alSourcef(source, AL_PITCH, pitch);
93 OpenALSoundSource::set_reference_distance(float distance)
95 alSourcef(source, AL_REFERENCE_DISTANCE, distance);
99 OpenALSoundSource::set_rollof_factor(float factor)
101 alSourcef(source, AL_ROLLOFF_FACTOR, factor);