4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "openal_sound_source.hpp"
22 #include "sound_manager.hpp"
23 #include "math/vector.hpp"
25 OpenALSoundSource::OpenALSoundSource()
27 alGenSources(1, &source);
28 SoundManager::check_al_error("Couldn't create audio source: ");
29 set_reference_distance(128);
32 OpenALSoundSource::~OpenALSoundSource()
35 alDeleteSources(1, &source);
39 OpenALSoundSource::stop()
42 alSourcei(source, AL_BUFFER, AL_NONE);
43 SoundManager::check_al_error("Problem stopping audio source: ");
47 OpenALSoundSource::play()
50 SoundManager::check_al_error("Couldn't start audio source: ");
54 OpenALSoundSource::playing()
56 ALint state = AL_PLAYING;
57 alGetSourcei(source, AL_SOURCE_STATE, &state);
58 return state != AL_STOPPED;
62 OpenALSoundSource::update()
67 OpenALSoundSource::set_looping(bool looping)
69 alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
73 OpenALSoundSource::set_position(const Vector& position)
75 alSource3f(source, AL_POSITION, position.x, position.y, 0);
79 OpenALSoundSource::set_velocity(const Vector& velocity)
81 alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
85 OpenALSoundSource::set_gain(float gain)
87 alSourcef(source, AL_GAIN, gain);
91 OpenALSoundSource::set_pitch(float pitch)
93 alSourcef(source, AL_PITCH, pitch);
97 OpenALSoundSource::set_reference_distance(float distance)
99 alSourcef(source, AL_REFERENCE_DISTANCE, distance);
103 OpenALSoundSource::set_rollof_factor(float factor)
105 alSourcef(source, AL_ROLLOFF_FACTOR, factor);