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"
19 #include "audio/sound_manager.hpp"
21 OpenALSoundSource::OpenALSoundSource() :
24 alGenSources(1, &source);
25 SoundManager::check_al_error("Couldn't create audio source: ");
26 set_reference_distance(128);
29 OpenALSoundSource::~OpenALSoundSource()
32 alDeleteSources(1, &source);
36 OpenALSoundSource::stop()
39 alSourcei(source, AL_BUFFER, AL_NONE);
40 SoundManager::check_al_error("Problem stopping audio source: ");
44 OpenALSoundSource::play()
47 SoundManager::check_al_error("Couldn't start audio source: ");
51 OpenALSoundSource::playing()
53 ALint state = AL_PLAYING;
54 alGetSourcei(source, AL_SOURCE_STATE, &state);
55 return state != AL_STOPPED;
59 OpenALSoundSource::pause()
61 alSourcePause(source);
62 SoundManager::check_al_error("Couldn't pause audio source: ");
66 OpenALSoundSource::resume()
77 OpenALSoundSource::paused()
79 ALint state = AL_PAUSED;
80 alGetSourcei(source, AL_SOURCE_STATE, &state);
81 return state == AL_PAUSED;
85 OpenALSoundSource::update()
90 OpenALSoundSource::set_looping(bool looping)
92 alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
96 OpenALSoundSource::set_relative(bool relative)
98 alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
102 OpenALSoundSource::set_position(const Vector& position)
104 alSource3f(source, AL_POSITION, position.x, position.y, 0);
108 OpenALSoundSource::set_velocity(const Vector& velocity)
110 alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
114 OpenALSoundSource::set_gain(float gain)
116 alSourcef(source, AL_GAIN, gain);
120 OpenALSoundSource::set_pitch(float pitch)
122 alSourcef(source, AL_PITCH, pitch);
126 OpenALSoundSource::set_reference_distance(float distance)
128 alSourcef(source, AL_REFERENCE_DISTANCE, distance);