]> git.tdb.fi Git - libs/al.git/blob - source/source.cpp
Remove the general-purpose attribute functions
[libs/al.git] / source / source.cpp
1 #include "buffer.h"
2 #include "source.h"
3
4 using namespace std;
5
6 namespace Msp {
7 namespace AL {
8
9 Source::Source()
10 {
11         alGenSources(1, &id);
12 }
13
14 Source::~Source()
15 {
16         alDeleteSources(1, &id);
17 }
18
19 SourceState Source::get_state() const
20 {
21         int state = INITIAL;
22         alGetSourcei(id, AL_SOURCE_STATE, &state);
23         return static_cast<SourceState>(state);
24 }
25
26 void Source::set_position(float x, float y, float z)
27 {
28         alSource3f(id, AL_POSITION, x, y, z);
29 }
30
31 void Source::set_velocity(float x, float y, float z)
32 {
33         alSource3f(id, AL_VELOCITY, x, y, z);
34 }
35
36 void Source::set_looping(bool l)
37 {
38         alSourcei(id, AL_LOOPING, l);
39 }
40
41 void Source::set_gain(float g)
42 {
43         alSourcef(id, AL_GAIN, g);
44 }
45
46 void Source::set_rolloff_factor(float f)
47 {
48         alSourcef(id, AL_ROLLOFF_FACTOR, f);
49 }
50
51 void Source::set_buffer(const Buffer &buffer)
52 {
53         alSourcei(id, AL_BUFFER, buffer.get_id());
54 }
55
56 void Source::queue_buffers(const vector<const Buffer *> &buffers)
57 {
58         vector<uint> ids;
59         ids.reserve(buffers.size());
60         for(vector<const Buffer *>::const_iterator i=buffers.begin(); i!=buffers.end(); ++i)
61                 ids.push_back((*i)->get_id());
62         alSourceQueueBuffers(id, ids.size(), &ids.front());
63 }
64
65 void Source::queue_buffer(const Buffer &buffer)
66 {
67         uint bid = buffer.get_id();
68         alSourceQueueBuffers(id, 1, &bid);
69 }
70
71 void Source::unqueue_buffers(const vector<const Buffer *> &buffers)
72 {
73         vector<uint> ids;
74         ids.reserve(buffers.size());
75         for(vector<const Buffer *>::const_iterator i=buffers.begin(); i!=buffers.end(); ++i)
76                 ids.push_back((*i)->get_id());
77         alSourceUnqueueBuffers(id, ids.size(), &ids.front());
78 }
79
80 void Source::unqueue_buffer(const Buffer &buffer)
81 {
82         uint bid = buffer.get_id();
83         alSourceUnqueueBuffers(id, 1, &bid);
84 }
85
86 void Source::clear_buffers()
87 {
88         alSourcei(id, AL_BUFFER, AL_NONE);
89 }
90
91 unsigned Source::get_buffers_queued() const
92 {
93         int n = 0;
94         alGetSourceiv(id, AL_BUFFERS_QUEUED, &n);
95         return n;
96 }
97
98 unsigned Source::get_buffers_processed() const
99 {
100         int n = 0;
101         alGetSourceiv(id, AL_BUFFERS_PROCESSED, &n);
102         return n;
103 }
104
105 void Source::play()
106 {
107         alSourcePlay(id);
108 }
109
110 void Source::pause()
111 {
112         alSourcePause(id);
113 }
114
115 void Source::stop()
116 {
117         alSourceStop(id);
118 }
119
120 void Source::rewind()
121 {
122         alSourceRewind(id);
123 }
124
125 } // namespace AL
126 } // namespace Msp