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.
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.
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
35 void ComputeAngleGains(const ALCdevice
*device
, ALfloat angle
, ALfloat elevation
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
38 sinf(angle
) * cosf(elevation
),
40 -cosf(angle
) * cosf(elevation
)
42 ComputeDirectionalGains(device
, dir
, ingain
, gains
);
45 void ComputeDirectionalGains(const ALCdevice
*device
, const ALfloat dir
[3], ALfloat ingain
, ALfloat gains
[MaxChannels
])
47 ALfloat coeffs
[MAX_AMBI_COEFFS
];
49 /* Convert from OpenAL coords to Ambisonics. */
54 coeffs
[0] = 0.7071f
; /* sqrt(1.0 / 2.0) */
55 coeffs
[1] = x
; /* X */
56 coeffs
[2] = y
; /* Y */
57 coeffs
[3] = z
; /* Z */
58 coeffs
[4] = 0.5f
* (3.0f
*z
*z
- 1.0f
); /* 0.5 * (3*Z*Z - 1) */
59 coeffs
[5] = 2.0f
* z
* x
; /* 2*Z*X */
60 coeffs
[6] = 2.0f
* y
* z
; /* 2*Y*Z */
61 coeffs
[7] = x
*x
- y
*y
; /* X*X - Y*Y */
62 coeffs
[8] = 2.0f
* x
* y
; /* 2*X*Y */
63 coeffs
[9] = 0.5f
* z
* (5.0f
*z
*z
- 3.0f
); /* 0.5 * Z * (5*Z*Z - 3) */
64 coeffs
[10] = 0.7262f
* x
* (5.0f
*z
*z
- 1.0f
); /* sqrt(135.0 / 256.0) * X * (5*Z*Z - 1) */
65 coeffs
[11] = 0.7262f
* y
* (5.0f
*z
*z
- 1.0f
); /* sqrt(135.0 / 256.0) * Y * (5*Z*Z - 1) */
66 coeffs
[12] = 2.5981f
* z
* (x
*x
- y
*y
); /* sqrt(27.0 / 4.0) * Z * (X*X - Y*Y) */
67 coeffs
[13] = 5.1962f
* x
* y
* z
; /* sqrt(27) * X * Y * Z */
68 coeffs
[14] = x
* (x
*x
- 3.0f
*y
*y
); /* X * (X*X - 3*Y*Y) */
69 coeffs
[15] = y
* (3.0f
*x
*x
- y
*y
); /* Y * (3*X*X - Y*Y) */
71 for(i
= 0;i
< MaxChannels
;i
++)
73 for(i
= 0;i
< device
->NumSpeakers
;i
++)
75 for(j
= 0;j
< MAX_AMBI_COEFFS
;j
++)
76 gains
[i
] += device
->Speaker
[i
].HOACoeff
[j
]*coeffs
[j
];
77 gains
[i
] = maxf(gains
[i
], 0.0f
) * ingain
;
81 void ComputeAmbientGains(const ALCdevice
*device
, ALfloat ingain
, ALfloat gains
[MaxChannels
])
85 for(i
= 0;i
< MaxChannels
;i
++)
87 for(i
= 0;i
< device
->NumSpeakers
;i
++)
88 gains
[i
] = device
->Speaker
[i
].HOACoeff
[0] * ingain
;
91 void ComputeBFormatGains(const ALCdevice
*device
, const ALfloat mtx
[4], ALfloat ingain
, ALfloat gains
[MaxChannels
])
95 for(i
= 0;i
< MaxChannels
;i
++)
97 for(i
= 0;i
< device
->NumSpeakers
;i
++)
100 gains
[i
] += device
->Speaker
[i
].FOACoeff
[j
] * mtx
[j
];
106 typedef struct ChannelMap
{
107 enum Channel ChanName
;
108 ChannelConfig Config
;
111 ALvoid
aluInitPanning(ALCdevice
*device
)
113 static const ChannelMap MonoCfg
[1] = {
114 { FrontCenter
, { DEG2RAD(0.0f
), DEG2RAD(0.0f
), { 1.4142f
}, { 1.4142f
} } },
116 { FrontLeft
, { DEG2RAD(-90.0f
), DEG2RAD(0.0f
), { 0.7071f
, 0.0f
, 0.5f
, 0.0f
}, { 0.7071f
, 0.0f
, 0.5f
, 0.0f
} } },
117 { FrontRight
, { DEG2RAD( 90.0f
), DEG2RAD(0.0f
), { 0.7071f
, 0.0f
, -0.5f
, 0.0f
}, { 0.7071f
, 0.0f
, -0.5f
, 0.0f
} } },
119 { FrontLeft
, { DEG2RAD( -45.0f
), DEG2RAD(0.0f
), { 0.353558f
, 0.306181f
, 0.306192f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, 0.117183f
}, { 0.353553f
, 0.250000f
, 0.250000f
, 0.0f
} } },
120 { FrontRight
, { DEG2RAD( 45.0f
), DEG2RAD(0.0f
), { 0.353543f
, 0.306181f
, -0.306192f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, -0.117193f
}, { 0.353553f
, 0.250000f
, -0.250000f
, 0.0f
} } },
121 { BackLeft
, { DEG2RAD(-135.0f
), DEG2RAD(0.0f
), { 0.353543f
, -0.306192f
, 0.306181f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, -0.117193f
}, { 0.353553f
, -0.250000f
, 0.250000f
, 0.0f
} } },
122 { BackRight
, { DEG2RAD( 135.0f
), DEG2RAD(0.0f
), { 0.353558f
, -0.306192f
, -0.306181f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, 0.117183f
}, { 0.353553f
, -0.250000f
, -0.250000f
, 0.0f
} } },
124 { FrontLeft
, { DEG2RAD( -30.0f
), DEG2RAD(0.0f
), { 0.208954f
, 0.212846f
, 0.238350f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.017738f
, 0.204014f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.051023f
, 0.047490f
}, { 0.208954f
, 0.162905f
, 0.182425f
, 0.0f
} } },
125 { FrontRight
, { DEG2RAD( 30.0f
), DEG2RAD(0.0f
), { 0.208954f
, 0.212846f
, -0.238350f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.017738f
, -0.204014f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.051023f
, -0.047490f
}, { 0.208954f
, 0.162905f
, -0.182425f
, 0.0f
} } },
126 { FrontCenter
, { DEG2RAD( 0.0f
), DEG2RAD(0.0f
), { 0.109403f
, 0.179490f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.142031f
, -0.000002f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.072024f
, -0.000001f
}, { 0.109403f
, 0.137375f
, 0.000000f
, 0.0f
} } },
127 { LFE
, { 0.0f
, 0.0f
, { 0.0f
}, { 0.0f
} } },
128 { SideLeft
, { DEG2RAD(-110.0f
), DEG2RAD(0.0f
), { 0.470936f
, -0.369626f
, 0.349386f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.031375f
, -0.058144f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.007119f
, -0.043968f
}, { 0.470934f
, -0.282903f
, 0.267406f
, 0.0f
} } },
129 { SideRight
, { DEG2RAD( 110.0f
), DEG2RAD(0.0f
), { 0.470936f
, -0.369626f
, -0.349386f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.031375f
, 0.058144f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.007119f
, 0.043968f
}, { 0.470934f
, -0.282903f
, -0.267406f
, 0.0f
} } },
131 { FrontLeft
, { DEG2RAD( -30.0f
), DEG2RAD(0.0f
), { 0.208954f
, 0.212846f
, 0.238350f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.017738f
, 0.204014f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.051023f
, 0.047490f
}, { 0.208954f
, 0.162905f
, 0.182425f
, 0.0f
} } },
132 { FrontRight
, { DEG2RAD( 30.0f
), DEG2RAD(0.0f
), { 0.208954f
, 0.212846f
, -0.238350f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.017738f
, -0.204014f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.051023f
, -0.047490f
}, { 0.208954f
, 0.162905f
, -0.182425f
, 0.0f
} } },
133 { FrontCenter
, { DEG2RAD( 0.0f
), DEG2RAD(0.0f
), { 0.109403f
, 0.179490f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.142031f
, -0.000002f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.072024f
, -0.000001f
}, { 0.109403f
, 0.137375f
, 0.000000f
, 0.0f
} } },
134 { LFE
, { 0.0f
, 0.0f
, { 0.0f
}, { 0.0f
} } },
135 { BackLeft
, { DEG2RAD(-110.0f
), DEG2RAD(0.0f
), { 0.470936f
, -0.369626f
, 0.349386f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.031375f
, -0.058144f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.007119f
, -0.043968f
}, { 0.470934f
, -0.282903f
, 0.267406f
, 0.0f
} } },
136 { BackRight
, { DEG2RAD( 110.0f
), DEG2RAD(0.0f
), { 0.470936f
, -0.369626f
, -0.349386f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.031375f
, 0.058144f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.007119f
, 0.043968f
}, { 0.470934f
, -0.282903f
, -0.267406f
, 0.0f
} } },
138 { FrontLeft
, { DEG2RAD(-30.0f
), DEG2RAD(0.0f
), { 0.167065f
, 0.200583f
, 0.172695f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.029855f
, 0.186407f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.039241f
, 0.068910f
}, { 0.167065f
, 0.153519f
, 0.132175f
, 0.0f
} } },
139 { FrontRight
, { DEG2RAD( 30.0f
), DEG2RAD(0.0f
), { 0.167065f
, 0.200583f
, -0.172695f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.029855f
, -0.186407f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.039241f
, -0.068910f
}, { 0.167065f
, 0.153519f
, -0.132175f
, 0.0f
} } },
140 { FrontCenter
, { DEG2RAD( 0.0f
), DEG2RAD(0.0f
), { 0.109403f
, 0.179490f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.142031f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.072024f
, -0.000001f
}, { 0.109403f
, 0.137375f
, 0.000000f
, 0.0f
} } },
141 { LFE
, { 0.0f
, 0.0f
, { 0.0f
}, { 0.0f
} } },
142 { BackCenter
, { DEG2RAD(180.0f
), DEG2RAD(0.0f
), { 0.353556f
, -0.461940f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.165723f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, 0.000005f
}, { 0.353556f
, -0.353554f
, 0.000000f
, 0.0f
} } },
143 { SideLeft
, { DEG2RAD(-90.0f
), DEG2RAD(0.0f
), { 0.289151f
, -0.081301f
, 0.401292f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.188208f
, -0.071420f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.010099f
, -0.032897f
}, { 0.289151f
, -0.062225f
, 0.307136f
, 0.0f
} } },
144 { SideRight
, { DEG2RAD( 90.0f
), DEG2RAD(0.0f
), { 0.289151f
, -0.081301f
, -0.401292f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.188208f
, 0.071420f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.010099f
, 0.032897f
}, { 0.289151f
, -0.062225f
, -0.307136f
, 0.0f
} } },
146 { FrontLeft
, { DEG2RAD( -30.0f
), DEG2RAD(0.0f
), { 0.167065f
, 0.200583f
, 0.172695f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.029855f
, 0.186407f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.039241f
, 0.068910f
}, { 0.167065f
, 0.153519f
, 0.132175f
, 0.0f
} } },
147 { FrontRight
, { DEG2RAD( 30.0f
), DEG2RAD(0.0f
), { 0.167065f
, 0.200583f
, -0.172695f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.029855f
, -0.186407f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.039241f
, -0.068910f
}, { 0.167065f
, 0.153519f
, -0.132175f
, 0.0f
} } },
148 { FrontCenter
, { DEG2RAD( 0.0f
), DEG2RAD(0.0f
), { 0.109403f
, 0.179490f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.142031f
, 0.000000f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.072024f
, 0.000000f
}, { 0.109403f
, 0.137375f
, 0.000000f
, 0.0f
} } },
149 { LFE
, { 0.0f
, 0.0f
, { 0.0f
}, { 0.0f
} } },
150 { BackLeft
, { DEG2RAD(-150.0f
), DEG2RAD(0.0f
), { 0.224752f
, -0.295009f
, 0.170325f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.105349f
, -0.182473f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, 0.065799f
}, { 0.224752f
, -0.225790f
, 0.130361f
, 0.0f
} } },
151 { BackRight
, { DEG2RAD( 150.0f
), DEG2RAD(0.0f
), { 0.224752f
, -0.295009f
, -0.170325f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.105349f
, 0.182473f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, -0.065799f
}, { 0.224752f
, -0.225790f
, -0.130361f
, 0.0f
} } },
152 { SideLeft
, { DEG2RAD( -90.0f
), DEG2RAD(0.0f
), { 0.224739f
, 0.000002f
, 0.340644f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.210697f
, 0.000002f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, -0.065795f
}, { 0.224739f
, 0.000000f
, 0.260717f
, 0.0f
} } },
153 { SideRight
, { DEG2RAD( 90.0f
), DEG2RAD(0.0f
), { 0.224739f
, 0.000002f
, -0.340644f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, -0.210697f
, -0.000002f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.0f
, 0.000000f
, 0.065795f
}, { 0.224739f
, 0.000000f
, -0.260717f
, 0.0f
} } },
155 const ChannelMap
*chanmap
= NULL
;
159 memset(device
->Speaker
, 0, sizeof(device
->Speaker
));
160 device
->NumSpeakers
= 0;
162 switch(device
->FmtChans
)
165 count
= COUNTOF(MonoCfg
);
170 count
= COUNTOF(StereoCfg
);
175 count
= COUNTOF(QuadCfg
);
180 count
= COUNTOF(X51SideCfg
);
181 chanmap
= X51SideCfg
;
185 count
= COUNTOF(X51RearCfg
);
186 chanmap
= X51RearCfg
;
190 count
= COUNTOF(X61Cfg
);
195 count
= COUNTOF(X71Cfg
);
199 for(i
= 0;i
< MaxChannels
&& device
->ChannelName
[i
] != InvalidChannel
;i
++)
201 for(j
= 0;j
< count
;j
++)
203 if(device
->ChannelName
[i
] == chanmap
[j
].ChanName
)
205 device
->Speaker
[i
] = chanmap
[j
].Config
;
210 ERR("Failed to match channel %u (label %d) in config\n", i
, device
->ChannelName
[i
]);
212 device
->NumSpeakers
= i
;