2010-08-03 00:21:36 -07:00
|
|
|
/**
|
|
|
|
* OpenAL cross platform audio library
|
|
|
|
* Copyright (C) 1999-2010 by authors.
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2014-08-18 14:11:03 +02:00
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-08-03 00:21:36 -07:00
|
|
|
* Or go to http://www.gnu.org/copyleft/lgpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
#include <cmath>
|
2018-12-09 17:24:00 -08:00
|
|
|
#include <numeric>
|
2018-12-08 14:22:20 -08:00
|
|
|
#include <algorithm>
|
2018-12-10 02:13:57 -08:00
|
|
|
#include <functional>
|
2018-12-08 14:22:20 -08:00
|
|
|
|
2010-08-03 00:21:36 -07:00
|
|
|
#include "alMain.h"
|
2016-01-28 00:02:46 -08:00
|
|
|
#include "alAuxEffectSlot.h"
|
2010-08-03 00:21:36 -07:00
|
|
|
#include "alu.h"
|
2018-01-11 07:56:54 -08:00
|
|
|
#include "alconfig.h"
|
2016-03-15 05:08:05 -07:00
|
|
|
#include "ambdec.h"
|
|
|
|
#include "bformatdec.h"
|
2018-04-21 23:23:46 -07:00
|
|
|
#include "filters/splitter.h"
|
2016-04-14 15:25:12 -07:00
|
|
|
#include "uhjfilter.h"
|
|
|
|
#include "bs2b.h"
|
2010-08-03 00:21:36 -07:00
|
|
|
|
|
|
|
|
2018-11-12 19:02:38 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr ALsizei FuMa2ACN[MAX_AMBI_COEFFS] = {
|
2015-08-28 10:58:30 -07:00
|
|
|
0, /* W */
|
|
|
|
3, /* X */
|
|
|
|
1, /* Y */
|
|
|
|
2, /* Z */
|
|
|
|
6, /* R */
|
|
|
|
7, /* S */
|
|
|
|
5, /* T */
|
|
|
|
8, /* U */
|
|
|
|
4, /* V */
|
|
|
|
12, /* K */
|
|
|
|
13, /* L */
|
|
|
|
11, /* M */
|
|
|
|
14, /* N */
|
|
|
|
10, /* O */
|
|
|
|
15, /* P */
|
|
|
|
9, /* Q */
|
|
|
|
};
|
2018-11-12 19:02:38 -08:00
|
|
|
constexpr ALsizei ACN2ACN[MAX_AMBI_COEFFS] = {
|
2016-07-31 07:46:38 -07:00
|
|
|
0, 1, 2, 3, 4, 5, 6, 7,
|
|
|
|
8, 9, 10, 11, 12, 13, 14, 15
|
|
|
|
};
|
2015-08-28 10:58:30 -07:00
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
inline const char *GetLabelFromChannel(enum Channel channel)
|
2014-11-15 00:19:56 -08:00
|
|
|
{
|
|
|
|
switch(channel)
|
|
|
|
{
|
|
|
|
case FrontLeft: return "front-left";
|
|
|
|
case FrontRight: return "front-right";
|
|
|
|
case FrontCenter: return "front-center";
|
|
|
|
case LFE: return "lfe";
|
|
|
|
case BackLeft: return "back-left";
|
|
|
|
case BackRight: return "back-right";
|
|
|
|
case BackCenter: return "back-center";
|
|
|
|
case SideLeft: return "side-left";
|
|
|
|
case SideRight: return "side-right";
|
2014-11-22 04:20:17 -08:00
|
|
|
|
2016-02-20 00:53:01 -08:00
|
|
|
case UpperFrontLeft: return "upper-front-left";
|
|
|
|
case UpperFrontRight: return "upper-front-right";
|
|
|
|
case UpperBackLeft: return "upper-back-left";
|
|
|
|
case UpperBackRight: return "upper-back-right";
|
|
|
|
case LowerFrontLeft: return "lower-front-left";
|
|
|
|
case LowerFrontRight: return "lower-front-right";
|
|
|
|
case LowerBackLeft: return "lower-back-left";
|
|
|
|
case LowerBackRight: return "lower-back-right";
|
|
|
|
|
2016-03-16 06:49:35 -07:00
|
|
|
case Aux0: return "aux-0";
|
|
|
|
case Aux1: return "aux-1";
|
|
|
|
case Aux2: return "aux-2";
|
|
|
|
case Aux3: return "aux-3";
|
2016-03-23 10:39:14 -07:00
|
|
|
case Aux4: return "aux-4";
|
|
|
|
case Aux5: return "aux-5";
|
|
|
|
case Aux6: return "aux-6";
|
|
|
|
case Aux7: return "aux-7";
|
|
|
|
case Aux8: return "aux-8";
|
2016-04-19 18:58:19 -07:00
|
|
|
case Aux9: return "aux-9";
|
|
|
|
case Aux10: return "aux-10";
|
|
|
|
case Aux11: return "aux-11";
|
|
|
|
case Aux12: return "aux-12";
|
|
|
|
case Aux13: return "aux-13";
|
|
|
|
case Aux14: return "aux-14";
|
|
|
|
case Aux15: return "aux-15";
|
2014-11-25 22:20:00 -08:00
|
|
|
|
2014-11-15 00:19:56 -08:00
|
|
|
case InvalidChannel: break;
|
|
|
|
}
|
|
|
|
return "(unknown)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-22 22:53:22 -08:00
|
|
|
struct ChannelMap {
|
|
|
|
Channel ChanName;
|
2014-11-05 03:46:00 -08:00
|
|
|
ChannelConfig Config;
|
2018-11-22 22:53:22 -08:00
|
|
|
};
|
2014-11-05 03:46:00 -08:00
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void SetChannelMap(const Channel (&devchans)[MAX_OUTPUT_CHANNELS], ChannelConfig *ambicoeffs,
|
|
|
|
const ChannelMap *chanmap, ALsizei count, ALsizei *outcount)
|
2014-11-12 19:26:53 -08:00
|
|
|
{
|
2018-12-09 18:16:00 -08:00
|
|
|
auto copy_coeffs = [&devchans,ambicoeffs](ALsizei maxchans, const ChannelMap &channel) -> ALsizei
|
|
|
|
{
|
|
|
|
const ALint idx{GetChannelIndex(devchans, channel.ChanName)};
|
|
|
|
if(idx < 0)
|
2014-11-12 19:26:53 -08:00
|
|
|
{
|
2018-12-09 18:16:00 -08:00
|
|
|
ERR("Failed to find %s channel in device\n", GetLabelFromChannel(channel.ChanName));
|
|
|
|
return maxchans;
|
2018-11-22 22:53:22 -08:00
|
|
|
}
|
2018-12-09 18:16:00 -08:00
|
|
|
|
|
|
|
std::copy(std::begin(channel.Config), std::end(channel.Config), ambicoeffs[idx]);
|
|
|
|
return maxi(maxchans, idx+1);
|
|
|
|
};
|
|
|
|
ALsizei maxcount{std::accumulate(chanmap, chanmap+count, ALsizei{0}, copy_coeffs)};
|
|
|
|
*outcount = mini(maxcount, MAX_OUTPUT_CHANNELS);
|
2014-11-12 19:26:53 -08:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:49:57 -08:00
|
|
|
bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
2018-12-10 14:49:57 -08:00
|
|
|
auto map_spkr = [device](const AmbDecConf::SpeakerConf &speaker) -> ALsizei
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
|
|
|
/* NOTE: AmbDec does not define any standard speaker names, however
|
|
|
|
* for this to work we have to by able to find the output channel
|
|
|
|
* the speaker definition corresponds to. Therefore, OpenAL Soft
|
|
|
|
* requires these channel labels to be recognized:
|
|
|
|
*
|
|
|
|
* LF = Front left
|
|
|
|
* RF = Front right
|
|
|
|
* LS = Side left
|
|
|
|
* RS = Side right
|
|
|
|
* LB = Back left
|
|
|
|
* RB = Back right
|
|
|
|
* CE = Front center
|
|
|
|
* CB = Back center
|
|
|
|
*
|
|
|
|
* Additionally, surround51 will acknowledge back speakers for side
|
|
|
|
* channels, and surround51rear will acknowledge side speakers for
|
|
|
|
* back channels, to avoid issues with an ambdec expecting 5.1 to
|
|
|
|
* use the side channels when the device is configured for back,
|
|
|
|
* and vice-versa.
|
|
|
|
*/
|
2018-12-10 14:49:57 -08:00
|
|
|
Channel ch{};
|
|
|
|
if(speaker.Name == "LF")
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = FrontLeft;
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "RF")
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = FrontRight;
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "CE")
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = FrontCenter;
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "LS")
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
|
|
|
if(device->FmtChans == DevFmtX51Rear)
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = BackLeft;
|
2016-03-15 05:08:05 -07:00
|
|
|
else
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = SideLeft;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "RS")
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
|
|
|
if(device->FmtChans == DevFmtX51Rear)
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = BackRight;
|
2016-03-15 05:08:05 -07:00
|
|
|
else
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = SideRight;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "LB")
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
|
|
|
if(device->FmtChans == DevFmtX51)
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = SideLeft;
|
2016-03-15 05:08:05 -07:00
|
|
|
else
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = BackLeft;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "RB")
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
|
|
|
if(device->FmtChans == DevFmtX51)
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = SideRight;
|
2016-03-15 05:08:05 -07:00
|
|
|
else
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = BackRight;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2018-12-10 14:49:57 -08:00
|
|
|
else if(speaker.Name == "CB")
|
2018-02-21 19:53:18 -08:00
|
|
|
ch = BackCenter;
|
2016-03-15 05:08:05 -07:00
|
|
|
else
|
|
|
|
{
|
2018-12-10 14:49:57 -08:00
|
|
|
const char *name{speaker.Name.c_str()};
|
2016-05-12 23:41:23 -07:00
|
|
|
unsigned int n;
|
2018-02-21 19:53:18 -08:00
|
|
|
char c;
|
2016-05-12 23:41:23 -07:00
|
|
|
|
2018-02-21 19:53:18 -08:00
|
|
|
if(sscanf(name, "AUX%u%c", &n, &c) == 1 && n < 16)
|
2018-12-10 14:49:57 -08:00
|
|
|
ch = static_cast<Channel>(Aux0+n);
|
2016-05-12 23:41:23 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("AmbDec speaker label \"%s\" not recognized\n", name);
|
2018-12-10 14:49:57 -08:00
|
|
|
return -1;
|
2016-05-12 23:41:23 -07:00
|
|
|
}
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2018-12-10 14:49:57 -08:00
|
|
|
const int chidx{GetChannelIdxByName(&device->RealOut, ch)};
|
2018-02-21 19:53:18 -08:00
|
|
|
if(chidx == -1)
|
2018-12-10 14:49:57 -08:00
|
|
|
ERR("Failed to lookup AmbDec speaker label %s\n", speaker.Name.c_str());
|
|
|
|
return chidx;
|
|
|
|
};
|
|
|
|
auto speakers_end = std::begin(conf->Speakers) + conf->NumSpeakers;
|
|
|
|
std::transform(std::begin(conf->Speakers), speakers_end, std::begin(speakermap), map_spkr);
|
|
|
|
/* Return success if no invalid entries are found. */
|
|
|
|
auto speakermap_end = std::begin(speakermap) + conf->NumSpeakers;
|
|
|
|
return std::find(std::begin(speakermap), speakermap_end, -1) == speakermap_end;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
constexpr ChannelMap MonoCfg[1] = {
|
2017-01-21 11:05:05 -08:00
|
|
|
{ FrontCenter, { 1.0f } },
|
2016-04-14 10:44:57 -07:00
|
|
|
}, StereoCfg[2] = {
|
2018-04-19 21:55:20 -07:00
|
|
|
{ FrontLeft, { 5.00000000e-1f, 2.88675135e-1f, 0.0f, 5.52305643e-2f } },
|
|
|
|
{ FrontRight, { 5.00000000e-1f, -2.88675135e-1f, 0.0f, 5.52305643e-2f } },
|
2016-04-14 10:44:57 -07:00
|
|
|
}, QuadCfg[4] = {
|
2017-01-21 11:05:05 -08:00
|
|
|
{ BackLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, -2.04124145e-1f } },
|
|
|
|
{ FrontLeft, { 3.53553391e-1f, 2.04124145e-1f, 0.0f, 2.04124145e-1f } },
|
|
|
|
{ FrontRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, 2.04124145e-1f } },
|
|
|
|
{ BackRight, { 3.53553391e-1f, -2.04124145e-1f, 0.0f, -2.04124145e-1f } },
|
2017-07-31 00:13:14 -07:00
|
|
|
}, X51SideCfg[4] = {
|
2017-07-30 23:39:06 -07:00
|
|
|
{ SideLeft, { 3.33000782e-1f, 1.89084803e-1f, 0.0f, -2.00042375e-1f, -2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
|
|
|
|
{ FrontLeft, { 1.88542860e-1f, 1.27709292e-1f, 0.0f, 1.66295695e-1f, 7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
|
|
|
|
{ FrontRight, { 1.88542860e-1f, -1.27709292e-1f, 0.0f, 1.66295695e-1f, -7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
|
|
|
|
{ SideRight, { 3.33000782e-1f, -1.89084803e-1f, 0.0f, -2.00042375e-1f, 2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
|
2017-07-31 00:13:14 -07:00
|
|
|
}, X51RearCfg[4] = {
|
2017-07-30 23:39:06 -07:00
|
|
|
{ BackLeft, { 3.33000782e-1f, 1.89084803e-1f, 0.0f, -2.00042375e-1f, -2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
|
|
|
|
{ FrontLeft, { 1.88542860e-1f, 1.27709292e-1f, 0.0f, 1.66295695e-1f, 7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
|
|
|
|
{ FrontRight, { 1.88542860e-1f, -1.27709292e-1f, 0.0f, 1.66295695e-1f, -7.30571517e-2f, 0.0f, 0.0f, 0.0f, 2.10901184e-2f } },
|
|
|
|
{ BackRight, { 3.33000782e-1f, -1.89084803e-1f, 0.0f, -2.00042375e-1f, 2.12307769e-2f, 0.0f, 0.0f, 0.0f, -1.14579885e-2f } },
|
2016-04-14 10:44:57 -07:00
|
|
|
}, X61Cfg[6] = {
|
2017-07-30 23:39:06 -07:00
|
|
|
{ SideLeft, { 2.04460341e-1f, 2.17177926e-1f, 0.0f, -4.39996780e-2f, -2.60790269e-2f, 0.0f, 0.0f, 0.0f, -6.87239792e-2f } },
|
|
|
|
{ FrontLeft, { 1.58923161e-1f, 9.21772680e-2f, 0.0f, 1.59658796e-1f, 6.66278083e-2f, 0.0f, 0.0f, 0.0f, 3.84686854e-2f } },
|
|
|
|
{ FrontRight, { 1.58923161e-1f, -9.21772680e-2f, 0.0f, 1.59658796e-1f, -6.66278083e-2f, 0.0f, 0.0f, 0.0f, 3.84686854e-2f } },
|
|
|
|
{ SideRight, { 2.04460341e-1f, -2.17177926e-1f, 0.0f, -4.39996780e-2f, 2.60790269e-2f, 0.0f, 0.0f, 0.0f, -6.87239792e-2f } },
|
2017-01-21 11:05:05 -08:00
|
|
|
{ BackCenter, { 2.50001688e-1f, 0.00000000e+0f, 0.0f, -2.50000094e-1f, 0.00000000e+0f, 0.0f, 0.0f, 0.0f, 6.05133395e-2f } },
|
|
|
|
}, X71Cfg[6] = {
|
|
|
|
{ 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 } },
|
|
|
|
{ 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 } },
|
|
|
|
{ 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 } },
|
|
|
|
{ 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 } },
|
|
|
|
{ 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 } },
|
|
|
|
{ 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 } },
|
2016-04-14 10:44:57 -07:00
|
|
|
};
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitNearFieldCtrl(ALCdevice *device, ALfloat ctrl_dist, ALsizei order, const ALsizei *RESTRICT chans_per_order)
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2018-12-10 14:49:57 -08:00
|
|
|
/* NFC is only used when AvgSpeakerDist is greater than 0, and can only be
|
|
|
|
* used when rendering to an ambisonic buffer.
|
|
|
|
*/
|
|
|
|
const char *devname{device->DeviceName.c_str()};
|
|
|
|
if(!GetConfigValueBool(devname, "decoder", "nfc", 1) || !(ctrl_dist > 0.0f))
|
|
|
|
return;
|
|
|
|
|
|
|
|
device->AvgSpeakerDist = minf(ctrl_dist, 10.0f);
|
|
|
|
TRACE("Using near-field reference distance: %.2f meters\n", device->AvgSpeakerDist);
|
|
|
|
|
|
|
|
auto iter = std::copy(chans_per_order, chans_per_order+order+1,
|
|
|
|
std::begin(device->NumChannelsPerOrder));
|
|
|
|
std::fill(iter, std::end(device->NumChannelsPerOrder), 0);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
|
2018-12-10 14:49:57 -08:00
|
|
|
void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2018-12-10 14:49:57 -08:00
|
|
|
using namespace std::placeholders;
|
2017-03-10 04:35:32 -08:00
|
|
|
|
2018-12-10 14:49:57 -08:00
|
|
|
auto speakers_end = std::begin(conf->Speakers) + conf->NumSpeakers;
|
|
|
|
const ALfloat maxdist{
|
|
|
|
std::accumulate(std::begin(conf->Speakers), speakers_end, float{0.0f},
|
|
|
|
std::bind(maxf, _1, std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2))
|
|
|
|
)
|
|
|
|
};
|
2017-03-10 04:35:32 -08:00
|
|
|
|
2018-12-10 14:49:57 -08:00
|
|
|
const char *devname{device->DeviceName.c_str()};
|
|
|
|
if(!GetConfigValueBool(devname, "decoder", "distance-comp", 1) || !(maxdist > 0.0f))
|
|
|
|
return;
|
2017-03-10 04:35:32 -08:00
|
|
|
|
2018-12-10 14:49:57 -08:00
|
|
|
auto srate = static_cast<ALfloat>(device->Frequency);
|
|
|
|
size_t total{0u};
|
|
|
|
for(ALsizei i{0};i < conf->NumSpeakers;i++)
|
|
|
|
{
|
|
|
|
const AmbDecConf::SpeakerConf &speaker = conf->Speakers[i];
|
|
|
|
const ALsizei chan{speakermap[i]};
|
|
|
|
|
|
|
|
/* Distance compensation only delays in steps of the sample rate. This
|
|
|
|
* is a bit less accurate since the delay time falls to the nearest
|
|
|
|
* sample time, but it's far simpler as it doesn't have to deal with
|
|
|
|
* phase offsets. This means at 48khz, for instance, the distance delay
|
|
|
|
* will be in steps of about 7 millimeters.
|
|
|
|
*/
|
|
|
|
const ALfloat delay{
|
|
|
|
std::floor((maxdist - speaker.Distance)/SPEEDOFSOUNDMETRESPERSEC*srate + 0.5f)
|
|
|
|
};
|
|
|
|
if(delay >= (ALfloat)MAX_DELAY_LENGTH)
|
|
|
|
ERR("Delay for speaker \"%s\" exceeds buffer length (%f >= %d)\n",
|
|
|
|
speaker.Name.c_str(), delay, MAX_DELAY_LENGTH);
|
|
|
|
|
|
|
|
device->ChannelDelay[chan].Length = static_cast<ALsizei>(clampf(
|
|
|
|
delay, 0.0f, (ALfloat)(MAX_DELAY_LENGTH-1)
|
|
|
|
));
|
|
|
|
device->ChannelDelay[chan].Gain = speaker.Distance / maxdist;
|
|
|
|
TRACE("Channel %u \"%s\" distance compensation: %d samples, %f gain\n", chan,
|
|
|
|
speaker.Name.c_str(), device->ChannelDelay[chan].Length,
|
|
|
|
device->ChannelDelay[chan].Gain
|
|
|
|
);
|
|
|
|
|
|
|
|
/* Round up to the next 4th sample, so each channel buffer starts
|
|
|
|
* 16-byte aligned.
|
|
|
|
*/
|
|
|
|
total += RoundUp(device->ChannelDelay[chan].Length, 4);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(total > 0)
|
|
|
|
{
|
2018-11-21 05:06:31 -08:00
|
|
|
device->ChannelDelay.resize(total);
|
|
|
|
device->ChannelDelay[0].Buffer = device->ChannelDelay.data();
|
2018-12-10 14:49:57 -08:00
|
|
|
auto set_bufptr = [](const DistanceComp::DistData &last, const DistanceComp::DistData &cur) -> DistanceComp::DistData
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2018-12-10 14:49:57 -08:00
|
|
|
DistanceComp::DistData ret{cur};
|
|
|
|
ret.Buffer = last.Buffer + RoundUp(last.Length, 4);
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
std::partial_sum(device->ChannelDelay.begin(), device->ChannelDelay.end(),
|
|
|
|
device->ChannelDelay.begin(), set_bufptr);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 22:32:10 -08:00
|
|
|
auto GetAmbiScales(AmbDecScale scaletype) noexcept -> const float(&)[MAX_AMBI_COEFFS]
|
|
|
|
{
|
|
|
|
if(scaletype == AmbDecScale::FuMa) return AmbiScale::FuMa2N3D;
|
|
|
|
if(scaletype == AmbDecScale::SN3D) return AmbiScale::SN3D2N3D;
|
|
|
|
return AmbiScale::N3D2N3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GetAmbiScales(AmbiNorm scaletype) noexcept -> const float(&)[MAX_AMBI_COEFFS]
|
|
|
|
{
|
|
|
|
if(scaletype == AmbiNorm::FuMa) return AmbiScale::FuMa2N3D;
|
|
|
|
if(scaletype == AmbiNorm::SN3D) return AmbiScale::SN3D2N3D;
|
|
|
|
return AmbiScale::N3D2N3D;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GetAmbiLayout(AmbiLayout layouttype) noexcept -> const ALsizei(&)[MAX_AMBI_COEFFS]
|
|
|
|
{
|
|
|
|
if(layouttype == AmbiLayout::FuMa) return FuMa2ACN;
|
|
|
|
return ACN2ACN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitPanning(ALCdevice *device)
|
2016-04-14 10:44:57 -07:00
|
|
|
{
|
|
|
|
const ChannelMap *chanmap = NULL;
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei coeffcount = 0;
|
|
|
|
ALsizei count = 0;
|
|
|
|
ALsizei i, j;
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2014-09-10 17:53:01 -07:00
|
|
|
switch(device->FmtChans)
|
2010-08-03 00:21:36 -07:00
|
|
|
{
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtMono:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(MonoCfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = MonoCfg;
|
2016-04-15 17:31:04 -07:00
|
|
|
coeffcount = 1;
|
2010-08-03 00:21:36 -07:00
|
|
|
break;
|
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtStereo:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(StereoCfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = StereoCfg;
|
2016-04-15 17:31:04 -07:00
|
|
|
coeffcount = 4;
|
2010-08-03 00:21:36 -07:00
|
|
|
break;
|
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtQuad:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(QuadCfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = QuadCfg;
|
2017-01-21 12:28:54 -08:00
|
|
|
coeffcount = 4;
|
2010-08-03 00:21:36 -07:00
|
|
|
break;
|
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtX51:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(X51SideCfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = X51SideCfg;
|
2016-04-15 17:31:04 -07:00
|
|
|
coeffcount = 9;
|
2011-05-28 19:35:32 -07:00
|
|
|
break;
|
|
|
|
|
2014-11-07 00:54:16 -08:00
|
|
|
case DevFmtX51Rear:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(X51RearCfg));
|
2014-11-07 00:54:16 -08:00
|
|
|
chanmap = X51RearCfg;
|
2016-04-15 17:31:04 -07:00
|
|
|
coeffcount = 9;
|
2014-11-07 00:54:16 -08:00
|
|
|
break;
|
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtX61:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(X61Cfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = X61Cfg;
|
2017-01-21 12:28:54 -08:00
|
|
|
coeffcount = 9;
|
2010-08-03 00:21:36 -07:00
|
|
|
break;
|
|
|
|
|
2010-12-04 19:50:00 -08:00
|
|
|
case DevFmtX71:
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(X71Cfg));
|
2014-11-05 03:46:00 -08:00
|
|
|
chanmap = X71Cfg;
|
2016-04-15 17:31:04 -07:00
|
|
|
coeffcount = 16;
|
2010-08-03 00:21:36 -07:00
|
|
|
break;
|
2014-11-25 22:20:00 -08:00
|
|
|
|
2017-04-12 18:26:07 -07:00
|
|
|
case DevFmtAmbi3D:
|
2014-11-25 22:20:00 -08:00
|
|
|
break;
|
2010-08-03 00:21:36 -07:00
|
|
|
}
|
2014-11-12 19:26:53 -08:00
|
|
|
|
2017-04-12 18:26:07 -07:00
|
|
|
if(device->FmtChans == DevFmtAmbi3D)
|
2016-07-29 21:55:43 -07:00
|
|
|
{
|
2018-12-10 21:30:22 -08:00
|
|
|
const char *devname{device->DeviceName.c_str()};
|
2018-12-10 22:32:10 -08:00
|
|
|
const ALsizei (&acnmap)[MAX_AMBI_COEFFS] = GetAmbiLayout(device->mAmbiLayout);
|
|
|
|
const ALfloat (&n3dscale)[MAX_AMBI_COEFFS] = GetAmbiScales(device->mAmbiScale);
|
2016-07-29 21:55:43 -07:00
|
|
|
|
2018-11-18 08:01:50 -08:00
|
|
|
count = (device->mAmbiOrder == 3) ? 16 :
|
|
|
|
(device->mAmbiOrder == 2) ? 9 :
|
|
|
|
(device->mAmbiOrder == 1) ? 4 : 1;
|
2016-07-29 21:55:43 -07:00
|
|
|
for(i = 0;i < count;i++)
|
|
|
|
{
|
2017-01-16 07:45:07 -08:00
|
|
|
ALsizei acn = acnmap[i];
|
2016-08-02 09:16:12 -07:00
|
|
|
device->Dry.Ambi.Map[i].Scale = 1.0f/n3dscale[acn];
|
2016-07-31 07:46:38 -07:00
|
|
|
device->Dry.Ambi.Map[i].Index = acn;
|
2016-07-29 21:55:43 -07:00
|
|
|
}
|
|
|
|
device->Dry.CoeffCount = 0;
|
|
|
|
device->Dry.NumChannels = count;
|
|
|
|
|
2018-11-18 08:01:50 -08:00
|
|
|
if(device->mAmbiOrder < 2)
|
2016-07-29 21:55:43 -07:00
|
|
|
{
|
2016-07-31 07:46:38 -07:00
|
|
|
device->FOAOut.Ambi = device->Dry.Ambi;
|
|
|
|
device->FOAOut.CoeffCount = device->Dry.CoeffCount;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 0;
|
2016-07-29 21:55:43 -07:00
|
|
|
}
|
2016-07-31 07:46:38 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FOA output is always ACN+N3D for higher-order ambisonic output.
|
|
|
|
* The upsampler expects this and will convert it for output.
|
|
|
|
*/
|
2018-12-08 14:22:20 -08:00
|
|
|
device->FOAOut.Ambi = AmbiConfig{};
|
2016-07-31 07:46:38 -07:00
|
|
|
for(i = 0;i < 4;i++)
|
|
|
|
{
|
|
|
|
device->FOAOut.Ambi.Map[i].Scale = 1.0f;
|
|
|
|
device->FOAOut.Ambi.Map[i].Index = i;
|
|
|
|
}
|
|
|
|
device->FOAOut.CoeffCount = 0;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 4;
|
2016-07-30 09:29:21 -07:00
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
ALfloat w_scale{1.0f}, xyz_scale{1.0f};
|
2018-11-18 08:01:50 -08:00
|
|
|
if(device->mAmbiOrder >= 3)
|
2018-02-13 03:03:26 -08:00
|
|
|
{
|
|
|
|
w_scale = W_SCALE_3H3P;
|
|
|
|
xyz_scale = XYZ_SCALE_3H3P;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w_scale = W_SCALE_2H2P;
|
|
|
|
xyz_scale = XYZ_SCALE_2H2P;
|
|
|
|
}
|
2018-12-08 02:50:34 -08:00
|
|
|
device->AmbiUp->reset(device, w_scale, xyz_scale);
|
2016-07-31 07:46:38 -07:00
|
|
|
}
|
2017-03-10 04:35:32 -08:00
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
ALfloat nfc_delay{0.0f};
|
2017-05-14 18:50:22 -07:00
|
|
|
if(ConfigValueFloat(devname, "decoder", "nfc-ref-delay", &nfc_delay) && nfc_delay > 0.0f)
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2018-12-10 21:30:22 -08:00
|
|
|
static constexpr ALsizei chans_per_order[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 };
|
2017-03-10 04:35:32 -08:00
|
|
|
nfc_delay = clampf(nfc_delay, 0.001f, 1000.0f);
|
|
|
|
InitNearFieldCtrl(device, nfc_delay * SPEEDOFSOUNDMETRESPERSEC,
|
2018-11-18 08:01:50 -08:00
|
|
|
device->mAmbiOrder, chans_per_order);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
2016-07-29 21:55:43 -07:00
|
|
|
}
|
2016-04-15 22:05:47 -07:00
|
|
|
else
|
2016-03-25 23:25:13 -07:00
|
|
|
{
|
2016-04-16 17:21:31 -07:00
|
|
|
SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs,
|
2017-01-21 11:05:05 -08:00
|
|
|
chanmap, count, &device->Dry.NumChannels);
|
2016-04-15 22:05:47 -07:00
|
|
|
device->Dry.CoeffCount = coeffcount;
|
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
const ALfloat w_scale{(device->Dry.CoeffCount > 9) ? W_SCALE_3H0P :
|
|
|
|
(device->Dry.CoeffCount > 4) ? W_SCALE_2H0P : 1.0f};
|
|
|
|
const ALfloat xyz_scale{(device->Dry.CoeffCount > 9) ? XYZ_SCALE_3H0P :
|
|
|
|
(device->Dry.CoeffCount > 4) ? XYZ_SCALE_2H0P : 1.0f};
|
2017-01-24 19:03:51 -08:00
|
|
|
|
2018-12-08 14:22:20 -08:00
|
|
|
device->FOAOut.Ambi = AmbiConfig{};
|
2017-01-24 19:03:51 -08:00
|
|
|
for(i = 0;i < device->Dry.NumChannels;i++)
|
2016-04-15 22:05:47 -07:00
|
|
|
{
|
2017-01-24 19:03:51 -08:00
|
|
|
device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
|
2016-04-15 22:05:47 -07:00
|
|
|
for(j = 1;j < 4;j++)
|
2017-01-24 19:03:51 -08:00
|
|
|
device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
|
|
|
device->FOAOut.CoeffCount = 4;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 0;
|
2016-03-25 23:25:13 -07:00
|
|
|
}
|
2017-02-20 16:57:25 -08:00
|
|
|
device->RealOut.NumChannels = 0;
|
2010-08-03 00:21:36 -07:00
|
|
|
}
|
2016-01-28 00:02:46 -08:00
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitCustomPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
|
|
|
if(conf->FreqBands != 1)
|
|
|
|
ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
|
|
|
|
conf->XOverFreq);
|
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
ALfloat w_scale{1.0f}, xyz_scale{1.0f};
|
2017-01-24 19:03:51 -08:00
|
|
|
if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
|
|
|
|
{
|
|
|
|
if(conf->ChanMask > 0x1ff)
|
|
|
|
{
|
2018-02-09 18:43:34 -08:00
|
|
|
w_scale = W_SCALE_3H3P;
|
|
|
|
xyz_scale = XYZ_SCALE_3H3P;
|
2017-01-24 19:03:51 -08:00
|
|
|
}
|
|
|
|
else if(conf->ChanMask > 0xf)
|
|
|
|
{
|
2018-02-09 18:43:34 -08:00
|
|
|
w_scale = W_SCALE_2H2P;
|
|
|
|
xyz_scale = XYZ_SCALE_2H2P;
|
2017-01-24 19:03:51 -08:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 16:42:32 -07:00
|
|
|
else
|
2017-01-24 19:03:51 -08:00
|
|
|
{
|
|
|
|
if(conf->ChanMask > 0x1ff)
|
|
|
|
{
|
2018-02-09 18:43:34 -08:00
|
|
|
w_scale = W_SCALE_3H0P;
|
|
|
|
xyz_scale = XYZ_SCALE_3H0P;
|
2017-01-24 19:03:51 -08:00
|
|
|
}
|
|
|
|
else if(conf->ChanMask > 0xf)
|
|
|
|
{
|
2018-02-09 18:43:34 -08:00
|
|
|
w_scale = W_SCALE_2H0P;
|
|
|
|
xyz_scale = XYZ_SCALE_2H0P;
|
2017-01-24 19:03:51 -08:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2018-12-10 22:32:10 -08:00
|
|
|
const ALfloat (&coeff_scale)[MAX_AMBI_COEFFS] = GetAmbiScales(conf->CoeffScale);
|
2018-12-10 21:30:22 -08:00
|
|
|
ChannelMap chanmap[MAX_OUTPUT_CHANNELS]{};
|
|
|
|
for(ALsizei i{0};i < conf->NumSpeakers;i++)
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2018-12-10 21:30:22 -08:00
|
|
|
const ALsizei chan{speakermap[i]};
|
2016-04-14 16:42:32 -07:00
|
|
|
|
|
|
|
chanmap[i].ChanName = device->RealOut.ChannelName[chan];
|
2018-12-10 21:30:22 -08:00
|
|
|
std::fill(std::begin(chanmap[i].Config), std::end(chanmap[i].Config), 0.0f);
|
|
|
|
|
|
|
|
ALsizei k{0};
|
|
|
|
ALfloat gain{conf->HFOrderGain[0]};
|
|
|
|
for(ALsizei j{0};j < MAX_AMBI_COEFFS;j++)
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2018-12-10 21:30:22 -08:00
|
|
|
if(j == 1) gain = conf->HFOrderGain[1];
|
2016-04-14 16:42:32 -07:00
|
|
|
else if(j == 4) gain = conf->HFOrderGain[2];
|
|
|
|
else if(j == 9) gain = conf->HFOrderGain[3];
|
|
|
|
if((conf->ChanMask&(1<<j)))
|
|
|
|
chanmap[i].Config[j] = conf->HFMatrix[i][k++] / coeff_scale[j] * gain;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-16 17:21:31 -07:00
|
|
|
SetChannelMap(device->RealOut.ChannelName, device->Dry.Ambi.Coeffs, chanmap,
|
2017-01-21 11:05:05 -08:00
|
|
|
conf->NumSpeakers, &device->Dry.NumChannels);
|
2016-04-15 17:31:04 -07:00
|
|
|
device->Dry.CoeffCount = (conf->ChanMask > 0x1ff) ? 16 :
|
|
|
|
(conf->ChanMask > 0xf) ? 9 : 4;
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2018-12-08 14:22:20 -08:00
|
|
|
device->FOAOut.Ambi = AmbiConfig{};
|
2018-12-10 21:30:22 -08:00
|
|
|
for(ALsizei i{0};i < device->Dry.NumChannels;i++)
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2017-01-24 19:03:51 -08:00
|
|
|
device->FOAOut.Ambi.Coeffs[i][0] = device->Dry.Ambi.Coeffs[i][0] * w_scale;
|
2018-12-10 21:30:22 -08:00
|
|
|
for(ALsizei j{1};j < 4;j++)
|
2017-01-24 19:03:51 -08:00
|
|
|
device->FOAOut.Ambi.Coeffs[i][j] = device->Dry.Ambi.Coeffs[i][j] * xyz_scale;
|
2016-04-14 16:42:32 -07:00
|
|
|
}
|
2016-04-15 22:05:47 -07:00
|
|
|
device->FOAOut.CoeffCount = 4;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 0;
|
|
|
|
|
|
|
|
device->RealOut.NumChannels = 0;
|
2017-02-20 09:08:57 -08:00
|
|
|
|
|
|
|
InitDistanceComp(device, conf, speakermap);
|
2016-04-14 16:42:32 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitHQPanning(ALCdevice *device, const AmbDecConf *conf, const ALsizei (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2018-12-08 01:32:43 -08:00
|
|
|
static constexpr ALsizei chans_per_order2d[MAX_AMBI_ORDER+1] = { 1, 2, 2, 2 };
|
|
|
|
static constexpr ALsizei chans_per_order3d[MAX_AMBI_ORDER+1] = { 1, 3, 5, 7 };
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2018-12-10 21:30:22 -08:00
|
|
|
ALsizei count;
|
2016-06-01 05:30:06 -07:00
|
|
|
if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
|
2016-04-15 22:05:47 -07:00
|
|
|
{
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr int map[MAX_AMBI_COEFFS] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
|
2016-04-19 18:58:19 -07:00
|
|
|
count = (conf->ChanMask > 0x1ff) ? 16 :
|
|
|
|
(conf->ChanMask > 0xf) ? 9 : 4;
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(map), std::begin(map)+count, std::begin(device->Dry.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr int map[MAX_AMBI2D_COEFFS] = { 0, 1, 3, 4, 8, 9, 15 };
|
2016-04-19 18:58:19 -07:00
|
|
|
count = (conf->ChanMask > 0x1ff) ? 7 :
|
|
|
|
(conf->ChanMask > 0xf) ? 5 : 3;
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(map), std::begin(map)+count, std::begin(device->Dry.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
|
|
|
device->Dry.CoeffCount = 0;
|
|
|
|
device->Dry.NumChannels = count;
|
2016-04-14 16:42:32 -07:00
|
|
|
|
|
|
|
TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
|
|
|
|
(conf->FreqBands == 1) ? "single" : "dual",
|
|
|
|
(conf->ChanMask > 0xf) ? (conf->ChanMask > 0x1ff) ? "third" : "second" : "first",
|
2016-06-01 05:30:06 -07:00
|
|
|
(conf->ChanMask&AMBI_PERIPHONIC_MASK) ? " periphonic" : ""
|
2016-04-14 16:42:32 -07:00
|
|
|
);
|
2018-12-08 02:50:34 -08:00
|
|
|
device->AmbiDecoder->reset(conf, count, device->Frequency, speakermap);
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2018-10-29 02:05:45 +01:00
|
|
|
if(conf->ChanMask <= 0xf)
|
2016-04-15 22:05:47 -07:00
|
|
|
{
|
2016-07-06 13:33:40 -07:00
|
|
|
device->FOAOut.Ambi = device->Dry.Ambi;
|
2016-04-15 22:05:47 -07:00
|
|
|
device->FOAOut.CoeffCount = device->Dry.CoeffCount;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 0;
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
2016-04-14 16:42:32 -07:00
|
|
|
else
|
|
|
|
{
|
2018-12-08 14:22:20 -08:00
|
|
|
device->FOAOut.Ambi = AmbiConfig{};
|
2017-02-19 17:45:27 -08:00
|
|
|
if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
|
2017-02-20 16:57:25 -08:00
|
|
|
{
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr int map[4] = { 0, 1, 2, 3 };
|
2017-02-20 16:57:25 -08:00
|
|
|
count = 4;
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(map), std::begin(map)+count, std::begin(device->FOAOut.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
2017-02-20 16:57:25 -08:00
|
|
|
}
|
2017-02-19 17:45:27 -08:00
|
|
|
else
|
2016-04-15 22:05:47 -07:00
|
|
|
{
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr int map[3] = { 0, 1, 3 };
|
2017-02-20 16:57:25 -08:00
|
|
|
count = 3;
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(map), std::begin(map)+count, std::begin(device->FOAOut.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
|
|
|
device->FOAOut.CoeffCount = 0;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = count;
|
2016-04-14 16:42:32 -07:00
|
|
|
}
|
2017-02-19 22:47:59 -08:00
|
|
|
|
2018-11-18 08:01:50 -08:00
|
|
|
device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->mAmbiOrder);
|
2017-02-20 16:57:25 -08:00
|
|
|
|
2018-12-09 22:34:21 -08:00
|
|
|
using namespace std::placeholders;
|
|
|
|
auto accum_spkr_dist = std::bind(
|
|
|
|
std::plus<float>{}, _1, std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2)
|
|
|
|
);
|
|
|
|
const ALfloat avg_dist{
|
|
|
|
std::accumulate(std::begin(conf->Speakers), std::begin(conf->Speakers)+conf->NumSpeakers,
|
|
|
|
float{0.0f}, accum_spkr_dist) / (ALfloat)conf->NumSpeakers
|
|
|
|
};
|
2017-03-10 04:35:32 -08:00
|
|
|
InitNearFieldCtrl(device, avg_dist,
|
|
|
|
(conf->ChanMask > 0x1ff) ? 3 : (conf->ChanMask > 0xf) ? 2 : 1,
|
2018-05-01 20:00:30 -07:00
|
|
|
(conf->ChanMask&AMBI_PERIPHONIC_MASK) ? chans_per_order3d : chans_per_order2d
|
2017-03-10 04:35:32 -08:00
|
|
|
);
|
|
|
|
|
2017-02-20 09:08:57 -08:00
|
|
|
InitDistanceComp(device, conf, speakermap);
|
2016-04-14 16:42:32 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitHrtfPanning(ALCdevice *device)
|
2016-04-14 10:44:57 -07:00
|
|
|
{
|
2017-01-18 19:16:24 -08:00
|
|
|
/* NOTE: azimuth goes clockwise. */
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr struct AngularPoint AmbiPoints[] = {
|
2018-02-13 03:03:26 -08:00
|
|
|
{ DEG2RAD( 90.0f), DEG2RAD( 0.0f) },
|
2018-05-14 05:28:06 -07:00
|
|
|
{ DEG2RAD( 35.2643897f), DEG2RAD( 45.0f) },
|
|
|
|
{ DEG2RAD( 35.2643897f), DEG2RAD( 135.0f) },
|
|
|
|
{ DEG2RAD( 35.2643897f), DEG2RAD(-135.0f) },
|
|
|
|
{ DEG2RAD( 35.2643897f), DEG2RAD( -45.0f) },
|
2017-01-18 19:16:24 -08:00
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( 0.0f) },
|
2018-02-10 05:16:28 -08:00
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( 45.0f) },
|
2018-02-13 03:03:26 -08:00
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( 90.0f) },
|
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( 135.0f) },
|
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( 180.0f) },
|
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD(-135.0f) },
|
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( -90.0f) },
|
|
|
|
{ DEG2RAD( 0.0f), DEG2RAD( -45.0f) },
|
2018-05-14 05:28:06 -07:00
|
|
|
{ DEG2RAD(-35.2643897f), DEG2RAD( 45.0f) },
|
|
|
|
{ DEG2RAD(-35.2643897f), DEG2RAD( 135.0f) },
|
|
|
|
{ DEG2RAD(-35.2643897f), DEG2RAD(-135.0f) },
|
|
|
|
{ DEG2RAD(-35.2643897f), DEG2RAD( -45.0f) },
|
2018-02-13 03:03:26 -08:00
|
|
|
{ DEG2RAD(-90.0f), DEG2RAD( 0.0f) },
|
2018-02-10 05:16:28 -08:00
|
|
|
};
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr ALfloat AmbiMatrixFOA[][MAX_AMBI_COEFFS] = {
|
2018-02-13 03:03:26 -08:00
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 1.23717915e-01f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.66025404e-02f },
|
|
|
|
{ 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f },
|
|
|
|
{ 5.55555556e-02f, -8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.66025404e-02f },
|
|
|
|
{ 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f },
|
|
|
|
{ 5.55555556e-02f, 8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, -1.23717915e-01f, 0.00000000e+00f },
|
2018-02-10 05:16:28 -08:00
|
|
|
}, AmbiMatrixHOA[][MAX_AMBI_COEFFS] = {
|
2018-03-31 20:44:14 -07:00
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 1.23717915e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, -5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, 7.14285715e-02f, 5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, 8.66025404e-02f, 0.00000000e+00f, 1.29099445e-01f },
|
|
|
|
{ 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f, -6.83467648e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.29099445e-01f },
|
|
|
|
{ 5.55555556e-02f, -6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f, 6.83467648e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, 0.00000000e+00f, -8.66025404e-02f, 0.00000000e+00f, 1.29099445e-01f },
|
|
|
|
{ 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, -6.12372435e-02f, -6.83467648e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 8.66025404e-02f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f, -1.29099445e-01f },
|
|
|
|
{ 5.55555556e-02f, 6.12372435e-02f, 0.00000000e+00f, 6.12372435e-02f, 6.83467648e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, -5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, -5.00000000e-02f, -4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 5.00000000e-02f, -7.14285715e-02f, 5.00000000e-02f, 4.55645099e-02f, 0.00000000e+00f },
|
|
|
|
{ 5.55555556e-02f, 0.00000000e+00f, -1.23717915e-01f, 0.00000000e+00f, 0.00000000e+00f, 0.00000000e+00f },
|
2017-01-18 19:16:24 -08:00
|
|
|
};
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr ALfloat AmbiOrderHFGainFOA[MAX_AMBI_ORDER+1] = {
|
2018-04-16 18:51:01 -07:00
|
|
|
3.00000000e+00f, 1.73205081e+00f
|
2018-02-10 05:16:28 -08:00
|
|
|
}, AmbiOrderHFGainHOA[MAX_AMBI_ORDER+1] = {
|
2018-04-16 18:51:01 -07:00
|
|
|
2.40192231e+00f, 1.86052102e+00f, 9.60768923e-01f
|
2017-01-18 19:16:24 -08:00
|
|
|
};
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr ALsizei IndexMap[6] = { 0, 1, 2, 3, 4, 8 };
|
|
|
|
static constexpr ALsizei ChansPerOrder[MAX_AMBI_ORDER+1] = { 1, 3, 2, 0 };
|
2018-10-29 11:32:50 -07:00
|
|
|
const ALfloat (*RESTRICT AmbiMatrix)[MAX_AMBI_COEFFS] = AmbiMatrixFOA;
|
|
|
|
const ALfloat *RESTRICT AmbiOrderHFGain = AmbiOrderHFGainFOA;
|
2018-12-09 22:34:21 -08:00
|
|
|
ALsizei count{4};
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2018-02-10 05:16:28 -08:00
|
|
|
static_assert(COUNTOF(AmbiPoints) == COUNTOF(AmbiMatrixFOA), "FOA Ambisonic HRTF mismatch");
|
|
|
|
static_assert(COUNTOF(AmbiPoints) == COUNTOF(AmbiMatrixHOA), "HOA Ambisonic HRTF mismatch");
|
2017-01-15 13:57:22 -08:00
|
|
|
|
2018-02-10 05:16:28 -08:00
|
|
|
if(device->AmbiUp)
|
|
|
|
{
|
|
|
|
AmbiMatrix = AmbiMatrixHOA;
|
|
|
|
AmbiOrderHFGain = AmbiOrderHFGainHOA;
|
2018-12-12 21:18:31 -08:00
|
|
|
count = static_cast<ALsizei>(COUNTOF(IndexMap));
|
2018-02-10 05:16:28 -08:00
|
|
|
}
|
|
|
|
|
2018-11-22 07:54:29 -08:00
|
|
|
device->mHrtfState.reset(
|
|
|
|
new (al_calloc(16, FAM_SIZE(DirectHrtfState, Chan, count))) DirectHrtfState{});
|
2017-03-11 06:20:04 -08:00
|
|
|
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(IndexMap), std::begin(IndexMap)+count, std::begin(device->Dry.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
Decode directly from B-Format to HRTF instead of a cube
Last time this attempted to average the HRIRs according to their contribution
to a given B-Format channel as if they were loudspeakers, as well as averaging
the HRIR delays. The latter part resulted in the loss of the ITD (inter-aural
time delay), a key component of HRTF.
This time, the HRIRs are averaged similar to above, except instead of averaging
the delays, they're applied to the resulting coefficients (for example, a delay
of 8 would apply the HRIR starting at the 8th sample of the target HRIR). This
does roughly double the IR length, as the largest delay is about 35 samples
while the filter is normally 32 samples. However, this is still smaller the
original data set IR (which was 256 samples), it also only needs to be applied
to 4 channels for first-order ambisonics, rather than the 8-channel cube. So
it's doing twice as much work per sample, but only working on half the number
of samples.
Additionally, since the resulting HRIRs no longer rely on an extra delay line,
a more efficient HRTF mixing function can be made that doesn't use one. Such a
function can also avoid the per-sample stepping parameters the original uses.
2016-08-11 23:20:35 -07:00
|
|
|
device->Dry.CoeffCount = 0;
|
|
|
|
device->Dry.NumChannels = count;
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2017-04-18 17:39:10 -07:00
|
|
|
if(device->AmbiUp)
|
2017-01-15 13:57:22 -08:00
|
|
|
{
|
2018-12-08 14:22:20 -08:00
|
|
|
device->FOAOut.Ambi = AmbiConfig{};
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(IndexMap), std::begin(IndexMap)+4, std::begin(device->FOAOut.Ambi.Map),
|
|
|
|
[](const ALsizei &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
|
|
|
);
|
2017-01-15 13:57:22 -08:00
|
|
|
device->FOAOut.CoeffCount = 0;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 4;
|
2017-01-15 13:57:22 -08:00
|
|
|
|
2018-12-08 02:50:34 -08:00
|
|
|
device->AmbiUp->reset(device, AmbiOrderHFGainFOA[0] / AmbiOrderHFGain[0],
|
|
|
|
AmbiOrderHFGainFOA[1] / AmbiOrderHFGain[1]);
|
2017-01-15 13:57:22 -08:00
|
|
|
}
|
2017-04-18 17:39:10 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
device->FOAOut.Ambi = device->Dry.Ambi;
|
|
|
|
device->FOAOut.CoeffCount = device->Dry.CoeffCount;
|
|
|
|
device->FOAOut.NumChannels = 0;
|
|
|
|
}
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2018-11-18 08:01:50 -08:00
|
|
|
device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->mAmbiOrder);
|
2017-02-20 16:57:25 -08:00
|
|
|
|
2017-07-31 01:20:42 -07:00
|
|
|
BuildBFormatHrtf(device->HrtfHandle,
|
2018-11-22 07:54:29 -08:00
|
|
|
device->mHrtfState.get(), device->Dry.NumChannels, AmbiPoints, AmbiMatrix,
|
2018-12-12 21:18:31 -08:00
|
|
|
static_cast<ALsizei>(COUNTOF(AmbiPoints)), AmbiOrderHFGain
|
2016-08-24 00:25:28 -07:00
|
|
|
);
|
2017-10-23 13:30:01 -07:00
|
|
|
|
2018-05-01 20:00:30 -07:00
|
|
|
InitNearFieldCtrl(device, device->HrtfHandle->distance, device->AmbiUp ? 2 : 1,
|
|
|
|
ChansPerOrder);
|
2016-04-14 10:44:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
void InitUhjPanning(ALCdevice *device)
|
2016-04-14 10:44:57 -07:00
|
|
|
{
|
2018-12-09 22:34:21 -08:00
|
|
|
static constexpr ALsizei count{3};
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2018-12-09 22:34:21 -08:00
|
|
|
std::transform(std::begin(FuMa2ACN), std::begin(FuMa2ACN)+count, std::begin(device->Dry.Ambi.Map),
|
|
|
|
[](const ALsizei &acn) noexcept -> BFChannelConfig
|
2018-12-10 21:30:22 -08:00
|
|
|
{ return BFChannelConfig{1.0f/AmbiScale::FuMa2N3D[acn], acn}; }
|
2018-12-09 22:34:21 -08:00
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
device->Dry.CoeffCount = 0;
|
|
|
|
device->Dry.NumChannels = count;
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2016-07-06 13:33:40 -07:00
|
|
|
device->FOAOut.Ambi = device->Dry.Ambi;
|
2016-04-15 22:05:47 -07:00
|
|
|
device->FOAOut.CoeffCount = device->Dry.CoeffCount;
|
2017-02-20 16:57:25 -08:00
|
|
|
device->FOAOut.NumChannels = 0;
|
|
|
|
|
2018-11-18 08:01:50 -08:00
|
|
|
device->RealOut.NumChannels = ChannelsFromDevFmt(device->FmtChans, device->mAmbiOrder);
|
2016-04-14 10:44:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
void CalcAmbiCoeffs(const ALfloat y, const ALfloat z, const ALfloat x, const ALfloat spread,
|
|
|
|
ALfloat (&coeffs)[MAX_AMBI_COEFFS])
|
|
|
|
{
|
|
|
|
/* Zeroth-order */
|
|
|
|
coeffs[0] = 1.0f; /* ACN 0 = 1 */
|
|
|
|
/* First-order */
|
|
|
|
coeffs[1] = SQRTF_3 * y; /* ACN 1 = sqrt(3) * Y */
|
|
|
|
coeffs[2] = SQRTF_3 * z; /* ACN 2 = sqrt(3) * Z */
|
|
|
|
coeffs[3] = SQRTF_3 * x; /* ACN 3 = sqrt(3) * X */
|
|
|
|
/* Second-order */
|
|
|
|
coeffs[4] = 3.872983346f * x * y; /* ACN 4 = sqrt(15) * X * Y */
|
|
|
|
coeffs[5] = 3.872983346f * y * z; /* ACN 5 = sqrt(15) * Y * Z */
|
|
|
|
coeffs[6] = 1.118033989f * (3.0f*z*z - 1.0f); /* ACN 6 = sqrt(5)/2 * (3*Z*Z - 1) */
|
|
|
|
coeffs[7] = 3.872983346f * x * z; /* ACN 7 = sqrt(15) * X * Z */
|
|
|
|
coeffs[8] = 1.936491673f * (x*x - y*y); /* ACN 8 = sqrt(15)/2 * (X*X - Y*Y) */
|
|
|
|
/* Third-order */
|
|
|
|
coeffs[9] = 2.091650066f * y * (3.0f*x*x - y*y); /* ACN 9 = sqrt(35/8) * Y * (3*X*X - Y*Y) */
|
|
|
|
coeffs[10] = 10.246950766f * z * x * y; /* ACN 10 = sqrt(105) * Z * X * Y */
|
|
|
|
coeffs[11] = 1.620185175f * y * (5.0f*z*z - 1.0f); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */
|
|
|
|
coeffs[12] = 1.322875656f * z * (5.0f*z*z - 3.0f); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */
|
|
|
|
coeffs[13] = 1.620185175f * x * (5.0f*z*z - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */
|
|
|
|
coeffs[14] = 5.123475383f * z * (x*x - y*y); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */
|
|
|
|
coeffs[15] = 2.091650066f * x * (x*x - 3.0f*y*y); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */
|
|
|
|
|
|
|
|
if(spread > 0.0f)
|
|
|
|
{
|
|
|
|
/* Implement the spread by using a spherical source that subtends the
|
|
|
|
* angle spread. See:
|
|
|
|
* http://www.ppsloan.org/publications/StupidSH36.pdf - Appendix A3
|
|
|
|
*
|
|
|
|
* When adjusted for N3D normalization instead of SN3D, these
|
|
|
|
* calculations are:
|
|
|
|
*
|
|
|
|
* ZH0 = -sqrt(pi) * (-1+ca);
|
|
|
|
* ZH1 = 0.5*sqrt(pi) * sa*sa;
|
|
|
|
* ZH2 = -0.5*sqrt(pi) * ca*(-1+ca)*(ca+1);
|
|
|
|
* ZH3 = -0.125*sqrt(pi) * (-1+ca)*(ca+1)*(5*ca*ca - 1);
|
|
|
|
* ZH4 = -0.125*sqrt(pi) * ca*(-1+ca)*(ca+1)*(7*ca*ca - 3);
|
|
|
|
* ZH5 = -0.0625*sqrt(pi) * (-1+ca)*(ca+1)*(21*ca*ca*ca*ca - 14*ca*ca + 1);
|
|
|
|
*
|
|
|
|
* The gain of the source is compensated for size, so that the
|
|
|
|
* loundness doesn't depend on the spread. Thus:
|
|
|
|
*
|
|
|
|
* ZH0 = 1.0f;
|
|
|
|
* ZH1 = 0.5f * (ca+1.0f);
|
|
|
|
* ZH2 = 0.5f * (ca+1.0f)*ca;
|
|
|
|
* ZH3 = 0.125f * (ca+1.0f)*(5.0f*ca*ca - 1.0f);
|
|
|
|
* ZH4 = 0.125f * (ca+1.0f)*(7.0f*ca*ca - 3.0f)*ca;
|
|
|
|
* ZH5 = 0.0625f * (ca+1.0f)*(21.0f*ca*ca*ca*ca - 14.0f*ca*ca + 1.0f);
|
|
|
|
*/
|
2018-12-10 21:30:22 -08:00
|
|
|
ALfloat ca = std::cos(spread * 0.5f);
|
2018-12-10 02:08:54 -08:00
|
|
|
/* Increase the source volume by up to +3dB for a full spread. */
|
2018-12-10 21:30:22 -08:00
|
|
|
ALfloat scale = std::sqrt(1.0f + spread/F_TAU);
|
2018-12-10 02:08:54 -08:00
|
|
|
|
|
|
|
ALfloat ZH0_norm = scale;
|
|
|
|
ALfloat ZH1_norm = 0.5f * (ca+1.f) * scale;
|
|
|
|
ALfloat ZH2_norm = 0.5f * (ca+1.f)*ca * scale;
|
|
|
|
ALfloat ZH3_norm = 0.125f * (ca+1.f)*(5.f*ca*ca-1.f) * scale;
|
|
|
|
|
|
|
|
/* Zeroth-order */
|
|
|
|
coeffs[0] *= ZH0_norm;
|
|
|
|
/* First-order */
|
|
|
|
coeffs[1] *= ZH1_norm;
|
|
|
|
coeffs[2] *= ZH1_norm;
|
|
|
|
coeffs[3] *= ZH1_norm;
|
|
|
|
/* Second-order */
|
|
|
|
coeffs[4] *= ZH2_norm;
|
|
|
|
coeffs[5] *= ZH2_norm;
|
|
|
|
coeffs[6] *= ZH2_norm;
|
|
|
|
coeffs[7] *= ZH2_norm;
|
|
|
|
coeffs[8] *= ZH2_norm;
|
|
|
|
/* Third-order */
|
|
|
|
coeffs[9] *= ZH3_norm;
|
|
|
|
coeffs[10] *= ZH3_norm;
|
|
|
|
coeffs[11] *= ZH3_norm;
|
|
|
|
coeffs[12] *= ZH3_norm;
|
|
|
|
coeffs[13] *= ZH3_norm;
|
|
|
|
coeffs[14] *= ZH3_norm;
|
|
|
|
coeffs[15] *= ZH3_norm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ComputePanningGainsMC(const ChannelConfig *chancoeffs, ALsizei numchans, ALsizei numcoeffs, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
|
|
|
|
{
|
|
|
|
ASSUME(numchans > 0);
|
|
|
|
auto iter = std::transform(chancoeffs, chancoeffs+numchans, std::begin(gains),
|
|
|
|
[numcoeffs,coeffs,ingain](const ChannelConfig &chancoeffs) -> ALfloat
|
|
|
|
{
|
|
|
|
ASSUME(numcoeffs > 0);
|
|
|
|
float gain{std::inner_product(std::begin(chancoeffs), std::begin(chancoeffs)+numcoeffs,
|
|
|
|
coeffs, float{0.0f})};
|
|
|
|
return clampf(gain, 0.0f, 1.0f) * ingain;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
std::fill(iter, std::end(gains), 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComputePanningGainsBF(const BFChannelConfig *chanmap, ALsizei numchans, const ALfloat*RESTRICT coeffs, ALfloat ingain, ALfloat (&gains)[MAX_OUTPUT_CHANNELS])
|
|
|
|
{
|
|
|
|
ASSUME(numchans > 0);
|
|
|
|
auto iter = std::transform(chanmap, chanmap+numchans, std::begin(gains),
|
|
|
|
[coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> ALfloat
|
|
|
|
{
|
|
|
|
ASSUME(chanmap.Index >= 0);
|
|
|
|
return chanmap.Scale * coeffs[chanmap.Index] * ingain;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
std::fill(iter, std::end(gains), 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 15:25:12 -07:00
|
|
|
void aluInitRenderer(ALCdevice *device, ALint hrtf_id, enum HrtfRequestMode hrtf_appreq, enum HrtfRequestMode hrtf_userreq)
|
|
|
|
{
|
2017-04-06 13:00:29 -07:00
|
|
|
/* Hold the HRTF the device last used, in case it's used again. */
|
|
|
|
struct Hrtf *old_hrtf = device->HrtfHandle;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2018-11-22 06:59:32 -08:00
|
|
|
device->mHrtfState = nullptr;
|
2018-11-22 04:53:29 -08:00
|
|
|
device->HrtfHandle = nullptr;
|
2018-11-18 19:28:01 -08:00
|
|
|
device->HrtfName.clear();
|
2016-04-14 15:25:12 -07:00
|
|
|
device->Render_Mode = NormalRender;
|
|
|
|
|
2018-12-05 16:35:06 -08:00
|
|
|
device->Dry.Ambi = AmbiConfig{};
|
2016-04-15 17:31:04 -07:00
|
|
|
device->Dry.CoeffCount = 0;
|
|
|
|
device->Dry.NumChannels = 0;
|
2018-12-05 16:35:06 -08:00
|
|
|
std::fill(std::begin(device->NumChannelsPerOrder), std::end(device->NumChannelsPerOrder), 0);
|
2016-04-15 17:31:04 -07:00
|
|
|
|
2017-03-10 04:35:32 -08:00
|
|
|
device->AvgSpeakerDist = 0.0f;
|
2018-11-21 05:06:31 -08:00
|
|
|
device->ChannelDelay.clear();
|
2017-02-19 22:47:59 -08:00
|
|
|
|
2018-11-22 04:53:29 -08:00
|
|
|
device->Stablizer = nullptr;
|
2017-07-31 23:49:48 -07:00
|
|
|
|
2016-04-14 15:25:12 -07:00
|
|
|
if(device->FmtChans != DevFmtStereo)
|
|
|
|
{
|
2017-01-29 16:42:02 -08:00
|
|
|
ALsizei speakermap[MAX_OUTPUT_CHANNELS];
|
2016-04-16 14:00:22 -07:00
|
|
|
const char *devname, *layout = NULL;
|
|
|
|
AmbDecConf conf, *pconf = NULL;
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2017-04-06 13:00:29 -07:00
|
|
|
if(old_hrtf)
|
|
|
|
Hrtf_DecRef(old_hrtf);
|
|
|
|
old_hrtf = NULL;
|
2016-04-14 15:25:12 -07:00
|
|
|
if(hrtf_appreq == Hrtf_Enable)
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2018-11-18 18:45:45 -08:00
|
|
|
devname = device->DeviceName.c_str();
|
2016-04-16 14:00:22 -07:00
|
|
|
switch(device->FmtChans)
|
|
|
|
{
|
|
|
|
case DevFmtQuad: layout = "quad"; break;
|
2017-02-19 22:59:55 -08:00
|
|
|
case DevFmtX51: /* fall-through */
|
|
|
|
case DevFmtX51Rear: layout = "surround51"; break;
|
2016-04-16 14:00:22 -07:00
|
|
|
case DevFmtX61: layout = "surround61"; break;
|
|
|
|
case DevFmtX71: layout = "surround71"; break;
|
2016-07-29 21:55:43 -07:00
|
|
|
/* Mono, Stereo, and Ambisonics output don't use custom decoders. */
|
2016-04-16 14:00:22 -07:00
|
|
|
case DevFmtMono:
|
|
|
|
case DevFmtStereo:
|
2017-04-12 18:26:07 -07:00
|
|
|
case DevFmtAmbi3D:
|
2016-04-16 14:00:22 -07:00
|
|
|
break;
|
|
|
|
}
|
2016-04-14 16:42:32 -07:00
|
|
|
if(layout)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2016-04-14 16:42:32 -07:00
|
|
|
const char *fname;
|
|
|
|
if(ConfigValueStr(devname, "decoder", layout, &fname))
|
|
|
|
{
|
2018-11-03 19:51:23 -07:00
|
|
|
if(!conf.load(fname))
|
2016-04-14 16:42:32 -07:00
|
|
|
ERR("Failed to load layout file %s\n", fname);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(conf.ChanMask > 0xffff)
|
|
|
|
ERR("Unsupported channel mask 0x%04x (max 0xffff)\n", conf.ChanMask);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(MakeSpeakerMap(device, &conf, speakermap))
|
|
|
|
pconf = &conf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pconf && GetConfigValueBool(devname, "decoder", "hq-mode", 0))
|
|
|
|
{
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiUp = nullptr;
|
2016-04-19 18:58:19 -07:00
|
|
|
if(!device->AmbiDecoder)
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiDecoder.reset(new BFormatDec{});
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiDecoder = nullptr;
|
2018-11-18 08:01:50 -08:00
|
|
|
if(device->FmtChans != DevFmtAmbi3D || device->mAmbiOrder < 2)
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiUp = nullptr;
|
|
|
|
else if(!device->AmbiUp)
|
|
|
|
device->AmbiUp.reset(new AmbiUpsampler{});
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
2016-04-14 16:42:32 -07:00
|
|
|
if(!pconf)
|
|
|
|
InitPanning(device);
|
|
|
|
else if(device->AmbiDecoder)
|
|
|
|
InitHQPanning(device, pconf, speakermap);
|
|
|
|
else
|
|
|
|
InitCustomPanning(device, pconf, speakermap);
|
|
|
|
|
2017-07-31 23:49:48 -07:00
|
|
|
/* Enable the stablizer only for formats that have front-left, front-
|
|
|
|
* right, and front-center outputs.
|
|
|
|
*/
|
|
|
|
switch(device->FmtChans)
|
|
|
|
{
|
|
|
|
case DevFmtX51:
|
|
|
|
case DevFmtX51Rear:
|
|
|
|
case DevFmtX61:
|
|
|
|
case DevFmtX71:
|
|
|
|
if(GetConfigValueBool(devname, NULL, "front-stablizer", 0))
|
|
|
|
{
|
|
|
|
/* Initialize band-splitting filters for the front-left and
|
|
|
|
* front-right channels, with a crossover at 5khz (could be
|
|
|
|
* higher).
|
|
|
|
*/
|
|
|
|
ALfloat scale = (ALfloat)(5000.0 / device->Frequency);
|
2018-11-22 04:53:29 -08:00
|
|
|
std::unique_ptr<FrontStablizer> stablizer{new FrontStablizer{}};
|
2017-07-31 23:49:48 -07:00
|
|
|
|
2018-12-05 15:38:05 -08:00
|
|
|
stablizer->LFilter.init(scale);
|
2017-07-31 23:49:48 -07:00
|
|
|
stablizer->RFilter = stablizer->LFilter;
|
|
|
|
|
|
|
|
/* Initialize all-pass filters for all other channels. */
|
2018-12-05 15:38:05 -08:00
|
|
|
stablizer->APFilter[0].init(scale);
|
2018-12-05 16:35:06 -08:00
|
|
|
std::fill(std::begin(stablizer->APFilter)+1, std::end(stablizer->APFilter),
|
|
|
|
stablizer->APFilter[0]);
|
2017-07-31 23:49:48 -07:00
|
|
|
|
2018-11-22 04:53:29 -08:00
|
|
|
device->Stablizer = std::move(stablizer);
|
2017-07-31 23:49:48 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DevFmtMono:
|
|
|
|
case DevFmtStereo:
|
|
|
|
case DevFmtQuad:
|
|
|
|
case DevFmtAmbi3D:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE("Front stablizer %s\n", device->Stablizer ? "enabled" : "disabled");
|
|
|
|
|
2016-04-14 15:25:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiDecoder = nullptr;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2018-12-05 16:35:06 -08:00
|
|
|
bool headphones{device->IsHeadphones != AL_FALSE};
|
2016-04-14 15:25:12 -07:00
|
|
|
if(device->Type != Loopback)
|
|
|
|
{
|
|
|
|
const char *mode;
|
2018-11-18 18:45:45 -08:00
|
|
|
if(ConfigValueStr(device->DeviceName.c_str(), NULL, "stereo-mode", &mode))
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
|
|
|
if(strcasecmp(mode, "headphones") == 0)
|
|
|
|
headphones = true;
|
|
|
|
else if(strcasecmp(mode, "speakers") == 0)
|
|
|
|
headphones = false;
|
|
|
|
else if(strcasecmp(mode, "auto") != 0)
|
|
|
|
ERR("Unexpected stereo-mode: %s\n", mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(hrtf_userreq == Hrtf_Default)
|
|
|
|
{
|
2016-04-16 14:00:22 -07:00
|
|
|
bool usehrtf = (headphones && hrtf_appreq != Hrtf_Disable) ||
|
|
|
|
(hrtf_appreq == Hrtf_Enable);
|
|
|
|
if(!usehrtf) goto no_hrtf;
|
|
|
|
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_ENABLED_SOFT;
|
2016-04-14 15:25:12 -07:00
|
|
|
if(headphones && hrtf_appreq != Hrtf_Disable)
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_HEADPHONES_DETECTED_SOFT;
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-16 14:00:22 -07:00
|
|
|
if(hrtf_userreq != Hrtf_Enable)
|
|
|
|
{
|
|
|
|
if(hrtf_appreq == Hrtf_Enable)
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_DENIED_SOFT;
|
2016-04-16 14:00:22 -07:00
|
|
|
goto no_hrtf;
|
|
|
|
}
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_REQUIRED_SOFT;
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
2018-11-18 19:19:35 -08:00
|
|
|
if(device->HrtfList.empty())
|
2018-11-18 18:45:45 -08:00
|
|
|
device->HrtfList = EnumerateHrtf(device->DeviceName.c_str());
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2018-11-18 19:19:35 -08:00
|
|
|
if(hrtf_id >= 0 && (size_t)hrtf_id < device->HrtfList.size())
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2018-11-18 19:19:35 -08:00
|
|
|
const EnumeratedHrtf &entry = device->HrtfList[hrtf_id];
|
|
|
|
struct Hrtf *hrtf = GetLoadedHrtf(entry.hrtf);
|
2017-04-05 12:27:30 -07:00
|
|
|
if(hrtf && hrtf->sampleRate == device->Frequency)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2017-04-05 11:29:58 -07:00
|
|
|
device->HrtfHandle = hrtf;
|
2018-11-18 19:28:01 -08:00
|
|
|
device->HrtfName = entry.name;
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
2017-04-06 13:00:29 -07:00
|
|
|
else if(hrtf)
|
|
|
|
Hrtf_DecRef(hrtf);
|
|
|
|
}
|
|
|
|
|
2018-12-05 16:35:06 -08:00
|
|
|
if(!device->HrtfHandle)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2018-12-05 16:35:06 -08:00
|
|
|
auto find_hrtf = [device](const EnumeratedHrtf &entry) -> bool
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2018-12-05 16:35:06 -08:00
|
|
|
struct Hrtf *hrtf = GetLoadedHrtf(entry.hrtf);
|
|
|
|
if(!hrtf) return false;
|
|
|
|
if(hrtf->sampleRate != device->Frequency)
|
|
|
|
{
|
|
|
|
Hrtf_DecRef(hrtf);
|
|
|
|
return false;
|
|
|
|
}
|
2017-04-05 11:29:58 -07:00
|
|
|
device->HrtfHandle = hrtf;
|
2018-11-18 19:28:01 -08:00
|
|
|
device->HrtfName = entry.name;
|
2018-12-05 16:35:06 -08:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
std::find_if(device->HrtfList.cbegin(), device->HrtfList.cend(), find_hrtf);
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
2017-03-10 10:47:43 -08:00
|
|
|
if(device->HrtfHandle)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2017-04-06 13:00:29 -07:00
|
|
|
if(old_hrtf)
|
|
|
|
Hrtf_DecRef(old_hrtf);
|
|
|
|
old_hrtf = NULL;
|
|
|
|
|
2016-04-16 14:00:22 -07:00
|
|
|
device->Render_Mode = HrtfRender;
|
2018-12-05 16:35:06 -08:00
|
|
|
const char *mode;
|
2018-11-18 18:45:45 -08:00
|
|
|
if(ConfigValueStr(device->DeviceName.c_str(), NULL, "hrtf-mode", &mode))
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
|
|
|
if(strcasecmp(mode, "full") == 0)
|
|
|
|
device->Render_Mode = HrtfRender;
|
|
|
|
else if(strcasecmp(mode, "basic") == 0)
|
|
|
|
device->Render_Mode = NormalRender;
|
|
|
|
else
|
|
|
|
ERR("Unexpected hrtf-mode: %s\n", mode);
|
|
|
|
}
|
|
|
|
|
2017-01-15 13:57:22 -08:00
|
|
|
if(device->Render_Mode == HrtfRender)
|
|
|
|
{
|
|
|
|
/* Don't bother with HOA when using full HRTF rendering. Nothing
|
|
|
|
* needs it, and it eases the CPU/memory load.
|
|
|
|
*/
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiUp = nullptr;
|
2017-01-15 13:57:22 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!device->AmbiUp)
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiUp.reset(new AmbiUpsampler{});
|
2017-01-15 13:57:22 -08:00
|
|
|
}
|
|
|
|
|
2016-11-01 14:07:14 -07:00
|
|
|
TRACE("%s HRTF rendering enabled, using \"%s\"\n",
|
2018-11-18 19:28:01 -08:00
|
|
|
((device->Render_Mode == HrtfRender) ? "Full" : "Basic"), device->HrtfName.c_str()
|
2016-11-01 14:07:14 -07:00
|
|
|
);
|
2017-04-18 17:39:10 -07:00
|
|
|
InitHrtfPanning(device);
|
2016-04-14 15:25:12 -07:00
|
|
|
return;
|
|
|
|
}
|
2017-03-10 10:47:43 -08:00
|
|
|
device->HrtfStatus = ALC_HRTF_UNSUPPORTED_FORMAT_SOFT;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
|
|
|
no_hrtf:
|
2017-04-06 13:00:29 -07:00
|
|
|
if(old_hrtf)
|
|
|
|
Hrtf_DecRef(old_hrtf);
|
2018-11-22 06:49:37 -08:00
|
|
|
old_hrtf = nullptr;
|
2016-04-14 15:25:12 -07:00
|
|
|
TRACE("HRTF disabled\n");
|
|
|
|
|
2017-02-22 19:18:01 -08:00
|
|
|
device->Render_Mode = StereoPair;
|
|
|
|
|
2018-11-22 05:37:35 -08:00
|
|
|
device->AmbiUp = nullptr;
|
2017-01-15 13:57:22 -08:00
|
|
|
|
2018-12-05 16:35:06 -08:00
|
|
|
int bs2blevel{((headphones && hrtf_appreq != Hrtf_Disable) ||
|
|
|
|
(hrtf_appreq == Hrtf_Enable)) ? 5 : 0};
|
2016-04-14 15:25:12 -07:00
|
|
|
if(device->Type != Loopback)
|
2018-11-18 18:45:45 -08:00
|
|
|
ConfigValueInt(device->DeviceName.c_str(), NULL, "cf_level", &bs2blevel);
|
2016-04-14 15:25:12 -07:00
|
|
|
if(bs2blevel > 0 && bs2blevel <= 6)
|
|
|
|
{
|
2018-11-22 06:49:37 -08:00
|
|
|
device->Bs2b.reset(new bs2b{});
|
|
|
|
bs2b_set_params(device->Bs2b.get(), bs2blevel, device->Frequency);
|
2016-04-14 15:25:12 -07:00
|
|
|
TRACE("BS2B enabled\n");
|
|
|
|
InitPanning(device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("BS2B disabled\n");
|
|
|
|
|
2018-12-05 16:35:06 -08:00
|
|
|
const char *mode;
|
2018-11-18 18:45:45 -08:00
|
|
|
if(ConfigValueStr(device->DeviceName.c_str(), NULL, "stereo-encoding", &mode))
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2017-02-22 19:18:01 -08:00
|
|
|
if(strcasecmp(mode, "uhj") == 0)
|
|
|
|
device->Render_Mode = NormalRender;
|
|
|
|
else if(strcasecmp(mode, "panpot") != 0)
|
|
|
|
ERR("Unexpected stereo-encoding: %s\n", mode);
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
if(device->Render_Mode == NormalRender)
|
|
|
|
{
|
2018-11-21 15:31:32 -08:00
|
|
|
device->Uhj_Encoder.reset(new Uhj2Encoder{});
|
2016-04-14 15:25:12 -07:00
|
|
|
TRACE("UHJ enabled\n");
|
|
|
|
InitUhjPanning(device);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("UHJ disabled\n");
|
|
|
|
InitPanning(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-01-28 00:02:46 -08:00
|
|
|
void aluInitEffectPanning(ALeffectslot *slot)
|
|
|
|
{
|
2018-12-08 14:22:20 -08:00
|
|
|
ALsizei i{0};
|
|
|
|
for(auto &chanmap : slot->ChanMap)
|
2016-04-14 21:50:36 -07:00
|
|
|
{
|
2018-12-08 14:22:20 -08:00
|
|
|
chanmap.Scale = 1.0f;
|
|
|
|
chanmap.Index = i++;
|
2016-04-14 21:50:36 -07:00
|
|
|
}
|
|
|
|
slot->NumChannels = i;
|
2016-01-28 00:02:46 -08:00
|
|
|
}
|