platformAudio.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORMAUDIO_H_
  23. #define _PLATFORMAUDIO_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef NO_AUDIO_SUPPORT
  28. #ifndef _PLATFORMAL_H_
  29. #include "platform/platformAL.h"
  30. #endif
  31. #ifndef _MMATH_H_
  32. #include "math/mMath.h"
  33. #endif
  34. #ifndef _BITSET_H_
  35. #include "collection/bitSet.h"
  36. #endif
  37. typedef U32 AUDIOHANDLE;
  38. #define NULL_AUDIOHANDLE 0
  39. //--------------------------------------------------------------------------
  40. namespace Audio
  41. {
  42. enum Constants {
  43. AudioVolumeChannels = 32
  44. };
  45. //--------------------------------------
  46. // sound property description
  47. struct Description
  48. {
  49. F32 mVolume; // 0-1 1=loudest volume
  50. S32 mVolumeChannel;
  51. bool mIsLooping;
  52. bool mIsStreaming;
  53. bool mIs3D;
  54. F32 mReferenceDistance;
  55. F32 mMaxDistance;
  56. U32 mConeInsideAngle;
  57. U32 mConeOutsideAngle;
  58. F32 mConeOutsideVolume;
  59. Point3F mConeVector;
  60. // environment info
  61. F32 mEnvironmentLevel;
  62. };
  63. void initOpenAL();
  64. void shutdownOpenAL();
  65. void destroy();
  66. }
  67. class AudioDescription;
  68. class AudioAsset;
  69. class AudioEnvironment;
  70. class AudioSampleEnvironment;
  71. class AudioStreamSource;
  72. AUDIOHANDLE alxCreateSource(const Audio::Description *desc, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
  73. AUDIOHANDLE alxCreateSource(AudioDescription *descObject, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
  74. AUDIOHANDLE alxCreateSource(const AudioAsset *profile, const MatrixF *transform=NULL);
  75. AudioStreamSource* alxFindAudioStreamSource(AUDIOHANDLE handle);
  76. AUDIOHANDLE alxPlay(AUDIOHANDLE handle);
  77. bool alxPause(AUDIOHANDLE handle);
  78. void alxPauseAll();
  79. void alxUnPause(AUDIOHANDLE handle);
  80. void alxUnPauseAll();
  81. void alxStop(AUDIOHANDLE handle);
  82. void alxStopAll();
  83. // one-shot helper alxPlay functions, create and play in one call
  84. AUDIOHANDLE alxPlay(const AudioAsset *profile, const MatrixF *transform=NULL, const Point3F *velocity=NULL);
  85. // Source
  86. void alxSourcef(AUDIOHANDLE handle, ALenum pname, ALfloat value);
  87. void alxSourcefv(AUDIOHANDLE handle, ALenum pname, ALfloat *values);
  88. void alxSource3f(AUDIOHANDLE handle, ALenum pname, ALfloat value1, ALfloat value2, ALfloat value3);
  89. void alxSourcei(AUDIOHANDLE handle, ALenum pname, ALint value);
  90. void alxSourceMatrixF(AUDIOHANDLE handle, const MatrixF *transform);
  91. void alxGetSourcef(AUDIOHANDLE handle, ALenum pname, ALfloat *value);
  92. void alxGetSourcefv(AUDIOHANDLE handle, ALenum pname, ALfloat *values);
  93. void alxGetSource3f(AUDIOHANDLE handle, ALenum pname, ALfloat *value1, ALfloat *value2, ALfloat *value3);
  94. void alxGetSourcei(AUDIOHANDLE handle, ALenum pname, ALint *value);
  95. /** alSource3f access extension for use with Point3F's
  96. */
  97. inline void alxSourcePoint3F(AUDIOHANDLE handle, ALenum pname, const Point3F *value)
  98. {
  99. alxSource3f(handle, pname, value->x, value->y, value->z);
  100. }
  101. /** alGetSource3f access extension for use with Point3F's
  102. */
  103. inline void alxSourceGetPoint3F(AUDIOHANDLE handle, ALenum pname, Point3F * value)
  104. {
  105. alxGetSource3f(handle, pname, &value->x, &value->y, &value->z);
  106. }
  107. // Listener
  108. void alxListenerMatrixF(const MatrixF *transform);
  109. void alxListenerf(ALenum param, ALfloat value);
  110. void alxGetListenerf(ALenum param, ALfloat *value);
  111. /** alListener3f access extension for use with Point3F's
  112. */
  113. inline void alxListenerPoint3F(ALenum pname, const Point3F *value)
  114. {
  115. alListener3f(pname, value->x, value->y, value->z);
  116. }
  117. /** alGetListener3f access extension for use with Point3F's
  118. */
  119. inline void alxGetListenerPoint3F(ALenum pname, Point3F *value)
  120. {
  121. alGetListener3f(pname, &value->x, &value->y, &value->z);
  122. }
  123. // Environment
  124. void alxEnvironmenti(ALenum pname, ALint value);
  125. void alxEnvironmentf(ALenum pname, ALfloat value);
  126. void alxGetEnvironmenti(ALenum pname, ALint * value);
  127. void alxGetEnvironmentf(ALenum pname, ALfloat * value);
  128. void alxSetEnvironment(const AudioEnvironment * environment);
  129. const AudioEnvironment * alxGetEnvironment();
  130. // misc
  131. void alxUpdateTypeGain(U32 type);
  132. bool alxIsValidHandle(AUDIOHANDLE handle);
  133. bool alxIsPlaying(AUDIOHANDLE handle);
  134. void alxUpdate();
  135. F32 alxGetStreamPosition( AUDIOHANDLE handle );
  136. F32 alxGetStreamDuration( AUDIOHANDLE handle );
  137. #endif // NO_AUDIO_SUPPORT
  138. #endif // _H_PLATFORMAUDIO_