src/audio/openal_sound_source.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "audio/openal_sound_source.hpp"
00018 #include "audio/sound_manager.hpp"
00019 
00020 OpenALSoundSource::OpenALSoundSource() :
00021   source()
00022 {
00023   alGenSources(1, &source);
00024   SoundManager::check_al_error("Couldn't create audio source: ");
00025   set_reference_distance(128);
00026 }
00027 
00028 OpenALSoundSource::~OpenALSoundSource()
00029 {
00030   stop();
00031   alDeleteSources(1, &source);
00032 }
00033 
00034 void
00035 OpenALSoundSource::stop()
00036 {
00037   alSourceStop(source);
00038   alSourcei(source, AL_BUFFER, AL_NONE);
00039   SoundManager::check_al_error("Problem stopping audio source: ");
00040 }
00041 
00042 void
00043 OpenALSoundSource::play()
00044 {
00045   alSourcePlay(source);
00046   SoundManager::check_al_error("Couldn't start audio source: ");
00047 }
00048 
00049 bool
00050 OpenALSoundSource::playing()
00051 {
00052   ALint state = AL_PLAYING;
00053   alGetSourcei(source, AL_SOURCE_STATE, &state);
00054   return state != AL_STOPPED;
00055 }
00056 
00057 void
00058 OpenALSoundSource::update()
00059 {
00060 }
00061 
00062 void
00063 OpenALSoundSource::set_looping(bool looping)
00064 {
00065   alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
00066 }
00067 
00068 void
00069 OpenALSoundSource::set_relative(bool relative)
00070 {
00071   alSourcei(source, AL_SOURCE_RELATIVE, relative ? AL_TRUE : AL_FALSE);
00072 }
00073 
00074 void
00075 OpenALSoundSource::set_position(const Vector& position)
00076 {
00077   alSource3f(source, AL_POSITION, position.x, position.y, 0);
00078 }
00079 
00080 void
00081 OpenALSoundSource::set_velocity(const Vector& velocity)
00082 {
00083   alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
00084 }
00085 
00086 void
00087 OpenALSoundSource::set_gain(float gain)
00088 {
00089   alSourcef(source, AL_GAIN, gain);
00090 }
00091 
00092 void
00093 OpenALSoundSource::set_pitch(float pitch)
00094 {
00095   alSourcef(source, AL_PITCH, pitch);
00096 }
00097 
00098 void
00099 OpenALSoundSource::set_reference_distance(float distance)
00100 {
00101   alSourcef(source, AL_REFERENCE_DISTANCE, distance);
00102 }
00103 
00104 /* EOF */

Generated on Mon Jun 9 03:38:16 2014 for SuperTux by  doxygen 1.5.1