platformAudio.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 _PLATFORMAL_H_
  28. #include "platform/platformAL.h"
  29. #endif
  30. #ifndef _MMATH_H_
  31. #include "math/mMath.h"
  32. #endif
  33. #ifndef _BITSET_H_
  34. #include "collection/bitSet.h"
  35. #endif
  36. typedef U32 AUDIOHANDLE;
  37. #define NULL_AUDIOHANDLE 0
  38. //--------------------------------------------------------------------------
  39. namespace Audio
  40. {
  41. enum Constants {
  42. AudioVolumeChannels = 32
  43. };
  44. //--------------------------------------
  45. // sound property description
  46. struct Description
  47. {
  48. F32 mVolume; // 0-1 1=loudest volume
  49. S32 mVolumeChannel;
  50. bool mIsLooping;
  51. bool mIsStreaming;
  52. bool mIs3D;
  53. F32 mReferenceDistance;
  54. F32 mMaxDistance;
  55. U32 mConeInsideAngle;
  56. U32 mConeOutsideAngle;
  57. F32 mConeOutsideVolume;
  58. Point3F mConeVector;
  59. // environment info
  60. F32 mEnvironmentLevel;
  61. };
  62. void initOpenAL();
  63. void shutdownOpenAL();
  64. void destroy();
  65. }
  66. class AudioDescription;
  67. class AudioAsset;
  68. class AudioEnvironment;
  69. class AudioSampleEnvironment;
  70. class AudioStreamSource;
  71. AUDIOHANDLE alxCreateSource(const Audio::Description *desc, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
  72. AUDIOHANDLE alxCreateSource(AudioDescription *descObject, const char *filename, const MatrixF *transform=NULL, AudioSampleEnvironment * sampleEnvironment = 0);
  73. AUDIOHANDLE alxCreateSource(const AudioAsset *profile, const MatrixF *transform=NULL);
  74. AUDIOHANDLE alxCreateSource_AD(const AudioAsset *profile, const AudioDescription* description, const MatrixF *transform);
  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. ALfloat ptArray[10];
  116. ptArray[0] = value->x;
  117. ptArray[1] = value->y;
  118. ptArray[2] = value->z;
  119. alListenerfv(pname, ptArray);
  120. }
  121. /** alGetListener3f access extension for use with Point3F's
  122. */
  123. inline void alxGetListenerPoint3F(ALenum pname, Point3F *value)
  124. {
  125. ALfloat ptArray[10];
  126. ptArray[0] = value->x;
  127. ptArray[1] = value->y;
  128. ptArray[2] = value->z;
  129. alGetListenerfv(pname, ptArray);
  130. value->x = ptArray[0];
  131. value->y = ptArray[1];
  132. value->z = ptArray[2];
  133. }
  134. // Environment
  135. void alxEnvironmenti(ALenum pname, ALint value);
  136. void alxEnvironmentf(ALenum pname, ALfloat value);
  137. void alxGetEnvironmenti(ALenum pname, ALint * value);
  138. void alxGetEnvironmentf(ALenum pname, ALfloat * value);
  139. void alxSetEnvironment(const AudioEnvironment * environment);
  140. const AudioEnvironment * alxGetEnvironment();
  141. // misc
  142. void alxUpdateTypeGain(U32 type);
  143. bool alxIsValidHandle(AUDIOHANDLE handle);
  144. bool alxIsPlaying(AUDIOHANDLE handle);
  145. void alxUpdate();
  146. F32 alxGetStreamPosition( AUDIOHANDLE handle );
  147. F32 alxGetStreamDuration( AUDIOHANDLE handle );
  148. #endif // _H_PLATFORMAUDIO_