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"
24 OpenALSoundSource::OpenALSoundSource()
26 alGenSources(1, &source);
27 SoundManager::check_al_error("Couldn't create audio source: ");
28 set_reference_distance(128);
31 OpenALSoundSource::~OpenALSoundSource()
34 alDeleteSources(1, &source);
38 OpenALSoundSource::stop()
41 alSourcei(source, AL_BUFFER, AL_NONE);
42 SoundManager::check_al_error("Problem stopping audio source: ");
46 OpenALSoundSource::play()
49 SoundManager::check_al_error("Couldn't start audio source: ");
53 OpenALSoundSource::playing()
55 ALint state = AL_PLAYING;
56 alGetSourcei(source, AL_SOURCE_STATE, &state);
57 return state != AL_STOPPED;
61 OpenALSoundSource::update()
66 OpenALSoundSource::set_looping(bool looping)
68 alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
72 OpenALSoundSource::set_position(const Vector& position)
74 alSource3f(source, AL_POSITION, position.x, position.y, 0);
78 OpenALSoundSource::set_velocity(const Vector& velocity)
80 alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
84 OpenALSoundSource::set_gain(float gain)
86 alSourcef(source, AL_GAIN, gain);
90 OpenALSoundSource::set_pitch(float pitch)
92 alSourcef(source, AL_PITCH, pitch);
96 OpenALSoundSource::set_reference_distance(float distance)
98 alSourcef(source, AL_REFERENCE_DISTANCE, distance);
102 OpenALSoundSource::set_rollof_factor(float factor)
104 alSourcef(source, AL_ROLLOFF_FACTOR, factor);