2010-08-03 23:19:36 -07:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-10-02 16:53:23 -07:00
|
|
|
#include "voice.h"
|
|
|
|
|
2019-07-28 11:28:36 -07:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <atomic>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
|
|
|
#include <memory>
|
|
|
|
#include <new>
|
2021-04-27 08:04:09 -07:00
|
|
|
#include <stdlib.h>
|
2019-07-28 11:28:36 -07:00
|
|
|
#include <utility>
|
2021-04-24 11:45:50 -07:00
|
|
|
#include <vector>
|
2018-12-20 07:10:09 -08:00
|
|
|
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "albyte.h"
|
|
|
|
#include "alnumeric.h"
|
|
|
|
#include "aloptional.h"
|
|
|
|
#include "alspan.h"
|
2019-09-16 15:10:36 -07:00
|
|
|
#include "alstring.h"
|
2021-04-27 08:26:42 -07:00
|
|
|
#include "ambidefs.h"
|
|
|
|
#include "async_event.h"
|
2020-12-15 01:31:09 -08:00
|
|
|
#include "buffer_storage.h"
|
2021-04-27 08:26:42 -07:00
|
|
|
#include "context.h"
|
|
|
|
#include "cpu_caps.h"
|
|
|
|
#include "devformat.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "filters/biquad.h"
|
|
|
|
#include "filters/nfc.h"
|
|
|
|
#include "filters/splitter.h"
|
|
|
|
#include "fmt_traits.h"
|
|
|
|
#include "logging.h"
|
|
|
|
#include "mixer.h"
|
|
|
|
#include "mixer/defs.h"
|
|
|
|
#include "mixer/hrtfdefs.h"
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "opthelpers.h"
|
2021-04-27 08:26:42 -07:00
|
|
|
#include "resampler_limits.h"
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "ringbuffer.h"
|
|
|
|
#include "vector.h"
|
2021-04-27 08:26:42 -07:00
|
|
|
#include "voice_change.h"
|
2019-05-26 19:41:11 -07:00
|
|
|
|
2020-04-03 03:52:23 -07:00
|
|
|
struct CTag;
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
struct SSETag;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
struct NEONTag;
|
|
|
|
#endif
|
|
|
|
struct CopyTag;
|
|
|
|
|
2011-05-06 00:20:40 -07:00
|
|
|
|
2021-06-21 09:04:33 -07:00
|
|
|
static_assert(!(sizeof(DeviceBase::MixerBufferLine)&15),
|
|
|
|
"DeviceBase::MixerBufferLine must be a multiple of 16 bytes");
|
2022-01-01 00:10:21 -08:00
|
|
|
static_assert(!(MaxResamplerEdge&3), "MaxResamplerEdge is not a multiple of 4");
|
2021-03-19 19:02:30 -07:00
|
|
|
|
2019-09-22 21:19:19 -07:00
|
|
|
Resampler ResamplerDefault{Resampler::Linear};
|
2017-04-20 23:21:46 -07:00
|
|
|
|
2019-09-19 21:01:10 -07:00
|
|
|
namespace {
|
|
|
|
|
2021-04-27 08:04:09 -07:00
|
|
|
using uint = unsigned int;
|
|
|
|
|
2020-11-20 03:59:14 -08:00
|
|
|
using HrtfMixerFunc = void(*)(const float *InSamples, float2 *AccumSamples, const uint IrSize,
|
2020-01-05 17:12:48 -08:00
|
|
|
const MixHrtfFilter *hrtfparams, const size_t BufferSize);
|
2020-04-08 06:17:04 -07:00
|
|
|
using HrtfMixerBlendFunc = void(*)(const float *InSamples, float2 *AccumSamples,
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams,
|
2019-11-03 00:30:33 -07:00
|
|
|
const size_t BufferSize);
|
2019-10-02 15:37:33 -07:00
|
|
|
|
2020-03-25 22:24:09 -07:00
|
|
|
HrtfMixerFunc MixHrtfSamples{MixHrtf_<CTag>};
|
|
|
|
HrtfMixerBlendFunc MixHrtfBlendSamples{MixHrtfBlend_<CTag>};
|
|
|
|
|
|
|
|
inline MixerFunc SelectMixer()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
|
|
|
return Mix_<NEONTag>;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
|
|
|
return Mix_<SSETag>;
|
|
|
|
#endif
|
|
|
|
return Mix_<CTag>;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:01:10 -07:00
|
|
|
inline HrtfMixerFunc SelectHrtfMixer()
|
2014-06-13 16:07:25 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtf_<NEONTag>;
|
2014-06-13 16:07:25 -07:00
|
|
|
#endif
|
2017-03-14 19:16:59 -07:00
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtf_<SSETag>;
|
2017-03-14 19:16:59 -07:00
|
|
|
#endif
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtf_<CTag>;
|
2014-06-13 16:07:25 -07:00
|
|
|
}
|
|
|
|
|
2019-09-19 21:01:10 -07:00
|
|
|
inline HrtfMixerBlendFunc SelectHrtfBlendMixer()
|
2017-05-03 03:29:21 -07:00
|
|
|
{
|
|
|
|
#ifdef HAVE_NEON
|
|
|
|
if((CPUCapFlags&CPU_CAP_NEON))
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtfBlend_<NEONTag>;
|
2017-05-03 03:29:21 -07:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SSE
|
|
|
|
if((CPUCapFlags&CPU_CAP_SSE))
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtfBlend_<SSETag>;
|
2017-05-03 03:29:21 -07:00
|
|
|
#endif
|
2019-01-23 12:23:05 -08:00
|
|
|
return MixHrtfBlend_<CTag>;
|
2017-05-03 03:29:21 -07:00
|
|
|
}
|
|
|
|
|
2019-09-19 21:01:10 -07:00
|
|
|
} // namespace
|
|
|
|
|
2021-04-27 08:26:42 -07:00
|
|
|
void Voice::InitMixer(al::optional<std::string> resampler)
|
2015-09-27 20:55:39 -07:00
|
|
|
{
|
2021-04-24 15:52:53 -07:00
|
|
|
if(resampler)
|
2015-10-01 00:34:13 -07:00
|
|
|
{
|
2019-09-21 12:08:45 -07:00
|
|
|
struct ResamplerEntry {
|
2019-09-28 01:58:29 -07:00
|
|
|
const char name[16];
|
2019-09-21 12:08:45 -07:00
|
|
|
const Resampler resampler;
|
|
|
|
};
|
|
|
|
constexpr ResamplerEntry ResamplerList[]{
|
2019-09-22 21:19:19 -07:00
|
|
|
{ "none", Resampler::Point },
|
|
|
|
{ "point", Resampler::Point },
|
2020-09-24 14:21:57 -07:00
|
|
|
{ "linear", Resampler::Linear },
|
2019-09-22 21:19:19 -07:00
|
|
|
{ "cubic", Resampler::Cubic },
|
|
|
|
{ "bsinc12", Resampler::BSinc12 },
|
2019-09-28 01:58:29 -07:00
|
|
|
{ "fast_bsinc12", Resampler::FastBSinc12 },
|
2019-09-22 21:19:19 -07:00
|
|
|
{ "bsinc24", Resampler::BSinc24 },
|
2019-09-28 01:58:29 -07:00
|
|
|
{ "fast_bsinc24", Resampler::FastBSinc24 },
|
2019-09-21 12:08:45 -07:00
|
|
|
};
|
|
|
|
|
2021-04-24 15:52:53 -07:00
|
|
|
const char *str{resampler->c_str()};
|
2019-09-21 12:08:45 -07:00
|
|
|
if(al::strcasecmp(str, "bsinc") == 0)
|
2017-08-27 10:16:36 -07:00
|
|
|
{
|
|
|
|
WARN("Resampler option \"%s\" is deprecated, using bsinc12\n", str);
|
2019-09-21 12:08:45 -07:00
|
|
|
str = "bsinc12";
|
2017-08-27 10:16:36 -07:00
|
|
|
}
|
2019-09-16 15:10:36 -07:00
|
|
|
else if(al::strcasecmp(str, "sinc4") == 0 || al::strcasecmp(str, "sinc8") == 0)
|
2015-10-01 00:34:13 -07:00
|
|
|
{
|
2018-01-07 05:32:07 -08:00
|
|
|
WARN("Resampler option \"%s\" is deprecated, using cubic\n", str);
|
2019-09-21 12:08:45 -07:00
|
|
|
str = "cubic";
|
2015-10-01 00:34:13 -07:00
|
|
|
}
|
2019-09-21 12:08:45 -07:00
|
|
|
|
|
|
|
auto iter = std::find_if(std::begin(ResamplerList), std::end(ResamplerList),
|
|
|
|
[str](const ResamplerEntry &entry) -> bool
|
|
|
|
{ return al::strcasecmp(str, entry.name) == 0; });
|
|
|
|
if(iter == std::end(ResamplerList))
|
2019-08-04 17:29:55 -07:00
|
|
|
ERR("Invalid resampler: %s\n", str);
|
2019-09-21 12:08:45 -07:00
|
|
|
else
|
|
|
|
ResamplerDefault = iter->resampler;
|
2015-10-01 00:34:13 -07:00
|
|
|
}
|
|
|
|
|
2020-03-25 22:24:09 -07:00
|
|
|
MixSamples = SelectMixer();
|
2017-05-03 03:29:21 -07:00
|
|
|
MixHrtfBlendSamples = SelectHrtfBlendMixer();
|
2015-09-27 20:55:39 -07:00
|
|
|
MixHrtfSamples = SelectHrtfMixer();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-20 02:59:02 -08:00
|
|
|
namespace {
|
|
|
|
|
2021-04-24 08:28:13 -07:00
|
|
|
void SendSourceStoppedEvent(ContextBase *context, uint id)
|
2019-03-09 16:48:07 -08:00
|
|
|
{
|
2019-07-30 09:05:54 -07:00
|
|
|
RingBuffer *ring{context->mAsyncEvents.get()};
|
2019-03-09 16:48:07 -08:00
|
|
|
auto evt_vec = ring->getWriteVector();
|
|
|
|
if(evt_vec.first.len < 1) return;
|
|
|
|
|
2021-10-08 11:05:36 -07:00
|
|
|
AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf),
|
2021-10-10 05:07:31 -07:00
|
|
|
AsyncEvent::SourceStateChange)};
|
2019-03-09 16:48:07 -08:00
|
|
|
evt->u.srcstate.id = id;
|
2021-04-25 14:29:21 -07:00
|
|
|
evt->u.srcstate.state = AsyncEvent::SrcState::Stop;
|
2019-03-09 16:48:07 -08:00
|
|
|
|
|
|
|
ring->writeAdvance(1);
|
|
|
|
}
|
|
|
|
|
2019-04-12 19:19:24 -07:00
|
|
|
|
2020-04-23 22:13:52 -07:00
|
|
|
const float *DoFilters(BiquadFilter &lpfilter, BiquadFilter &hpfilter, float *dst,
|
2019-12-25 18:39:22 -08:00
|
|
|
const al::span<const float> src, int type)
|
2019-04-12 19:19:24 -07:00
|
|
|
{
|
|
|
|
switch(type)
|
|
|
|
{
|
2019-12-25 18:39:22 -08:00
|
|
|
case AF_None:
|
2020-04-23 22:13:52 -07:00
|
|
|
lpfilter.clear();
|
|
|
|
hpfilter.clear();
|
2019-12-25 18:39:22 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_LowPass:
|
2020-04-23 22:13:52 -07:00
|
|
|
lpfilter.process(src, dst);
|
|
|
|
hpfilter.clear();
|
2019-12-25 18:39:22 -08:00
|
|
|
return dst;
|
|
|
|
case AF_HighPass:
|
2020-04-23 22:13:52 -07:00
|
|
|
lpfilter.clear();
|
|
|
|
hpfilter.process(src, dst);
|
2019-12-25 18:39:22 -08:00
|
|
|
return dst;
|
|
|
|
|
|
|
|
case AF_BandPass:
|
2020-04-23 22:13:52 -07:00
|
|
|
DualBiquad{lpfilter, hpfilter}.process(src, dst);
|
2019-12-25 18:39:22 -08:00
|
|
|
return dst;
|
2019-04-12 19:19:24 -07:00
|
|
|
}
|
2019-12-25 18:39:22 -08:00
|
|
|
return src.data();
|
2019-04-12 19:19:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
template<FmtType Type>
|
|
|
|
inline void LoadSamples(const al::span<float*> dstSamples, const size_t dstOffset,
|
|
|
|
const al::byte *src, const size_t srcOffset, const FmtChannels srcChans, const size_t srcStep,
|
|
|
|
const size_t samples) noexcept
|
|
|
|
{
|
|
|
|
constexpr size_t sampleSize{sizeof(typename al::FmtTypeTraits<Type>::Type)};
|
|
|
|
auto s = src + srcOffset*srcStep*sampleSize;
|
|
|
|
if(srcChans == FmtUHJ2 || srcChans == FmtSuperStereo)
|
|
|
|
{
|
|
|
|
al::LoadSampleArray<Type>(dstSamples[0]+dstOffset, s, srcStep, samples);
|
|
|
|
al::LoadSampleArray<Type>(dstSamples[1]+dstOffset, s+sampleSize, srcStep, samples);
|
|
|
|
std::fill_n(dstSamples[2]+dstOffset, samples, 0.0f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(auto *dst : dstSamples)
|
|
|
|
{
|
|
|
|
al::LoadSampleArray<Type>(dst+dstOffset, s, srcStep, samples);
|
|
|
|
s += sampleSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadSamples(const al::span<float*> dstSamples, const size_t dstOffset, const al::byte *src,
|
|
|
|
const size_t srcOffset, const FmtType srcType, const FmtChannels srcChans,
|
|
|
|
const size_t srcStep, const size_t samples) noexcept
|
2011-10-04 09:47:08 -07:00
|
|
|
{
|
2021-03-19 19:02:30 -07:00
|
|
|
#define HANDLE_FMT(T) case T: \
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples<T>(dstSamples, dstOffset, src, srcOffset, srcChans, srcStep, \
|
|
|
|
samples); \
|
2021-03-19 19:02:30 -07:00
|
|
|
break
|
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
switch(srcType)
|
2011-10-04 09:47:08 -07:00
|
|
|
{
|
2020-08-26 21:29:16 -07:00
|
|
|
HANDLE_FMT(FmtUByte);
|
|
|
|
HANDLE_FMT(FmtShort);
|
|
|
|
HANDLE_FMT(FmtFloat);
|
|
|
|
HANDLE_FMT(FmtDouble);
|
|
|
|
HANDLE_FMT(FmtMulaw);
|
|
|
|
HANDLE_FMT(FmtAlaw);
|
2011-10-04 09:47:08 -07:00
|
|
|
}
|
2018-01-17 08:49:49 -08:00
|
|
|
#undef HANDLE_FMT
|
2011-10-04 09:47:08 -07:00
|
|
|
}
|
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
void LoadBufferStatic(VoiceBufferItem *buffer, VoiceBufferItem *bufferLoopItem,
|
2021-03-31 09:37:30 -07:00
|
|
|
const size_t dataPosInt, const FmtType sampleType, const FmtChannels sampleChannels,
|
2022-01-01 21:19:53 -08:00
|
|
|
const size_t srcStep, const size_t samplesToLoad, const al::span<float*> voiceSamples)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2021-03-19 19:02:30 -07:00
|
|
|
const uint loopStart{buffer->mLoopStart};
|
|
|
|
const uint loopEnd{buffer->mLoopEnd};
|
|
|
|
ASSUME(loopEnd > loopStart);
|
2019-03-09 21:32:14 -08:00
|
|
|
|
|
|
|
/* If current pos is beyond the loop range, do not loop */
|
2021-03-19 19:02:30 -07:00
|
|
|
if(!bufferLoopItem || dataPosInt >= loopEnd)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2019-08-11 03:34:35 -07:00
|
|
|
/* Load what's left to play from the buffer */
|
2021-03-19 19:02:30 -07:00
|
|
|
const size_t remaining{minz(samplesToLoad, buffer->mSampleLen-dataPosInt)};
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples(voiceSamples, 0, buffer->mSamples, dataPosInt, sampleType, sampleChannels,
|
|
|
|
srcStep, remaining);
|
2019-08-11 03:34:35 -07:00
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
if(const size_t toFill{samplesToLoad - remaining})
|
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
for(auto *chanbuffer : voiceSamples)
|
2021-03-19 19:02:30 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
auto srcsamples = chanbuffer + remaining - 1;
|
2021-03-19 19:02:30 -07:00
|
|
|
std::fill_n(srcsamples + 1, toFill, *srcsamples);
|
|
|
|
}
|
|
|
|
}
|
2019-03-09 21:32:14 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-11 03:34:35 -07:00
|
|
|
/* Load what's left of this loop iteration */
|
2021-03-19 19:02:30 -07:00
|
|
|
const size_t remaining{minz(samplesToLoad, loopEnd-dataPosInt)};
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples(voiceSamples, 0, buffer->mSamples, dataPosInt, sampleType, sampleChannels,
|
|
|
|
srcStep, remaining);
|
2021-03-19 19:02:30 -07:00
|
|
|
|
|
|
|
/* Load repeats of the loop to fill the buffer. */
|
|
|
|
const auto loopSize = static_cast<size_t>(loopEnd - loopStart);
|
|
|
|
size_t samplesLoaded{remaining};
|
|
|
|
while(const size_t toFill{minz(samplesToLoad - samplesLoaded, loopSize)})
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples(voiceSamples, samplesLoaded, buffer->mSamples, loopStart, sampleType,
|
|
|
|
sampleChannels, srcStep, toFill);
|
2021-03-19 19:02:30 -07:00
|
|
|
samplesLoaded += toFill;
|
2019-03-09 21:32:14 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
void LoadBufferCallback(VoiceBufferItem *buffer, const size_t numCallbackSamples,
|
2021-06-21 07:36:47 -07:00
|
|
|
const FmtType sampleType, const FmtChannels sampleChannels, const size_t srcStep,
|
2022-01-01 21:19:53 -08:00
|
|
|
const size_t samplesToLoad, const al::span<float*> voiceSamples)
|
2020-02-17 17:13:00 -08:00
|
|
|
{
|
|
|
|
/* Load what's left to play from the buffer */
|
2021-03-19 19:02:30 -07:00
|
|
|
const size_t remaining{minz(samplesToLoad, numCallbackSamples)};
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples(voiceSamples, 0, buffer->mSamples, 0, sampleType, sampleChannels, srcStep,
|
|
|
|
remaining);
|
2020-02-17 17:13:00 -08:00
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
if(const size_t toFill{samplesToLoad - remaining})
|
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
for(auto *chanbuffer : voiceSamples)
|
2021-03-19 19:02:30 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
auto srcsamples = chanbuffer + remaining - 1;
|
2021-03-19 19:02:30 -07:00
|
|
|
std::fill_n(srcsamples + 1, toFill, *srcsamples);
|
|
|
|
}
|
|
|
|
}
|
2020-02-17 17:13:00 -08:00
|
|
|
}
|
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
void LoadBufferQueue(VoiceBufferItem *buffer, VoiceBufferItem *bufferLoopItem,
|
2021-03-31 09:37:30 -07:00
|
|
|
size_t dataPosInt, const FmtType sampleType, const FmtChannels sampleChannels,
|
2022-01-01 21:19:53 -08:00
|
|
|
const size_t srcStep, const size_t samplesToLoad, const al::span<float*> voiceSamples)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
|
|
|
/* Crawl the buffer queue to fill in the temp buffer */
|
2021-03-19 19:02:30 -07:00
|
|
|
size_t samplesLoaded{0};
|
|
|
|
while(buffer && samplesLoaded != samplesToLoad)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2021-01-24 09:29:56 -08:00
|
|
|
if(dataPosInt >= buffer->mSampleLen)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2021-01-24 09:29:56 -08:00
|
|
|
dataPosInt -= buffer->mSampleLen;
|
|
|
|
buffer = buffer->mNext.load(std::memory_order_acquire);
|
|
|
|
if(!buffer) buffer = bufferLoopItem;
|
2019-03-09 21:32:14 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
const size_t remaining{minz(samplesToLoad-samplesLoaded, buffer->mSampleLen-dataPosInt)};
|
2022-01-01 21:19:53 -08:00
|
|
|
LoadSamples(voiceSamples, samplesLoaded, buffer->mSamples, dataPosInt, sampleType,
|
|
|
|
sampleChannels, srcStep, remaining);
|
2019-03-09 21:32:14 -08:00
|
|
|
|
2021-03-19 19:02:30 -07:00
|
|
|
samplesLoaded += remaining;
|
|
|
|
if(samplesLoaded == samplesToLoad)
|
|
|
|
break;
|
2019-03-09 21:32:14 -08:00
|
|
|
|
2021-01-24 09:29:56 -08:00
|
|
|
dataPosInt = 0;
|
|
|
|
buffer = buffer->mNext.load(std::memory_order_acquire);
|
|
|
|
if(!buffer) buffer = bufferLoopItem;
|
2019-03-09 21:32:14 -08:00
|
|
|
}
|
2021-03-19 19:02:30 -07:00
|
|
|
if(const size_t toFill{samplesToLoad - samplesLoaded})
|
|
|
|
{
|
|
|
|
size_t chanidx{0};
|
2022-01-01 21:19:53 -08:00
|
|
|
for(auto *chanbuffer : voiceSamples)
|
2021-03-19 19:02:30 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
auto srcsamples = chanbuffer + samplesLoaded - 1;
|
2021-03-19 19:02:30 -07:00
|
|
|
std::fill_n(srcsamples + 1, toFill, *srcsamples);
|
|
|
|
++chanidx;
|
|
|
|
}
|
|
|
|
}
|
2019-03-09 21:32:14 -08:00
|
|
|
}
|
|
|
|
|
2019-09-21 21:14:11 -07:00
|
|
|
|
2020-11-20 03:59:14 -08:00
|
|
|
void DoHrtfMix(const float *samples, const uint DstBufferSize, DirectParams &parms,
|
2021-12-18 03:44:31 -08:00
|
|
|
const float TargetGain, const uint Counter, uint OutPos, const bool IsPlaying,
|
|
|
|
DeviceBase *Device)
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2021-03-19 19:02:30 -07:00
|
|
|
const uint IrSize{Device->mIrSize};
|
2019-09-21 21:14:11 -07:00
|
|
|
auto &HrtfSamples = Device->HrtfSourceData;
|
2022-03-30 04:06:00 -07:00
|
|
|
auto &AccumSamples = Device->HrtfAccumData;
|
2019-09-21 21:14:11 -07:00
|
|
|
|
|
|
|
/* Copy the HRTF history and new input samples into a temp buffer. */
|
2020-01-13 19:45:13 -08:00
|
|
|
auto src_iter = std::copy(parms.Hrtf.History.begin(), parms.Hrtf.History.end(),
|
2019-09-21 21:14:11 -07:00
|
|
|
std::begin(HrtfSamples));
|
|
|
|
std::copy_n(samples, DstBufferSize, src_iter);
|
|
|
|
/* Copy the last used samples back into the history buffer for later. */
|
2021-12-18 03:44:31 -08:00
|
|
|
if(likely(IsPlaying))
|
|
|
|
std::copy_n(std::begin(HrtfSamples) + DstBufferSize, parms.Hrtf.History.size(),
|
|
|
|
parms.Hrtf.History.begin());
|
2019-09-21 21:14:11 -07:00
|
|
|
|
2020-05-25 16:57:38 -07:00
|
|
|
/* If fading and this is the first mixing pass, fade between the IRs. */
|
2020-11-20 03:59:14 -08:00
|
|
|
uint fademix{0u};
|
2020-05-25 16:57:38 -07:00
|
|
|
if(Counter && OutPos == 0)
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2020-05-25 16:57:38 -07:00
|
|
|
fademix = minu(DstBufferSize, Counter);
|
2019-09-21 21:14:11 -07:00
|
|
|
|
|
|
|
float gain{TargetGain};
|
|
|
|
|
|
|
|
/* The new coefficients need to fade in completely since they're
|
|
|
|
* replacing the old ones. To keep the gain fading consistent,
|
|
|
|
* interpolate between the old and new target gains given how much of
|
|
|
|
* the fade time this mix handles.
|
|
|
|
*/
|
2020-05-25 16:57:38 -07:00
|
|
|
if(Counter > fademix)
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2020-04-08 06:17:04 -07:00
|
|
|
const float a{static_cast<float>(fademix) / static_cast<float>(Counter)};
|
2022-04-06 17:41:24 -07:00
|
|
|
gain = lerpf(parms.Hrtf.Old.Gain, TargetGain, a);
|
2019-09-21 21:14:11 -07:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:39:30 -08:00
|
|
|
MixHrtfFilter hrtfparams{
|
|
|
|
parms.Hrtf.Target.Coeffs,
|
|
|
|
parms.Hrtf.Target.Delay,
|
|
|
|
0.0f, gain / static_cast<float>(fademix)};
|
2019-11-03 00:30:33 -07:00
|
|
|
MixHrtfBlendSamples(HrtfSamples, AccumSamples+OutPos, IrSize, &parms.Hrtf.Old, &hrtfparams,
|
|
|
|
fademix);
|
2021-02-06 14:39:30 -08:00
|
|
|
|
2019-09-21 21:14:11 -07:00
|
|
|
/* Update the old parameters with the result. */
|
|
|
|
parms.Hrtf.Old = parms.Hrtf.Target;
|
2020-01-05 17:12:48 -08:00
|
|
|
parms.Hrtf.Old.Gain = gain;
|
2019-11-03 00:30:33 -07:00
|
|
|
OutPos += fademix;
|
2019-09-21 21:14:11 -07:00
|
|
|
}
|
|
|
|
|
2020-05-25 16:57:38 -07:00
|
|
|
if(fademix < DstBufferSize)
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint todo{DstBufferSize - fademix};
|
2019-09-21 21:14:11 -07:00
|
|
|
float gain{TargetGain};
|
|
|
|
|
|
|
|
/* Interpolate the target gain if the gain fading lasts longer than
|
|
|
|
* this mix.
|
|
|
|
*/
|
|
|
|
if(Counter > DstBufferSize)
|
|
|
|
{
|
|
|
|
const float a{static_cast<float>(todo) / static_cast<float>(Counter-fademix)};
|
2022-04-06 17:41:24 -07:00
|
|
|
gain = lerpf(parms.Hrtf.Old.Gain, TargetGain, a);
|
2019-09-21 21:14:11 -07:00
|
|
|
}
|
|
|
|
|
2021-02-06 14:39:30 -08:00
|
|
|
MixHrtfFilter hrtfparams{
|
|
|
|
parms.Hrtf.Target.Coeffs,
|
|
|
|
parms.Hrtf.Target.Delay,
|
|
|
|
parms.Hrtf.Old.Gain,
|
|
|
|
(gain - parms.Hrtf.Old.Gain) / static_cast<float>(todo)};
|
2019-11-03 00:30:33 -07:00
|
|
|
MixHrtfSamples(HrtfSamples+fademix, AccumSamples+OutPos, IrSize, &hrtfparams, todo);
|
2021-02-06 14:39:30 -08:00
|
|
|
|
2020-01-05 17:12:48 -08:00
|
|
|
/* Store the now-current gain for next time. */
|
|
|
|
parms.Hrtf.Old.Gain = gain;
|
2019-09-21 21:14:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-05 18:25:50 -08:00
|
|
|
void DoNfcMix(const al::span<const float> samples, FloatBufferLine *OutBuffer, DirectParams &parms,
|
2021-04-24 08:28:13 -07:00
|
|
|
const float *TargetGains, const uint Counter, const uint OutPos, DeviceBase *Device)
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2020-01-05 18:25:50 -08:00
|
|
|
using FilterProc = void (NfcFilter::*)(const al::span<const float>, float*);
|
2020-12-04 13:53:56 -08:00
|
|
|
static constexpr FilterProc NfcProcess[MaxAmbiOrder+1]{
|
2020-01-05 18:25:50 -08:00
|
|
|
nullptr, &NfcFilter::process1, &NfcFilter::process2, &NfcFilter::process3};
|
|
|
|
|
|
|
|
float *CurrentGains{parms.Gains.Current.data()};
|
|
|
|
MixSamples(samples, {OutBuffer, 1u}, CurrentGains, TargetGains, Counter, OutPos);
|
|
|
|
++OutBuffer;
|
|
|
|
++CurrentGains;
|
|
|
|
++TargetGains;
|
2019-09-21 21:14:11 -07:00
|
|
|
|
2019-12-24 23:36:08 -08:00
|
|
|
const al::span<float> nfcsamples{Device->NfcSampleData, samples.size()};
|
2020-01-05 18:25:50 -08:00
|
|
|
size_t order{1};
|
|
|
|
while(const size_t chancount{Device->NumChannelsPerOrder[order]})
|
2019-09-21 21:14:11 -07:00
|
|
|
{
|
2020-01-05 18:25:50 -08:00
|
|
|
(parms.NFCtrlFilter.*NfcProcess[order])(samples, nfcsamples.data());
|
|
|
|
MixSamples(nfcsamples, {OutBuffer, chancount}, CurrentGains, TargetGains, Counter, OutPos);
|
|
|
|
OutBuffer += chancount;
|
|
|
|
CurrentGains += chancount;
|
|
|
|
TargetGains += chancount;
|
2020-12-04 13:53:56 -08:00
|
|
|
if(++order == MaxAmbiOrder+1)
|
2020-01-05 18:25:50 -08:00
|
|
|
break;
|
|
|
|
}
|
2019-09-21 21:14:11 -07:00
|
|
|
}
|
|
|
|
|
2018-11-20 02:59:02 -08:00
|
|
|
} // namespace
|
2012-09-11 05:24:19 -07:00
|
|
|
|
2021-04-24 08:28:13 -07:00
|
|
|
void Voice::mix(const State vstate, ContextBase *Context, const uint SamplesToDo)
|
2010-09-22 09:38:24 -07:00
|
|
|
{
|
2019-10-05 21:23:31 -07:00
|
|
|
static constexpr std::array<float,MAX_OUTPUT_CHANNELS> SilentTarget{};
|
2019-03-09 18:34:00 -08:00
|
|
|
|
2018-11-25 13:19:01 -08:00
|
|
|
ASSUME(SamplesToDo > 0);
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2019-03-11 20:00:14 -07:00
|
|
|
/* Get voice info */
|
2020-11-20 03:59:14 -08:00
|
|
|
uint DataPosInt{mPosition.load(std::memory_order_relaxed)};
|
|
|
|
uint DataPosFrac{mPositionFrac.load(std::memory_order_relaxed)};
|
2021-01-25 09:08:49 -08:00
|
|
|
VoiceBufferItem *BufferListItem{mCurrentBuffer.load(std::memory_order_relaxed)};
|
|
|
|
VoiceBufferItem *BufferLoopItem{mLoopBuffer.load(std::memory_order_relaxed)};
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint increment{mStep};
|
2020-01-08 06:40:58 -08:00
|
|
|
if UNLIKELY(increment < 1)
|
|
|
|
{
|
|
|
|
/* If the voice is supposed to be stopping but can't be mixed, just
|
|
|
|
* stop it before bailing.
|
|
|
|
*/
|
2020-03-28 17:20:38 -07:00
|
|
|
if(vstate == Stopping)
|
|
|
|
mPlayState.store(Stopped, std::memory_order_release);
|
2020-01-08 06:40:58 -08:00
|
|
|
return;
|
|
|
|
}
|
2018-11-25 13:19:01 -08:00
|
|
|
|
2021-04-24 08:28:13 -07:00
|
|
|
DeviceBase *Device{Context->mDevice};
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint NumSends{Device->NumAuxSends};
|
2018-11-25 13:19:01 -08:00
|
|
|
|
2020-10-21 17:16:27 -07:00
|
|
|
ResamplerFunc Resample{(increment == MixerFracOne && DataPosFrac == 0) ?
|
2019-08-31 14:53:28 -07:00
|
|
|
Resample_<CopyTag,CTag> : mResampler};
|
2018-11-25 13:19:01 -08:00
|
|
|
|
2021-12-23 13:43:10 -08:00
|
|
|
uint Counter{mFlags.test(VoiceIsFading) ? SamplesToDo : 0};
|
2018-12-25 19:54:14 -08:00
|
|
|
if(!Counter)
|
|
|
|
{
|
|
|
|
/* No fading, just overwrite the old/current params. */
|
2020-03-25 21:06:24 -07:00
|
|
|
for(auto &chandata : mChans)
|
2018-12-25 19:54:14 -08:00
|
|
|
{
|
2019-09-14 18:27:57 -07:00
|
|
|
{
|
|
|
|
DirectParams &parms = chandata.mDryParams;
|
2021-12-23 13:43:10 -08:00
|
|
|
if(!mFlags.test(VoiceHasHrtf))
|
2019-10-05 21:23:31 -07:00
|
|
|
parms.Gains.Current = parms.Gains.Target;
|
2019-09-14 18:27:57 -07:00
|
|
|
else
|
|
|
|
parms.Hrtf.Old = parms.Hrtf.Target;
|
|
|
|
}
|
2020-11-20 03:59:14 -08:00
|
|
|
for(uint send{0};send < NumSends;++send)
|
2018-12-25 19:54:14 -08:00
|
|
|
{
|
2019-08-31 14:53:28 -07:00
|
|
|
if(mSend[send].Buffer.empty())
|
2019-06-03 22:24:26 -07:00
|
|
|
continue;
|
2018-12-25 19:54:14 -08:00
|
|
|
|
2019-06-24 13:21:06 -07:00
|
|
|
SendParams &parms = chandata.mWetParams[send];
|
2019-10-05 21:23:31 -07:00
|
|
|
parms.Gains.Current = parms.Gains.Target;
|
2019-06-03 22:24:26 -07:00
|
|
|
}
|
2018-12-25 19:54:14 -08:00
|
|
|
}
|
|
|
|
}
|
2021-01-27 14:17:46 -08:00
|
|
|
else if UNLIKELY(!BufferListItem)
|
|
|
|
Counter = std::min(Counter, 64u);
|
2021-01-08 18:54:46 -08:00
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
std::array<float*,DeviceBase::MixerChannelsMax> SamplePointers;
|
|
|
|
const al::span<float*> MixingSamples{SamplePointers.data(), mChans.size()};
|
|
|
|
auto offset_bufferline = [](DeviceBase::MixerBufferLine &bufline) noexcept -> float*
|
|
|
|
{ return bufline.data() + MaxResamplerEdge; };
|
|
|
|
std::transform(Device->mSampleData.end() - mChans.size(), Device->mSampleData.end(),
|
|
|
|
MixingSamples.begin(), offset_bufferline);
|
|
|
|
|
2022-05-17 02:28:57 -07:00
|
|
|
const uint PostPadding{MaxResamplerEdge + mDecoderPadding};
|
2020-11-20 03:59:14 -08:00
|
|
|
uint buffers_done{0u};
|
|
|
|
uint OutPos{0u};
|
2010-09-22 09:38:24 -07:00
|
|
|
do {
|
2013-10-26 08:49:37 -07:00
|
|
|
/* Figure out how many buffer samples will be needed */
|
2020-11-20 03:59:14 -08:00
|
|
|
uint DstBufferSize{SamplesToDo - OutPos};
|
|
|
|
uint SrcBufferSize;
|
2018-12-01 13:47:56 -08:00
|
|
|
|
2020-10-21 17:16:27 -07:00
|
|
|
if(increment <= MixerFracOne)
|
2018-12-01 13:47:56 -08:00
|
|
|
{
|
2020-06-29 12:16:30 -07:00
|
|
|
/* Calculate the last written dst sample pos. */
|
|
|
|
uint64_t DataSize64{DstBufferSize - 1};
|
|
|
|
/* Calculate the last read src sample pos. */
|
2020-10-21 17:16:27 -07:00
|
|
|
DataSize64 = (DataSize64*increment + DataPosFrac) >> MixerFracBits;
|
2020-06-29 12:16:30 -07:00
|
|
|
/* +1 to get the src sample count, include padding. */
|
2021-03-31 09:37:30 -07:00
|
|
|
DataSize64 += 1 + PostPadding;
|
2020-06-29 12:16:30 -07:00
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
/* Result is guaranteed to be <= BufferLineSize+PostPadding since
|
|
|
|
* we won't use more src samples than dst samples+padding.
|
2018-12-01 13:47:56 -08:00
|
|
|
*/
|
2020-11-20 03:59:14 -08:00
|
|
|
SrcBufferSize = static_cast<uint>(DataSize64);
|
2020-06-29 12:16:30 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint64_t DataSize64{DstBufferSize};
|
|
|
|
/* Calculate the end src sample pos, include padding. */
|
2020-10-21 17:16:27 -07:00
|
|
|
DataSize64 = (DataSize64*increment + DataPosFrac) >> MixerFracBits;
|
2021-03-31 09:37:30 -07:00
|
|
|
DataSize64 += PostPadding;
|
2020-06-29 12:16:30 -07:00
|
|
|
|
2021-06-21 09:04:33 -07:00
|
|
|
if(DataSize64 <= DeviceBase::MixerLineSize - MaxResamplerEdge)
|
2020-11-20 03:59:14 -08:00
|
|
|
SrcBufferSize = static_cast<uint>(DataSize64);
|
2020-07-12 18:51:10 -07:00
|
|
|
else
|
2020-03-23 11:35:08 -07:00
|
|
|
{
|
2020-06-29 12:16:30 -07:00
|
|
|
/* If the source size got saturated, we can't fill the desired
|
2020-07-12 18:51:10 -07:00
|
|
|
* dst size. Figure out how many samples we can actually mix.
|
2020-03-23 11:35:08 -07:00
|
|
|
*/
|
2021-06-21 09:04:33 -07:00
|
|
|
SrcBufferSize = DeviceBase::MixerLineSize - MaxResamplerEdge;
|
2020-07-12 18:51:10 -07:00
|
|
|
|
2021-03-31 09:37:30 -07:00
|
|
|
DataSize64 = SrcBufferSize - PostPadding;
|
2020-10-21 17:16:27 -07:00
|
|
|
DataSize64 = ((DataSize64<<MixerFracBits) - DataPosFrac) / increment;
|
2020-06-29 12:16:30 -07:00
|
|
|
if(DataSize64 < DstBufferSize)
|
|
|
|
{
|
|
|
|
/* Some mixers require being 16-byte aligned, so also limit
|
|
|
|
* to a multiple of 4 samples to maintain alignment.
|
|
|
|
*/
|
2020-11-20 03:59:14 -08:00
|
|
|
DstBufferSize = static_cast<uint>(DataSize64) & ~3u;
|
2022-01-08 23:21:35 -08:00
|
|
|
/* If the voice is stopping, only one mixing iteration will
|
|
|
|
* be done, so ensure it fades out completely this mix.
|
|
|
|
*/
|
|
|
|
if(unlikely(vstate == Stopping))
|
|
|
|
Counter = std::min(Counter, DstBufferSize);
|
2020-06-29 12:16:30 -07:00
|
|
|
}
|
2021-03-31 09:37:30 -07:00
|
|
|
ASSUME(DstBufferSize > 0);
|
2020-03-23 11:35:08 -07:00
|
|
|
}
|
2018-12-01 13:47:56 -08:00
|
|
|
}
|
2012-09-26 17:16:25 -07:00
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
if(unlikely(!BufferListItem))
|
2010-09-22 09:38:24 -07:00
|
|
|
{
|
2022-01-08 23:21:35 -08:00
|
|
|
const size_t srcOffset{(increment*DstBufferSize + DataPosFrac)>>MixerFracBits};
|
2021-06-21 09:04:33 -07:00
|
|
|
auto prevSamples = mPrevSamples.data();
|
2022-01-01 21:19:53 -08:00
|
|
|
SrcBufferSize = SrcBufferSize - PostPadding + MaxResamplerEdge;
|
|
|
|
for(auto *chanbuffer : MixingSamples)
|
2021-01-27 14:17:46 -08:00
|
|
|
{
|
2021-06-21 09:04:33 -07:00
|
|
|
auto srcend = std::copy_n(prevSamples->data(), MaxResamplerPadding,
|
2022-01-01 21:19:53 -08:00
|
|
|
chanbuffer-MaxResamplerEdge);
|
2021-03-19 19:02:30 -07:00
|
|
|
|
2021-01-27 14:17:46 -08:00
|
|
|
/* When loading from a voice that ended prematurely, only take
|
|
|
|
* the samples that get closest to 0 amplitude. This helps
|
|
|
|
* certain sounds fade out better.
|
|
|
|
*/
|
|
|
|
auto abs_lt = [](const float lhs, const float rhs) noexcept -> bool
|
|
|
|
{ return std::abs(lhs) < std::abs(rhs); };
|
2022-01-01 21:19:53 -08:00
|
|
|
auto srciter = std::min_element(chanbuffer, srcend, abs_lt);
|
2010-11-25 11:16:19 -08:00
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
std::fill(srciter+1, chanbuffer + SrcBufferSize, *srciter);
|
2022-01-08 23:21:35 -08:00
|
|
|
|
|
|
|
std::copy_n(chanbuffer-MaxResamplerEdge+srcOffset, prevSamples->size(),
|
|
|
|
prevSamples->data());
|
|
|
|
++prevSamples;
|
2010-09-22 09:38:24 -07:00
|
|
|
}
|
2021-03-19 19:02:30 -07:00
|
|
|
}
|
|
|
|
else
|
2021-03-31 09:37:30 -07:00
|
|
|
{
|
2021-06-21 09:04:33 -07:00
|
|
|
auto prevSamples = mPrevSamples.data();
|
2022-01-01 21:19:53 -08:00
|
|
|
for(auto *chanbuffer : MixingSamples)
|
2021-06-21 09:04:33 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
std::copy_n(prevSamples->data(), MaxResamplerEdge, chanbuffer-MaxResamplerEdge);
|
2021-06-21 09:04:33 -07:00
|
|
|
++prevSamples;
|
|
|
|
}
|
2021-12-23 13:43:10 -08:00
|
|
|
if(mFlags.test(VoiceIsStatic))
|
2021-12-15 14:28:26 -08:00
|
|
|
LoadBufferStatic(BufferListItem, BufferLoopItem, DataPosInt, mFmtType,
|
|
|
|
mFmtChannels, mFrameStep, SrcBufferSize, MixingSamples);
|
2021-12-23 13:43:10 -08:00
|
|
|
else if(mFlags.test(VoiceIsCallback))
|
2021-06-14 01:51:04 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
if(!mFlags.test(VoiceCallbackStopped) && SrcBufferSize > mNumCallbackSamples)
|
2021-06-14 01:51:04 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
const size_t byteOffset{mNumCallbackSamples*mFrameSize};
|
|
|
|
const size_t needBytes{SrcBufferSize*mFrameSize - byteOffset};
|
|
|
|
|
|
|
|
const int gotBytes{BufferListItem->mCallback(BufferListItem->mUserData,
|
|
|
|
&BufferListItem->mSamples[byteOffset], static_cast<int>(needBytes))};
|
|
|
|
if(gotBytes < 0)
|
|
|
|
mFlags.set(VoiceCallbackStopped);
|
|
|
|
else if(static_cast<uint>(gotBytes) < needBytes)
|
2021-06-14 01:51:04 -07:00
|
|
|
{
|
2022-01-01 21:19:53 -08:00
|
|
|
mFlags.set(VoiceCallbackStopped);
|
|
|
|
mNumCallbackSamples += static_cast<uint>(gotBytes) / mFrameSize;
|
2021-06-14 01:51:04 -07:00
|
|
|
}
|
2022-01-01 21:19:53 -08:00
|
|
|
else
|
|
|
|
mNumCallbackSamples = SrcBufferSize;
|
2021-06-14 01:51:04 -07:00
|
|
|
}
|
2021-03-31 09:37:30 -07:00
|
|
|
LoadBufferCallback(BufferListItem, mNumCallbackSamples, mFmtType, mFmtChannels,
|
2021-12-15 14:28:26 -08:00
|
|
|
mFrameStep, SrcBufferSize, MixingSamples);
|
2021-06-14 01:51:04 -07:00
|
|
|
}
|
2021-03-31 09:37:30 -07:00
|
|
|
else
|
|
|
|
LoadBufferQueue(BufferListItem, BufferLoopItem, DataPosInt, mFmtType, mFmtChannels,
|
2021-12-15 14:28:26 -08:00
|
|
|
mFrameStep, SrcBufferSize, MixingSamples);
|
2021-03-31 09:37:30 -07:00
|
|
|
|
2022-01-01 21:19:53 -08:00
|
|
|
const size_t srcOffset{(increment*DstBufferSize + DataPosFrac)>>MixerFracBits};
|
2021-03-31 09:37:30 -07:00
|
|
|
if(mDecoder)
|
|
|
|
{
|
|
|
|
SrcBufferSize = SrcBufferSize - PostPadding + MaxResamplerEdge;
|
2022-05-14 21:23:03 -07:00
|
|
|
mDecoder->decode(MixingSamples, SrcBufferSize,
|
2022-06-07 01:00:21 -07:00
|
|
|
likely(vstate == Playing) ? srcOffset : 0);
|
2021-03-31 09:37:30 -07:00
|
|
|
}
|
2022-01-01 21:19:53 -08:00
|
|
|
/* Store the last source samples used for next time. */
|
|
|
|
if(likely(vstate == Playing))
|
|
|
|
{
|
|
|
|
prevSamples = mPrevSamples.data();
|
|
|
|
for(auto *chanbuffer : MixingSamples)
|
|
|
|
{
|
|
|
|
/* Store the last source samples used for next time. */
|
|
|
|
std::copy_n(chanbuffer-MaxResamplerEdge+srcOffset, prevSamples->size(),
|
|
|
|
prevSamples->data());
|
|
|
|
++prevSamples;
|
|
|
|
}
|
|
|
|
}
|
2021-03-31 09:37:30 -07:00
|
|
|
}
|
2010-09-22 09:38:24 -07:00
|
|
|
|
2021-06-21 09:04:33 -07:00
|
|
|
auto voiceSamples = MixingSamples.begin();
|
2021-03-19 19:02:30 -07:00
|
|
|
for(auto &chandata : mChans)
|
|
|
|
{
|
2019-02-21 17:48:08 -08:00
|
|
|
/* Resample, then apply ambisonic upsampling as needed. */
|
2022-01-01 21:19:53 -08:00
|
|
|
float *ResampledData{Resample(&mResampleState, *voiceSamples, DataPosFrac, increment,
|
2021-03-19 19:02:30 -07:00
|
|
|
{Device->ResampledData, DstBufferSize})};
|
2021-06-21 09:04:33 -07:00
|
|
|
++voiceSamples;
|
2022-01-01 21:19:53 -08:00
|
|
|
|
2021-12-23 13:43:10 -08:00
|
|
|
if(mFlags.test(VoiceIsAmbisonic))
|
2021-12-09 22:00:35 -08:00
|
|
|
chandata.mAmbiSplitter.processScale({ResampledData, DstBufferSize},
|
|
|
|
chandata.mAmbiHFScale, chandata.mAmbiLFScale);
|
2019-02-21 17:48:08 -08:00
|
|
|
|
|
|
|
/* Now filter and mix to the appropriate outputs. */
|
2021-03-19 19:02:30 -07:00
|
|
|
const al::span<float,BufferLineSize> FilterBuf{Device->FilteredData};
|
2012-09-26 17:16:25 -07:00
|
|
|
{
|
2019-06-24 13:33:09 -07:00
|
|
|
DirectParams &parms = chandata.mDryParams;
|
2021-03-19 19:02:30 -07:00
|
|
|
const float *samples{DoFilters(parms.LowPass, parms.HighPass, FilterBuf.data(),
|
2019-12-25 18:39:22 -08:00
|
|
|
{ResampledData, DstBufferSize}, mDirect.FilterType)};
|
2012-09-14 04:13:18 -07:00
|
|
|
|
2021-12-23 13:43:10 -08:00
|
|
|
if(mFlags.test(VoiceHasHrtf))
|
2016-02-14 01:22:01 -08:00
|
|
|
{
|
2021-12-18 03:44:31 -08:00
|
|
|
const float TargetGain{parms.Hrtf.Target.Gain * likely(vstate == Playing)};
|
|
|
|
DoHrtfMix(samples, DstBufferSize, parms, TargetGain, Counter, OutPos,
|
|
|
|
(vstate == Playing), Device);
|
2019-03-10 12:50:38 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-18 03:44:31 -08:00
|
|
|
const float *TargetGains{likely(vstate == Playing) ? parms.Gains.Target.data()
|
|
|
|
: SilentTarget.data()};
|
2021-12-23 13:43:10 -08:00
|
|
|
if(mFlags.test(VoiceHasNfc))
|
2021-12-18 03:44:31 -08:00
|
|
|
DoNfcMix({samples, DstBufferSize}, mDirect.Buffer.data(), parms,
|
|
|
|
TargetGains, Counter, OutPos, Device);
|
|
|
|
else
|
|
|
|
MixSamples({samples, DstBufferSize}, mDirect.Buffer,
|
|
|
|
parms.Gains.Current.data(), TargetGains, Counter, OutPos);
|
2019-03-10 12:50:38 -07:00
|
|
|
}
|
2012-09-26 17:16:25 -07:00
|
|
|
}
|
2012-09-11 05:24:19 -07:00
|
|
|
|
2020-11-20 03:59:14 -08:00
|
|
|
for(uint send{0};send < NumSends;++send)
|
2012-09-08 21:34:36 -07:00
|
|
|
{
|
2019-08-31 14:53:28 -07:00
|
|
|
if(mSend[send].Buffer.empty())
|
2019-06-03 22:24:26 -07:00
|
|
|
continue;
|
2012-09-11 05:24:19 -07:00
|
|
|
|
2019-06-24 13:33:09 -07:00
|
|
|
SendParams &parms = chandata.mWetParams[send];
|
2021-03-19 19:02:30 -07:00
|
|
|
const float *samples{DoFilters(parms.LowPass, parms.HighPass, FilterBuf.data(),
|
2019-12-25 18:39:22 -08:00
|
|
|
{ResampledData, DstBufferSize}, mSend[send].FilterType)};
|
2016-02-14 01:22:01 -08:00
|
|
|
|
2021-12-18 03:44:31 -08:00
|
|
|
const float *TargetGains{likely(vstate == Playing) ? parms.Gains.Target.data()
|
|
|
|
: SilentTarget.data()};
|
2019-10-05 21:23:31 -07:00
|
|
|
MixSamples({samples, DstBufferSize}, mSend[send].Buffer,
|
|
|
|
parms.Gains.Current.data(), TargetGains, Counter, OutPos);
|
2019-09-03 21:23:54 -07:00
|
|
|
}
|
2012-04-27 23:46:51 -07:00
|
|
|
}
|
2022-01-08 23:21:35 -08:00
|
|
|
/* If the voice is stopping, we're now done. */
|
|
|
|
if(unlikely(vstate == Stopping))
|
|
|
|
break;
|
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
/* Update positions */
|
2014-06-02 19:19:22 -07:00
|
|
|
DataPosFrac += increment*DstBufferSize;
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint SrcSamplesDone{DataPosFrac>>MixerFracBits};
|
2020-02-17 17:13:00 -08:00
|
|
|
DataPosInt += SrcSamplesDone;
|
2020-10-21 17:16:27 -07:00
|
|
|
DataPosFrac &= MixerFracMask;
|
2014-06-02 19:19:22 -07:00
|
|
|
|
2012-09-26 17:16:25 -07:00
|
|
|
OutPos += DstBufferSize;
|
2019-08-20 06:03:31 -07:00
|
|
|
Counter = maxu(DstBufferSize, Counter) - DstBufferSize;
|
2010-08-03 23:19:36 -07:00
|
|
|
|
2021-12-18 03:44:31 -08:00
|
|
|
if(unlikely(!BufferListItem))
|
2019-03-09 18:34:00 -08:00
|
|
|
{
|
2019-05-05 01:51:46 -07:00
|
|
|
/* Do nothing extra when there's no buffers. */
|
2019-03-09 18:34:00 -08:00
|
|
|
}
|
2021-12-23 13:43:10 -08:00
|
|
|
else if(mFlags.test(VoiceIsStatic))
|
2010-08-03 23:19:36 -07:00
|
|
|
{
|
2018-02-01 21:07:55 -08:00
|
|
|
if(BufferLoopItem)
|
2010-11-25 11:16:19 -08:00
|
|
|
{
|
2018-02-01 21:07:55 -08:00
|
|
|
/* Handle looping static source */
|
2021-01-24 02:07:39 -08:00
|
|
|
const uint LoopStart{BufferListItem->mLoopStart};
|
|
|
|
const uint LoopEnd{BufferListItem->mLoopEnd};
|
2018-02-01 21:07:55 -08:00
|
|
|
if(DataPosInt >= LoopEnd)
|
|
|
|
{
|
|
|
|
assert(LoopEnd > LoopStart);
|
|
|
|
DataPosInt = ((DataPosInt-LoopStart)%(LoopEnd-LoopStart)) + LoopStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Handle non-looping static source */
|
2019-08-11 03:34:35 -07:00
|
|
|
if(DataPosInt >= BufferListItem->mSampleLen)
|
2018-02-01 21:07:55 -08:00
|
|
|
{
|
2019-01-07 03:37:13 -08:00
|
|
|
BufferListItem = nullptr;
|
2018-02-01 21:07:55 -08:00
|
|
|
break;
|
|
|
|
}
|
2011-02-06 01:07:37 -08:00
|
|
|
}
|
2017-12-16 11:34:52 -08:00
|
|
|
}
|
2021-12-23 13:43:10 -08:00
|
|
|
else if(mFlags.test(VoiceIsCallback))
|
2020-02-17 04:50:00 -08:00
|
|
|
{
|
2022-01-08 23:21:35 -08:00
|
|
|
/* Handle callback buffer source */
|
|
|
|
if(SrcSamplesDone < mNumCallbackSamples)
|
2020-02-17 17:13:00 -08:00
|
|
|
{
|
2022-01-08 23:21:35 -08:00
|
|
|
const size_t byteOffset{SrcSamplesDone*mFrameSize};
|
|
|
|
const size_t byteEnd{mNumCallbackSamples*mFrameSize};
|
|
|
|
al::byte *data{BufferListItem->mSamples};
|
|
|
|
std::copy(data+byteOffset, data+byteEnd, data);
|
|
|
|
mNumCallbackSamples -= SrcSamplesDone;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BufferListItem = nullptr;
|
|
|
|
mNumCallbackSamples = 0;
|
2020-02-17 17:13:00 -08:00
|
|
|
}
|
2020-02-17 04:50:00 -08:00
|
|
|
}
|
2019-10-14 20:45:23 -07:00
|
|
|
else
|
2017-12-16 11:34:52 -08:00
|
|
|
{
|
2018-02-01 21:07:55 -08:00
|
|
|
/* Handle streaming source */
|
2019-10-14 20:45:23 -07:00
|
|
|
do {
|
|
|
|
if(BufferListItem->mSampleLen > DataPosInt)
|
|
|
|
break;
|
2011-02-06 01:07:37 -08:00
|
|
|
|
2019-10-14 20:45:23 -07:00
|
|
|
DataPosInt -= BufferListItem->mSampleLen;
|
2018-09-16 17:38:55 -07:00
|
|
|
|
2019-10-14 20:45:23 -07:00
|
|
|
++buffers_done;
|
|
|
|
BufferListItem = BufferListItem->mNext.load(std::memory_order_relaxed);
|
|
|
|
if(!BufferListItem) BufferListItem = BufferLoopItem;
|
|
|
|
} while(BufferListItem);
|
2010-08-03 23:19:36 -07:00
|
|
|
}
|
2022-01-08 23:21:35 -08:00
|
|
|
} while(OutPos < SamplesToDo);
|
2010-08-03 23:19:36 -07:00
|
|
|
|
2021-12-23 13:43:10 -08:00
|
|
|
mFlags.set(VoiceIsFading);
|
2016-02-14 01:22:01 -08:00
|
|
|
|
2019-03-09 18:34:00 -08:00
|
|
|
/* Don't update positions and buffers if we were stopping. */
|
2021-12-18 03:44:31 -08:00
|
|
|
if(unlikely(vstate == Stopping))
|
2019-03-09 18:34:00 -08:00
|
|
|
{
|
2020-03-28 17:20:38 -07:00
|
|
|
mPlayState.store(Stopped, std::memory_order_release);
|
2019-03-09 18:34:00 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-31 14:53:28 -07:00
|
|
|
/* Capture the source ID in case it's reset for stopping. */
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint SourceID{mSourceID.load(std::memory_order_relaxed)};
|
2019-08-31 14:53:28 -07:00
|
|
|
|
2019-03-11 20:00:14 -07:00
|
|
|
/* Update voice info */
|
2019-08-31 14:53:28 -07:00
|
|
|
mPosition.store(DataPosInt, std::memory_order_relaxed);
|
|
|
|
mPositionFrac.store(DataPosFrac, std::memory_order_relaxed);
|
|
|
|
mCurrentBuffer.store(BufferListItem, std::memory_order_relaxed);
|
2019-10-14 20:45:23 -07:00
|
|
|
if(!BufferListItem)
|
2019-03-09 21:32:14 -08:00
|
|
|
{
|
2019-08-31 14:53:28 -07:00
|
|
|
mLoopBuffer.store(nullptr, std::memory_order_relaxed);
|
|
|
|
mSourceID.store(0u, std::memory_order_relaxed);
|
2019-03-09 21:32:14 -08:00
|
|
|
}
|
|
|
|
std::atomic_thread_fence(std::memory_order_release);
|
2018-02-01 01:36:03 -08:00
|
|
|
|
2018-02-01 21:07:55 -08:00
|
|
|
/* Send any events now, after the position/buffer info was updated. */
|
2020-11-20 03:59:14 -08:00
|
|
|
const uint enabledevt{Context->mEnabledEvts.load(std::memory_order_acquire)};
|
2021-10-10 05:07:31 -07:00
|
|
|
if(buffers_done > 0 && (enabledevt&AsyncEvent::BufferCompleted))
|
2018-12-04 16:33:26 -08:00
|
|
|
{
|
2019-07-30 09:05:54 -07:00
|
|
|
RingBuffer *ring{Context->mAsyncEvents.get()};
|
2018-12-27 10:44:02 -08:00
|
|
|
auto evt_vec = ring->getWriteVector();
|
|
|
|
if(evt_vec.first.len > 0)
|
2018-12-25 09:32:38 -08:00
|
|
|
{
|
2021-10-08 11:05:36 -07:00
|
|
|
AsyncEvent *evt{al::construct_at(reinterpret_cast<AsyncEvent*>(evt_vec.first.buf),
|
2021-10-10 05:07:31 -07:00
|
|
|
AsyncEvent::BufferCompleted)};
|
2018-12-25 09:32:38 -08:00
|
|
|
evt->u.bufcomp.id = SourceID;
|
|
|
|
evt->u.bufcomp.count = buffers_done;
|
2018-12-26 21:22:17 -08:00
|
|
|
ring->writeAdvance(1);
|
2018-12-25 09:32:38 -08:00
|
|
|
}
|
2018-12-04 16:33:26 -08:00
|
|
|
}
|
2018-02-01 01:36:03 -08:00
|
|
|
|
2019-10-14 20:45:23 -07:00
|
|
|
if(!BufferListItem)
|
2019-03-09 16:48:07 -08:00
|
|
|
{
|
2019-03-09 21:32:14 -08:00
|
|
|
/* If the voice just ended, set it to Stopping so the next render
|
|
|
|
* ensures any residual noise fades to 0 amplitude.
|
|
|
|
*/
|
2020-03-28 17:20:38 -07:00
|
|
|
mPlayState.store(Stopping, std::memory_order_release);
|
2021-10-10 05:07:31 -07:00
|
|
|
if((enabledevt&AsyncEvent::SourceStateChange))
|
2019-08-31 14:53:28 -07:00
|
|
|
SendSourceStoppedEvent(Context, SourceID);
|
2019-03-09 16:48:07 -08:00
|
|
|
}
|
2010-08-03 23:19:36 -07:00
|
|
|
}
|
2021-03-30 07:04:06 -07:00
|
|
|
|
2021-04-24 08:28:13 -07:00
|
|
|
void Voice::prepare(DeviceBase *device)
|
2021-03-30 07:04:06 -07:00
|
|
|
{
|
2021-12-15 02:01:22 -08:00
|
|
|
/* Even if storing really high order ambisonics, we only mix channels for
|
2022-01-02 00:18:29 -08:00
|
|
|
* orders up to the device order. The rest are simply dropped.
|
2021-12-15 02:01:22 -08:00
|
|
|
*/
|
|
|
|
uint num_channels{(mFmtChannels == FmtUHJ2 || mFmtChannels == FmtSuperStereo) ? 3 :
|
2022-01-02 00:18:29 -08:00
|
|
|
ChannelsFromFmt(mFmtChannels, minu(mAmbiOrder, device->mAmbiOrder))};
|
2021-12-15 02:01:22 -08:00
|
|
|
if(unlikely(num_channels > device->mSampleData.size()))
|
|
|
|
{
|
|
|
|
ERR("Unexpected channel count: %u (limit: %zu, %d:%d)\n", num_channels,
|
|
|
|
device->mSampleData.size(), mFmtChannels, mAmbiOrder);
|
|
|
|
num_channels = static_cast<uint>(device->mSampleData.size());
|
|
|
|
}
|
|
|
|
if(mChans.capacity() > 2 && num_channels < mChans.capacity())
|
|
|
|
{
|
|
|
|
decltype(mChans){}.swap(mChans);
|
|
|
|
decltype(mPrevSamples){}.swap(mPrevSamples);
|
|
|
|
}
|
|
|
|
mChans.reserve(maxu(2, num_channels));
|
|
|
|
mChans.resize(num_channels);
|
|
|
|
mPrevSamples.reserve(maxu(2, num_channels));
|
|
|
|
mPrevSamples.resize(num_channels);
|
|
|
|
|
2022-05-14 21:23:03 -07:00
|
|
|
if(mFmtChannels == FmtSuperStereo)
|
2022-05-17 02:28:57 -07:00
|
|
|
{
|
2022-08-08 03:44:25 -07:00
|
|
|
if(UhjQuality >= UhjLengthHq)
|
|
|
|
{
|
|
|
|
mDecoder = std::make_unique<UhjStereoDecoder<UhjLengthHq>>();
|
|
|
|
mDecoderPadding = UhjStereoDecoder<UhjLengthHq>::sFilterDelay;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDecoder = std::make_unique<UhjStereoDecoder<UhjLengthLq>>();
|
|
|
|
mDecoderPadding = UhjStereoDecoder<UhjLengthLq>::sFilterDelay;
|
|
|
|
}
|
2022-05-17 02:28:57 -07:00
|
|
|
}
|
2022-05-14 21:23:03 -07:00
|
|
|
else if(IsUHJ(mFmtChannels))
|
2022-05-17 02:28:57 -07:00
|
|
|
{
|
2022-08-08 03:44:25 -07:00
|
|
|
if(UhjQuality >= UhjLengthHq)
|
|
|
|
{
|
|
|
|
mDecoder = std::make_unique<UhjDecoder<UhjLengthHq>>();
|
|
|
|
mDecoderPadding = UhjDecoder<UhjLengthHq>::sFilterDelay;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mDecoder = std::make_unique<UhjDecoder<UhjLengthLq>>();
|
|
|
|
mDecoderPadding = UhjDecoder<UhjLengthLq>::sFilterDelay;
|
|
|
|
}
|
2022-05-17 02:28:57 -07:00
|
|
|
}
|
2021-12-11 17:50:24 -08:00
|
|
|
else
|
2022-05-17 02:28:57 -07:00
|
|
|
{
|
2021-03-31 09:37:30 -07:00
|
|
|
mDecoder = nullptr;
|
2022-05-17 02:28:57 -07:00
|
|
|
mDecoderPadding = 0;
|
|
|
|
}
|
2021-03-31 09:37:30 -07:00
|
|
|
|
2021-03-30 07:04:06 -07:00
|
|
|
/* Clear the stepping value explicitly so the mixer knows not to mix this
|
|
|
|
* until the update gets applied.
|
|
|
|
*/
|
|
|
|
mStep = 0;
|
|
|
|
|
|
|
|
/* Make sure the sample history is cleared. */
|
2021-06-21 09:04:33 -07:00
|
|
|
std::fill(mPrevSamples.begin(), mPrevSamples.end(), HistoryLine{});
|
2021-03-30 07:04:06 -07:00
|
|
|
|
2022-09-02 09:41:19 -07:00
|
|
|
/* Don't need to set the VoiceIsAmbisonic flag if the device is not higher
|
|
|
|
* order than the voice. No HF scaling is necessary to mix it.
|
2021-03-30 07:04:06 -07:00
|
|
|
*/
|
2022-09-02 09:41:19 -07:00
|
|
|
if(mAmbiOrder && device->mAmbiOrder > mAmbiOrder)
|
2021-03-30 07:04:06 -07:00
|
|
|
{
|
2022-09-02 09:41:19 -07:00
|
|
|
const uint8_t *OrderFromChan{Is2DAmbisonic(mFmtChannels) ?
|
|
|
|
AmbiIndex::OrderFrom2DChannel().data() : AmbiIndex::OrderFromChannel().data()};
|
2022-09-03 21:06:39 -07:00
|
|
|
const auto scales = AmbiScale::GetHFOrderScales(mAmbiOrder, device->mAmbiOrder);
|
2022-09-02 09:41:19 -07:00
|
|
|
|
|
|
|
const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)};
|
|
|
|
for(auto &chandata : mChans)
|
|
|
|
{
|
|
|
|
chandata.mAmbiHFScale = scales[*(OrderFromChan++)];
|
|
|
|
chandata.mAmbiLFScale = 1.0f;
|
|
|
|
chandata.mAmbiSplitter = splitter;
|
|
|
|
chandata.mDryParams = DirectParams{};
|
|
|
|
chandata.mDryParams.NFCtrlFilter = device->mNFCtrlFilter;
|
|
|
|
std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{});
|
|
|
|
}
|
|
|
|
/* 2-channel UHJ needs different shelf filters. However, we can't just
|
|
|
|
* use different shelf filters after mixing it and with any old speaker
|
|
|
|
* setup the user has. To make this work, we apply the expected shelf
|
|
|
|
* filters for decoding UHJ2 to quad (only needs LF scaling), and act
|
|
|
|
* as if those 4 quad channels are encoded right back onto higher-order
|
|
|
|
* B-Format.
|
|
|
|
*
|
|
|
|
* This isn't perfect, but without an entirely separate and limited
|
|
|
|
* UHJ2 path, it's better than nothing.
|
|
|
|
*/
|
|
|
|
if(mFmtChannels == FmtUHJ2)
|
|
|
|
{
|
|
|
|
mChans[0].mAmbiHFScale = 1.0f;
|
|
|
|
mChans[0].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sWLFScale;
|
|
|
|
mChans[1].mAmbiHFScale = 1.0f;
|
|
|
|
mChans[1].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sXYLFScale;
|
|
|
|
mChans[2].mAmbiHFScale = 1.0f;
|
|
|
|
mChans[2].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sXYLFScale;
|
|
|
|
}
|
|
|
|
mFlags.set(VoiceIsAmbisonic);
|
|
|
|
}
|
|
|
|
else if(mFmtChannels == FmtUHJ2 && !device->mUhjEncoder)
|
|
|
|
{
|
|
|
|
/* 2-channel UHJ with first-order output also needs the shelf filter
|
|
|
|
* correction applied, except with UHJ output (UHJ2->B-Format->UHJ2 is
|
|
|
|
* identity, so don't mess with it).
|
|
|
|
*/
|
2021-12-09 22:00:35 -08:00
|
|
|
const BandSplitter splitter{device->mXOverFreq / static_cast<float>(device->Frequency)};
|
|
|
|
for(auto &chandata : mChans)
|
|
|
|
{
|
|
|
|
chandata.mAmbiHFScale = 1.0f;
|
|
|
|
chandata.mAmbiLFScale = 1.0f;
|
|
|
|
chandata.mAmbiSplitter = splitter;
|
|
|
|
chandata.mDryParams = DirectParams{};
|
2021-12-11 21:42:34 -08:00
|
|
|
chandata.mDryParams.NFCtrlFilter = device->mNFCtrlFilter;
|
2021-12-09 22:00:35 -08:00
|
|
|
std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{});
|
|
|
|
}
|
2022-08-07 13:09:12 -07:00
|
|
|
mChans[0].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sWLFScale;
|
|
|
|
mChans[1].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sXYLFScale;
|
|
|
|
mChans[2].mAmbiLFScale = UhjDecoder<UhjLengthStd>::sXYLFScale;
|
2021-12-23 13:43:10 -08:00
|
|
|
mFlags.set(VoiceIsAmbisonic);
|
2021-03-30 07:04:06 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(auto &chandata : mChans)
|
|
|
|
{
|
|
|
|
chandata.mDryParams = DirectParams{};
|
2021-12-11 21:42:34 -08:00
|
|
|
chandata.mDryParams.NFCtrlFilter = device->mNFCtrlFilter;
|
2021-03-30 07:04:06 -07:00
|
|
|
std::fill_n(chandata.mWetParams.begin(), device->NumAuxSends, SendParams{});
|
|
|
|
}
|
2021-12-23 13:43:10 -08:00
|
|
|
mFlags.reset(VoiceIsAmbisonic);
|
2021-03-30 07:04:06 -07:00
|
|
|
}
|
|
|
|
}
|