added radio images and removed intro background image
[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::update()
44 {
45 }
46
47 void
48 SoundSource::set_looping(bool looping)
49 {
50   alSourcei(source, AL_LOOPING, looping ? AL_TRUE : AL_FALSE);
51 }
52
53 void
54 SoundSource::set_position(Vector position)
55 {
56   alSource3f(source, AL_POSITION, position.x, position.y, 0);
57 }
58
59 void
60 SoundSource::set_velocity(Vector velocity)
61 {
62   alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, 0);
63 }
64
65 void
66 SoundSource::set_gain(float gain)
67 {
68   alSourcef(source, AL_GAIN, gain);
69 }
70
71 void
72 SoundSource::set_reference_distance(float distance)
73 {
74   alSourcef(source, AL_REFERENCE_DISTANCE, distance);
75 }