OALplus (0.52.0) a C++ wrapper for OpenAL

device.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OALPLUS_DEVICE_1303201647_HPP
14 #define OALPLUS_DEVICE_1303201647_HPP
15 
16 #include <oalplus/config.hpp>
17 #include <oalplus/fwd.hpp>
18 #include <oalplus/alfunc.hpp>
19 #include <oalplus/error/alc.hpp>
20 #include <oalplus/data_format.hpp>
21 
22 #include <oalplus/detail/sep_str_range.hpp>
23 
24 #include <cstring>
25 #include <cassert>
26 
27 namespace oalplus {
28 
31 {
32 private:
33  const ALchar* _ptr;
34 public:
35  DeviceSpecRange(const ALchar* ptr)
36  : _ptr(ptr)
37  { }
38 
39  typedef const ALchar* ValueType;
40 
42  bool Empty(void) const
43  {
44  return !_ptr || !(*_ptr);
45  }
46 
48  const ALchar* Front(void) const
49  {
50  assert(!Empty());
51  return _ptr;
52  }
53 
55  void Next(void)
56  {
57  assert(!Empty());
58  _ptr += std::strlen(_ptr)+1;
59  }
60 
62  void StepFront(void)
63  {
64  Next();
65  }
66 };
67 
68 class DevCommonOps
69 {
70 protected:
71  friend class ContextOps;
72  friend class Context;
73 
74  ::ALCdevice* _device;
75 
76  DevCommonOps(::ALCdevice* device)
77  : _device(device)
78  {
79  assert(_device);
80  }
81 public:
83  DevCommonOps(DevCommonOps&& tmp)
84  : _device(tmp._device)
85  {
86  tmp._device = nullptr;
87  }
88 
89 #if OALPLUS_DOCUMENTATION_ONLY
90 
96  static Range<String> Extensions(void);
97 #else
98  static aux::SepStrRange Extensions(void)
99  {
100  const ALchar* str = OALPLUS_ALCFUNC(GetString)(
101  nullptr,
102  ALC_EXTENSIONS
103  );
104  OALPLUS_CHECK_SIMPLE_ALC(nullptr, GetString);
105 
106  return aux::SepStrRange((const char*)str);
107  }
108 #endif
109 };
110 
112 
115 template <>
116 class DeviceOps<tag::Playback>
117  : public DevCommonOps
118 {
119 protected:
120  friend class ContextOps;
121 
122  DeviceOps(::ALCdevice* device)
123  : DevCommonOps(device)
124  { }
125 public:
127 
132  const ALchar* Specifier(void) const
133  {
134  const ALchar* str = OALPLUS_ALCFUNC(GetString)(
135  _device,
136  ALC_DEVICE_SPECIFIER
137  );
138  OALPLUS_CHECK_SIMPLE_ALC(_device, GetString);
139  return str;
140  }
141 
143 
149  {
150  const ALchar* ptr = OALPLUS_ALCFUNC(GetString)(
151  nullptr,
152  ALC_DEVICE_SPECIFIER
153  );
154  OALPLUS_CHECK_SIMPLE_ALC(nullptr, GetString);
155  return DeviceSpecRange(ptr);
156  }
157 };
158 
160 
163 template <>
164 class DeviceOps<tag::Capture>
165  : public DevCommonOps
166 {
167 protected:
168  DeviceOps(::ALCdevice* device)
169  : DevCommonOps(device)
170  { }
171 public:
173 
178  const ALchar* Specifier(void) const
179  {
180  const ALchar* str = OALPLUS_ALCFUNC(GetString)(
181  _device,
182  ALC_CAPTURE_DEVICE_SPECIFIER
183  );
184  OALPLUS_CHECK_SIMPLE_ALC(_device, GetString);
185  return str;
186  }
187 
189 
195  {
196  const ALchar* ptr = OALPLUS_ALCFUNC(GetString)(
197  nullptr,
198  ALC_CAPTURE_DEVICE_SPECIFIER
199  );
200  OALPLUS_CHECK_SIMPLE_ALC(nullptr, GetString);
201  return DeviceSpecRange(ptr);
202  }
203 
205 
209  void Start(void)
210  {
211  OALPLUS_ALCFUNC(CaptureStart)(_device);
212  OALPLUS_CHECK_SIMPLE_ALC(_device, CaptureStart);
213  }
214 
216 
220  void Stop(void)
221  {
222  OALPLUS_ALCFUNC(CaptureStop)(_device);
223  OALPLUS_CHECK_SIMPLE_ALC(_device, CaptureStop);
224  }
225 
227 
232  ALCsizei Samples(void) const
233  {
234  ALCint result = 0;
235  OALPLUS_ALCFUNC(GetIntegerv)(
236  _device,
237  ALC_CAPTURE_SAMPLES,
238  1, &result
239  );
240  OALPLUS_CHECK_SIMPLE_ALC(_device, GetIntegerv);
241  return ALCsizei(result);
242  }
243 
245 
249  void Samples(ALCvoid* buffer, ALCsizei samples) const
250  {
251  OALPLUS_ALCFUNC(CaptureSamples)(_device, buffer, samples);
252  OALPLUS_CHECK_SIMPLE_ALC(_device, CaptureSamples);
253  }
254 };
255 
257 class Device
258  : public DeviceOps<tag::Playback>
259 {
260 private:
262 public:
264 
268  Device(void)
269  : Base(OALPLUS_ALCFUNC(OpenDevice)(nullptr))
270  {
271  OALPLUS_CHECK_SIMPLE_ALC(_device,OpenDevice);
272  }
273 
275 
279  Device(const ALchar* dev_spec)
280  : Base(OALPLUS_ALCFUNC(OpenDevice)(dev_spec))
281  {
282  OALPLUS_CHECK_SIMPLE_ALC(_device,OpenDevice);
283  }
284 
286 
290  ~Device(void)
291  {
292  if(_device)
293  {
294  OALPLUS_ALCFUNC(CloseDevice)(_device);
295  }
296  }
297 };
298 
301  : public DeviceOps<tag::Capture>
302 {
303 private:
305 public:
307 
311  CaptureDevice(ALCuint frequency, DataFormat format, ALCsizei bufsize)
312  : Base(OALPLUS_ALCFUNC(CaptureOpenDevice)(
313  nullptr,
314  frequency,
315  ALCenum(format),
316  bufsize
317  ))
318  {
319  OALPLUS_CHECK_SIMPLE_ALC(_device,CaptureOpenDevice);
320  }
321 
323 
328  const ALchar* dev_spec,
329  ALCuint frequency,
330  DataFormat format,
331  ALCsizei bufsize
332  ): Base(OALPLUS_ALCFUNC(CaptureOpenDevice)(
333  dev_spec,
334  frequency,
335  ALCenum(format),
336  bufsize
337  ))
338  {
339  OALPLUS_CHECK_SIMPLE_ALC(_device,CaptureOpenDevice);
340  }
341 
343 
348  {
349  if(_device)
350  {
351  OALPLUS_ALCFUNC(CaptureCloseDevice)(_device);
352  }
353  }
354 };
355 
356 } // namespace oalplus
357 
358 #endif // include guard
void Next(void)
Goes to the next specifier in the range.
Definition: device.hpp:55
Audio playback device.
Definition: device.hpp:257
void Samples(ALCvoid *buffer, ALCsizei samples) const
Gets the samples captured on this device.
Definition: device.hpp:249
Class implementing audio playback device-specific operations.
Definition: device.hpp:116
Forward declarations.
const ALchar * Front(void) const
Returns the specifier string at the front of the range.
Definition: device.hpp:48
void Stop(void)
Stop audio capture on this device.
Definition: device.hpp:220
Compile-time configuration options.
Helper macro expanding into OpenAL function name.
const ALchar * Specifier(void) const
Returns the capture device specifier string.
Definition: device.hpp:178
CaptureDevice(ALCuint frequency, DataFormat format, ALCsizei bufsize)
Constructs an object referencing the default audio device.
Definition: device.hpp:311
~Device(void)
Closes this device.
Definition: device.hpp:290
void StepFront(void)
A synonym for Next.
Definition: device.hpp:62
bool Empty(void) const
Returns true when the range is empty (at the end of traversal)
Definition: device.hpp:42
A range for iteration through the device specifier strings.
Definition: device.hpp:30
const ALchar * Specifier(void) const
Returns the device specifier string.
Definition: device.hpp:132
static DeviceSpecRange Specifiers(void)
Returns a range of specifier strings for available capture devices.
Definition: device.hpp:194
CaptureDevice(const ALchar *dev_spec, ALCuint frequency, DataFormat format, ALCsizei bufsize)
Constructs an object referencing the specified audio device.
Definition: device.hpp:327
Data format enumeration.
void Start(void)
Starts audio capture on this device.
Definition: device.hpp:209
Audio capture device.
Definition: device.hpp:300
Device(void)
Constructs an object referencing the default audio device.
Definition: device.hpp:268
Device(const ALchar *dev_spec)
Constructs an object referencing the specified audio device.
Definition: device.hpp:279
Class implementing audio capture device-specific operations.
Definition: device.hpp:164
~CaptureDevice(void)
Closes this device.
Definition: device.hpp:347
Base wrapper for OpenAL context operations.
Definition: context.hpp:54
static DeviceSpecRange Specifiers(void)
Returns a range of specifier strings for available audio devices.
Definition: device.hpp:148
ALCsizei Samples(void) const
Gets the number of samples captured on this device.
Definition: device.hpp:232

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).