alu.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #ifndef _ALU_H_
  2. #define _ALU_H_
  3. #include "AL/al.h"
  4. #include "AL/alc.h"
  5. #include "AL/alext.h"
  6. #include <math.h>
  7. #ifdef HAVE_FLOAT_H
  8. #include <float.h>
  9. #endif
  10. #ifndef M_PI
  11. #define M_PI 3.14159265358979323846 /* pi */
  12. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  13. #endif
  14. #ifdef HAVE_POWF
  15. #define aluPow(x,y) ((ALfloat)powf((float)(x),(float)(y)))
  16. #else
  17. #define aluPow(x,y) ((ALfloat)pow((double)(x),(double)(y)))
  18. #endif
  19. #ifdef HAVE_SQRTF
  20. #define aluSqrt(x) ((ALfloat)sqrtf((float)(x)))
  21. #else
  22. #define aluSqrt(x) ((ALfloat)sqrt((double)(x)))
  23. #endif
  24. #ifdef HAVE_ACOSF
  25. #define aluAcos(x) ((ALfloat)acosf((float)(x)))
  26. #else
  27. #define aluAcos(x) ((ALfloat)acos((double)(x)))
  28. #endif
  29. #ifdef HAVE_ATANF
  30. #define aluAtan(x) ((ALfloat)atanf((float)(x)))
  31. #else
  32. #define aluAtan(x) ((ALfloat)atan((double)(x)))
  33. #endif
  34. #ifdef HAVE_FABSF
  35. #define aluFabs(x) ((ALfloat)fabsf((float)(x)))
  36. #else
  37. #define aluFabs(x) ((ALfloat)fabs((double)(x)))
  38. #endif
  39. // fixes for mingw32.
  40. #if defined(max) && !defined(__max)
  41. #define __max max
  42. #endif
  43. #if defined(min) && !defined(__min)
  44. #define __min min
  45. #endif
  46. #define QUADRANT_NUM 128
  47. #define LUT_NUM (4 * QUADRANT_NUM)
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. typedef enum {
  52. FRONT_LEFT = 0,
  53. FRONT_RIGHT,
  54. FRONT_CENTER,
  55. LFE,
  56. BACK_LEFT,
  57. BACK_RIGHT,
  58. BACK_CENTER,
  59. SIDE_LEFT,
  60. SIDE_RIGHT,
  61. OUTPUTCHANNELS
  62. } Channel;
  63. #define BUFFERSIZE 8192
  64. /* NOTE: The AL_FORMAT_REAR* enums aren't handled here because they're
  65. * converted to AL_FORMAT_QUAD* when loaded */
  66. static __inline ALuint aluBytesFromFormat(ALenum format)
  67. {
  68. switch(format)
  69. {
  70. case AL_FORMAT_MONO8:
  71. case AL_FORMAT_STEREO8:
  72. case AL_FORMAT_QUAD8_LOKI:
  73. case AL_FORMAT_QUAD8:
  74. case AL_FORMAT_51CHN8:
  75. case AL_FORMAT_61CHN8:
  76. case AL_FORMAT_71CHN8:
  77. return 1;
  78. case AL_FORMAT_MONO16:
  79. case AL_FORMAT_STEREO16:
  80. case AL_FORMAT_QUAD16_LOKI:
  81. case AL_FORMAT_QUAD16:
  82. case AL_FORMAT_51CHN16:
  83. case AL_FORMAT_61CHN16:
  84. case AL_FORMAT_71CHN16:
  85. return 2;
  86. case AL_FORMAT_MONO_FLOAT32:
  87. case AL_FORMAT_STEREO_FLOAT32:
  88. case AL_FORMAT_QUAD32:
  89. case AL_FORMAT_51CHN32:
  90. case AL_FORMAT_61CHN32:
  91. case AL_FORMAT_71CHN32:
  92. return 4;
  93. case AL_FORMAT_MONO_DOUBLE_EXT:
  94. case AL_FORMAT_STEREO_DOUBLE_EXT:
  95. return 8;
  96. default:
  97. return 0;
  98. }
  99. }
  100. static __inline ALuint aluChannelsFromFormat(ALenum format)
  101. {
  102. switch(format)
  103. {
  104. case AL_FORMAT_MONO8:
  105. case AL_FORMAT_MONO16:
  106. case AL_FORMAT_MONO_FLOAT32:
  107. case AL_FORMAT_MONO_DOUBLE_EXT:
  108. return 1;
  109. case AL_FORMAT_STEREO8:
  110. case AL_FORMAT_STEREO16:
  111. case AL_FORMAT_STEREO_FLOAT32:
  112. case AL_FORMAT_STEREO_DOUBLE_EXT:
  113. return 2;
  114. case AL_FORMAT_QUAD8_LOKI:
  115. case AL_FORMAT_QUAD16_LOKI:
  116. case AL_FORMAT_QUAD8:
  117. case AL_FORMAT_QUAD16:
  118. case AL_FORMAT_QUAD32:
  119. return 4;
  120. case AL_FORMAT_51CHN8:
  121. case AL_FORMAT_51CHN16:
  122. case AL_FORMAT_51CHN32:
  123. return 6;
  124. case AL_FORMAT_61CHN8:
  125. case AL_FORMAT_61CHN16:
  126. case AL_FORMAT_61CHN32:
  127. return 7;
  128. case AL_FORMAT_71CHN8:
  129. case AL_FORMAT_71CHN16:
  130. case AL_FORMAT_71CHN32:
  131. return 8;
  132. default:
  133. return 0;
  134. }
  135. }
  136. static __inline ALuint aluFrameSizeFromFormat(ALenum format)
  137. {
  138. return aluBytesFromFormat(format) * aluChannelsFromFormat(format);
  139. }
  140. static __inline ALint aluCart2LUTpos(ALfloat re, ALfloat im)
  141. {
  142. ALint pos = 0;
  143. ALfloat denom = aluFabs(re) + aluFabs(im);
  144. if(denom > 0.0f)
  145. pos = (ALint)(QUADRANT_NUM*aluFabs(im) / denom + 0.5);
  146. if(re < 0.0)
  147. pos = 2 * QUADRANT_NUM - pos;
  148. if(im < 0.0)
  149. pos = LUT_NUM - pos;
  150. return pos%LUT_NUM;
  151. }
  152. ALvoid aluInitPanning(ALCdevice *Device);
  153. ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size);
  154. ALvoid aluHandleDisconnect(ALCdevice *device);
  155. #ifdef __cplusplus
  156. }
  157. #endif
  158. #endif