* In the usage help, put LEVELFILE into brackets since it's an optional argument.
[supertux.git] / src / audio / sound_source.cpp
1 #include <config.h>
2
3 #include "sound_source.hpp"
4 #include "sound_manager.hpp"
5
6 SoundSource::SoundSource()
7 {
8   alGenSources(1, &source);
9   SoundManager::check_al_error("Couldn't create audio source: ");
10   set_reference_distance(128);
11 }
12
13 SoundSource::~SoundSource()
14 {
15   stop();
16   alDeleteSources(1, &source);
17 }
18
19 void
20 SoundSource::stop()
21 {
22   alSourceStop(source);
23   alSourcei(source, AL_BUFFER, AL_NONE);
24   SoundManager::check_al_error("Problem stopping audio source: ");
25 }
26
27 void
28 SoundSource::play()
29 {
30   alSourcePlay(source);
31   SoundManager::check_al_error("Couldn't start audio source: ");
32 }
33
34 bool
35 SoundSource::playing()
36 {
37   ALint state = AL_PLAYING;
38   alGetSourcei(source, AL_SOURCE_STATE, &state);
39   return state != AL_STOPPED;
40 }
41
42 void
43 SoundSource::set_looping(bool looping)
44 {
45   alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
46 }
47
48 void
49 SoundSource::set_position(Vector position)
50 {
51   alSource3f(source, AL_POSITION, position.x, position.y, 0);
52 }
53
54 void
55 SoundSource::set_velocity(Vector velocity)
56 {
57   alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
58 }
59
60 void
61 SoundSource::set_gain(float gain)
62 {
63   alSourcef(source, AL_GAIN, gain);
64 }
65
66 void
67 SoundSource::set_reference_distance(float distance)
68 {
69   alSourcef(source, AL_REFERENCE_DISTANCE, distance);
70 }