00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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