OALplus (0.52.0) a C++ wrapper for OpenAL

buffer.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OALPLUS_BUFFER_1303201647_HPP
14 #define OALPLUS_BUFFER_1303201647_HPP
15 
16 #include <oalplus/config.hpp>
17 #include <oalplus/fwd.hpp>
18 #include <oalplus/alfunc.hpp>
19 #include <oalplus/data_format.hpp>
20 #include <oalplus/error/object.hpp>
21 #include <oalplus/object/wrapper.hpp>
22 
23 #include <cassert>
24 
25 namespace oalplus {
26 
28 
35 template <>
36 class ObjGenDelOps<tag::Buffer>
37 {
38 protected:
39  static void Gen(tag::Generate, ALsizei count, ALuint* names)
40  {
41  assert(names != nullptr);
42  OALPLUS_ALFUNC(GenBuffers)(count, names);
43  OALPLUS_CHECK_SIMPLE(GenBuffers);
44  }
45 
46  static void Delete(ALsizei count, ALuint* names)
47  {
48  assert(names != nullptr);
49  OALPLUS_ALFUNC(DeleteBuffers)(count, names);
50  OALPLUS_VERIFY_SIMPLE(DeleteBuffers);
51  }
52 
53  static ALboolean IsA(ALuint name)
54  {
55  assert(name != 0);
56  ALboolean result = OALPLUS_ALFUNC(IsBuffer)(name);
57  OALPLUS_VERIFY_SIMPLE(IsBuffer);
58  return result;
59  }
60 };
61 
63 
69 template <>
70 class ObjectOps<tag::DirectState, tag::Buffer>
71  : public ObjectName<tag::Buffer>
72 {
73 protected:
74  ObjectOps(void) { }
75 public:
77 
81  void Data(
82  DataFormat format,
83  const ALvoid* data,
84  ALsizei size,
85  ALsizei frequency
86  )
87  {
88  OALPLUS_ALFUNC(BufferData)(
89  ALuint(this->_name),
90  ALenum(format),
91  data,
92  size,
93  frequency
94  );
95  OALPLUS_CHECK(
96  BufferData,
97  ObjectError,
98  Object(*this)
99  );
100  }
101 
103 
108  ALsizei Frequency(void) const
109  {
110  ALint result = 0;
111  OALPLUS_ALFUNC(GetBufferiv)(
112  _name,
113  AL_FREQUENCY,
114  &result
115  );
116  OALPLUS_VERIFY(
117  GetBufferiv,
118  ObjectError,
119  Object(*this)
120  );
121  return ALsizei(result);
122  }
123 
125 
130  ALsizei Size(void) const
131  {
132  ALint result = 0;
133  OALPLUS_ALFUNC(GetBufferiv)(
134  _name,
135  AL_SIZE,
136  &result
137  );
138  OALPLUS_VERIFY(
139  GetBufferiv,
140  ObjectError,
141  Object(*this)
142  );
143  return ALsizei(result);
144  }
145 
147 
152  ALsizei Bits(void) const
153  {
154  ALint result = 0;
155  OALPLUS_ALFUNC(GetBufferiv)(
156  _name,
157  AL_BITS,
158  &result
159  );
160  OALPLUS_VERIFY(
161  GetBufferiv,
162  ObjectError,
163  Object(*this)
164  );
165  return ALsizei(result);
166  }
167 
169 
174  ALsizei Channels(void) const
175  {
176  ALint result = 0;
177  OALPLUS_ALFUNC(GetBufferiv)(
178  _name,
179  AL_CHANNELS,
180  &result
181  );
182  OALPLUS_VERIFY(
183  GetBufferiv,
184  ObjectError,
185  Object(*this)
186  );
187  return ALsizei(result);
188  }
189 
191 
199  ALfloat Duration(void) const
200  {
201  ALfloat s = Size();
202  ALfloat f = Frequency();
203  ALfloat b = Bits()/8.0f;
204  ALfloat c = Channels();
205  ALfloat bps = f*b*c;
206  return bps>0.0f?ALfloat(s/bps):ALfloat(0);
207  }
208 };
209 
210 } // namespace oalplus
211 namespace oglplus {
212 
213 template <>
214 class ObjGenDelOps<oalplus::tag::Buffer>
215  : public oalplus::ObjGenDelOps<oalplus::tag::Buffer>
216 { };
217 
218 template <typename OpsTag>
219 class ObjectOps<OpsTag, oalplus::tag::Buffer>
220  : public oalplus::ObjectOps<OpsTag, oalplus::tag::Buffer>
221 { };
222 
223 } // namespace oglplus
224 namespace oalplus {
225 
227  BufferOps;
228 
230 
233 typedef Object<BufferOps> Buffer;
234 
235 } // namespace oalplus
236 
237 #endif // include guard
ALsizei Size(void) const
Returns the size of the data stored in this buffer.
Definition: buffer.hpp:130
ALsizei Frequency(void) const
Returns the sampling frequency of the data stored in this buffer.
Definition: buffer.hpp:108
void Data(DataFormat format, const ALvoid *data, ALsizei size, ALsizei frequency)
Specifies the buffer data.
Definition: buffer.hpp:81
Forward declarations.
Compile-time configuration options.
ALfloat Duration(void) const
Returns the duration of the sound stored in this buffer.
Definition: buffer.hpp:199
Helper macro expanding into OpenAL function name.
ObjectOps< tag::ExplicitSel, tag::Buffer > BufferOps
Object< BufferOps > Buffer
An oalplus_object encapsulating the OpenAL buffer functionality.
Definition: buffer.hpp:233
ALsizei Bits(void) const
Returns the number of bits of the data stored in this buffer.
Definition: buffer.hpp:152
Data format enumeration.
ALsizei Channels(void) const
Returns the number of channels of the data stored in this buffer.
Definition: buffer.hpp:174

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).