panning.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. /**
  2. * OpenAL cross platform audio library
  3. * Copyright (C) 1999-2010 by authors.
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the
  16. * Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. * Or go to http://www.gnu.org/copyleft/lgpl.html
  19. */
  20. #include "config.h"
  21. #include <math.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include <assert.h>
  26. #include "alMain.h"
  27. #include "alAuxEffectSlot.h"
  28. #include "alu.h"
  29. #include "bool.h"
  30. #include "ambdec.h"
  31. #include "bformatdec.h"
  32. #include "uhjfilter.h"
  33. #include "bs2b.h"
  34. extern inline void CalcAngleCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS]);
  35. static const ALsizei FuMa2ACN[MAX_AMBI_COEFFS] = {
  36. 0, /* W */
  37. 3, /* X */
  38. 1, /* Y */
  39. 2, /* Z */
  40. 6, /* R */
  41. 7, /* S */
  42. 5, /* T */
  43. 8, /* U */
  44. 4, /* V */
  45. 12, /* K */
  46. 13, /* L */
  47. 11, /* M */
  48. 14, /* N */
  49. 10, /* O */
  50. 15, /* P */
  51. 9, /* Q */
  52. };
  53. static const ALsizei ACN2ACN[MAX_AMBI_COEFFS] = {
  54. 0, 1, 2, 3, 4, 5, 6, 7,
  55. 8, 9, 10, 11, 12, 13, 14, 15
  56. };
  57. /* NOTE: These are scale factors as applied to Ambisonics content. Decoder
  58. * coefficients should be divided by these values to get proper N3D scalings.
  59. */
  60. static const ALfloat UnitScale[MAX_AMBI_COEFFS] = {
  61. 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
  62. 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f
  63. };
  64. static const ALfloat SN3D2N3DScale[MAX_AMBI_COEFFS] = {
  65. 1.000000000f, /* ACN 0 (W), sqrt(1) */
  66. 1.732050808f, /* ACN 1 (Y), sqrt(3) */
  67. 1.732050808f, /* ACN 2 (Z), sqrt(3) */
  68. 1.732050808f, /* ACN 3 (X), sqrt(3) */
  69. 2.236067978f, /* ACN 4 (V), sqrt(5) */
  70. 2.236067978f, /* ACN 5 (T), sqrt(5) */
  71. 2.236067978f, /* ACN 6 (R), sqrt(5) */
  72. 2.236067978f, /* ACN 7 (S), sqrt(5) */
  73. 2.236067978f, /* ACN 8 (U), sqrt(5) */
  74. 2.645751311f, /* ACN 9 (Q), sqrt(7) */
  75. 2.645751311f, /* ACN 10 (O), sqrt(7) */
  76. 2.645751311f, /* ACN 11 (M), sqrt(7) */
  77. 2.645751311f, /* ACN 12 (K), sqrt(7) */
  78. 2.645751311f, /* ACN 13 (L), sqrt(7) */
  79. 2.645751311f, /* ACN 14 (N), sqrt(7) */
  80. 2.645751311f, /* ACN 15 (P), sqrt(7) */
  81. };
  82. static const ALfloat FuMa2N3DScale[MAX_AMBI_COEFFS] = {
  83. 1.414213562f, /* ACN 0 (W), sqrt(2) */
  84. 1.732050808f, /* ACN 1 (Y), sqrt(3) */
  85. 1.732050808f, /* ACN 2 (Z), sqrt(3) */
  86. 1.732050808f, /* ACN 3 (X), sqrt(3) */
  87. 1.936491673f, /* ACN 4 (V), sqrt(15)/2 */
  88. 1.936491673f, /* ACN 5 (T), sqrt(15)/2 */
  89. 2.236067978f, /* ACN 6 (R), sqrt(5) */
  90. 1.936491673f, /* ACN 7 (S), sqrt(15)/2 */
  91. 1.936491673f, /* ACN 8 (U), sqrt(15)/2 */
  92. 2.091650066f, /* ACN 9 (Q), sqrt(35/8) */
  93. 1.972026594f, /* ACN 10 (O), sqrt(35)/3 */
  94. 2.231093404f, /* ACN 11 (M), sqrt(224/45) */
  95. 2.645751311f, /* ACN 12 (K), sqrt(7) */
  96. 2.231093404f, /* ACN 13 (L), sqrt(224/45) */
  97. 1.972026594f, /* ACN 14 (N), sqrt(35)/3 */
  98. 2.091650066f, /* ACN 15 (P), sqrt(35/8) */
  99. };
  100. void CalcDirectionCoeffs(const ALfloat dir[3], ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
  101. {
  102. /* Convert from OpenAL coords to Ambisonics. */
  103. ALfloat x = -dir[2];
  104. ALfloat y = -dir[0];
  105. ALfloat z = dir[1];
  106. /* Zeroth-order */
  107. coeffs[0] = 1.0f; /* ACN 0 = 1 */
  108. /* First-order */
  109. coeffs[1] = 1.732050808f * y; /* ACN 1 = sqrt(3) * Y */
  110. coeffs[2] = 1.732050808f * z; /* ACN 2 = sqrt(3) * Z */
  111. coeffs[3] = 1.732050808f * x; /* ACN 3 = sqrt(3) * X */
  112. /* Second-order */
  113. coeffs[4] = 3.872983346f * x * y; /* ACN 4 = sqrt(15) * X * Y */
  114. coeffs[5] = 3.872983346f * y * z; /* ACN 5 = sqrt(15) * Y * Z */
  115. coeffs[6] = 1.118033989f * (3.0f*z*z - 1.0f); /* ACN 6 = sqrt(5)/2 * (3*Z*Z - 1) */
  116. coeffs[7] = 3.872983346f * x * z; /* ACN 7 = sqrt(15) * X * Z */
  117. coeffs[8] = 1.936491673f * (x*x - y*y); /* ACN 8 = sqrt(15)/2 * (X*X - Y*Y) */
  118. /* Third-order */
  119. coeffs[9] = 2.091650066f * y * (3.0f*x*x - y*y); /* ACN 9 = sqrt(35/8) * Y * (3*X*X - Y*Y) */
  120. coeffs[10] = 10.246950766f * z * x * y; /* ACN 10 = sqrt(105) * Z * X * Y */
  121. coeffs[11] = 1.620185175f * y * (5.0f*z*z - 1.0f); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */
  122. coeffs[12] = 1.322875656f * z * (5.0f*z*z - 3.0f); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */
  123. coeffs[13] = 1.620185175f * x * (5.0f*z*z - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */
  124. coeffs[14] = 5.123475383f * z * (x*x - y*y); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */
  125. coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */
  126. if(spread > 0.0f)
  127. {
  128. /* Implement the spread by using a spherical source that subtends the
  129. * angle spread. See:
  130. * http://www.ppsloan.org/publications/StupidSH36.pdf - Appendix A3
  131. *
  132. * When adjusted for N3D normalization instead of SN3D, these
  133. * calculations are:
  134. *
  135. * ZH0 = -sqrt(pi) * (-1+ca);
  136. * ZH1 = 0.5*sqrt(pi) * sa*sa;
  137. * ZH2 = -0.5*sqrt(pi) * ca*(-1+ca)*(ca+1);
  138. * ZH3 = -0.125*sqrt(pi) * (-1+ca)*(ca+1)*(5*ca*ca - 1);
  139. * ZH4 = -0.125*sqrt(pi) * ca*(-1+ca)*(ca+1)*(7*ca*ca - 3);
  140. * ZH5 = -0.0625*sqrt(pi) * (-1+ca)*(ca+1)*(21*ca*ca*ca*ca - 14*ca*ca + 1);
  141. *
  142. * The gain of the source is compensated for size, so that the
  143. * loundness doesn't depend on the spread. Thus:
  144. *
  145. * ZH0 = 1.0f;
  146. * ZH1 = 0.5f * (ca+1.0f);
  147. * ZH2 = 0.5f * (ca+1.0f)*ca;
  148. * ZH3 = 0.125f * (ca+1.0f)*(5.0f*ca*ca - 1.0f);
  149. * ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca;
  150. * ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f);
  151. */
  152. ALfloat ca = cosf(spread * 0.5f);
  153. /* Increase the source volume by up to +3dB for a full spread. */
  154. ALfloat scale = sqrtf(1.0f + spread/F_TAU);
  155. ALfloat ZH0_norm = scale;
  156. ALfloat ZH1_norm = 0.5f * (ca+1.f) * scale;
  157. ALfloat ZH2_norm = 0.5f * (ca+1.f)*ca * scale;
  158. ALfloat ZH3_norm = 0.125f * (ca+1.f)*(5.f*ca*ca-1.f) * scale;
  159. /* Zeroth-order */
  160. coeffs[0] *= ZH0_norm;
  161. /* First-order */
  162. coeffs[1] *= ZH1_norm;
  163. coeffs[2] *= ZH1_norm;
  164. coeffs[3] *= ZH1_norm;
  165. /* Second-order */
  166. coeffs[4] *= ZH2_norm;
  167. coeffs[5] *= ZH2_norm;
  168. coeffs[6] *= ZH2_norm;
  169. coeffs[7] *= ZH2_norm;
  170. coeffs[8] *= ZH2_norm;
  171. /* Third-order */
  172. coeffs[9] *= ZH3_norm;
  173. coeffs[10] *= ZH3_norm;
  174. coeffs[11] *= ZH3_norm;
  175. coeffs[12] *= ZH3_norm;
  176. coeffs[13] *= ZH3_norm;
  177. coeffs[14] *= ZH3_norm;
  178. coeffs[15] *= ZH3_norm;
  179. }
  180. }
  181. void CalcAnglePairwiseCoeffs(ALfloat azimuth, ALfloat elevation, ALfloat spread, ALfloat coeffs[MAX_AMBI_COEFFS])
  182. {
  183. ALfloat sign = (azimuth < 0.0f) ? -1.0f : 1.0f;
  184. if(!(fabsf(azimuth) > F_PI_2))
  185. azimuth = minf(fabsf(azimuth) * F_PI_2 / (F_PI/6.0f), F_PI_2) * sign;
  186. CalcAngleCoeffs(azimuth, elevation, spread, coeffs);
  187. }
  188. void ComputeAmbientGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  189. {
  190. ALsizei i;
  191. for(i = 0;i < numchans;i++)
  192. gains[i] = chancoeffs[i][0] * 1.414213562f * ingain;
  193. for(;i < MAX_OUTPUT_CHANNELS;i++)
  194. gains[i] = 0.0f;
  195. }
  196. void ComputeAmbientGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  197. {
  198. ALfloat gain = 0.0f;
  199. ALsizei i;
  200. for(i = 0;i < numchans;i++)
  201. {
  202. if(chanmap[i].Index == 0)
  203. gain += chanmap[i].Scale;
  204. }
  205. gains[0] = gain * 1.414213562f * ingain;
  206. for(i = 1;i < MAX_OUTPUT_CHANNELS;i++)
  207. gains[i] = 0.0f;
  208. }
  209. void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  210. {
  211. ALsizei i, j;
  212. for(i = 0;i < numchans;i++)
  213. {
  214. float gain = 0.0f;
  215. for(j = 0;j < numcoeffs;j++)
  216. gain += chancoeffs[i][j]*coeffs[j];
  217. gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
  218. }
  219. for(;i < MAX_OUTPUT_CHANNELS;i++)
  220. gains[i] = 0.0f;
  221. }
  222. void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat coeffs[MAX_AMBI_COEFFS], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  223. {
  224. ALsizei i;
  225. for(i = 0;i < numchans;i++)
  226. gains[i] = chanmap[i].Scale * coeffs[chanmap[i].Index] * ingain;
  227. for(;i < MAX_OUTPUT_CHANNELS;i++)
  228. gains[i] = 0.0f;
  229. }
  230. void ComputeFirstOrderGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  231. {
  232. ALsizei i, j;
  233. for(i = 0;i < numchans;i++)
  234. {
  235. float gain = 0.0f;
  236. for(j = 0;j < 4;j++)
  237. gain += chancoeffs[i][j] * mtx[j];
  238. gains[i] = clampf(gain, 0.0f, 1.0f) * ingain;
  239. }
  240. for(;i < MAX_OUTPUT_CHANNELS;i++)
  241. gains[i] = 0.0f;
  242. }
  243. void ComputeFirstOrderGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat mtx[4], ALfloat ingain, ALfloat gains[MAX_OUTPUT_CHANNELS])
  244. {
  245. ALsizei i;
  246. for(i = 0;i < numchans;i++)
  247. gains[i] = chanmap[i].Scale * mtx[chanmap[i].Index] * ingain;
  248. for(;i < MAX_OUTPUT_CHANNELS;i++)
  249. gains[i] = 0.0f;
  250. }
  251. static inline const char *GetLabelFromChannel(enum Channel channel)
  252. {
  253. switch(channel)
  254. {
  255. case FrontLeft: return "front-left";
  256. case FrontRight: return "front-right";
  257. case FrontCenter: return "front-center";
  258. case LFE: return "lfe";
  259. case BackLeft: return "back-left";
  260. case BackRight: return "back-right";
  261. case BackCenter: return "back-center";
  262. case SideLeft: return "side-left";
  263. case SideRight: return "side-right";
  264. case UpperFrontLeft: return "upper-front-left";
  265. case UpperFrontRight: return "upper-front-right";
  266. case UpperBackLeft: return "upper-back-left";
  267. case UpperBackRight: return "upper-back-right";
  268. case LowerFrontLeft: return "lower-front-left";
  269. case LowerFrontRight: return "lower-front-right";
  270. case LowerBackLeft: return "lower-back-left";
  271. case LowerBackRight: return "lower-back-right";
  272. case Aux0: return "aux-0";
  273. case Aux1: return "aux-1";
  274. case Aux2: return "aux-2";
  275. case Aux3: return "aux-3";
  276. case Aux4: return "aux-4";
  277. case Aux5: return "aux-5";
  278. case Aux6: return "aux-6";
  279. case Aux7: return "aux-7";
  280. case Aux8: return "aux-8";
  281. case Aux9: return "aux-9";
  282. case Aux10: return "aux-10";
  283. case Aux11: return "aux-11";
  284. case Aux12: return "aux-12";
  285. case Aux13: return "aux-13";
  286. case Aux14: return "aux-14";
  287. case Aux15: return "aux-15";
  288. case InvalidChannel: break;
  289. }
  290. return "(unknown)";
  291. }
  292. typedef struct ChannelMap {
  293. enum Channel ChanName;
  294. ChannelConfig Config;
  295. } ChannelMap;
  296. static void SetChannelMap(const enum Channel *devchans, ChannelConfig *ambicoeffs,
  297. const ChannelMap *chanmap, size_t count, ALsizei *outcount)
  298. {
  299. size_t j, k;
  300. ALsizei i;
  301. for(i = 0;i < MAX_OUTPUT_CHANNELS && devchans[i] != InvalidChannel;i++)
  302. {
  303. if(devchans[i] == LFE)
  304. {
  305. for(j = 0;j < MAX_AMBI_COEFFS;j++)
  306. ambicoeffs[i][j] = 0.0f;
  307. continue;
  308. }
  309. for(j = 0;j < count;j++)
  310. {
  311. if(devchans[i] != chanmap[j].ChanName)
  312. continue;
  313. for(k = 0;k < MAX_AMBI_COEFFS;++k)
  314. ambicoeffs[i][k] = chanmap[j].Config[k];
  315. break;
  316. }
  317. if(j == count)
  318. ERR("Failed to match %s channel (%u) in channel map\n", GetLabelFromChannel(devchans[i]), i);
  319. }
  320. *outcount = i;
  321. }
  322. static bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei speakermap[MAX_OUTPUT_CHANNELS])
  323. {
  324. ALsizei i;
  325. for(i = 0;i < conf->NumSpeakers;i++)
  326. {
  327. int c = -1;
  328. /* NOTE: AmbDec does not define any standard speaker names, however
  329. * for this to work we have to by able to find the output channel
  330. * the speaker definition corresponds to. Therefore, OpenAL Soft
  331. * requires these channel labels to be recognized:
  332. *
  333. * LF = Front left
  334. * RF = Front right
  335. * LS = Side left
  336. * RS = Side right
  337. * LB = Back left
  338. * RB = Back right
  339. * CE = Front center
  340. * CB = Back center
  341. *
  342. * Additionally, surround51 will acknowledge back speakers for side
  343. * channels, and surround51rear will acknowledge side speakers for
  344. * back channels, to avoid issues with an ambdec expecting 5.1 to
  345. * use the side channels when the device is configured for back,
  346. * and vice-versa.
  347. */
  348. if(alstr_cmp_cstr(conf->Speakers[i].Name, "LF") == 0)
  349. c = GetChannelIdxByName(device->RealOut, FrontLeft);
  350. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RF") == 0)
  351. c = GetChannelIdxByName(device->RealOut, FrontRight);
  352. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "CE") == 0)
  353. c = GetChannelIdxByName(device->RealOut, FrontCenter);
  354. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "LS") == 0)
  355. {
  356. if(device->FmtChans == DevFmtX51Rear)
  357. c = GetChannelIdxByName(device->RealOut, BackLeft);
  358. else
  359. c = GetChannelIdxByName(device->RealOut, SideLeft);
  360. }
  361. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RS") == 0)
  362. {
  363. if(device->FmtChans == DevFmtX51Rear)
  364. c = GetChannelIdxByName(device->RealOut, BackRight);
  365. else
  366. c = GetChannelIdxByName(device->RealOut, SideRight);
  367. }
  368. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "LB") == 0)
  369. {
  370. if(device->FmtChans == DevFmtX51)
  371. c = GetChannelIdxByName(device->RealOut, SideLeft);
  372. else
  373. c = GetChannelIdxByName(device->RealOut, BackLeft);
  374. }
  375. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "RB") == 0)
  376. {
  377. if(device->FmtChans == DevFmtX51)
  378. c = GetChannelIdxByName(device->RealOut, SideRight);
  379. else
  380. c = GetChannelIdxByName(device->RealOut, BackRight);
  381. }
  382. else if(alstr_cmp_cstr(conf->Speakers[i].Name, "CB") == 0)
  383. c = GetChannelIdxByName(device->RealOut, BackCenter);
  384. else
  385. {
  386. const char *name = alstr_get_cstr(conf->Speakers[i].Name);
  387. unsigned int n;
  388. char ch;
  389. if(sscanf(name, "AUX%u%c", &n, &ch) == 1 && n < 16)
  390. c = GetChannelIdxByName(device->RealOut, Aux0+n);
  391. else
  392. {
  393. ERR("AmbDec speaker label \"%s\" not recognized\n", name);
  394. return false;
  395. }
  396. }
  397. if(c == -1)
  398. {
  399. ERR("Failed to lookup AmbDec speaker label %s\n",
  400. alstr_get_cstr(conf->Speakers[i].Name));
  401. return false;
  402. }
  403. speakermap[i] = c;
  404. }
  405. return true;
  406. }
  407. static const ChannelMap MonoCfg[1] = {
  408. { FrontCenter, { 1.0f } },
  409. }, StereoCfg[2] = {
  410. { FrontLeft, { 5.00000000e-1f, 2.88675135e-1f, 0.0f, 1.19573156e-1f } },
  411. { FrontRight, { 5.00000000e-1f, -2.88675135e-1f, 0.0f, 1.19573156e-1f } },
  412. }, QuadCfg[4] = {
  413. { BackLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, -2.04124145e-1f } },
  414. { FrontLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, 2.04124145e-1f } },
  415. { FrontRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, 2.04124145e-1f } },
  416. { BackRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, -2.04124145e-1f } },
  417. }, X51SideCfg[5] = {
  418. { SideLeft, { 3.33001372e-1f, 1.89085671e-1f, 0.0f, -2.00041334e-1f, -2.12309737e-2f, 0.0f, 0.0f, 0.0f, -1.14573483e-2f } },
  419. { FrontLeft, { 1.47751298e-1f, 1.28994110e-1f, 0.0f, 1.15190495e-1f, 7.44949143e-2f, 0.0f, 0.0f, 0.0f, -6.47739980e-3f } },
  420. { FrontCenter, { 7.73595729e-2f, 0.00000000e+0f, 0.0f, 9.71390298e-2f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 5.18625335e-2f } },
  421. { FrontRight, { 1.47751298e-1f, -1.28994110e-1f, 0.0f, 1.15190495e-1f, -7.44949143e-2f, 0.0f, 0.0f, 0.0f, -6.47739980e-3f } },
  422. { SideRight, { 3.33001372e-1f, -1.89085671e-1f, 0.0f, -2.00041334e-1f, 2.12309737e-2f, 0.0f, 0.0f, 0.0f, -1.14573483e-2f } },
  423. }, X51RearCfg[5] = {
  424. { BackLeft, { 3.33001372e-1f, 1.89085671e-1f, 0.0f, -2.00041334e-1f, -2.12309737e-2f, 0.0f, 0.0f, 0.0f, -1.14573483e-2f } },
  425. { FrontLeft, { 1.47751298e-1f, 1.28994110e-1f, 0.0f, 1.15190495e-1f, 7.44949143e-2f, 0.0f, 0.0f, 0.0f, -6.47739980e-3f } },
  426. { FrontCenter, { 7.73595729e-2f, 0.00000000e+0f, 0.0f, 9.71390298e-2f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 5.18625335e-2f } },
  427. { FrontRight, { 1.47751298e-1f, -1.28994110e-1f, 0.0f, 1.15190495e-1f, -7.44949143e-2f, 0.0f, 0.0f, 0.0f, -6.47739980e-3f } },
  428. { BackRight, { 3.33001372e-1f, -1.89085671e-1f, 0.0f, -2.00041334e-1f, 2.12309737e-2f, 0.0f, 0.0f, 0.0f, -1.14573483e-2f } },
  429. }, X61Cfg[6] = {
  430. { SideLeft, { 2.04462744e-1f, 2.17178497e-1f, 0.0f, -4.39990188e-2f, -2.60787329e-2f, 0.0f, 0.0f, 0.0f, -6.87238843e-2f } },
  431. { FrontLeft, { 1.18130342e-1f, 9.34633906e-2f, 0.0f, 1.08553749e-1f, 6.80658795e-2f, 0.0f, 0.0f, 0.0f, 1.08999485e-2f } },
  432. { FrontCenter, { 7.73595729e-2f, 0.00000000e+0f, 0.0f, 9.71390298e-2f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 5.18625335e-2f } },
  433. { FrontRight, { 1.18130342e-1f, -9.34633906e-2f, 0.0f, 1.08553749e-1f, -6.80658795e-2f, 0.0f, 0.0f, 0.0f, 1.08999485e-2f } },
  434. { SideRight, { 2.04462744e-1f, -2.17178497e-1f, 0.0f, -4.39990188e-2f, 2.60787329e-2f, 0.0f, 0.0f, 0.0f, -6.87238843e-2f } },
  435. { BackCenter, { 2.50001688e-1f, 0.00000000e+0f, 0.0f, -2.50000094e-1f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 6.05133395e-2f } },
  436. }, X71Cfg[6] = {
  437. { BackLeft, { 2.04124145e-1f, 1.08880247e-1f, 0.0f, -1.88586120e-1f, -1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  438. { SideLeft, { 2.04124145e-1f, 2.17760495e-1f, 0.0f, 0.00000000e+0f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, -1.49071198e-1f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  439. { FrontLeft, { 2.04124145e-1f, 1.08880247e-1f, 0.0f, 1.88586120e-1f, 1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  440. { FrontRight, { 2.04124145e-1f, -1.08880247e-1f, 0.0f, 1.88586120e-1f, -1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  441. { SideRight, { 2.04124145e-1f, -2.17760495e-1f, 0.0f, 0.00000000e+0f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, -1.49071198e-1f, 3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  442. { BackRight, { 2.04124145e-1f, -1.08880247e-1f, 0.0f, -1.88586120e-1f, 1.29099444e-1f, 0.0f, 0.0f, 0.0f, 7.45355993e-2f, -3.73460789e-2f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.00000000e+0f } },
  443. };
  444. static void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, bool periphonic)
  445. {
  446. const char *devname = alstr_get_cstr(device->DeviceName);
  447. ALsizei i;
  448. if(GetConfigValueBool(devname, "decoder", "nfc", 1) && ctrl_dist > 0.0f)
  449. {
  450. /* NFC is only used when AvgSpeakerDist is greater than 0, and
  451. * METERS_PER_UNIT is also greater than 0. In addition, NFC can only be
  452. * used when rendering to an ambisonic buffer.
  453. */
  454. device->AvgSpeakerDist = ctrl_dist;
  455. device->Dry.NumChannelsPerOrder[0] = 1;
  456. if(periphonic)
  457. for(i = 1;i < order+1;i++)
  458. device->Dry.NumChannelsPerOrder[i] = (i+1)*(i+1) - i*i;
  459. else
  460. for(i = 1;i < order+1;i++)
  461. device->Dry.NumChannelsPerOrder[i] = (i*2+1) - ((i-1)*2+1);
  462. for(;i < MAX_AMBI_ORDER+1;i++)
  463. device->Dry.NumChannelsPerOrder[i] = 0;
  464. }
  465. }
  466. static void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
  467. {
  468. const char *devname = alstr_get_cstr(device->DeviceName);
  469. ALfloat maxdist = 0.0f;
  470. ALsizei total = 0;
  471. ALsizei i;
  472. for(i = 0;i < conf->NumSpeakers;i++)
  473. maxdist = maxf(maxdist, conf->Speakers[i].Distance);
  474. if(GetConfigValueBool(devname, "decoder", "distance-comp", 1) && maxdist > 0.0f)
  475. {
  476. ALfloat srate = (ALfloat)device->Frequency;
  477. for(i = 0;i < conf->NumSpeakers;i++)
  478. {
  479. ALsizei chan = speakermap[i];
  480. ALfloat delay;
  481. /* Distance compensation only delays in steps of the sample rate.
  482. * This is a bit less accurate since the delay time falls to the
  483. * nearest sample time, but it's far simpler as it doesn't have to
  484. * deal with phase offsets. This means at 48khz, for instance, the
  485. * distance delay will be in steps of about 7 millimeters.
  486. */
  487. delay = floorf((maxdist-conf->Speakers[i].Distance) / SPEEDOFSOUNDMETRESPERSEC *
  488. srate + 0.5f);
  489. if(delay >= (ALfloat)MAX_DELAY_LENGTH)
  490. ERR("Delay for speaker \"%s\" exceeds buffer length (%f >= %u)\n",
  491. alstr_get_cstr(conf->Speakers[i].Name), delay, MAX_DELAY_LENGTH);
  492. device->ChannelDelay[chan].Length = (ALsizei)clampf(
  493. delay, 0.0f, (ALfloat)(MAX_DELAY_LENGTH-1)
  494. );
  495. device->ChannelDelay[chan].Gain = conf->Speakers[i].Distance / maxdist;
  496. TRACE("Channel %u \"%s\" distance compensation: %d samples, %f gain\n", chan,
  497. alstr_get_cstr(conf->Speakers[i].Name), device->ChannelDelay[chan].Length,
  498. device->ChannelDelay[chan].Gain
  499. );
  500. /* Round up to the next 4th sample, so each channel buffer starts
  501. * 16-byte aligned.
  502. */
  503. total += RoundUp(device->ChannelDelay[chan].Length, 4);
  504. }
  505. }
  506. if(total > 0)
  507. {
  508. device->ChannelDelay[0].Buffer = al_calloc(16, total * sizeof(ALfloat));
  509. for(i = 1;i < MAX_OUTPUT_CHANNELS;i++)
  510. {
  511. size_t len = RoundUp(device->ChannelDelay[i-1].Length, 4);
  512. device->ChannelDelay[i].Buffer = device->ChannelDelay[i-1].Buffer + len;
  513. }
  514. }
  515. }
  516. static void InitPanning(ALCdevice *device)
  517. {
  518. const ChannelMap *chanmap = NULL;
  519. ALsizei coeffcount = 0;
  520. ALsizei count = 0;
  521. ALsizei i, j;
  522. switch(device->FmtChans)
  523. {
  524. case DevFmtMono:
  525. count = COUNTOF(MonoCfg);
  526. chanmap = MonoCfg;
  527. coeffcount = 1;
  528. break;
  529. case DevFmtStereo:
  530. count = COUNTOF(StereoCfg);
  531. chanmap = StereoCfg;
  532. coeffcount = 4;
  533. break;
  534. case DevFmtQuad:
  535. count = COUNTOF(QuadCfg);
  536. chanmap = QuadCfg;
  537. coeffcount = 4;
  538. break;
  539. case DevFmtX51:
  540. count = COUNTOF(X51SideCfg);
  541. chanmap = X51SideCfg;
  542. coeffcount = 9;
  543. break;
  544. case DevFmtX51Rear:
  545. count = COUNTOF(X51RearCfg);
  546. chanmap = X51RearCfg;
  547. coeffcount = 9;
  548. break;
  549. case DevFmtX61:
  550. count = COUNTOF(X61Cfg);
  551. chanmap = X61Cfg;
  552. coeffcount = 9;
  553. break;
  554. case DevFmtX71:
  555. count = COUNTOF(X71Cfg);
  556. chanmap = X71Cfg;
  557. coeffcount = 16;
  558. break;
  559. case DevFmtAmbi3D:
  560. break;
  561. }
  562. if(device->FmtChans == DevFmtAmbi3D)
  563. {
  564. const char *devname = alstr_get_cstr(device->DeviceName);
  565. const ALsizei *acnmap = (device->AmbiLayout == AmbiLayout_FuMa) ? FuMa2ACN : ACN2ACN;
  566. const ALfloat *n3dscale = (device->AmbiScale == AmbiNorm_FuMa) ? FuMa2N3DScale :
  567. (device->AmbiScale == AmbiNorm_SN3D) ? SN3D2N3DScale :
  568. /*(device->AmbiScale == AmbiNorm_N3D) ?*/ UnitScale;
  569. ALfloat nfc_delay = 0.0f;
  570. count = (device->AmbiOrder == 3) ? 16 :
  571. (device->AmbiOrder == 2) ? 9 :
  572. (device->AmbiOrder == 1) ? 4 : 1;
  573. for(i = 0;i < count;i++)
  574. {
  575. ALsizei acn = acnmap[i];
  576. device->Dry.Ambi.Map[i].Scale = 1.0f/n3dscale[acn];
  577. device->Dry.Ambi.Map[i].Index = acn;
  578. }
  579. device->Dry.CoeffCount = 0;
  580. device->Dry.NumChannels = count;
  581. if(device->AmbiOrder < 2)
  582. {
  583. device->FOAOut.Ambi = device->Dry.Ambi;
  584. device->FOAOut.CoeffCount = device->Dry.CoeffCount;
  585. device->FOAOut.NumChannels = 0;
  586. }
  587. else
  588. {
  589. /* FOA output is always ACN+N3D for higher-order ambisonic output.
  590. * The upsampler expects this and will convert it for output.
  591. */
  592. memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
  593. for(i = 0;i < 4;i++)
  594. {
  595. device->FOAOut.Ambi.Map[i].Scale = 1.0f;
  596. device->FOAOut.Ambi.Map[i].Index = i;
  597. }
  598. device->FOAOut.CoeffCount = 0;
  599. device->FOAOut.NumChannels = 4;
  600. ambiup_reset(device->AmbiUp, device);
  601. }
  602. if(ConfigValueFloat(devname, "decoder", "nfc-ref-delay", &nfc_delay) && nfc_delay > 0.0f)
  603. {
  604. nfc_delay = clampf(nfc_delay, 0.001f, 1000.0f);
  605. InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC,
  606. device->AmbiOrder, true);
  607. }
  608. }
  609. else
  610. {
  611. ALfloat w_scale, xyz_scale;
  612. SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs,
  613. chanmap, count, &device->Dry.NumChannels);
  614. device->Dry.CoeffCount = coeffcount;
  615. w_scale = (device->Dry.CoeffCount > 9) ? W_SCALE2D_THIRD :
  616. (device->Dry.CoeffCount > 4) ? W_SCALE2D_SECOND : 1.0f;
  617. xyz_scale = (device->Dry.CoeffCount > 9) ? XYZ_SCALE2D_THIRD :
  618. (device->Dry.CoeffCount > 4) ? XYZ_SCALE2D_SECOND : 1.0f;
  619. memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
  620. for(i = 0;i < device->Dry.NumChannels;i++)
  621. {
  622. device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
  623. for(j = 1;j < 4;j++)
  624. device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
  625. }
  626. device->FOAOut.CoeffCount = 4;
  627. device->FOAOut.NumChannels = 0;
  628. }
  629. device->RealOut.NumChannels = 0;
  630. }
  631. static void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
  632. {
  633. ChannelMap chanmap[MAX_OUTPUT_CHANNELS];
  634. const ALfloat *coeff_scale = UnitScale;
  635. ALfloat w_scale = 1.0f;
  636. ALfloat xyz_scale = 1.0f;
  637. ALsizei i, j;
  638. if(conf->FreqBands != 1)
  639. ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
  640. conf->XOverFreq);
  641. if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
  642. {
  643. if(conf->ChanMask > 0x1ff)
  644. {
  645. w_scale = W_SCALE3D_THIRD;
  646. xyz_scale = XYZ_SCALE3D_THIRD;
  647. }
  648. else if(conf->ChanMask > 0xf)
  649. {
  650. w_scale = W_SCALE3D_SECOND;
  651. xyz_scale = XYZ_SCALE3D_SECOND;
  652. }
  653. }
  654. else
  655. {
  656. if(conf->ChanMask > 0x1ff)
  657. {
  658. w_scale = W_SCALE2D_THIRD;
  659. xyz_scale = XYZ_SCALE2D_THIRD;
  660. }
  661. else if(conf->ChanMask > 0xf)
  662. {
  663. w_scale = W_SCALE2D_SECOND;
  664. xyz_scale = XYZ_SCALE2D_SECOND;
  665. }
  666. }
  667. if(conf->CoeffScale == ADS_SN3D)
  668. coeff_scale = SN3D2N3DScale;
  669. else if(conf->CoeffScale == ADS_FuMa)
  670. coeff_scale = FuMa2N3DScale;
  671. for(i = 0;i < conf->NumSpeakers;i++)
  672. {
  673. ALsizei chan = speakermap[i];
  674. ALfloat gain;
  675. ALsizei k = 0;
  676. for(j = 0;j < MAX_AMBI_COEFFS;j++)
  677. chanmap[i].Config[j] = 0.0f;
  678. chanmap[i].ChanName = device->RealOut.ChannelName[chan];
  679. for(j = 0;j < MAX_AMBI_COEFFS;j++)
  680. {
  681. if(j == 0) gain = conf->HFOrderGain[0];
  682. else if(j == 1) gain = conf->HFOrderGain[1];
  683. else if(j == 4) gain = conf->HFOrderGain[2];
  684. else if(j == 9) gain = conf->HFOrderGain[3];
  685. if((conf->ChanMask&(1<<j)))
  686. chanmap[i].Config[j] = conf->HFMatrix[i][k++] / coeff_scale[j] * gain;
  687. }
  688. }
  689. SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs, chanmap,
  690. conf->NumSpeakers, &device->Dry.NumChannels);
  691. device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
  692. (conf->ChanMask > 0xf) ? 9 : 4;
  693. memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
  694. for(i = 0;i < device->Dry.NumChannels;i++)
  695. {
  696. device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
  697. for(j = 1;j < 4;j++)
  698. device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
  699. }
  700. device->FOAOut.CoeffCount = 4;
  701. device->FOAOut.NumChannels = 0;
  702. device->RealOut.NumChannels = 0;
  703. InitDistanceComp(device, conf, speakermap);
  704. }
  705. static void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei speakermap[MAX_OUTPUT_CHANNELS])
  706. {
  707. ALfloat avg_dist;
  708. ALsizei count;
  709. ALsizei i;
  710. if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
  711. {
  712. count = (conf->ChanMask > 0x1ff) ? 16 :
  713. (conf->ChanMask > 0xf) ? 9 : 4;
  714. for(i = 0;i < count;i++)
  715. {
  716. device->Dry.Ambi.Map[i].Scale = 1.0f;
  717. device->Dry.Ambi.Map[i].Index = i;
  718. }
  719. }
  720. else
  721. {
  722. static const int map[MAX_AMBI2D_COEFFS] = { 0, 1, 3, 4, 8, 9, 15 };
  723. count = (conf->ChanMask > 0x1ff) ? 7 :
  724. (conf->ChanMask > 0xf) ? 5 : 3;
  725. for(i = 0;i < count;i++)
  726. {
  727. device->Dry.Ambi.Map[i].Scale = 1.0f;
  728. device->Dry.Ambi.Map[i].Index = map[i];
  729. }
  730. }
  731. device->Dry.CoeffCount = 0;
  732. device->Dry.NumChannels = count;
  733. TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
  734. (conf->FreqBands == 1) ? "single" : "dual",
  735. (conf->ChanMask > 0xf) ? (conf->ChanMask > 0x1ff) ? "third" : "second" : "first",
  736. (conf->ChanMask&AMBI_PERIPHONIC_MASK) ? " periphonic" : ""
  737. );
  738. bformatdec_reset(device->AmbiDecoder, conf, count, device->Frequency, speakermap);
  739. if(!(conf->ChanMask > 0xf))
  740. {
  741. device->FOAOut.Ambi = device->Dry.Ambi;
  742. device->FOAOut.CoeffCount = device->Dry.CoeffCount;
  743. device->FOAOut.NumChannels = 0;
  744. }
  745. else
  746. {
  747. memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
  748. if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
  749. {
  750. count = 4;
  751. for(i = 0;i < count;i++)
  752. {
  753. device->FOAOut.Ambi.Map[i].Scale = 1.0f;
  754. device->FOAOut.Ambi.Map[i].Index = i;
  755. }
  756. }
  757. else
  758. {
  759. static const int map[3] = { 0, 1, 3 };
  760. count = 3;
  761. for(i = 0;i < count;i++)
  762. {
  763. device->FOAOut.Ambi.Map[i].Scale = 1.0f;
  764. device->FOAOut.Ambi.Map[i].Index = map[i];
  765. }
  766. }
  767. device->FOAOut.CoeffCount = 0;
  768. device->FOAOut.NumChannels = count;
  769. }
  770. device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
  771. avg_dist = 0.0f;
  772. for(i = 0;i < conf->NumSpeakers;i++)
  773. avg_dist += conf->Speakers[i].Distance;
  774. avg_dist /= (ALfloat)conf->NumSpeakers;
  775. InitNearFieldCtrl(device, avg_dist,
  776. (conf->ChanMask > 0x1ff) ? 3 : (conf->ChanMask > 0xf) ? 2 : 1,
  777. !!(conf->ChanMask&AMBI_PERIPHONIC_MASK)
  778. );
  779. InitDistanceComp(device, conf, speakermap);
  780. }
  781. static void InitHrtfPanning(ALCdevice *device)
  782. {
  783. /* NOTE: azimuth goes clockwise. */
  784. static const ALfloat AmbiPoints[][2] = {
  785. { DEG2RAD( 90.0f), DEG2RAD( 0.0f) },
  786. { DEG2RAD( 35.0f), DEG2RAD( -45.0f) },
  787. { DEG2RAD( 35.0f), DEG2RAD( 45.0f) },
  788. { DEG2RAD( 35.0f), DEG2RAD( 135.0f) },
  789. { DEG2RAD( 35.0f), DEG2RAD(-135.0f) },
  790. { DEG2RAD( 0.0f), DEG2RAD( 0.0f) },
  791. { DEG2RAD( 0.0f), DEG2RAD( 90.0f) },
  792. { DEG2RAD( 0.0f), DEG2RAD( 180.0f) },
  793. { DEG2RAD( 0.0f), DEG2RAD( -90.0f) },
  794. { DEG2RAD(-35.0f), DEG2RAD( -45.0f) },
  795. { DEG2RAD(-35.0f), DEG2RAD( 45.0f) },
  796. { DEG2RAD(-35.0f), DEG2RAD( 135.0f) },
  797. { DEG2RAD(-35.0f), DEG2RAD(-135.0f) },
  798. { DEG2RAD(-90.0f), DEG2RAD( 0.0f) },
  799. };
  800. static const ALfloat AmbiMatrixFOA[][2][MAX_AMBI_COEFFS] = {
  801. { { 1.88982237e-001f, 0.00000000e+000f, 1.90399923e-001f, 0.00000000e+000f }, { 7.14285714e-002f, 0.00000000e+000f, 1.24646009e-001f, 0.00000000e+000f } },
  802. { { 1.88982237e-001f, 1.09057783e-001f, 1.09208910e-001f, 1.09057783e-001f }, { 7.14285714e-002f, 7.13950780e-002f, 7.14940135e-002f, 7.13950780e-002f } },
  803. { { 1.88982237e-001f, -1.09057783e-001f, 1.09208910e-001f, 1.09057783e-001f }, { 7.14285714e-002f, -7.13950780e-002f, 7.14940135e-002f, 7.13950780e-002f } },
  804. { { 1.88982237e-001f, -1.09057783e-001f, 1.09208910e-001f, -1.09057783e-001f }, { 7.14285714e-002f, -7.13950780e-002f, 7.14940135e-002f, -7.13950780e-002f } },
  805. { { 1.88982237e-001f, 1.09057783e-001f, 1.09208910e-001f, -1.09057783e-001f }, { 7.14285714e-002f, 7.13950780e-002f, 7.14940135e-002f, -7.13950780e-002f } },
  806. { { 1.88982237e-001f, 0.00000000e+000f, 0.00000000e+000f, 1.88281281e-001f }, { 7.14285714e-002f, 0.00000000e+000f, 0.00000000e+000f, 1.23259031e-001f } },
  807. { { 1.88982237e-001f, -1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f }, { 7.14285714e-002f, -1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f } },
  808. { { 1.88982237e-001f, 0.00000000e+000f, 0.00000000e+000f, -1.88281281e-001f }, { 7.14285714e-002f, 0.00000000e+000f, 0.00000000e+000f, -1.23259031e-001f } },
  809. { { 1.88982237e-001f, 1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f }, { 7.14285714e-002f, 1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f } },
  810. { { 1.88982237e-001f, 1.09057783e-001f, -1.09208910e-001f, 1.09057783e-001f }, { 7.14285714e-002f, 7.13950780e-002f, -7.14940135e-002f, 7.13950780e-002f } },
  811. { { 1.88982237e-001f, -1.09057783e-001f, -1.09208910e-001f, 1.09057783e-001f }, { 7.14285714e-002f, -7.13950780e-002f, -7.14940135e-002f, 7.13950780e-002f } },
  812. { { 1.88982237e-001f, -1.09057783e-001f, -1.09208910e-001f, -1.09057783e-001f }, { 7.14285714e-002f, -7.13950780e-002f, -7.14940135e-002f, -7.13950780e-002f } },
  813. { { 1.88982237e-001f, 1.09057783e-001f, -1.09208910e-001f, -1.09057783e-001f }, { 7.14285714e-002f, 7.13950780e-002f, -7.14940135e-002f, -7.13950780e-002f } },
  814. { { 1.88982237e-001f, 0.00000000e+000f, -1.90399923e-001f, 0.00000000e+000f }, { 7.14285714e-002f, 0.00000000e+000f, -1.24646009e-001f, 0.00000000e+000f } }
  815. }, AmbiMatrixHOA[][2][MAX_AMBI_COEFFS] = {
  816. { { 1.43315266e-001f, 0.00000000e+000f, 1.90399923e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 1.18020996e-001f, 0.00000000e+000f, 0.00000000e+000f }, { 7.26741039e-002f, 0.00000000e+000f, 1.24646009e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 1.49618920e-001f, 0.00000000e+000f, 0.00000000e+000f } },
  817. { { 1.40852210e-001f, 1.09057783e-001f, 1.09208910e-001f, 1.09057783e-001f, 7.58818830e-002f, 7.66295578e-002f, -3.28314629e-004f, 7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, 7.13950780e-002f, 7.14940135e-002f, 7.13950780e-002f, 9.61978444e-002f, 9.71456952e-002f, -4.16214759e-004f, 9.71456952e-002f, 0.00000000e+000f } },
  818. { { 1.40852210e-001f, -1.09057783e-001f, 1.09208910e-001f, 1.09057783e-001f, -7.58818830e-002f, -7.66295578e-002f, -3.28314629e-004f, 7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, -7.13950780e-002f, 7.14940135e-002f, 7.13950780e-002f, -9.61978444e-002f, -9.71456952e-002f, -4.16214759e-004f, 9.71456952e-002f, 0.00000000e+000f } },
  819. { { 1.40852210e-001f, -1.09057783e-001f, 1.09208910e-001f, -1.09057783e-001f, 7.58818830e-002f, -7.66295578e-002f, -3.28314629e-004f, -7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, -7.13950780e-002f, 7.14940135e-002f, -7.13950780e-002f, 9.61978444e-002f, -9.71456952e-002f, -4.16214759e-004f, -9.71456952e-002f, 0.00000000e+000f } },
  820. { { 1.40852210e-001f, 1.09057783e-001f, 1.09208910e-001f, -1.09057783e-001f, -7.58818830e-002f, 7.66295578e-002f, -3.28314629e-004f, -7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, 7.13950780e-002f, 7.14940135e-002f, -7.13950780e-002f, -9.61978444e-002f, 9.71456952e-002f, -4.16214759e-004f, -9.71456952e-002f, 0.00000000e+000f } },
  821. { { 1.39644596e-001f, 0.00000000e+000f, 0.00000000e+000f, 1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f, -5.83538687e-002f, 0.00000000e+000f, 1.01835015e-001f }, { 7.08127349e-002f, 0.00000000e+000f, 0.00000000e+000f, 1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f, -7.39770307e-002f, 0.00000000e+000f, 1.29099445e-001f } },
  822. { { 1.39644596e-001f, -1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, -5.83538687e-002f, 0.00000000e+000f, -1.01835015e-001f }, { 7.08127349e-002f, -1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, -7.39770307e-002f, 0.00000000e+000f, -1.29099445e-001f } },
  823. { { 1.39644596e-001f, 0.00000000e+000f, 0.00000000e+000f, -1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f, -5.83538687e-002f, 0.00000000e+000f, 1.01835015e-001f }, { 7.08127349e-002f, 0.00000000e+000f, 0.00000000e+000f, -1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f, -7.39770307e-002f, 0.00000000e+000f, 1.29099445e-001f } },
  824. { { 1.39644596e-001f, 1.88281281e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, -5.83538687e-002f, 0.00000000e+000f, -1.01835015e-001f }, { 7.08127349e-002f, 1.23259031e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, -7.39770307e-002f, 0.00000000e+000f, -1.29099445e-001f } },
  825. { { 1.40852210e-001f, 1.09057783e-001f, -1.09208910e-001f, 1.09057783e-001f, 7.58818830e-002f, -7.66295578e-002f, -3.28314629e-004f, -7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, 7.13950780e-002f, -7.14940135e-002f, 7.13950780e-002f, 9.61978444e-002f, -9.71456952e-002f, -4.16214759e-004f, -9.71456952e-002f, 0.00000000e+000f } },
  826. { { 1.40852210e-001f, -1.09057783e-001f, -1.09208910e-001f, 1.09057783e-001f, -7.58818830e-002f, 7.66295578e-002f, -3.28314629e-004f, -7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, -7.13950780e-002f, -7.14940135e-002f, 7.13950780e-002f, -9.61978444e-002f, 9.71456952e-002f, -4.16214759e-004f, -9.71456952e-002f, 0.00000000e+000f } },
  827. { { 1.40852210e-001f, -1.09057783e-001f, -1.09208910e-001f, -1.09057783e-001f, 7.58818830e-002f, 7.66295578e-002f, -3.28314629e-004f, 7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, -7.13950780e-002f, -7.14940135e-002f, -7.13950780e-002f, 9.61978444e-002f, 9.71456952e-002f, -4.16214759e-004f, 9.71456952e-002f, 0.00000000e+000f } },
  828. { { 1.40852210e-001f, 1.09057783e-001f, -1.09208910e-001f, -1.09057783e-001f, -7.58818830e-002f, -7.66295578e-002f, -3.28314629e-004f, 7.66295578e-002f, 0.00000000e+000f }, { 7.14251066e-002f, 7.13950780e-002f, -7.14940135e-002f, -7.13950780e-002f, -9.61978444e-002f, -9.71456952e-002f, -4.16214759e-004f, 9.71456952e-002f, 0.00000000e+000f } },
  829. { { 1.43315266e-001f, 0.00000000e+000f, -1.90399923e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 1.18020996e-001f, 0.00000000e+000f, 0.00000000e+000f }, { 7.26741039e-002f, 0.00000000e+000f, -1.24646009e-001f, 0.00000000e+000f, 0.00000000e+000f, 0.00000000e+000f, 1.49618920e-001f, 0.00000000e+000f, 0.00000000e+000f } },
  830. };
  831. const ALfloat (*AmbiMatrix)[2][MAX_AMBI_COEFFS] = device->AmbiUp ? AmbiMatrixHOA :
  832. AmbiMatrixFOA;
  833. ALsizei count = device->AmbiUp ? 9 : 4;
  834. ALsizei i;
  835. static_assert(COUNTOF(AmbiPoints) <= HRTF_AMBI_MAX_CHANNELS, "HRTF_AMBI_MAX_CHANNELS is too small");
  836. device->Hrtf = al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count));
  837. for(i = 0;i < count;i++)
  838. {
  839. device->Dry.Ambi.Map[i].Scale = 1.0f;
  840. device->Dry.Ambi.Map[i].Index = i;
  841. }
  842. device->Dry.CoeffCount = 0;
  843. device->Dry.NumChannels = count;
  844. if(device->AmbiUp)
  845. {
  846. memset(&device->FOAOut.Ambi, 0, sizeof(device->FOAOut.Ambi));
  847. for(i = 0;i < 4;i++)
  848. {
  849. device->FOAOut.Ambi.Map[i].Scale = 1.0f;
  850. device->FOAOut.Ambi.Map[i].Index = i;
  851. }
  852. device->FOAOut.CoeffCount = 0;
  853. device->FOAOut.NumChannels = 4;
  854. ambiup_reset(device->AmbiUp, device);
  855. }
  856. else
  857. {
  858. device->FOAOut.Ambi = device->Dry.Ambi;
  859. device->FOAOut.CoeffCount = device->Dry.CoeffCount;
  860. device->FOAOut.NumChannels = 0;
  861. }
  862. device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
  863. device->Hrtf->IrSize = BuildBFormatHrtf(device->HrtfHandle,
  864. device->Hrtf, device->Dry.NumChannels,
  865. AmbiPoints, AmbiMatrix, COUNTOF(AmbiPoints)
  866. );
  867. }
  868. static void InitUhjPanning(ALCdevice *device)
  869. {
  870. ALsizei count = 3;
  871. ALsizei i;
  872. for(i = 0;i < count;i++)
  873. {
  874. ALsizei acn = FuMa2ACN[i];
  875. device->Dry.Ambi.Map[i].Scale = 1.0f/FuMa2N3DScale[acn];
  876. device->Dry.Ambi.Map[i].Index = acn;
  877. }
  878. device->Dry.CoeffCount = 0;
  879. device->Dry.NumChannels = count;
  880. device->FOAOut.Ambi = device->Dry.Ambi;
  881. device->FOAOut.CoeffCount = device->Dry.CoeffCount;
  882. device->FOAOut.NumChannels = 0;
  883. device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder);
  884. }
  885. void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
  886. {
  887. /* Hold the HRTF the device last used, in case it's used again. */
  888. struct Hrtf *old_hrtf = device->HrtfHandle;
  889. const char *mode;
  890. bool headphones;
  891. int bs2blevel;
  892. size_t i;
  893. al_free(device->Hrtf);
  894. device->Hrtf = NULL;
  895. device->HrtfHandle = NULL;
  896. alstr_clear(&device->HrtfName);
  897. device->Render_Mode = NormalRender;
  898. memset(&device->Dry.Ambi, 0, sizeof(device->Dry.Ambi));
  899. device->Dry.CoeffCount = 0;
  900. device->Dry.NumChannels = 0;
  901. for(i = 0;i < MAX_AMBI_ORDER+1;i++)
  902. device->Dry.NumChannelsPerOrder[i] = 0;
  903. device->AvgSpeakerDist = 0.0f;
  904. memset(device->ChannelDelay, 0, sizeof(device->ChannelDelay));
  905. for(i = 0;i < MAX_OUTPUT_CHANNELS;i++)
  906. {
  907. device->ChannelDelay[i].Gain = 1.0f;
  908. device->ChannelDelay[i].Length = 0;
  909. }
  910. if(device->FmtChans != DevFmtStereo)
  911. {
  912. ALsizei speakermap[MAX_OUTPUT_CHANNELS];
  913. const char *devname, *layout = NULL;
  914. AmbDecConf conf, *pconf = NULL;
  915. if(old_hrtf)
  916. Hrtf_DecRef(old_hrtf);
  917. old_hrtf = NULL;
  918. if(hrtf_appreq == Hrtf_Enable)
  919. device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
  920. ambdec_init(&conf);
  921. devname = alstr_get_cstr(device->DeviceName);
  922. switch(device->FmtChans)
  923. {
  924. case DevFmtQuad: layout = "quad"; break;
  925. case DevFmtX51: /* fall-through */
  926. case DevFmtX51Rear: layout = "surround51"; break;
  927. case DevFmtX61: layout = "surround61"; break;
  928. case DevFmtX71: layout = "surround71"; break;
  929. /* Mono, Stereo, and Ambisonics output don't use custom decoders. */
  930. case DevFmtMono:
  931. case DevFmtStereo:
  932. case DevFmtAmbi3D:
  933. break;
  934. }
  935. if(layout)
  936. {
  937. const char *fname;
  938. if(ConfigValueStr(devname, "decoder", layout, &fname))
  939. {
  940. if(!ambdec_load(&conf, fname))
  941. ERR("Failed to load layout file %s\n", fname);
  942. else
  943. {
  944. if(conf.ChanMask > 0xffff)
  945. ERR("Unsupported channel mask 0x%04x (max 0xffff)\n", conf.ChanMask);
  946. else
  947. {
  948. if(MakeSpeakerMap(device, &conf, speakermap))
  949. pconf = &conf;
  950. }
  951. }
  952. }
  953. }
  954. if(pconf && GetConfigValueBool(devname, "decoder", "hq-mode", 0))
  955. {
  956. ambiup_free(device->AmbiUp);
  957. device->AmbiUp = NULL;
  958. if(!device->AmbiDecoder)
  959. device->AmbiDecoder = bformatdec_alloc();
  960. }
  961. else
  962. {
  963. bformatdec_free(device->AmbiDecoder);
  964. device->AmbiDecoder = NULL;
  965. if(device->FmtChans == DevFmtAmbi3D && device->AmbiOrder > 1)
  966. {
  967. if(!device->AmbiUp)
  968. device->AmbiUp = ambiup_alloc();
  969. }
  970. else
  971. {
  972. ambiup_free(device->AmbiUp);
  973. device->AmbiUp = NULL;
  974. }
  975. }
  976. if(!pconf)
  977. InitPanning(device);
  978. else if(device->AmbiDecoder)
  979. InitHQPanning(device, pconf, speakermap);
  980. else
  981. InitCustomPanning(device, pconf, speakermap);
  982. ambdec_deinit(&conf);
  983. return;
  984. }
  985. bformatdec_free(device->AmbiDecoder);
  986. device->AmbiDecoder = NULL;
  987. headphones = device->IsHeadphones;
  988. if(device->Type != Loopback)
  989. {
  990. const char *mode;
  991. if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-mode", &mode))
  992. {
  993. if(strcasecmp(mode, "headphones") == 0)
  994. headphones = true;
  995. else if(strcasecmp(mode, "speakers") == 0)
  996. headphones = false;
  997. else if(strcasecmp(mode, "auto") != 0)
  998. ERR("Unexpected stereo-mode: %s\n", mode);
  999. }
  1000. }
  1001. if(hrtf_userreq == Hrtf_Default)
  1002. {
  1003. bool usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
  1004. (hrtf_appreq == Hrtf_Enable);
  1005. if(!usehrtf) goto no_hrtf;
  1006. device->HrtfStatus = ALC_HRTF_ENABLED_SOFT;
  1007. if(headphones && hrtf_appreq != Hrtf_Disable)
  1008. device->HrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
  1009. }
  1010. else
  1011. {
  1012. if(hrtf_userreq != Hrtf_Enable)
  1013. {
  1014. if(hrtf_appreq == Hrtf_Enable)
  1015. device->HrtfStatus = ALC_HRTF_DENIED_SOFT;
  1016. goto no_hrtf;
  1017. }
  1018. device->HrtfStatus = ALC_HRTF_REQUIRED_SOFT;
  1019. }
  1020. if(VECTOR_SIZE(device->HrtfList) == 0)
  1021. {
  1022. VECTOR_DEINIT(device->HrtfList);
  1023. device->HrtfList = EnumerateHrtf(device->DeviceName);
  1024. }
  1025. if(hrtf_id >= 0 && (size_t)hrtf_id < VECTOR_SIZE(device->HrtfList))
  1026. {
  1027. const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, hrtf_id);
  1028. struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
  1029. if(hrtf && hrtf->sampleRate == device->Frequency)
  1030. {
  1031. device->HrtfHandle = hrtf;
  1032. alstr_copy(&device->HrtfName, entry->name);
  1033. }
  1034. else if(hrtf)
  1035. Hrtf_DecRef(hrtf);
  1036. }
  1037. for(i = 0;!device->HrtfHandle && i < VECTOR_SIZE(device->HrtfList);i++)
  1038. {
  1039. const EnumeratedHrtf *entry = &VECTOR_ELEM(device->HrtfList, i);
  1040. struct Hrtf *hrtf = GetLoadedHrtf(entry->hrtf);
  1041. if(hrtf && hrtf->sampleRate == device->Frequency)
  1042. {
  1043. device->HrtfHandle = hrtf;
  1044. alstr_copy(&device->HrtfName, entry->name);
  1045. }
  1046. else if(hrtf)
  1047. Hrtf_DecRef(hrtf);
  1048. }
  1049. if(device->HrtfHandle)
  1050. {
  1051. if(old_hrtf)
  1052. Hrtf_DecRef(old_hrtf);
  1053. old_hrtf = NULL;
  1054. device->Render_Mode = HrtfRender;
  1055. if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "hrtf-mode", &mode))
  1056. {
  1057. if(strcasecmp(mode, "full") == 0)
  1058. device->Render_Mode = HrtfRender;
  1059. else if(strcasecmp(mode, "basic") == 0)
  1060. device->Render_Mode = NormalRender;
  1061. else
  1062. ERR("Unexpected hrtf-mode: %s\n", mode);
  1063. }
  1064. if(device->Render_Mode == HrtfRender)
  1065. {
  1066. /* Don't bother with HOA when using full HRTF rendering. Nothing
  1067. * needs it, and it eases the CPU/memory load.
  1068. */
  1069. ambiup_free(device->AmbiUp);
  1070. device->AmbiUp = NULL;
  1071. }
  1072. else
  1073. {
  1074. if(!device->AmbiUp)
  1075. device->AmbiUp = ambiup_alloc();
  1076. }
  1077. TRACE("%s HRTF rendering enabled, using \"%s\"\n",
  1078. ((device->Render_Mode == HrtfRender) ? "Full" : "Basic"),
  1079. alstr_get_cstr(device->HrtfName)
  1080. );
  1081. InitHrtfPanning(device);
  1082. return;
  1083. }
  1084. device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
  1085. no_hrtf:
  1086. if(old_hrtf)
  1087. Hrtf_DecRef(old_hrtf);
  1088. old_hrtf = NULL;
  1089. TRACE("HRTF disabled\n");
  1090. device->Render_Mode = StereoPair;
  1091. ambiup_free(device->AmbiUp);
  1092. device->AmbiUp = NULL;
  1093. bs2blevel = ((headphones && hrtf_appreq != Hrtf_Disable) ||
  1094. (hrtf_appreq == Hrtf_Enable)) ? 5 : 0;
  1095. if(device->Type != Loopback)
  1096. ConfigValueInt(alstr_get_cstr(device->DeviceName), NULL, "cf_level", &bs2blevel);
  1097. if(bs2blevel > 0 && bs2blevel <= 6)
  1098. {
  1099. device->Bs2b = al_calloc(16, sizeof(*device->Bs2b));
  1100. bs2b_set_params(device->Bs2b, bs2blevel, device->Frequency);
  1101. TRACE("BS2B enabled\n");
  1102. InitPanning(device);
  1103. return;
  1104. }
  1105. TRACE("BS2B disabled\n");
  1106. if(ConfigValueStr(alstr_get_cstr(device->DeviceName), NULL, "stereo-encoding", &mode))
  1107. {
  1108. if(strcasecmp(mode, "uhj") == 0)
  1109. device->Render_Mode = NormalRender;
  1110. else if(strcasecmp(mode, "panpot") != 0)
  1111. ERR("Unexpected stereo-encoding: %s\n", mode);
  1112. }
  1113. if(device->Render_Mode == NormalRender)
  1114. {
  1115. device->Uhj_Encoder = al_calloc(16, sizeof(Uhj2Encoder));
  1116. TRACE("UHJ enabled\n");
  1117. InitUhjPanning(device);
  1118. return;
  1119. }
  1120. TRACE("UHJ disabled\n");
  1121. InitPanning(device);
  1122. }
  1123. void aluInitEffectPanning(ALeffectslot *slot)
  1124. {
  1125. ALsizei i;
  1126. memset(slot->ChanMap, 0, sizeof(slot->ChanMap));
  1127. slot->NumChannels = 0;
  1128. for(i = 0;i < MAX_EFFECT_CHANNELS;i++)
  1129. {
  1130. slot->ChanMap[i].Scale = 1.0f;
  1131. slot->ChanMap[i].Index = i;
  1132. }
  1133. slot->NumChannels = i;
  1134. }