OALplus (0.52.0) a C++ wrapper for OpenAL

source.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OALPLUS_SOURCE_1303201647_HPP
14 #define OALPLUS_SOURCE_1303201647_HPP
15 
16 #include <oalplus/config.hpp>
17 #include <oalplus/fwd.hpp>
18 #include <oalplus/alfunc.hpp>
19 #include <oalplus/math/angle.hpp>
20 #include <oalplus/math/vector.hpp>
21 #include <oalplus/error/basic.hpp>
22 #include <oalplus/object/wrapper.hpp>
23 #include <oalplus/object/sequence.hpp>
24 #include <oalplus/buffer.hpp>
25 #include <oalplus/source_state.hpp>
26 #include <oalplus/source_type.hpp>
27 
28 #include <cassert>
29 
30 namespace oalplus {
31 
33 
40 template <>
41 class ObjGenDelOps<tag::Source>
42 {
43 protected:
44  static void Gen(tag::Generate, ALsizei count, ALuint* names)
45  {
46  assert(names != nullptr);
47  OALPLUS_ALFUNC(GenSources)(count, names);
48  OALPLUS_CHECK_SIMPLE(GenSources);
49  }
50 
51  static void Delete(ALsizei count, ALuint* names)
52  {
53  assert(names != nullptr);
54  OALPLUS_ALFUNC(DeleteSources)(count, names);
55  OALPLUS_VERIFY_SIMPLE(DeleteSources);
56  }
57 
58  static ALboolean IsA(ALuint name)
59  {
60  assert(name != 0);
61  ALboolean result = OALPLUS_ALFUNC(IsSource)(name);
62  OALPLUS_VERIFY_SIMPLE(IsSource);
63  return result;
64  }
65 };
66 
68 
73 template <>
74 class ObjectOps<tag::DirectState, tag::Source>
75  : public ObjectName<tag::Source>
76 {
77 protected:
78  ObjectOps(void) { }
79 public:
81 
85  void Play(void)
86  {
87  OALPLUS_ALFUNC(SourcePlay)(_name);
88  OALPLUS_VERIFY(
89  SourcePlay,
90  ObjectError,
91  Object(*this)
92  );
93  }
94 
96 
100  void Pause(void)
101  {
102  OALPLUS_ALFUNC(SourcePause)(_name);
103  OALPLUS_VERIFY(
104  SourcePause,
105  ObjectError,
106  Object(*this)
107  );
108  }
109 
111 
115  void Stop(void)
116  {
117  OALPLUS_ALFUNC(SourceStop)(_name);
118  OALPLUS_VERIFY(
119  SourceStop,
120  ObjectError,
121  Object(*this)
122  );
123  }
124 
126 
130  void Rewind(void)
131  {
132  OALPLUS_ALFUNC(SourceRewind)(_name);
133  OALPLUS_VERIFY(
134  SourceRewind,
135  ObjectError,
136  Object(*this)
137  );
138  }
139 
141 
146  SourceState State(void) const
147  {
148  ALint result = 0;
149  OALPLUS_ALFUNC(GetSourceiv)(
150  _name,
151  AL_SOURCE_STATE,
152  &result
153  );
154  OALPLUS_VERIFY(
155  GetSourceiv,
156  ObjectError,
157  Object(*this)
158  );
159  return SourceState(result);
160  }
161 
163 
168  void Relative(bool value)
169  {
170  OALPLUS_ALFUNC(Sourcei)(
171  _name,
172  AL_SOURCE_RELATIVE,
173  value?AL_TRUE:AL_FALSE
174  );
175  OALPLUS_VERIFY(
176  Sourcei,
177  ObjectError,
178  Object(*this)
179  );
180  }
181 
183 
188  bool Relative(void) const
189  {
190  ALint result;
191  OALPLUS_ALFUNC(GetSourceiv)(
192  _name,
193  AL_SOURCE_RELATIVE,
194  &result
195  );
196  OALPLUS_VERIFY(
197  GetSourceiv,
198  ObjectError,
199  Object(*this)
200  );
201  return result == AL_TRUE;
202  }
203 
205 
210  void Type(SourceType type)
211  {
212  OALPLUS_ALFUNC(Sourcei)(
213  _name,
214  AL_SOURCE_TYPE,
215  ALenum(type)
216  );
217  OALPLUS_VERIFY(
218  Sourcei,
219  ObjectError,
220  Object(*this)
221  );
222  }
223 
225 
230  SourceType Type(void) const
231  {
232  ALint result;
233  OALPLUS_ALFUNC(GetSourceiv)(
234  _name,
235  AL_SOURCE_TYPE,
236  &result
237  );
238  OALPLUS_VERIFY(
239  GetSourceiv,
240  ObjectError,
241  Object(*this)
242  );
243  return SourceType(ALenum(result));
244  }
245 
247 
252  void Looping(bool value)
253  {
254  OALPLUS_ALFUNC(Sourcei)(
255  _name,
256  AL_LOOPING,
257  value?AL_TRUE:AL_FALSE
258  );
259  OALPLUS_VERIFY(
260  Sourcei,
261  ObjectError,
262  Object(*this)
263  );
264  }
265 
267 
272  bool Looping(void) const
273  {
274  ALint result;
275  OALPLUS_ALFUNC(GetSourceiv)(
276  _name,
277  AL_LOOPING,
278  &result
279  );
280  OALPLUS_VERIFY(
281  GetSourceiv,
282  ObjectError,
283  Object(*this)
284  );
285  return result == AL_TRUE;
286  }
287 
289 
294  void Buffer(const BufferName& buffer)
295  {
296  OALPLUS_ALFUNC(Sourcei)(
297  _name,
298  AL_BUFFER,
299  GetALName(buffer)
300  );
301  OALPLUS_VERIFY(
302  Sourcei,
303  ObjectError,
304  Object(*this)
305  );
306  }
307 
309 
314  void DetachBuffers(void)
315  {
316  OALPLUS_ALFUNC(Sourcei)(
317  _name,
318  AL_BUFFER,
319  0
320  );
321  OALPLUS_VERIFY(
322  Sourcei,
323  ObjectError,
324  Object(*this)
325  );
326  }
327 
329 
333  void QueueBuffers(const Sequence<BufferName>& buffers)
334  {
335  OALPLUS_ALFUNC(SourceQueueBuffers)(
336  _name,
337  buffers.size(),
338  const_cast<ALuint*>(GetALNames(buffers))
339  );
340  OALPLUS_VERIFY(
341  SourceQueueBuffers,
342  ObjectError,
343  Object(*this)
344  );
345  }
346 
348 
352  void UnqueueBuffers(const Sequence<BufferName>& buffers)
353  {
354  OALPLUS_ALFUNC(SourceUnqueueBuffers)(
355  _name,
356  buffers.size(),
357  const_cast<ALuint*>(GetALNames(buffers))
358  );
359  OALPLUS_VERIFY(
360  SourceUnqueueBuffers,
361  ObjectError,
362  Object(*this)
363  );
364  }
365 
367 
372  void Gain(ALfloat value)
373  {
374  OALPLUS_ALFUNC(Sourcef)(
375  _name,
376  AL_GAIN,
377  value
378  );
379  OALPLUS_CHECK(
380  Sourcef,
381  ObjectError,
382  Object(*this)
383  );
384  }
385 
387 
392  ALfloat Gain(void) const
393  {
394  ALfloat result;
395  OALPLUS_ALFUNC(GetSourcefv)(
396  _name,
397  AL_GAIN,
398  &result
399  );
400  OALPLUS_VERIFY(
401  GetSourcefv,
402  ObjectError,
403  Object(*this)
404  );
405  return result;
406  }
407 
409 
414  void MinGain(ALfloat value)
415  {
416  OALPLUS_ALFUNC(Sourcef)(
417  _name,
418  AL_MIN_GAIN,
419  value
420  );
421  OALPLUS_CHECK(
422  Sourcef,
423  ObjectError,
424  Object(*this)
425  );
426  }
427 
429 
434  ALfloat MinGain(void) const
435  {
436  ALfloat result;
437  OALPLUS_ALFUNC(GetSourcefv)(
438  _name,
439  AL_MIN_GAIN,
440  &result
441  );
442  OALPLUS_VERIFY(
443  GetSourcefv,
444  ObjectError,
445  Object(*this)
446  );
447  return result;
448  }
449 
451 
456  void MaxGain(ALfloat value)
457  {
458  OALPLUS_ALFUNC(Sourcef)(
459  _name,
460  AL_MAX_GAIN,
461  value
462  );
463  OALPLUS_CHECK(
464  Sourcef,
465  ObjectError,
466  Object(*this)
467  );
468  }
469 
471 
476  ALfloat MaxGain(void) const
477  {
478  ALfloat result;
479  OALPLUS_ALFUNC(GetSourcefv)(
480  _name,
481  AL_MAX_GAIN,
482  &result
483  );
484  OALPLUS_VERIFY(
485  GetSourcefv,
486  ObjectError,
487  Object(*this)
488  );
489  return result;
490  }
491 
493 
498  void ReferenceDistance(ALfloat value)
499  {
500  OALPLUS_ALFUNC(Sourcef)(
501  _name,
502  AL_REFERENCE_DISTANCE,
503  value
504  );
505  OALPLUS_CHECK(
506  Sourcef,
507  ObjectError,
508  Object(*this)
509  );
510  }
511 
513 
518  ALfloat ReferenceDistance(void) const
519  {
520  ALfloat result;
521  OALPLUS_ALFUNC(GetSourcefv)(
522  _name,
523  AL_REFERENCE_DISTANCE,
524  &result
525  );
526  OALPLUS_VERIFY(
527  GetSourcefv,
528  ObjectError,
529  Object(*this)
530  );
531  return result;
532  }
533 
535 
540  void RolloffFactor(ALfloat value)
541  {
542  OALPLUS_ALFUNC(Sourcef)(
543  _name,
544  AL_ROLLOFF_FACTOR,
545  value
546  );
547  OALPLUS_CHECK(
548  Sourcef,
549  ObjectError,
550  Object(*this)
551  );
552  }
553 
555 
560  ALfloat RolloffFactor(void) const
561  {
562  ALfloat result;
563  OALPLUS_ALFUNC(GetSourcefv)(
564  _name,
565  AL_ROLLOFF_FACTOR,
566  &result
567  );
568  OALPLUS_VERIFY(
569  GetSourcefv,
570  ObjectError,
571  Object(*this)
572  );
573  return result;
574  }
575 
577 
582  void MaxDistance(ALfloat value)
583  {
584  OALPLUS_ALFUNC(Sourcef)(
585  _name,
586  AL_MAX_DISTANCE,
587  value
588  );
589  OALPLUS_CHECK(
590  Sourcef,
591  ObjectError,
592  Object(*this)
593  );
594  }
595 
597 
602  ALfloat MaxDistance(void) const
603  {
604  ALfloat result;
605  OALPLUS_ALFUNC(GetSourcefv)(
606  _name,
607  AL_MAX_DISTANCE,
608  &result
609  );
610  OALPLUS_VERIFY(
611  GetSourcefv,
612  ObjectError,
613  Object(*this)
614  );
615  return result;
616  }
617 
619 
624  void Pitch(ALfloat value)
625  {
626  OALPLUS_ALFUNC(Sourcef)(
627  _name,
628  AL_PITCH,
629  value
630  );
631  OALPLUS_CHECK(
632  Sourcef,
633  ObjectError,
634  Object(*this)
635  );
636  }
637 
639 
644  ALfloat Pitch(void) const
645  {
646  ALfloat result;
647  OALPLUS_ALFUNC(GetSourcefv)(
648  _name,
649  AL_PITCH,
650  &result
651  );
652  OALPLUS_VERIFY(
653  GetSourcefv,
654  ObjectError,
655  Object(*this)
656  );
657  return result;
658  }
659 
661 
666  void Position(const Vec3f& dir)
667  {
668  OALPLUS_ALFUNC(Sourcefv)(
669  _name,
670  AL_POSITION,
671  dir.Data()
672  );
673  OALPLUS_CHECK(
674  Sourcefv,
675  ObjectError,
676  Object(*this)
677  );
678  }
679 
681 
686  void Position(ALfloat x, ALfloat y, ALfloat z)
687  {
688  OALPLUS_ALFUNC(Source3f)(
689  _name,
690  AL_POSITION,
691  x, y, z
692  );
693  OALPLUS_CHECK(
694  Source3f,
695  ObjectError,
696  Object(*this)
697  );
698  }
699 
701 
706  Vec3f Position(void) const
707  {
708  ALfloat result[3];
709  OALPLUS_ALFUNC(GetSourcefv)(
710  _name,
711  AL_POSITION,
712  result
713  );
714  OALPLUS_VERIFY(
715  GetSourcefv,
716  ObjectError,
717  Object(*this)
718  );
719  return Vec3f(result);
720  }
721 
723 
728  void Velocity(const Vec3f& dir)
729  {
730  OALPLUS_ALFUNC(Sourcefv)(
731  _name,
732  AL_VELOCITY,
733  dir.Data()
734  );
735  OALPLUS_CHECK(
736  Sourcefv,
737  ObjectError,
738  Object(*this)
739  );
740  }
741 
743 
748  void Velocity(ALfloat x, ALfloat y, ALfloat z)
749  {
750  OALPLUS_ALFUNC(Source3f)(
751  _name,
752  AL_VELOCITY,
753  x, y, z
754  );
755  OALPLUS_CHECK(
756  Source3f,
757  ObjectError,
758  Object(*this)
759  );
760  }
761 
763 
768  Vec3f Velocity(void) const
769  {
770  ALfloat result[3];
771  OALPLUS_ALFUNC(GetSourcefv)(
772  _name,
773  AL_VELOCITY,
774  result
775  );
776  OALPLUS_VERIFY(
777  GetSourcefv,
778  ObjectError,
779  Object(*this)
780  );
781  return Vec3f(result);
782  }
783 
785 
790  void Direction(const Vec3f& dir)
791  {
792  OALPLUS_ALFUNC(Sourcefv)(
793  _name,
794  AL_DIRECTION,
795  dir.Data()
796  );
797  OALPLUS_CHECK(
798  Sourcefv,
799  ObjectError,
800  Object(*this)
801  );
802  }
803 
805 
810  void Direction(ALfloat x, ALfloat y, ALfloat z)
811  {
812  OALPLUS_ALFUNC(Source3f)(
813  _name,
814  AL_DIRECTION,
815  x, y, z
816  );
817  OALPLUS_CHECK(
818  Source3f,
819  ObjectError,
820  Object(*this)
821  );
822  }
823 
825 
830  Vec3f Direction(void) const
831  {
832  ALfloat result[3];
833  OALPLUS_ALFUNC(GetSourcefv)(
834  _name,
835  AL_DIRECTION,
836  result
837  );
838  OALPLUS_VERIFY(
839  GetSourcefv,
840  ObjectError,
841  Object(*this)
842  );
843  return Vec3f(result);
844  }
845 
847 
852  void ConeInnerAngle(Anglef angle)
853  {
854  OALPLUS_ALFUNC(Sourcef)(
855  _name,
856  AL_CONE_INNER_ANGLE,
857  angle.ValueInDegrees()
858  );
859  OALPLUS_CHECK(
860  Sourcef,
861  ObjectError,
862  Object(*this)
863  );
864  }
865 
867 
872  Anglef ConeInnerAngle(void) const
873  {
874  ALfloat result;
875  OALPLUS_ALFUNC(GetSourcefv)(
876  _name,
877  AL_CONE_INNER_ANGLE,
878  &result
879  );
880  OALPLUS_VERIFY(
881  GetSourcefv,
882  ObjectError,
883  Object(*this)
884  );
885  return Anglef::Degrees(result);
886  }
887 
889 
894  void ConeOuterAngle(Anglef angle)
895  {
896  OALPLUS_ALFUNC(Sourcef)(
897  _name,
898  AL_CONE_OUTER_ANGLE,
899  angle.ValueInDegrees()
900  );
901  OALPLUS_CHECK(
902  Sourcef,
903  ObjectError,
904  Object(*this)
905  );
906  }
907 
909 
914  Anglef ConeOuterAngle(void) const
915  {
916  ALfloat result;
917  OALPLUS_ALFUNC(GetSourcefv)(
918  _name,
919  AL_CONE_OUTER_ANGLE,
920  &result
921  );
922  OALPLUS_VERIFY(
923  GetSourcefv,
924  ObjectError,
925  Object(*this)
926  );
927  return Anglef::Degrees(result);
928  }
929 
931 
936  void ConeOuterGain(ALfloat value)
937  {
938  OALPLUS_ALFUNC(Sourcef)(
939  _name,
940  AL_CONE_OUTER_GAIN,
941  value
942  );
943  OALPLUS_CHECK(
944  Sourcef,
945  ObjectError,
946  Object(*this)
947  );
948  }
949 
951 
956  ALfloat ConeOuterGain(void) const
957  {
958  ALfloat result;
959  OALPLUS_ALFUNC(GetSourcefv)(
960  _name,
961  AL_CONE_OUTER_GAIN,
962  &result
963  );
964  OALPLUS_VERIFY(
965  GetSourcefv,
966  ObjectError,
967  Object(*this)
968  );
969  return result;
970  }
971 
973 
978  void SecOffset(ALfloat value)
979  {
980  OALPLUS_ALFUNC(Sourcef)(
981  _name,
982  AL_SEC_OFFSET,
983  value
984  );
985  OALPLUS_CHECK(
986  Sourcef,
987  ObjectError,
988  Object(*this)
989  );
990  }
991 
993 
998  void SampleOffset(ALfloat value)
999  {
1000  OALPLUS_ALFUNC(Sourcef)(
1001  _name,
1002  AL_SAMPLE_OFFSET,
1003  value
1004  );
1005  OALPLUS_CHECK(
1006  Sourcef,
1007  ObjectError,
1008  Object(*this)
1009  );
1010  }
1011 
1013 
1018  void ByteOffset(ALfloat value)
1019  {
1020  OALPLUS_ALFUNC(Sourcef)(
1021  _name,
1022  AL_BYTE_OFFSET,
1023  value
1024  );
1025  OALPLUS_CHECK(
1026  Sourcef,
1027  ObjectError,
1028  Object(*this)
1029  );
1030  }
1031 
1032 };
1033 
1034 } // namespace oalplus
1035 namespace oglplus {
1036 
1037 template <>
1038 class ObjGenDelOps<oalplus::tag::Source>
1039  : public oalplus::ObjGenDelOps<oalplus::tag::Source>
1040 { };
1041 
1042 template <typename OpsTag>
1043 class ObjectOps<OpsTag, oalplus::tag::Source>
1044  : public oalplus::ObjectOps<OpsTag, oalplus::tag::Source>
1045 { };
1046 
1047 } // namespace oglplus
1048 namespace oalplus {
1049 
1051  SourceOps;
1052 
1054 
1057 typedef Object<SourceOps> Source;
1058 
1059 } // namespace oalplus
1060 
1061 #endif // include guard
void Play(void)
Starts the audio playback.
Definition: source.hpp:85
void QueueBuffers(const Sequence< BufferName > &buffers)
Enqueues multiple buffers to the source.
Definition: source.hpp:333
void DetachBuffers(void)
Detaches all queued buffers from the source.
Definition: source.hpp:314
void Direction(const Vec3f &dir)
Sets the direction of the source.
Definition: source.hpp:790
void UnqueueBuffers(const Sequence< BufferName > &buffers)
Removes multiple buffers from the sources queue.
Definition: source.hpp:352
Vector< GLfloat, 3 > Vec3f
SourceType Type(void) const
Returns the source type.
Definition: source.hpp:230
void SecOffset(ALfloat value)
Sets the Sec-offset value.
Definition: source.hpp:978
Forward declarations.
void ConeOuterAngle(Anglef angle)
Sets the sound cone's outer angle.
Definition: source.hpp:894
void Position(ALfloat x, ALfloat y, ALfloat z)
Sets the position of the source.
Definition: source.hpp:686
Vec3f Direction(void) const
Returns the direction of the source.
Definition: source.hpp:830
void Velocity(ALfloat x, ALfloat y, ALfloat z)
Sets the velocity of the source.
Definition: source.hpp:748
Compile-time configuration options.
void ConeOuterGain(ALfloat value)
Sets the sound cone's outer gain value.
Definition: source.hpp:936
Helper macro expanding into OpenAL function name.
void Gain(ALfloat value)
Sets the value of gain.
Definition: source.hpp:372
void MinGain(ALfloat value)
Sets the minimal value of gain.
Definition: source.hpp:414
void ReferenceDistance(ALfloat value)
Sets the reference distance.
Definition: source.hpp:498
void MaxGain(ALfloat value)
Sets the maximum value of gain.
Definition: source.hpp:456
Vec3f Position(void) const
Returns the position of the source.
Definition: source.hpp:706
void MaxDistance(ALfloat value)
Sets the value of max distance used with some distance models.
Definition: source.hpp:582
void Rewind(void)
Rewinds the audio track.
Definition: source.hpp:130
Angle< GLfloat > Anglef
void ConeInnerAngle(Anglef angle)
Sets the sound cone's inner angle.
Definition: source.hpp:852
ALfloat Pitch(void) const
Returns the value of pitch.
Definition: source.hpp:644
void ByteOffset(ALfloat value)
Sets the byte-offset value.
Definition: source.hpp:1018
void Looping(bool value)
Sets the looping mode.
Definition: source.hpp:252
ALfloat MaxGain(void) const
Returns the maximum value of gain.
Definition: source.hpp:476
ALfloat RolloffFactor(void) const
Returns the value of rolloff factor.
Definition: source.hpp:560
ALfloat Gain(void) const
Returns the value of gain.
Definition: source.hpp:392
void Velocity(const Vec3f &dir)
Sets the velocity of the source.
Definition: source.hpp:728
ALfloat ReferenceDistance(void) const
Returns the reference distance.
Definition: source.hpp:518
void Position(const Vec3f &dir)
Sets the position of the source.
Definition: source.hpp:666
Object< SourceOps > Source
An oalplus_object encapsulating the OpenAL source functionality.
Definition: source.hpp:1057
ALfloat MinGain(void) const
Returns the minimal value of gain.
Definition: source.hpp:434
void Type(SourceType type)
Sets the source type.
Definition: source.hpp:210
SourceState State(void) const
Returns the source state.
Definition: source.hpp:146
void Stop(void)
Stops the audio playback.
Definition: source.hpp:115
Anglef ConeOuterAngle(void) const
Returns the sound cone's outer angle.
Definition: source.hpp:914
void SampleOffset(ALfloat value)
Sets the sample-offset value.
Definition: source.hpp:998
Wrapper for OpenAL buffer object.
void Pitch(ALfloat value)
Sets the value of pitch.
Definition: source.hpp:624
bool Relative(void) const
Returns true if the source is relative.
Definition: source.hpp:188
OpenAL Source type enumeration.
ALfloat MaxDistance(void) const
Returns the value of max distance used with some distance models.
Definition: source.hpp:602
void Pause(void)
Pauses the audio playback.
Definition: source.hpp:100
void Relative(bool value)
Sets the source to relative or absoulte state.
Definition: source.hpp:168
ALfloat ConeOuterGain(void) const
Returns the sound cone's outer gain value.
Definition: source.hpp:956
void Direction(ALfloat x, ALfloat y, ALfloat z)
Sets the direction of the source.
Definition: source.hpp:810
void Buffer(const BufferName &buffer)
Assigns an audio buffer to the source.
Definition: source.hpp:294
Anglef ConeInnerAngle(void) const
Returns the sound cone's inner angle.
Definition: source.hpp:872
OpenAL source execution state enumeration.
void RolloffFactor(ALfloat value)
Sets the value of rolloff factor.
Definition: source.hpp:540
Angle< AngleValueType > Degrees(AngleValueType val_deg)
bool Looping(void) const
Returns true if the source is in looping mode.
Definition: source.hpp:272
Vec3f Velocity(void) const
Returns the velocity of the source.
Definition: source.hpp:768

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