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"
|
|
|
|
|
2019-08-05 18:36:39 -07:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <chrono>
|
2019-01-09 19:42:40 +01:00
|
|
|
#include <cmath>
|
2019-08-05 18:36:39 -07:00
|
|
|
#include <cstdio>
|
2019-01-09 19:42:40 +01:00
|
|
|
#include <cstring>
|
2018-12-10 02:13:57 -08:00
|
|
|
#include <functional>
|
2019-08-05 18:36:39 -07:00
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <new>
|
|
|
|
#include <numeric>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "AL/alext.h"
|
2018-12-08 14:22:20 -08:00
|
|
|
|
2019-07-29 17:54:07 -07:00
|
|
|
#include "al/auxeffectslot.h"
|
2019-07-28 18:33:29 -07:00
|
|
|
#include "alcmain.h"
|
2018-01-11 07:56:54 -08:00
|
|
|
#include "alconfig.h"
|
2020-11-02 04:24:36 -08:00
|
|
|
#include "alcontext.h"
|
2019-08-05 18:36:39 -07:00
|
|
|
#include "almalloc.h"
|
|
|
|
#include "alnumeric.h"
|
|
|
|
#include "aloptional.h"
|
|
|
|
#include "alspan.h"
|
2019-09-16 15:10:36 -07:00
|
|
|
#include "alstring.h"
|
2019-08-05 18:36:39 -07:00
|
|
|
#include "alu.h"
|
2016-03-15 05:08:05 -07:00
|
|
|
#include "ambdec.h"
|
2019-08-05 18:36:39 -07:00
|
|
|
#include "ambidefs.h"
|
2016-03-15 05:08:05 -07:00
|
|
|
#include "bformatdec.h"
|
2016-04-14 15:25:12 -07:00
|
|
|
#include "bs2b.h"
|
2019-08-05 18:36:39 -07:00
|
|
|
#include "devformat.h"
|
2020-06-15 02:05:10 -07:00
|
|
|
#include "front_stablizer.h"
|
2019-08-05 18:36:39 -07:00
|
|
|
#include "hrtf.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "math_defs.h"
|
|
|
|
#include "opthelpers.h"
|
|
|
|
#include "uhjfilter.h"
|
2019-05-23 13:30:16 -07:00
|
|
|
|
2010-08-03 00:21:36 -07:00
|
|
|
|
2019-02-19 15:39:33 -08:00
|
|
|
constexpr std::array<float,MAX_AMBI_CHANNELS> AmbiScale::FromN3D;
|
|
|
|
constexpr std::array<float,MAX_AMBI_CHANNELS> AmbiScale::FromSN3D;
|
|
|
|
constexpr std::array<float,MAX_AMBI_CHANNELS> AmbiScale::FromFuMa;
|
2019-09-14 08:29:02 -07:00
|
|
|
constexpr std::array<uint8_t,MAX_AMBI_CHANNELS> AmbiIndex::FromFuMa;
|
2019-12-01 17:52:36 -08:00
|
|
|
constexpr std::array<uint8_t,MAX_AMBI2D_CHANNELS> AmbiIndex::FromFuMa2D;
|
2019-09-14 08:29:02 -07:00
|
|
|
constexpr std::array<uint8_t,MAX_AMBI_CHANNELS> AmbiIndex::FromACN;
|
|
|
|
constexpr std::array<uint8_t,MAX_AMBI2D_CHANNELS> AmbiIndex::From2D;
|
2020-01-04 00:59:49 -08:00
|
|
|
constexpr std::array<uint8_t,MAX_AMBI_CHANNELS> AmbiIndex::OrderFromChannel;
|
|
|
|
constexpr std::array<uint8_t,MAX_AMBI2D_CHANNELS> AmbiIndex::OrderFrom2DChannel;
|
2018-11-12 19:02:38 -08:00
|
|
|
|
2018-12-15 23:28:49 -08:00
|
|
|
|
|
|
|
namespace {
|
2015-08-28 10:58:30 -07:00
|
|
|
|
2019-03-16 15:15:59 -07:00
|
|
|
using namespace std::placeholders;
|
2019-03-31 18:54:43 -07:00
|
|
|
using std::chrono::seconds;
|
|
|
|
using std::chrono::nanoseconds;
|
2019-03-16 15:15:59 -07:00
|
|
|
|
2018-12-15 00:38:38 -08:00
|
|
|
inline const char *GetLabelFromChannel(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
|
|
|
|
2020-06-15 13:49:45 -07:00
|
|
|
case TopFrontLeft: return "top-front-left";
|
|
|
|
case TopFrontCenter: return "top-front-center";
|
|
|
|
case TopFrontRight: return "top-front-right";
|
|
|
|
case TopCenter: return "top-center";
|
|
|
|
case TopBackLeft: return "top-back-left";
|
|
|
|
case TopBackCenter: return "top-back-center";
|
|
|
|
case TopBackRight: return "top-back-right";
|
2016-02-20 00:53:01 -08:00
|
|
|
|
2019-04-02 15:53:27 -07:00
|
|
|
case MaxChannels: break;
|
2014-11-15 00:19:56 -08:00
|
|
|
}
|
|
|
|
return "(unknown)";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
std::unique_ptr<FrontStablizer> CreateStablizer(const size_t outchans, const ALuint srate)
|
|
|
|
{
|
|
|
|
auto stablizer = FrontStablizer::Create(outchans);
|
|
|
|
for(auto &buf : stablizer->DelayBuf)
|
|
|
|
std::fill(buf.begin(), buf.end(), 0.0f);
|
|
|
|
|
|
|
|
/* Initialize band-splitting filter for the mid signal, with a crossover at
|
|
|
|
* 5khz (could be higher).
|
|
|
|
*/
|
|
|
|
stablizer->MidFilter.init(5000.0f / static_cast<float>(srate));
|
|
|
|
|
|
|
|
return stablizer;
|
|
|
|
}
|
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
void AllocChannels(ALCdevice *device, const size_t main_chans, const size_t real_chans)
|
2019-07-03 22:32:39 -07:00
|
|
|
{
|
2020-05-06 14:53:27 -07:00
|
|
|
TRACE("Channel config, Main: %zu, Real: %zu\n", main_chans, real_chans);
|
2019-07-03 22:32:39 -07:00
|
|
|
|
|
|
|
/* Allocate extra channels for any post-filter output. */
|
2020-05-06 14:53:27 -07:00
|
|
|
const size_t num_chans{main_chans + real_chans};
|
2019-07-03 22:32:39 -07:00
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
TRACE("Allocating %zu channels, %zu bytes\n", num_chans,
|
2019-07-03 22:32:39 -07:00
|
|
|
num_chans*sizeof(device->MixBuffer[0]));
|
|
|
|
device->MixBuffer.resize(num_chans);
|
2020-05-06 14:53:27 -07:00
|
|
|
al::span<FloatBufferLine> buffer{device->MixBuffer};
|
2019-07-03 22:32:39 -07:00
|
|
|
|
2019-07-04 15:02:12 -07:00
|
|
|
device->Dry.Buffer = buffer.first(main_chans);
|
|
|
|
buffer = buffer.subspan(main_chans);
|
2019-07-03 22:32:39 -07:00
|
|
|
if(real_chans != 0)
|
2019-07-04 15:02:12 -07:00
|
|
|
{
|
|
|
|
device->RealOut.Buffer = buffer.first(real_chans);
|
|
|
|
buffer = buffer.subspan(real_chans);
|
|
|
|
}
|
2019-07-03 22:32:39 -07:00
|
|
|
else
|
2019-07-04 15:02:12 -07:00
|
|
|
device->RealOut.Buffer = device->Dry.Buffer;
|
2019-07-03 22:32:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-22 22:53:22 -08:00
|
|
|
struct ChannelMap {
|
|
|
|
Channel ChanName;
|
2020-04-08 06:17:04 -07:00
|
|
|
float Config[MAX_AMBI2D_CHANNELS];
|
2018-11-22 22:53:22 -08:00
|
|
|
};
|
2014-11-05 03:46:00 -08:00
|
|
|
|
2019-09-12 04:17:21 -07:00
|
|
|
bool MakeSpeakerMap(ALCdevice *device, const AmbDecConf *conf, ALuint (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2016-03-15 05:08:05 -07:00
|
|
|
{
|
2019-09-12 04:17:21 -07:00
|
|
|
auto map_spkr = [device](const AmbDecConf::SpeakerConf &speaker) -> ALuint
|
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
|
|
|
|
{
|
2020-06-15 02:27:29 -07:00
|
|
|
ERR("AmbDec speaker label \"%s\" not recognized\n", speaker.Name.c_str());
|
|
|
|
return INVALID_CHANNEL_INDEX;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
2019-09-12 04:17:21 -07:00
|
|
|
const ALuint chidx{GetChannelIdxByName(device->RealOut, ch)};
|
|
|
|
if(chidx == INVALID_CHANNEL_INDEX)
|
2018-12-10 14:49:57 -08:00
|
|
|
ERR("Failed to lookup AmbDec speaker label %s\n", speaker.Name.c_str());
|
|
|
|
return chidx;
|
|
|
|
};
|
2018-12-15 02:42:04 -08:00
|
|
|
std::transform(conf->Speakers.begin(), conf->Speakers.end(), std::begin(speakermap), map_spkr);
|
2018-12-10 14:49:57 -08:00
|
|
|
/* Return success if no invalid entries are found. */
|
2019-09-12 04:17:21 -07:00
|
|
|
auto spkrmap_end = std::begin(speakermap) + conf->Speakers.size();
|
|
|
|
return std::find(std::begin(speakermap), spkrmap_end, INVALID_CHANNEL_INDEX) == spkrmap_end;
|
2016-03-15 05:08:05 -07:00
|
|
|
}
|
|
|
|
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2020-04-08 06:17:04 -07:00
|
|
|
void InitNearFieldCtrl(ALCdevice *device, float ctrl_dist, ALuint order, bool is3d)
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2020-06-16 14:01:39 -07:00
|
|
|
static const ALuint chans_per_order2d[MAX_AMBI_ORDER+1]{ 1, 2, 2, 2 };
|
|
|
|
static const ALuint chans_per_order3d[MAX_AMBI_ORDER+1]{ 1, 3, 5, 7 };
|
|
|
|
|
2019-04-29 12:50:13 -07:00
|
|
|
/* NFC is only used when AvgSpeakerDist is greater than 0. */
|
2018-12-10 14:49:57 -08:00
|
|
|
const char *devname{device->DeviceName.c_str()};
|
2019-04-29 13:07:02 -07:00
|
|
|
if(!GetConfigValueBool(devname, "decoder", "nfc", 0) || !(ctrl_dist > 0.0f))
|
2018-12-10 14:49:57 -08:00
|
|
|
return;
|
|
|
|
|
2019-07-06 19:09:26 -07:00
|
|
|
device->AvgSpeakerDist = clampf(ctrl_dist, 0.1f, 10.0f);
|
2018-12-10 14:49:57 -08:00
|
|
|
TRACE("Using near-field reference distance: %.2f meters\n", device->AvgSpeakerDist);
|
|
|
|
|
2020-06-16 14:01:39 -07:00
|
|
|
auto iter = std::copy_n(is3d ? chans_per_order3d : chans_per_order2d, order+1u,
|
2018-12-10 14:49:57 -08:00
|
|
|
std::begin(device->NumChannelsPerOrder));
|
2019-06-05 23:00:28 -07:00
|
|
|
std::fill(iter, std::end(device->NumChannelsPerOrder), 0u);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
|
2019-09-12 04:17:21 -07:00
|
|
|
void InitDistanceComp(ALCdevice *device, const AmbDecConf *conf,
|
|
|
|
const ALuint (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2017-03-10 04:35:32 -08:00
|
|
|
{
|
2019-06-08 01:39:28 -07:00
|
|
|
auto get_max = std::bind(maxf, _1,
|
|
|
|
std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2));
|
2020-04-08 06:17:04 -07:00
|
|
|
const float maxdist{std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), 0.0f,
|
|
|
|
get_max)};
|
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
|
|
|
|
2020-10-21 16:39:21 -07:00
|
|
|
const auto distSampleScale = static_cast<float>(device->Frequency) / SpeedOfSoundMetersPerSec;
|
2019-06-08 01:39:28 -07:00
|
|
|
const auto ChanDelay = device->ChannelDelay.as_span();
|
2018-12-10 14:49:57 -08:00
|
|
|
size_t total{0u};
|
2018-12-15 02:42:04 -08:00
|
|
|
for(size_t i{0u};i < conf->Speakers.size();i++)
|
2018-12-10 14:49:57 -08:00
|
|
|
{
|
|
|
|
const AmbDecConf::SpeakerConf &speaker = conf->Speakers[i];
|
2019-09-12 04:17:21 -07:00
|
|
|
const ALuint chan{speakermap[i]};
|
2018-12-10 14:49:57 -08:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
2020-04-08 06:17:04 -07:00
|
|
|
float delay{std::floor((maxdist - speaker.Distance)*distSampleScale + 0.5f)};
|
|
|
|
if(delay > float{MAX_DELAY_LENGTH-1})
|
2019-06-08 01:39:28 -07:00
|
|
|
{
|
|
|
|
ERR("Delay for speaker \"%s\" exceeds buffer length (%f > %d)\n",
|
|
|
|
speaker.Name.c_str(), delay, MAX_DELAY_LENGTH-1);
|
2020-04-08 06:17:04 -07:00
|
|
|
delay = float{MAX_DELAY_LENGTH-1};
|
2019-06-08 01:39:28 -07:00
|
|
|
}
|
|
|
|
|
2019-08-25 17:54:36 -07:00
|
|
|
ChanDelay[chan].Length = static_cast<ALuint>(delay);
|
2019-06-08 01:39:28 -07:00
|
|
|
ChanDelay[chan].Gain = speaker.Distance / maxdist;
|
2019-08-25 17:54:36 -07:00
|
|
|
TRACE("Channel %u \"%s\" distance compensation: %u samples, %f gain\n", chan,
|
2019-06-08 01:39:28 -07:00
|
|
|
speaker.Name.c_str(), ChanDelay[chan].Length, ChanDelay[chan].Gain);
|
2018-12-10 14:49:57 -08:00
|
|
|
|
|
|
|
/* Round up to the next 4th sample, so each channel buffer starts
|
|
|
|
* 16-byte aligned.
|
|
|
|
*/
|
2019-06-08 01:39:28 -07:00
|
|
|
total += RoundUp(ChanDelay[chan].Length, 4);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(total > 0)
|
|
|
|
{
|
2019-06-08 01:39:28 -07:00
|
|
|
device->ChannelDelay.setSampleCount(total);
|
|
|
|
ChanDelay[0].Buffer = device->ChannelDelay.getSamples();
|
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;
|
|
|
|
};
|
2019-06-08 01:39:28 -07:00
|
|
|
std::partial_sum(ChanDelay.begin(), ChanDelay.end(), ChanDelay.begin(), set_bufptr);
|
2017-03-10 04:35:32 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 22:32:10 -08:00
|
|
|
|
2020-08-28 00:09:46 -07:00
|
|
|
auto GetAmbiScales(DevAmbiScaling scaletype) noexcept -> const std::array<float,MAX_AMBI_CHANNELS>&
|
2018-12-10 22:32:10 -08:00
|
|
|
{
|
2020-08-28 00:09:46 -07:00
|
|
|
if(scaletype == DevAmbiScaling::FuMa) return AmbiScale::FromFuMa;
|
|
|
|
if(scaletype == DevAmbiScaling::SN3D) return AmbiScale::FromSN3D;
|
2018-12-20 02:46:59 -08:00
|
|
|
return AmbiScale::FromN3D;
|
2018-12-10 22:32:10 -08:00
|
|
|
}
|
|
|
|
|
2020-08-28 00:09:46 -07:00
|
|
|
auto GetAmbiLayout(DevAmbiLayout layouttype) noexcept -> const std::array<uint8_t,MAX_AMBI_CHANNELS>&
|
2018-12-10 22:32:10 -08:00
|
|
|
{
|
2020-08-28 00:09:46 -07:00
|
|
|
if(layouttype == DevAmbiLayout::FuMa) return AmbiIndex::FromFuMa;
|
2018-12-20 02:46:59 -08:00
|
|
|
return AmbiIndex::FromACN;
|
2018-12-10 22:32:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
using ChannelCoeffs = std::array<float,MAX_AMBI2D_CHANNELS>;
|
2020-05-07 02:13:11 -07:00
|
|
|
enum DecoderMode : bool {
|
|
|
|
SingleBand = false,
|
|
|
|
DualBand = true
|
|
|
|
};
|
|
|
|
|
|
|
|
template<DecoderMode Mode, size_t N>
|
|
|
|
struct DecoderConfig;
|
|
|
|
|
|
|
|
template<size_t N>
|
|
|
|
struct DecoderConfig<SingleBand, N> {
|
|
|
|
ALuint mOrder;
|
|
|
|
std::array<Channel,N> mChannels;
|
|
|
|
std::array<float,MAX_AMBI_ORDER+1> mOrderGain;
|
|
|
|
std::array<ChannelCoeffs,N> mCoeffs;
|
|
|
|
};
|
2020-05-06 14:53:27 -07:00
|
|
|
|
|
|
|
template<size_t N>
|
2020-05-07 02:13:11 -07:00
|
|
|
struct DecoderConfig<DualBand, N> {
|
2020-05-06 14:53:27 -07:00
|
|
|
ALuint mOrder;
|
|
|
|
std::array<Channel,N> mChannels;
|
|
|
|
std::array<float,MAX_AMBI_ORDER+1> mOrderGain;
|
|
|
|
std::array<ChannelCoeffs,N> mCoeffs;
|
2020-05-07 02:13:11 -07:00
|
|
|
std::array<float,MAX_AMBI_ORDER+1> mOrderGainLF;
|
|
|
|
std::array<ChannelCoeffs,N> mCoeffsLF;
|
2020-05-06 14:53:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
2020-05-07 02:13:11 -07:00
|
|
|
struct DecoderConfig<DualBand, 0> {
|
2020-05-06 14:53:27 -07:00
|
|
|
ALuint mOrder;
|
|
|
|
al::span<const Channel> mChannels;
|
|
|
|
al::span<const float> mOrderGain;
|
|
|
|
al::span<const ChannelCoeffs> mCoeffs;
|
2020-05-07 02:13:11 -07:00
|
|
|
al::span<const float> mOrderGainLF;
|
|
|
|
al::span<const ChannelCoeffs> mCoeffsLF;
|
2020-05-06 14:53:27 -07:00
|
|
|
|
|
|
|
template<size_t N>
|
2020-05-07 02:13:11 -07:00
|
|
|
DecoderConfig& operator=(const DecoderConfig<SingleBand,N> &rhs) noexcept
|
2020-05-06 14:53:27 -07:00
|
|
|
{
|
|
|
|
mOrder = rhs.mOrder;
|
|
|
|
mChannels = rhs.mChannels;
|
|
|
|
mOrderGain = rhs.mOrderGain;
|
|
|
|
mCoeffs = rhs.mCoeffs;
|
2020-05-07 02:13:11 -07:00
|
|
|
mOrderGainLF = {};
|
|
|
|
mCoeffsLF = {};
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<size_t N>
|
|
|
|
DecoderConfig& operator=(const DecoderConfig<DualBand,N> &rhs) noexcept
|
|
|
|
{
|
|
|
|
mOrder = rhs.mOrder;
|
|
|
|
mChannels = rhs.mChannels;
|
|
|
|
mOrderGain = rhs.mOrderGain;
|
|
|
|
mCoeffs = rhs.mCoeffs;
|
|
|
|
mOrderGainLF = rhs.mOrderGainLF;
|
|
|
|
mCoeffsLF = rhs.mCoeffsLF;
|
2020-05-06 14:53:27 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
2020-05-07 02:13:11 -07:00
|
|
|
using DecoderView = DecoderConfig<DualBand, 0>;
|
2020-05-06 14:53:27 -07:00
|
|
|
|
2020-05-07 02:13:11 -07:00
|
|
|
constexpr DecoderConfig<SingleBand, 1> MonoConfig{
|
2020-05-06 14:53:27 -07:00
|
|
|
0, {{FrontCenter}},
|
|
|
|
{{1.0f}},
|
|
|
|
{{ {{1.0f}} }}
|
|
|
|
};
|
2020-05-07 02:13:11 -07:00
|
|
|
constexpr DecoderConfig<SingleBand, 2> StereoConfig{
|
2020-05-06 14:53:27 -07:00
|
|
|
1, {{FrontLeft, FrontRight}},
|
|
|
|
{{1.0f, 1.0f}},
|
|
|
|
{{
|
|
|
|
{{5.00000000e-1f, 2.88675135e-1f, 5.52305643e-2f}},
|
|
|
|
{{5.00000000e-1f, -2.88675135e-1f, 5.52305643e-2f}},
|
|
|
|
}}
|
|
|
|
};
|
2020-05-07 03:15:46 -07:00
|
|
|
constexpr DecoderConfig<DualBand, 4> QuadConfig{
|
2020-05-06 22:36:29 -07:00
|
|
|
2, {{BackLeft, FrontLeft, FrontRight, BackRight}},
|
2020-05-07 03:15:46 -07:00
|
|
|
/*HF*/{{1.15470054e+0f, 1.00000000e+0f, 5.77350269e-1f}},
|
|
|
|
{{
|
|
|
|
{{2.50000000e-1f, 2.04124145e-1f, -2.04124145e-1f, -1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, 2.04124145e-1f, 2.04124145e-1f, 1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, -2.04124145e-1f, 2.04124145e-1f, -1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, -2.04124145e-1f, -2.04124145e-1f, 1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
}},
|
|
|
|
/*LF*/{{1.00000000e+0f, 1.00000000e+0f, 1.00000000e+0f}},
|
2020-05-06 14:53:27 -07:00
|
|
|
{{
|
2020-05-06 22:36:29 -07:00
|
|
|
{{2.50000000e-1f, 2.04124145e-1f, -2.04124145e-1f, -1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, 2.04124145e-1f, 2.04124145e-1f, 1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, -2.04124145e-1f, 2.04124145e-1f, -1.29099445e-1f, 0.00000000e+0f}},
|
|
|
|
{{2.50000000e-1f, -2.04124145e-1f, -2.04124145e-1f, 1.29099445e-1f, 0.00000000e+0f}},
|
2020-05-06 14:53:27 -07:00
|
|
|
}}
|
|
|
|
};
|
2020-05-07 02:13:11 -07:00
|
|
|
constexpr DecoderConfig<SingleBand, 4> X51Config{
|
2020-05-06 14:53:27 -07:00
|
|
|
2, {{SideLeft, FrontLeft, FrontRight, SideRight}},
|
|
|
|
{{1.0f, 1.0f, 1.0f}},
|
|
|
|
{{
|
|
|
|
{{3.33000782e-1f, 1.89084803e-1f, -2.00042375e-1f, -2.12307769e-2f, -1.14579885e-2f}},
|
|
|
|
{{1.88542860e-1f, 1.27709292e-1f, 1.66295695e-1f, 7.30571517e-2f, 2.10901184e-2f}},
|
|
|
|
{{1.88542860e-1f, -1.27709292e-1f, 1.66295695e-1f, -7.30571517e-2f, 2.10901184e-2f}},
|
|
|
|
{{3.33000782e-1f, -1.89084803e-1f, -2.00042375e-1f, 2.12307769e-2f, -1.14579885e-2f}},
|
|
|
|
}}
|
|
|
|
};
|
2020-05-07 02:13:11 -07:00
|
|
|
constexpr DecoderConfig<SingleBand, 4> X51RearConfig{
|
2020-05-06 14:53:27 -07:00
|
|
|
2, {{BackLeft, FrontLeft, FrontRight, BackRight}},
|
|
|
|
{{1.0f, 1.0f, 1.0f}},
|
|
|
|
{{
|
|
|
|
{{3.33000782e-1f, 1.89084803e-1f, -2.00042375e-1f, -2.12307769e-2f, -1.14579885e-2f}},
|
|
|
|
{{1.88542860e-1f, 1.27709292e-1f, 1.66295695e-1f, 7.30571517e-2f, 2.10901184e-2f}},
|
|
|
|
{{1.88542860e-1f, -1.27709292e-1f, 1.66295695e-1f, -7.30571517e-2f, 2.10901184e-2f}},
|
|
|
|
{{3.33000782e-1f, -1.89084803e-1f, -2.00042375e-1f, 2.12307769e-2f, -1.14579885e-2f}},
|
|
|
|
}}
|
|
|
|
};
|
2020-05-07 02:13:11 -07:00
|
|
|
constexpr DecoderConfig<SingleBand, 5> X61Config{
|
2020-05-06 14:53:27 -07:00
|
|
|
2, {{SideLeft, FrontLeft, FrontRight, SideRight, BackCenter}},
|
|
|
|
{{1.0f, 1.0f, 1.0f}},
|
|
|
|
{{
|
|
|
|
{{2.04460341e-1f, 2.17177926e-1f, -4.39996780e-2f, -2.60790269e-2f, -6.87239792e-2f}},
|
|
|
|
{{1.58923161e-1f, 9.21772680e-2f, 1.59658796e-1f, 6.66278083e-2f, 3.84686854e-2f}},
|
|
|
|
{{1.58923161e-1f, -9.21772680e-2f, 1.59658796e-1f, -6.66278083e-2f, 3.84686854e-2f}},
|
|
|
|
{{2.04460341e-1f, -2.17177926e-1f, -4.39996780e-2f, 2.60790269e-2f, -6.87239792e-2f}},
|
|
|
|
{{2.50001688e-1f, 0.00000000e+0f, -2.50000094e-1f, 0.00000000e+0f, 6.05133395e-2f}},
|
|
|
|
}}
|
|
|
|
};
|
2020-05-07 03:15:46 -07:00
|
|
|
constexpr DecoderConfig<DualBand, 6> X71Config{
|
2020-05-06 14:53:27 -07:00
|
|
|
3, {{BackLeft, SideLeft, FrontLeft, FrontRight, SideRight, BackRight}},
|
2020-05-07 03:15:46 -07:00
|
|
|
/*HF*/{{1.22474487e+0f, 1.13151672e+0f, 8.66025404e-1f, 4.68689571e-1f}},
|
|
|
|
{{
|
|
|
|
{{1.66666667e-1f, 9.62250449e-2f, -1.66666667e-1f, -1.49071198e-1f, 8.60662966e-2f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, 1.92450090e-1f, 0.00000000e+0f, 0.00000000e+0f, -1.72132593e-1f, -7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, 9.62250449e-2f, 1.66666667e-1f, 1.49071198e-1f, 8.60662966e-2f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -9.62250449e-2f, 1.66666667e-1f, -1.49071198e-1f, 8.60662966e-2f, -7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -1.92450090e-1f, 0.00000000e+0f, 0.00000000e+0f, -1.72132593e-1f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -9.62250449e-2f, -1.66666667e-1f, 1.49071198e-1f, 8.60662966e-2f, -7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
}},
|
|
|
|
/*LF*/{{1.00000000e+0f, 1.00000000e+0f, 1.00000000e+0f, 1.00000000e+0f}},
|
2020-05-06 14:53:27 -07:00
|
|
|
{{
|
2020-05-06 22:36:29 -07:00
|
|
|
{{1.66666667e-1f, 9.62250449e-2f, -1.66666667e-1f, -1.49071198e-1f, 8.60662966e-2f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, 1.92450090e-1f, 0.00000000e+0f, 0.00000000e+0f, -1.72132593e-1f, -7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, 9.62250449e-2f, 1.66666667e-1f, 1.49071198e-1f, 8.60662966e-2f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -9.62250449e-2f, 1.66666667e-1f, -1.49071198e-1f, 8.60662966e-2f, -7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -1.92450090e-1f, 0.00000000e+0f, 0.00000000e+0f, -1.72132593e-1f, 7.96819073e-2f, 0.00000000e+0f}},
|
|
|
|
{{1.66666667e-1f, -9.62250449e-2f, -1.66666667e-1f, 1.49071198e-1f, 8.60662966e-2f, -7.96819073e-2f, 0.00000000e+0f}},
|
2020-05-06 14:53:27 -07:00
|
|
|
}}
|
|
|
|
};
|
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
void InitPanning(ALCdevice *device, const bool hqdec=false, const bool stablize=false)
|
2016-04-14 10:44:57 -07:00
|
|
|
{
|
2020-05-07 02:13:11 -07:00
|
|
|
DecoderView decoder{};
|
2014-09-10 17:53:01 -07:00
|
|
|
switch(device->FmtChans)
|
2010-08-03 00:21:36 -07:00
|
|
|
{
|
2020-05-06 14:53:27 -07:00
|
|
|
case DevFmtMono:
|
|
|
|
decoder = MonoConfig;
|
|
|
|
break;
|
|
|
|
case DevFmtStereo:
|
|
|
|
decoder = StereoConfig;
|
|
|
|
break;
|
|
|
|
case DevFmtQuad:
|
|
|
|
decoder = QuadConfig;
|
|
|
|
break;
|
|
|
|
case DevFmtX51:
|
|
|
|
decoder = X51Config;
|
|
|
|
break;
|
|
|
|
case DevFmtX51Rear:
|
|
|
|
decoder = X51RearConfig;
|
|
|
|
break;
|
|
|
|
case DevFmtX61:
|
|
|
|
decoder = X61Config;
|
|
|
|
break;
|
|
|
|
case DevFmtX71:
|
|
|
|
decoder = X71Config;
|
|
|
|
break;
|
|
|
|
case DevFmtAmbi3D:
|
|
|
|
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()};
|
2019-09-14 08:29:02 -07:00
|
|
|
const std::array<uint8_t,MAX_AMBI_CHANNELS> &acnmap = GetAmbiLayout(device->mAmbiLayout);
|
2019-02-19 15:39:33 -08:00
|
|
|
const std::array<float,MAX_AMBI_CHANNELS> &n3dscale = GetAmbiScales(device->mAmbiScale);
|
2016-07-29 21:55:43 -07:00
|
|
|
|
2019-02-21 01:23:11 -08:00
|
|
|
/* For DevFmtAmbi3D, the ambisonic order is already set. */
|
2019-05-23 13:30:16 -07:00
|
|
|
const size_t count{AmbiChannelsFromOrder(device->mAmbiOrder)};
|
2019-01-05 21:55:14 -08:00
|
|
|
std::transform(acnmap.begin(), acnmap.begin()+count, std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[&n3dscale](const uint8_t &acn) noexcept -> BFChannelConfig
|
2018-12-15 00:38:38 -08:00
|
|
|
{ return BFChannelConfig{1.0f/n3dscale[acn], acn}; }
|
|
|
|
);
|
2020-05-06 14:53:27 -07:00
|
|
|
AllocChannels(device, count, 0);
|
2016-07-29 21:55:43 -07:00
|
|
|
|
2020-04-08 06:17:04 -07:00
|
|
|
float nfc_delay{ConfigValueFloat(devname, "decoder", "nfc-ref-delay").value_or(0.0f)};
|
2019-06-30 16:38:25 -07:00
|
|
|
if(nfc_delay > 0.0f)
|
2020-10-21 16:39:21 -07:00
|
|
|
InitNearFieldCtrl(device, nfc_delay * SpeedOfSoundMetersPerSec, device->mAmbiOrder,
|
2020-01-04 16:49:49 -08:00
|
|
|
true);
|
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
|
|
|
{
|
2020-05-07 03:15:46 -07:00
|
|
|
const bool dual_band{hqdec && !decoder.mCoeffsLF.empty()};
|
|
|
|
al::vector<ChannelDec> chancoeffs, chancoeffslf;
|
2020-05-06 14:53:27 -07:00
|
|
|
for(size_t i{0u};i < decoder.mChannels.size();++i)
|
2019-01-05 19:21:25 -08:00
|
|
|
{
|
2020-05-06 14:53:27 -07:00
|
|
|
const ALuint idx{GetChannelIdxByName(device->RealOut, decoder.mChannels[i])};
|
2019-09-12 04:17:21 -07:00
|
|
|
if(idx == INVALID_CHANNEL_INDEX)
|
2019-01-05 19:21:25 -08:00
|
|
|
{
|
|
|
|
ERR("Failed to find %s channel in device\n",
|
2020-05-06 14:53:27 -07:00
|
|
|
GetLabelFromChannel(decoder.mChannels[i]));
|
2019-01-05 19:21:25 -08:00
|
|
|
continue;
|
|
|
|
}
|
2020-05-06 14:53:27 -07:00
|
|
|
|
2020-05-07 03:15:46 -07:00
|
|
|
chancoeffs.resize(maxz(chancoeffs.size(), idx+1u), ChannelDec{});
|
|
|
|
al::span<float,MAX_AMBI_CHANNELS> coeffs{chancoeffs[idx]};
|
2020-05-06 14:53:27 -07:00
|
|
|
size_t start{0};
|
|
|
|
for(ALuint o{0};o <= decoder.mOrder;++o)
|
|
|
|
{
|
|
|
|
size_t count{o ? 2u : 1u};
|
|
|
|
do {
|
2020-05-07 03:15:46 -07:00
|
|
|
coeffs[start] = decoder.mCoeffs[i][start] * decoder.mOrderGain[o];
|
|
|
|
++start;
|
|
|
|
} while(--count);
|
|
|
|
}
|
|
|
|
if(!dual_band)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
chancoeffslf.resize(maxz(chancoeffslf.size(), idx+1u), ChannelDec{});
|
|
|
|
coeffs = chancoeffslf[idx];
|
|
|
|
start = 0;
|
|
|
|
for(ALuint o{0};o <= decoder.mOrder;++o)
|
|
|
|
{
|
|
|
|
size_t count{o ? 2u : 1u};
|
|
|
|
do {
|
|
|
|
coeffs[start] = decoder.mCoeffsLF[i][start] * decoder.mOrderGainLF[o];
|
2020-05-06 14:53:27 -07:00
|
|
|
++start;
|
|
|
|
} while(--count);
|
|
|
|
}
|
2019-01-05 19:21:25 -08:00
|
|
|
}
|
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
/* For non-DevFmtAmbi3D, set the ambisonic order. */
|
|
|
|
device->mAmbiOrder = decoder.mOrder;
|
2019-02-21 01:23:11 -08:00
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
/* Built-in speaker decoders are always 2D. */
|
|
|
|
const size_t ambicount{Ambi2DChannelsFromOrder(decoder.mOrder)};
|
|
|
|
std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+ambicount,
|
2019-01-05 21:55:14 -08:00
|
|
|
std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
2019-01-05 19:21:25 -08:00
|
|
|
);
|
2020-05-06 14:53:27 -07:00
|
|
|
AllocChannels(device, ambicount, device->channelsFromFmt());
|
2019-01-05 19:21:25 -08:00
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
std::unique_ptr<FrontStablizer> stablizer;
|
|
|
|
if(stablize)
|
|
|
|
{
|
|
|
|
/* Only enable the stablizer if the decoder does not output to the
|
|
|
|
* front-center channel.
|
|
|
|
*/
|
|
|
|
const auto cidx = device->RealOut.ChannelIndex[FrontCenter];
|
|
|
|
bool hasfc{false};
|
|
|
|
if(cidx < chancoeffs.size())
|
|
|
|
{
|
|
|
|
for(const auto &coeff : chancoeffs[cidx])
|
|
|
|
hasfc |= coeff != 0.0f;
|
|
|
|
}
|
|
|
|
if(!hasfc && cidx < chancoeffslf.size())
|
|
|
|
{
|
|
|
|
for(const auto &coeff : chancoeffslf[cidx])
|
|
|
|
hasfc |= coeff != 0.0f;
|
|
|
|
}
|
|
|
|
if(!hasfc)
|
|
|
|
{
|
|
|
|
stablizer = CreateStablizer(device->channelsFromFmt(), device->Frequency);
|
|
|
|
TRACE("Front stablizer enabled\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 03:15:46 -07:00
|
|
|
TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
|
|
|
|
!dual_band ? "single" : "dual",
|
2020-05-06 14:53:27 -07:00
|
|
|
(decoder.mOrder > 2) ? "third" :
|
|
|
|
(decoder.mOrder > 1) ? "second" : "first",
|
2020-01-04 00:37:59 -08:00
|
|
|
"");
|
2020-06-15 02:05:10 -07:00
|
|
|
device->AmbiDecoder = BFormatDec::Create(ambicount, chancoeffs, chancoeffslf,
|
|
|
|
std::move(stablizer));
|
2016-03-25 23:25:13 -07:00
|
|
|
}
|
2010-08-03 00:21:36 -07:00
|
|
|
}
|
2016-01-28 00:02:46 -08:00
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
void InitCustomPanning(ALCdevice *device, const bool hqdec, const bool stablize,
|
|
|
|
const AmbDecConf *conf, const ALuint (&speakermap)[MAX_OUTPUT_CHANNELS])
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2019-04-29 12:50:13 -07:00
|
|
|
if(!hqdec && conf->FreqBands != 1)
|
|
|
|
ERR("Basic renderer uses the high-frequency matrix as single-band (xover_freq = %.0fhz)\n",
|
|
|
|
conf->XOverFreq);
|
|
|
|
|
2019-09-12 04:17:21 -07:00
|
|
|
const ALuint order{(conf->ChanMask > AMBI_2ORDER_MASK) ? 3u :
|
|
|
|
(conf->ChanMask > AMBI_1ORDER_MASK) ? 2u : 1u};
|
2019-09-13 20:04:22 -07:00
|
|
|
device->mAmbiOrder = order;
|
2019-02-21 01:23:11 -08:00
|
|
|
|
2020-05-06 14:53:27 -07:00
|
|
|
size_t count;
|
2016-06-01 05:30:06 -07:00
|
|
|
if((conf->ChanMask&AMBI_PERIPHONIC_MASK))
|
2016-04-15 22:05:47 -07:00
|
|
|
{
|
2020-05-06 14:53:27 -07:00
|
|
|
count = AmbiChannelsFromOrder(order);
|
2020-01-04 00:04:55 -08:00
|
|
|
std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+count,
|
2019-01-05 21:55:14 -08:00
|
|
|
std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
2018-12-09 22:34:21 -08:00
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-06 14:53:27 -07:00
|
|
|
count = Ambi2DChannelsFromOrder(order);
|
2018-12-20 04:19:35 -08:00
|
|
|
std::transform(AmbiIndex::From2D.begin(), AmbiIndex::From2D.begin()+count,
|
2019-01-05 21:55:14 -08:00
|
|
|
std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
2018-12-09 22:34:21 -08:00
|
|
|
);
|
2016-04-15 22:05:47 -07:00
|
|
|
}
|
2019-07-03 22:32:39 -07:00
|
|
|
AllocChannels(device, count, device->channelsFromFmt());
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
std::unique_ptr<FrontStablizer> stablizer;
|
|
|
|
if(stablize)
|
|
|
|
{
|
|
|
|
/* Only enable the stablizer if the decoder does not output to the
|
|
|
|
* front-center channel.
|
|
|
|
*/
|
|
|
|
size_t cidx{0};
|
|
|
|
for(;cidx < conf->Speakers.size();++cidx)
|
|
|
|
{
|
|
|
|
if(speakermap[cidx] == FrontCenter)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool hasfc{false};
|
|
|
|
if(cidx < conf->LFMatrix.size())
|
|
|
|
{
|
|
|
|
for(const auto &coeff : conf->LFMatrix[cidx])
|
|
|
|
hasfc |= coeff != 0.0f;
|
|
|
|
}
|
|
|
|
if(!hasfc && cidx < conf->HFMatrix.size())
|
|
|
|
{
|
|
|
|
for(const auto &coeff : conf->HFMatrix[cidx])
|
|
|
|
hasfc |= coeff != 0.0f;
|
|
|
|
}
|
|
|
|
if(!hasfc)
|
|
|
|
{
|
|
|
|
stablizer = CreateStablizer(device->channelsFromFmt(), device->Frequency);
|
|
|
|
TRACE("Front stablizer enabled\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-14 16:42:32 -07:00
|
|
|
TRACE("Enabling %s-band %s-order%s ambisonic decoder\n",
|
2019-04-29 12:50:13 -07:00
|
|
|
(!hqdec || conf->FreqBands == 1) ? "single" : "dual",
|
2018-12-14 23:26:44 -08:00
|
|
|
(conf->ChanMask > AMBI_2ORDER_MASK) ? "third" :
|
|
|
|
(conf->ChanMask > AMBI_1ORDER_MASK) ? "second" : "first",
|
2016-06-01 05:30:06 -07:00
|
|
|
(conf->ChanMask&AMBI_PERIPHONIC_MASK) ? " periphonic" : ""
|
2016-04-14 16:42:32 -07:00
|
|
|
);
|
2020-06-15 02:05:10 -07:00
|
|
|
device->AmbiDecoder = BFormatDec::Create(conf, hqdec, count, device->Frequency, speakermap,
|
|
|
|
std::move(stablizer));
|
2016-04-14 16:42:32 -07:00
|
|
|
|
2019-04-29 12:50:13 -07:00
|
|
|
auto accum_spkr_dist = std::bind(std::plus<float>{}, _1,
|
|
|
|
std::bind(std::mem_fn(&AmbDecConf::SpeakerConf::Distance), _2));
|
2020-01-15 10:33:56 -08:00
|
|
|
const float avg_dist{
|
2019-09-08 01:36:19 -07:00
|
|
|
std::accumulate(conf->Speakers.begin(), conf->Speakers.end(), 0.0f, accum_spkr_dist) /
|
2020-01-15 10:33:56 -08:00
|
|
|
static_cast<float>(conf->Speakers.size())};
|
2020-01-04 16:49:49 -08:00
|
|
|
InitNearFieldCtrl(device, avg_dist, order, !!(conf->ChanMask&AMBI_PERIPHONIC_MASK));
|
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
|
|
|
{
|
2019-11-13 08:39:27 -08:00
|
|
|
constexpr float PI{al::MathDefs<float>::Pi()};
|
2019-11-30 18:42:04 -08:00
|
|
|
constexpr float PI_2{PI / 2.0f};
|
|
|
|
constexpr float PI_4{PI_2 / 2.0f};
|
|
|
|
constexpr float PI3_4{PI_4 * 3.0f};
|
|
|
|
static const float CornerElev{static_cast<float>(std::atan2(1.0, std::sqrt(2.0)))};
|
2019-11-18 00:32:01 -08:00
|
|
|
static const AngularPoint AmbiPoints1O[]{
|
2019-12-06 23:11:26 -08:00
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ -PI_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{-PI3_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ PI_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ PI3_4} },
|
|
|
|
{ EvRadians{-CornerElev}, AzRadians{ -PI_4} },
|
|
|
|
{ EvRadians{-CornerElev}, AzRadians{-PI3_4} },
|
|
|
|
{ EvRadians{-CornerElev}, AzRadians{ PI_4} },
|
|
|
|
{ EvRadians{-CornerElev}, AzRadians{ PI3_4} },
|
2019-11-18 00:32:01 -08:00
|
|
|
}, AmbiPoints2O[]{
|
2019-12-06 23:11:26 -08:00
|
|
|
{ EvRadians{ -CornerElev}, AzRadians{ -PI_4} },
|
|
|
|
{ EvRadians{ -CornerElev}, AzRadians{ -PI3_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ -PI3_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ PI3_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ PI_4} },
|
|
|
|
{ EvRadians{ -CornerElev}, AzRadians{ PI_4} },
|
|
|
|
{ EvRadians{ -CornerElev}, AzRadians{ PI3_4} },
|
|
|
|
{ EvRadians{ CornerElev}, AzRadians{ -PI_4} },
|
|
|
|
{ EvRadians{-1.205932499e+00f}, AzRadians{ -PI_2} },
|
|
|
|
{ EvRadians{ 1.205932499e+00f}, AzRadians{ PI_2} },
|
|
|
|
{ EvRadians{-1.205932499e+00f}, AzRadians{ PI_2} },
|
|
|
|
{ EvRadians{ 1.205932499e+00f}, AzRadians{ -PI_2} },
|
|
|
|
{ EvRadians{ 0.0f}, AzRadians{-1.205932499e+00f} },
|
|
|
|
{ EvRadians{ 0.0f}, AzRadians{-1.935660155e+00f} },
|
|
|
|
{ EvRadians{ 0.0f}, AzRadians{ 1.205932499e+00f} },
|
|
|
|
{ EvRadians{ 0.0f}, AzRadians{ 1.935660155e+00f} },
|
|
|
|
{ EvRadians{-3.648638281e-01f}, AzRadians{ PI} },
|
|
|
|
{ EvRadians{ 3.648638281e-01f}, AzRadians{ PI} },
|
|
|
|
{ EvRadians{ 3.648638281e-01f}, AzRadians{ 0.0f} },
|
|
|
|
{ EvRadians{-3.648638281e-01f}, AzRadians{ 0.0f} },
|
2018-02-10 05:16:28 -08:00
|
|
|
};
|
2019-11-18 00:32:01 -08:00
|
|
|
static const float AmbiMatrix1O[][MAX_AMBI_CHANNELS]{
|
|
|
|
{ 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, 1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, 1.250000000e-01f },
|
|
|
|
{ 1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f, -1.250000000e-01f },
|
|
|
|
}, AmbiMatrix2O[][MAX_AMBI_CHANNELS]{
|
2019-11-30 18:42:04 -08:00
|
|
|
{ 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, -6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 5.000000000e-02f, -6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, -6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, -5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 5.000000000e-02f, 6.454972244e-02f, 6.454972244e-02f, 0.000000000e+00f, 6.454972244e-02f, 0.000000000e+00f },
|
|
|
|
{ 5.000000000e-02f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f },
|
|
|
|
{ 5.000000000e-02f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f },
|
|
|
|
{ 5.000000000e-02f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f },
|
|
|
|
{ 5.000000000e-02f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, 6.454972244e-02f, 9.045084972e-02f, 0.000000000e+00f, -1.232790000e-02f },
|
|
|
|
{ 5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f },
|
|
|
|
{ 5.000000000e-02f, 8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f },
|
|
|
|
{ 5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, 3.090169944e-02f, -6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f },
|
|
|
|
{ 5.000000000e-02f, -8.090169944e-02f, 0.000000000e+00f, -3.090169944e-02f, 6.454972244e-02f, 0.000000000e+00f, -5.590169944e-02f, 0.000000000e+00f, -7.216878365e-02f },
|
|
|
|
{ 5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f },
|
|
|
|
{ 5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, -8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f },
|
|
|
|
{ 5.000000000e-02f, 0.000000000e+00f, 3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, 6.454972244e-02f, 8.449668365e-02f },
|
|
|
|
{ 5.000000000e-02f, 0.000000000e+00f, -3.090169944e-02f, 8.090169944e-02f, 0.000000000e+00f, 0.000000000e+00f, -3.454915028e-02f, -6.454972244e-02f, 8.449668365e-02f },
|
2017-01-18 19:16:24 -08:00
|
|
|
};
|
2019-10-25 01:43:23 -07:00
|
|
|
static const float AmbiOrderHFGain1O[MAX_AMBI_ORDER+1]{
|
2019-11-18 00:32:01 -08:00
|
|
|
2.000000000e+00f, 1.154700538e+00f
|
2019-06-02 20:38:43 -07:00
|
|
|
}, AmbiOrderHFGain2O[MAX_AMBI_ORDER+1]{
|
2019-11-30 18:42:04 -08:00
|
|
|
2.357022604e+00f, 1.825741858e+00f, 9.428090416e-01f
|
2017-01-18 19:16:24 -08:00
|
|
|
};
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2019-11-18 00:32:01 -08:00
|
|
|
static_assert(al::size(AmbiPoints1O) == al::size(AmbiMatrix1O), "First-Order Ambisonic HRTF mismatch");
|
|
|
|
static_assert(al::size(AmbiPoints2O) == al::size(AmbiMatrix2O), "Second-Order Ambisonic HRTF mismatch");
|
2017-01-15 13:57:22 -08:00
|
|
|
|
2018-12-17 07:29:55 -08:00
|
|
|
/* Don't bother with HOA when using full HRTF rendering. Nothing needs it,
|
|
|
|
* and it eases the CPU/memory load.
|
|
|
|
*/
|
2020-09-01 05:46:19 -07:00
|
|
|
device->mRenderMode = RenderMode::Hrtf;
|
2019-09-13 20:04:22 -07:00
|
|
|
ALuint ambi_order{1};
|
2019-06-30 16:15:15 -07:00
|
|
|
if(auto modeopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "hrtf-mode"))
|
2018-02-10 05:16:28 -08:00
|
|
|
{
|
2019-09-24 13:51:40 -07:00
|
|
|
struct HrtfModeEntry {
|
|
|
|
char name[8];
|
|
|
|
RenderMode mode;
|
|
|
|
ALuint order;
|
|
|
|
};
|
2019-10-25 01:43:23 -07:00
|
|
|
static const HrtfModeEntry hrtf_modes[]{
|
2020-09-01 05:46:19 -07:00
|
|
|
{ "full", RenderMode::Hrtf, 1 },
|
|
|
|
{ "ambi1", RenderMode::Normal, 1 },
|
|
|
|
{ "ambi2", RenderMode::Normal, 2 },
|
2019-09-24 13:51:40 -07:00
|
|
|
};
|
|
|
|
|
2019-06-30 16:15:15 -07:00
|
|
|
const char *mode{modeopt->c_str()};
|
2019-11-09 12:51:51 -08:00
|
|
|
if(al::strcasecmp(mode, "basic") == 0 || al::strcasecmp(mode, "ambi3") == 0)
|
2019-06-02 20:38:43 -07:00
|
|
|
{
|
|
|
|
ERR("HRTF mode \"%s\" deprecated, substituting \"%s\"\n", mode, "ambi2");
|
|
|
|
mode = "ambi2";
|
|
|
|
}
|
|
|
|
|
2019-09-24 13:51:40 -07:00
|
|
|
auto match_entry = [mode](const HrtfModeEntry &entry) -> bool
|
|
|
|
{ return al::strcasecmp(mode, entry.name) == 0; };
|
|
|
|
auto iter = std::find_if(std::begin(hrtf_modes), std::end(hrtf_modes), match_entry);
|
|
|
|
if(iter == std::end(hrtf_modes))
|
|
|
|
ERR("Unexpected hrtf-mode: %s\n", mode);
|
|
|
|
else
|
2019-06-02 20:38:43 -07:00
|
|
|
{
|
2019-09-24 13:51:40 -07:00
|
|
|
device->mRenderMode = iter->mode;
|
|
|
|
ambi_order = iter->order;
|
2019-06-02 20:38:43 -07:00
|
|
|
}
|
2018-02-10 05:16:28 -08:00
|
|
|
}
|
2019-10-24 14:33:43 -07:00
|
|
|
TRACE("%u%s order %sHRTF rendering enabled, using \"%s\"\n", ambi_order,
|
|
|
|
(((ambi_order%100)/10) == 1) ? "th" :
|
|
|
|
((ambi_order%10) == 1) ? "st" :
|
|
|
|
((ambi_order%10) == 2) ? "nd" :
|
|
|
|
((ambi_order%10) == 3) ? "rd" : "th",
|
2020-09-01 05:46:19 -07:00
|
|
|
(device->mRenderMode == RenderMode::Hrtf) ? "+ Full " : "",
|
2019-06-02 20:38:43 -07:00
|
|
|
device->HrtfName.c_str());
|
|
|
|
|
2020-01-13 08:55:10 -08:00
|
|
|
al::span<const AngularPoint> AmbiPoints{AmbiPoints1O};
|
|
|
|
const float (*AmbiMatrix)[MAX_AMBI_CHANNELS]{AmbiMatrix1O};
|
|
|
|
al::span<const float,MAX_AMBI_ORDER+1> AmbiOrderHFGain{AmbiOrderHFGain1O};
|
2019-11-09 12:51:51 -08:00
|
|
|
if(ambi_order >= 2)
|
2019-11-18 00:32:01 -08:00
|
|
|
{
|
|
|
|
AmbiPoints = AmbiPoints2O;
|
|
|
|
AmbiMatrix = AmbiMatrix2O;
|
2019-06-02 20:38:43 -07:00
|
|
|
AmbiOrderHFGain = AmbiOrderHFGain2O;
|
2019-11-18 00:32:01 -08:00
|
|
|
}
|
2019-02-21 01:23:11 -08:00
|
|
|
device->mAmbiOrder = ambi_order;
|
2018-02-10 05:16:28 -08:00
|
|
|
|
2019-02-21 04:05:49 -08:00
|
|
|
const size_t count{AmbiChannelsFromOrder(ambi_order)};
|
2020-01-04 00:04:55 -08:00
|
|
|
std::transform(AmbiIndex::FromACN.begin(), AmbiIndex::FromACN.begin()+count,
|
2019-02-24 18:00:49 -08:00
|
|
|
std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &index) noexcept { return BFChannelConfig{1.0f, index}; }
|
2018-12-09 22:34:21 -08:00
|
|
|
);
|
2020-05-06 14:53:27 -07:00
|
|
|
AllocChannels(device, count, device->channelsFromFmt());
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2020-03-01 17:16:09 -08:00
|
|
|
HrtfStore *Hrtf{device->mHrtf.get()};
|
2020-05-01 10:28:16 -07:00
|
|
|
auto hrtfstate = DirectHrtfState::Create(count);
|
|
|
|
hrtfstate->build(Hrtf, AmbiPoints, AmbiMatrix, AmbiOrderHFGain);
|
|
|
|
device->mHrtfState = std::move(hrtfstate);
|
2017-10-23 13:30:01 -07:00
|
|
|
|
2020-01-04 16:49:49 -08:00
|
|
|
InitNearFieldCtrl(device, Hrtf->field[0].distance, ambi_order, true);
|
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
|
|
|
{
|
2019-02-21 01:23:11 -08:00
|
|
|
/* UHJ is always 2D first-order. */
|
2019-10-25 01:43:23 -07:00
|
|
|
constexpr size_t count{Ambi2DChannelsFromOrder(1)};
|
2016-04-14 10:44:57 -07:00
|
|
|
|
2019-02-21 04:05:49 -08:00
|
|
|
device->mAmbiOrder = 1;
|
2019-02-21 01:23:11 -08:00
|
|
|
|
2018-12-20 03:26:46 -08:00
|
|
|
auto acnmap_end = AmbiIndex::FromFuMa.begin() + count;
|
2019-01-05 21:55:14 -08:00
|
|
|
std::transform(AmbiIndex::FromFuMa.begin(), acnmap_end, std::begin(device->Dry.AmbiMap),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &acn) noexcept -> BFChannelConfig
|
2018-12-20 02:46:59 -08:00
|
|
|
{ return BFChannelConfig{1.0f/AmbiScale::FromFuMa[acn], acn}; }
|
2018-12-09 22:34:21 -08:00
|
|
|
);
|
2020-05-06 14:53:27 -07:00
|
|
|
AllocChannels(device, count, device->channelsFromFmt());
|
2016-04-14 10:44:57 -07:00
|
|
|
}
|
|
|
|
|
2018-12-10 02:08:54 -08:00
|
|
|
} // namespace
|
|
|
|
|
2020-04-08 10:15:43 -07:00
|
|
|
void aluInitRenderer(ALCdevice *device, int hrtf_id, HrtfRequestMode hrtf_appreq,
|
|
|
|
HrtfRequestMode hrtf_userreq)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2017-04-06 13:00:29 -07:00
|
|
|
/* Hold the HRTF the device last used, in case it's used again. */
|
2020-03-01 17:16:09 -08:00
|
|
|
HrtfStorePtr old_hrtf{std::move(device->mHrtf)};
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2018-11-22 06:59:32 -08:00
|
|
|
device->mHrtfState = nullptr;
|
2018-12-22 09:20:50 -08:00
|
|
|
device->mHrtf = nullptr;
|
2018-11-18 19:28:01 -08:00
|
|
|
device->HrtfName.clear();
|
2020-09-01 05:46:19 -07:00
|
|
|
device->mRenderMode = RenderMode::Normal;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
|
|
|
if(device->FmtChans != DevFmtStereo)
|
|
|
|
{
|
2018-12-15 00:38:38 -08:00
|
|
|
old_hrtf = nullptr;
|
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-12-15 00:38:38 -08:00
|
|
|
const char *layout{nullptr};
|
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;
|
|
|
|
}
|
2018-12-15 00:38:38 -08:00
|
|
|
|
|
|
|
const char *devname{device->DeviceName.c_str()};
|
2019-09-12 04:17:21 -07:00
|
|
|
ALuint speakermap[MAX_OUTPUT_CHANNELS];
|
2018-12-15 00:38:38 -08:00
|
|
|
AmbDecConf *pconf{nullptr};
|
|
|
|
AmbDecConf conf{};
|
2016-04-14 16:42:32 -07:00
|
|
|
if(layout)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-06-30 16:15:15 -07:00
|
|
|
if(auto decopt = ConfigValueStr(devname, "decoder", layout))
|
2016-04-14 16:42:32 -07:00
|
|
|
{
|
2019-06-30 16:15:15 -07:00
|
|
|
if(!conf.load(decopt->c_str()))
|
|
|
|
ERR("Failed to load layout file %s\n", decopt->c_str());
|
2018-12-15 02:42:04 -08:00
|
|
|
else if(conf.Speakers.size() > MAX_OUTPUT_CHANNELS)
|
2019-04-11 16:01:11 -07:00
|
|
|
ERR("Unsupported speaker count %zu (max %d)\n", conf.Speakers.size(),
|
2018-12-15 02:42:04 -08:00
|
|
|
MAX_OUTPUT_CHANNELS);
|
2018-12-15 00:38:38 -08:00
|
|
|
else if(conf.ChanMask > AMBI_3ORDER_MASK)
|
|
|
|
ERR("Unsupported channel mask 0x%04x (max 0x%x)\n", conf.ChanMask,
|
|
|
|
AMBI_3ORDER_MASK);
|
|
|
|
else if(MakeSpeakerMap(device, &conf, speakermap))
|
|
|
|
pconf = &conf;
|
2016-04-14 16:42:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 02:05:10 -07:00
|
|
|
/* Enable the stablizer only for formats that have front-left, front-
|
|
|
|
* right, and front-center outputs.
|
|
|
|
*/
|
|
|
|
const bool stablize{device->RealOut.ChannelIndex[FrontCenter] != INVALID_CHANNEL_INDEX
|
|
|
|
&& device->RealOut.ChannelIndex[FrontLeft] != INVALID_CHANNEL_INDEX
|
|
|
|
&& device->RealOut.ChannelIndex[FrontRight] != INVALID_CHANNEL_INDEX
|
|
|
|
&& GetConfigValueBool(devname, nullptr, "front-stablizer", 0) != 0};
|
|
|
|
const bool hqdec{GetConfigValueBool(devname, "decoder", "hq-mode", 1) != 0};
|
2016-04-14 16:42:32 -07:00
|
|
|
if(!pconf)
|
2020-06-15 02:05:10 -07:00
|
|
|
InitPanning(device, hqdec, stablize);
|
2016-04-14 16:42:32 -07:00
|
|
|
else
|
2020-06-15 02:05:10 -07:00
|
|
|
InitCustomPanning(device, hqdec, stablize, pconf, speakermap);
|
|
|
|
if(auto *ambidec{device->AmbiDecoder.get()})
|
|
|
|
{
|
|
|
|
device->PostProcess = ambidec->hasStablizer() ? &ALCdevice::ProcessAmbiDecStablized
|
|
|
|
: &ALCdevice::ProcessAmbiDec;
|
|
|
|
}
|
2016-04-14 15:25:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-28 15:37:34 -07:00
|
|
|
bool headphones{device->IsHeadphones};
|
2020-09-01 05:46:19 -07:00
|
|
|
if(device->Type != DeviceType::Loopback)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-06-30 16:15:15 -07:00
|
|
|
if(auto modeopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "stereo-mode"))
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-06-30 16:15:15 -07:00
|
|
|
const char *mode{modeopt->c_str()};
|
2019-09-16 15:10:36 -07:00
|
|
|
if(al::strcasecmp(mode, "headphones") == 0)
|
2016-04-14 15:25:12 -07:00
|
|
|
headphones = true;
|
2019-09-16 15:10:36 -07:00
|
|
|
else if(al::strcasecmp(mode, "speakers") == 0)
|
2016-04-14 15:25:12 -07:00
|
|
|
headphones = false;
|
2019-09-16 15:10:36 -07:00
|
|
|
else if(al::strcasecmp(mode, "auto") != 0)
|
2016-04-14 15:25:12 -07:00
|
|
|
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
|
|
|
|
2019-09-14 08:29:02 -07:00
|
|
|
if(hrtf_id >= 0 && static_cast<ALuint>(hrtf_id) < device->HrtfList.size())
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-11-28 14:51:45 -08:00
|
|
|
const char *devname{device->DeviceName.c_str()};
|
2019-11-28 08:24:29 -08:00
|
|
|
const std::string &hrtfname = device->HrtfList[static_cast<ALuint>(hrtf_id)];
|
2020-03-01 17:16:09 -08:00
|
|
|
if(HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)})
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2020-03-01 17:16:09 -08:00
|
|
|
device->mHrtf = std::move(hrtf);
|
2019-11-28 08:24:29 -08:00
|
|
|
device->HrtfName = hrtfname;
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
2017-04-06 13:00:29 -07:00
|
|
|
}
|
|
|
|
|
2018-12-22 09:20:50 -08:00
|
|
|
if(!device->mHrtf)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-11-28 14:51:45 -08:00
|
|
|
const char *devname{device->DeviceName.c_str()};
|
|
|
|
auto find_hrtf = [device,devname](const std::string &hrtfname) -> bool
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2020-03-01 17:16:09 -08:00
|
|
|
HrtfStorePtr hrtf{GetLoadedHrtf(hrtfname, devname, device->Frequency)};
|
2018-12-05 16:35:06 -08:00
|
|
|
if(!hrtf) return false;
|
2020-03-01 17:16:09 -08:00
|
|
|
device->mHrtf = std::move(hrtf);
|
2019-11-28 08:24:29 -08:00
|
|
|
device->HrtfName = hrtfname;
|
2018-12-05 16:35:06 -08:00
|
|
|
return true;
|
|
|
|
};
|
2020-10-20 18:33:53 +02:00
|
|
|
(void)std::find_if(device->HrtfList.cbegin(), device->HrtfList.cend(), find_hrtf);
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
2018-12-22 09:20:50 -08:00
|
|
|
if(device->mHrtf)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2018-12-15 00:38:38 -08:00
|
|
|
old_hrtf = nullptr;
|
2017-04-06 13:00:29 -07:00
|
|
|
|
2017-04-18 17:39:10 -07:00
|
|
|
InitHrtfPanning(device);
|
2019-08-07 11:43:53 -07:00
|
|
|
device->PostProcess = &ALCdevice::ProcessHrtf;
|
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:
|
2018-11-22 06:49:37 -08:00
|
|
|
old_hrtf = nullptr;
|
2016-04-14 15:25:12 -07:00
|
|
|
|
2020-09-01 05:46:19 -07:00
|
|
|
device->mRenderMode = RenderMode::Pairwise;
|
2017-02-22 19:18:01 -08:00
|
|
|
|
2020-09-01 05:46:19 -07:00
|
|
|
if(device->Type != DeviceType::Loopback)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-06-30 12:00:10 -07:00
|
|
|
if(auto cflevopt = ConfigValueInt(device->DeviceName.c_str(), nullptr, "cf_level"))
|
|
|
|
{
|
|
|
|
if(*cflevopt > 0 && *cflevopt <= 6)
|
|
|
|
{
|
2020-03-22 08:51:06 -07:00
|
|
|
device->Bs2b = std::make_unique<bs2b>();
|
2019-09-14 08:29:02 -07:00
|
|
|
bs2b_set_params(device->Bs2b.get(), *cflevopt,
|
|
|
|
static_cast<int>(device->Frequency));
|
2019-06-30 12:00:10 -07:00
|
|
|
TRACE("BS2B enabled\n");
|
|
|
|
InitPanning(device);
|
2019-08-07 11:43:53 -07:00
|
|
|
device->PostProcess = &ALCdevice::ProcessBs2b;
|
2019-06-30 12:00:10 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
2019-06-30 16:15:15 -07:00
|
|
|
if(auto encopt = ConfigValueStr(device->DeviceName.c_str(), nullptr, "stereo-encoding"))
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2019-06-30 16:15:15 -07:00
|
|
|
const char *mode{encopt->c_str()};
|
2019-09-16 15:10:36 -07:00
|
|
|
if(al::strcasecmp(mode, "uhj") == 0)
|
2020-09-01 05:46:19 -07:00
|
|
|
device->mRenderMode = RenderMode::Normal;
|
2019-09-16 15:10:36 -07:00
|
|
|
else if(al::strcasecmp(mode, "panpot") != 0)
|
2017-02-22 19:18:01 -08:00
|
|
|
ERR("Unexpected stereo-encoding: %s\n", mode);
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
2020-09-01 05:46:19 -07:00
|
|
|
if(device->mRenderMode == RenderMode::Normal)
|
2016-04-14 15:25:12 -07:00
|
|
|
{
|
2020-03-22 08:51:06 -07:00
|
|
|
device->Uhj_Encoder = std::make_unique<Uhj2Encoder>();
|
2016-04-14 15:25:12 -07:00
|
|
|
TRACE("UHJ enabled\n");
|
|
|
|
InitUhjPanning(device);
|
2019-08-07 11:43:53 -07:00
|
|
|
device->PostProcess = &ALCdevice::ProcessUhj;
|
2016-04-14 15:25:12 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-25 23:17:34 -07:00
|
|
|
TRACE("Stereo rendering\n");
|
2016-04-14 15:25:12 -07:00
|
|
|
InitPanning(device);
|
2019-08-07 11:43:53 -07:00
|
|
|
device->PostProcess = &ALCdevice::ProcessAmbiDec;
|
2016-04-14 15:25:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-02 04:24:36 -08:00
|
|
|
void aluInitEffectPanning(ALeffectslot *slot, ALCcontext *context)
|
2016-01-28 00:02:46 -08:00
|
|
|
{
|
2020-11-02 04:24:36 -08:00
|
|
|
ALCdevice *device{context->mDevice.get()};
|
2019-02-21 04:23:01 -08:00
|
|
|
const size_t count{AmbiChannelsFromOrder(device->mAmbiOrder)};
|
2020-11-02 04:24:36 -08:00
|
|
|
|
|
|
|
ALuint idx{0};
|
|
|
|
for(auto &wetbuffer : context->mWetBuffers)
|
|
|
|
{
|
|
|
|
if(!wetbuffer->mInUse)
|
|
|
|
break;
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
if(idx == context->mWetBuffers.size())
|
|
|
|
{
|
|
|
|
auto newbuffer = WetBufferPtr{new(FamCount(count)) WetBuffer{count}};
|
|
|
|
context->mWetBuffers.emplace_back(std::move(newbuffer));
|
|
|
|
}
|
|
|
|
auto *wetbuffer = context->mWetBuffers[idx].get();
|
|
|
|
slot->mWetBuffer = wetbuffer;
|
|
|
|
wetbuffer->mInUse = true;
|
2019-02-20 21:01:08 -08:00
|
|
|
|
2020-01-04 00:04:55 -08:00
|
|
|
auto acnmap_end = AmbiIndex::FromACN.begin() + count;
|
|
|
|
auto iter = std::transform(AmbiIndex::FromACN.begin(), acnmap_end, slot->Wet.AmbiMap.begin(),
|
2019-09-14 08:29:02 -07:00
|
|
|
[](const uint8_t &acn) noexcept -> BFChannelConfig
|
2020-11-02 04:24:36 -08:00
|
|
|
{ return BFChannelConfig{1.0f, acn}; });
|
2019-03-22 19:25:55 -07:00
|
|
|
std::fill(iter, slot->Wet.AmbiMap.end(), BFChannelConfig{});
|
2020-11-02 04:24:36 -08:00
|
|
|
slot->Wet.Buffer = {wetbuffer->mBuffer.data(), count};
|
2016-01-28 00:02:46 -08:00
|
|
|
}
|
2019-07-04 14:03:27 -07:00
|
|
|
|
|
|
|
|
2020-04-21 23:58:53 -07:00
|
|
|
std::array<float,MAX_AMBI_CHANNELS> CalcAmbiCoeffs(const float y, const float z, const float x,
|
|
|
|
const float spread)
|
2019-07-04 14:03:27 -07:00
|
|
|
{
|
2020-04-21 23:58:53 -07:00
|
|
|
std::array<float,MAX_AMBI_CHANNELS> coeffs;
|
|
|
|
|
2019-07-04 14:03:27 -07:00
|
|
|
/* Zeroth-order */
|
|
|
|
coeffs[0] = 1.0f; /* ACN 0 = 1 */
|
|
|
|
/* First-order */
|
|
|
|
coeffs[1] = 1.732050808f * y; /* ACN 1 = sqrt(3) * Y */
|
|
|
|
coeffs[2] = 1.732050808f * z; /* ACN 2 = sqrt(3) * Z */
|
|
|
|
coeffs[3] = 1.732050808f * x; /* ACN 3 = sqrt(3) * X */
|
|
|
|
/* Second-order */
|
2020-01-05 03:38:19 -08:00
|
|
|
const float xx{x*x}, yy{y*y}, zz{z*z};
|
|
|
|
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*zz - 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 * (xx - yy); /* ACN 8 = sqrt(15)/2 * (X*X - Y*Y) */
|
2019-07-04 14:03:27 -07:00
|
|
|
/* Third-order */
|
2020-01-05 03:38:19 -08:00
|
|
|
coeffs[9] = 2.091650066f * y * (3.0f*xx - yy); /* 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*zz - 1.0f); /* ACN 11 = sqrt(21/8) * Y * (5*Z*Z - 1) */
|
|
|
|
coeffs[12] = 1.322875656f * z * (5.0f*zz - 3.0f); /* ACN 12 = sqrt(7)/2 * Z * (5*Z*Z - 3) */
|
|
|
|
coeffs[13] = 1.620185175f * x * (5.0f*zz - 1.0f); /* ACN 13 = sqrt(21/8) * X * (5*Z*Z - 1) */
|
|
|
|
coeffs[14] = 5.123475383f * z * (xx - yy); /* ACN 14 = sqrt(105)/2 * Z * (X*X - Y*Y) */
|
|
|
|
coeffs[15] = 2.091650066f * x * (xx - 3.0f*yy); /* ACN 15 = sqrt(35/8) * X * (X*X - 3*Y*Y) */
|
2019-07-04 14:03:27 -07:00
|
|
|
/* Fourth-order */
|
|
|
|
/* ACN 16 = sqrt(35)*3/2 * X * Y * (X*X - Y*Y) */
|
|
|
|
/* ACN 17 = sqrt(35/2)*3/2 * (3*X*X - Y*Y) * Y * Z */
|
|
|
|
/* ACN 18 = sqrt(5)*3/2 * X * Y * (7*Z*Z - 1) */
|
|
|
|
/* ACN 19 = sqrt(5/2)*3/2 * Y * Z * (7*Z*Z - 3) */
|
|
|
|
/* ACN 20 = 3/8 * (35*Z*Z*Z*Z - 30*Z*Z + 3) */
|
|
|
|
/* ACN 21 = sqrt(5/2)*3/2 * X * Z * (7*Z*Z - 3) */
|
|
|
|
/* ACN 22 = sqrt(5)*3/4 * (X*X - Y*Y) * (7*Z*Z - 1) */
|
|
|
|
/* ACN 23 = sqrt(35/2)*3/2 * (X*X - 3*Y*Y) * X * Z */
|
|
|
|
/* ACN 24 = sqrt(35)*3/8 * (X*X*X*X - 6*X*X*Y*Y + Y*Y*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
|
|
|
|
* loudness 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);
|
|
|
|
*/
|
2019-10-05 20:00:22 -07:00
|
|
|
const float ca{std::cos(spread * 0.5f)};
|
2019-07-04 14:03:27 -07:00
|
|
|
/* Increase the source volume by up to +3dB for a full spread. */
|
2019-10-05 20:00:22 -07:00
|
|
|
const float scale{std::sqrt(1.0f + spread/al::MathDefs<float>::Tau())};
|
2019-07-04 14:03:27 -07:00
|
|
|
|
2019-10-05 20:00:22 -07:00
|
|
|
const float ZH0_norm{scale};
|
|
|
|
const float ZH1_norm{scale * 0.5f * (ca+1.f)};
|
|
|
|
const float ZH2_norm{scale * 0.5f * (ca+1.f)*ca};
|
|
|
|
const float ZH3_norm{scale * 0.125f * (ca+1.f)*(5.f*ca*ca-1.f)};
|
2019-07-04 14:03:27 -07:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2020-04-21 23:58:53 -07:00
|
|
|
|
|
|
|
return coeffs;
|
2019-07-04 14:03:27 -07:00
|
|
|
}
|
|
|
|
|
2019-10-05 20:00:22 -07:00
|
|
|
void ComputePanGains(const MixParams *mix, const float*RESTRICT coeffs, const float ingain,
|
|
|
|
const al::span<float,MAX_OUTPUT_CHANNELS> gains)
|
2019-07-04 14:03:27 -07:00
|
|
|
{
|
|
|
|
auto ambimap = mix->AmbiMap.cbegin();
|
|
|
|
|
2019-10-05 20:00:22 -07:00
|
|
|
auto iter = std::transform(ambimap, ambimap+mix->Buffer.size(), gains.begin(),
|
|
|
|
[coeffs,ingain](const BFChannelConfig &chanmap) noexcept -> float
|
2019-09-14 08:50:07 -07:00
|
|
|
{ return chanmap.Scale * coeffs[chanmap.Index] * ingain; }
|
2019-07-04 14:03:27 -07:00
|
|
|
);
|
2019-10-05 20:00:22 -07:00
|
|
|
std::fill(iter, gains.end(), 0.0f);
|
2019-07-04 14:03:27 -07:00
|
|
|
}
|