2019-07-28 18:33:29 -07:00
|
|
|
#ifndef ALC_MAIN_H
|
|
|
|
#define ALC_MAIN_H
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2019-07-28 11:28:36 -07:00
|
|
|
#include <algorithm>
|
2018-11-19 06:50:37 -08:00
|
|
|
#include <array>
|
2019-07-28 11:28:36 -07:00
|
|
|
#include <atomic>
|
2018-11-22 12:53:16 -08:00
|
|
|
#include <chrono>
|
2019-07-28 11:28:36 -07:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2018-11-18 07:33:42 -08:00
|
|
|
|
2009-05-16 23:26:39 -07:00
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "AL/alext.h"
|
|
|
|
|
2019-06-08 23:49:15 -07:00
|
|
|
#include "albyte.h"
|
2016-03-29 00:44:58 -07:00
|
|
|
#include "almalloc.h"
|
2019-02-11 11:07:06 -08:00
|
|
|
#include "alnumeric.h"
|
2019-06-08 01:39:28 -07:00
|
|
|
#include "alspan.h"
|
2018-12-15 03:30:47 -08:00
|
|
|
#include "ambidefs.h"
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "atomic.h"
|
2019-08-05 15:03:18 -07:00
|
|
|
#include "devformat.h"
|
2019-08-05 15:11:03 -07:00
|
|
|
#include "filters/splitter.h"
|
2019-03-28 09:29:20 -07:00
|
|
|
#include "hrtf.h"
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "inprogext.h"
|
2019-08-01 13:28:53 -07:00
|
|
|
#include "intrusive_ptr.h"
|
2019-07-28 11:28:36 -07:00
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
class BFormatDec;
|
|
|
|
struct ALbuffer;
|
|
|
|
struct ALeffect;
|
|
|
|
struct ALfilter;
|
|
|
|
struct BackendBase;
|
|
|
|
struct Compressor;
|
|
|
|
struct EffectState;
|
|
|
|
struct Uhj2Encoder;
|
|
|
|
struct bs2b;
|
2013-10-28 12:48:13 -07:00
|
|
|
|
2010-07-30 20:23:55 -07:00
|
|
|
|
2019-04-26 18:56:54 -07:00
|
|
|
#define MIN_OUTPUT_RATE 8000
|
|
|
|
#define DEFAULT_OUTPUT_RATE 44100
|
|
|
|
#define DEFAULT_UPDATE_SIZE 882 /* 20ms */
|
|
|
|
#define DEFAULT_NUM_UPDATES 3
|
2011-09-18 09:52:40 -07:00
|
|
|
|
|
|
|
|
2012-02-23 15:25:30 -08:00
|
|
|
enum DeviceType {
|
|
|
|
Playback,
|
|
|
|
Capture,
|
|
|
|
Loopback
|
|
|
|
};
|
|
|
|
|
2012-09-14 02:14:29 -07:00
|
|
|
|
2016-02-26 21:48:03 -08:00
|
|
|
enum RenderMode {
|
|
|
|
NormalRender,
|
|
|
|
StereoPair,
|
|
|
|
HrtfRender
|
2015-02-11 09:32:05 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-11-25 15:30:32 -08:00
|
|
|
struct BufferSubList {
|
2019-02-11 11:07:06 -08:00
|
|
|
uint64_t FreeMask{~0_u64};
|
2018-12-24 19:29:01 -08:00
|
|
|
ALbuffer *Buffers{nullptr}; /* 64 */
|
2018-11-25 15:30:32 -08:00
|
|
|
|
|
|
|
BufferSubList() noexcept = default;
|
|
|
|
BufferSubList(const BufferSubList&) = delete;
|
|
|
|
BufferSubList(BufferSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Buffers{rhs.Buffers}
|
2019-02-11 11:07:06 -08:00
|
|
|
{ rhs.FreeMask = ~0_u64; rhs.Buffers = nullptr; }
|
2018-11-25 15:30:32 -08:00
|
|
|
~BufferSubList();
|
|
|
|
|
|
|
|
BufferSubList& operator=(const BufferSubList&) = delete;
|
|
|
|
BufferSubList& operator=(BufferSubList&& rhs) noexcept
|
|
|
|
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Buffers, rhs.Buffers); return *this; }
|
|
|
|
};
|
2018-01-27 01:51:01 -08:00
|
|
|
|
2018-11-25 16:13:07 -08:00
|
|
|
struct EffectSubList {
|
2019-02-11 11:07:06 -08:00
|
|
|
uint64_t FreeMask{~0_u64};
|
2018-12-24 19:29:01 -08:00
|
|
|
ALeffect *Effects{nullptr}; /* 64 */
|
2018-01-27 19:01:25 -08:00
|
|
|
|
2018-11-25 16:13:07 -08:00
|
|
|
EffectSubList() noexcept = default;
|
|
|
|
EffectSubList(const EffectSubList&) = delete;
|
|
|
|
EffectSubList(EffectSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Effects{rhs.Effects}
|
2019-02-11 11:07:06 -08:00
|
|
|
{ rhs.FreeMask = ~0_u64; rhs.Effects = nullptr; }
|
2018-11-25 16:13:07 -08:00
|
|
|
~EffectSubList();
|
|
|
|
|
|
|
|
EffectSubList& operator=(const EffectSubList&) = delete;
|
|
|
|
EffectSubList& operator=(EffectSubList&& rhs) noexcept
|
|
|
|
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Effects, rhs.Effects); return *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FilterSubList {
|
2019-02-11 11:07:06 -08:00
|
|
|
uint64_t FreeMask{~0_u64};
|
2018-12-24 19:29:01 -08:00
|
|
|
ALfilter *Filters{nullptr}; /* 64 */
|
2018-11-25 16:13:07 -08:00
|
|
|
|
|
|
|
FilterSubList() noexcept = default;
|
|
|
|
FilterSubList(const FilterSubList&) = delete;
|
|
|
|
FilterSubList(FilterSubList&& rhs) noexcept : FreeMask{rhs.FreeMask}, Filters{rhs.Filters}
|
2019-02-11 11:07:06 -08:00
|
|
|
{ rhs.FreeMask = ~0_u64; rhs.Filters = nullptr; }
|
2018-11-25 16:13:07 -08:00
|
|
|
~FilterSubList();
|
|
|
|
|
|
|
|
FilterSubList& operator=(const FilterSubList&) = delete;
|
|
|
|
FilterSubList& operator=(FilterSubList&& rhs) noexcept
|
|
|
|
{ std::swap(FreeMask, rhs.FreeMask); std::swap(Filters, rhs.Filters); return *this; }
|
|
|
|
};
|
2018-01-27 19:40:47 -08:00
|
|
|
|
2018-01-27 01:51:01 -08:00
|
|
|
|
2017-02-19 22:47:59 -08:00
|
|
|
/* Maximum delay in samples for speaker distance compensation. */
|
2017-02-28 21:01:13 -08:00
|
|
|
#define MAX_DELAY_LENGTH 1024
|
2017-02-19 22:47:59 -08:00
|
|
|
|
2018-11-21 05:06:31 -08:00
|
|
|
class DistanceComp {
|
2018-12-10 14:49:57 -08:00
|
|
|
public:
|
2018-11-21 05:06:31 -08:00
|
|
|
struct DistData {
|
|
|
|
ALfloat Gain{1.0f};
|
2019-08-25 17:54:36 -07:00
|
|
|
ALuint Length{0u}; /* Valid range is [0...MAX_DELAY_LENGTH). */
|
2018-11-21 05:06:31 -08:00
|
|
|
ALfloat *Buffer{nullptr};
|
2018-12-10 14:49:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2019-06-08 02:17:08 -07:00
|
|
|
std::array<DistData,MAX_OUTPUT_CHANNELS> mChannels;
|
2018-11-21 05:06:31 -08:00
|
|
|
al::vector<ALfloat,16> mSamples;
|
|
|
|
|
|
|
|
public:
|
2019-06-08 01:39:28 -07:00
|
|
|
void setSampleCount(size_t new_size) { mSamples.resize(new_size); }
|
2018-11-21 05:06:31 -08:00
|
|
|
void clear() noexcept
|
|
|
|
{
|
2019-06-08 02:17:08 -07:00
|
|
|
for(auto &chan : mChannels)
|
2018-11-21 05:06:31 -08:00
|
|
|
{
|
|
|
|
chan.Gain = 1.0f;
|
|
|
|
chan.Length = 0;
|
|
|
|
chan.Buffer = nullptr;
|
|
|
|
}
|
2019-06-08 01:39:28 -07:00
|
|
|
using SampleVecT = decltype(mSamples);
|
|
|
|
SampleVecT{}.swap(mSamples);
|
2018-11-21 05:06:31 -08:00
|
|
|
}
|
|
|
|
|
2019-06-08 01:39:28 -07:00
|
|
|
ALfloat *getSamples() noexcept { return mSamples.data(); }
|
2018-12-10 14:49:57 -08:00
|
|
|
|
2019-06-08 02:17:08 -07:00
|
|
|
al::span<DistData,MAX_OUTPUT_CHANNELS> as_span() { return mChannels; }
|
2018-11-21 05:06:31 -08:00
|
|
|
};
|
2017-02-19 22:47:59 -08:00
|
|
|
|
2019-01-05 21:55:14 -08:00
|
|
|
struct BFChannelConfig {
|
|
|
|
ALfloat Scale;
|
2019-09-14 08:50:07 -07:00
|
|
|
ALuint Index;
|
2019-01-05 21:55:14 -08:00
|
|
|
};
|
|
|
|
|
2012-09-14 02:14:29 -07:00
|
|
|
/* Size for temporary storage of buffer data, in ALfloats. Larger values need
|
2012-10-05 06:42:26 -07:00
|
|
|
* more memory, while smaller values may need more iterations. The value needs
|
2012-09-14 02:14:29 -07:00
|
|
|
* to be a sensible size, however, as it constrains the max stepping value used
|
|
|
|
* for mixing, as well as the maximum number of samples per mixing iteration.
|
|
|
|
*/
|
2019-02-24 16:13:51 -08:00
|
|
|
#define BUFFERSIZE 1024
|
|
|
|
|
2019-05-28 16:22:36 -07:00
|
|
|
using FloatBufferLine = std::array<float,BUFFERSIZE>;
|
|
|
|
|
2019-09-28 14:35:42 -07:00
|
|
|
/* Maximum number of samples to pad on the ends of a buffer for resampling.
|
|
|
|
* Note that the padding is symmetric (half at the beginning and half at the
|
|
|
|
* end)!
|
2019-02-24 16:13:51 -08:00
|
|
|
*/
|
2019-09-28 14:35:42 -07:00
|
|
|
#define MAX_RESAMPLER_PADDING 48
|
2019-02-24 16:13:51 -08:00
|
|
|
|
2012-09-14 02:14:29 -07:00
|
|
|
|
2019-08-05 15:11:03 -07:00
|
|
|
struct FrontStablizer {
|
|
|
|
static constexpr size_t DelayLength{256u};
|
|
|
|
|
|
|
|
alignas(16) float DelayBuf[MAX_OUTPUT_CHANNELS][DelayLength];
|
|
|
|
|
|
|
|
BandSplitter LFilter, RFilter;
|
|
|
|
alignas(16) float LSplit[2][BUFFERSIZE];
|
|
|
|
alignas(16) float RSplit[2][BUFFERSIZE];
|
|
|
|
|
|
|
|
alignas(16) float TempBuf[BUFFERSIZE + DelayLength];
|
|
|
|
|
|
|
|
DEF_NEWDEL(FrontStablizer)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-12-24 19:29:01 -08:00
|
|
|
struct MixParams {
|
2019-01-05 21:55:14 -08:00
|
|
|
/* Coefficient channel mapping for mixing to the buffer. */
|
2019-07-04 15:02:12 -07:00
|
|
|
std::array<BFChannelConfig,MAX_OUTPUT_CHANNELS> AmbiMap{};
|
2018-01-11 03:45:23 -08:00
|
|
|
|
2019-07-04 15:02:12 -07:00
|
|
|
al::span<FloatBufferLine> Buffer;
|
2018-12-24 19:29:01 -08:00
|
|
|
};
|
2018-01-11 03:45:23 -08:00
|
|
|
|
2018-12-24 19:29:01 -08:00
|
|
|
struct RealMixParams {
|
2019-09-12 04:17:21 -07:00
|
|
|
std::array<ALuint,MaxChannels> ChannelIndex{};
|
2018-01-11 03:45:23 -08:00
|
|
|
|
2019-07-03 23:26:33 -07:00
|
|
|
al::span<FloatBufferLine> Buffer;
|
2018-12-24 19:29:01 -08:00
|
|
|
};
|
2018-01-11 03:45:23 -08:00
|
|
|
|
2019-06-08 23:49:15 -07:00
|
|
|
enum {
|
|
|
|
// Frequency was requested by the app or config file
|
|
|
|
FrequencyRequest,
|
|
|
|
// Channel configuration was requested by the config file
|
|
|
|
ChannelsRequest,
|
|
|
|
// Sample type was requested by the config file
|
|
|
|
SampleTypeRequest,
|
|
|
|
|
|
|
|
// Specifies if the DSP is paused at user request
|
|
|
|
DevicePaused,
|
|
|
|
// Specifies if the device is currently running
|
|
|
|
DeviceRunning,
|
|
|
|
|
|
|
|
DeviceFlagsCount
|
|
|
|
};
|
|
|
|
|
2019-08-01 13:28:53 -07:00
|
|
|
struct ALCdevice : public al::intrusive_ref<ALCdevice> {
|
2018-12-30 21:58:14 -08:00
|
|
|
std::atomic<bool> Connected{true};
|
2018-12-27 10:25:09 -08:00
|
|
|
const DeviceType Type{};
|
2018-11-18 07:33:42 -08:00
|
|
|
|
|
|
|
ALuint Frequency{};
|
|
|
|
ALuint UpdateSize{};
|
2019-04-26 15:58:25 -07:00
|
|
|
ALuint BufferSize{};
|
|
|
|
|
2018-11-18 07:33:42 -08:00
|
|
|
DevFmtChannels FmtChans{};
|
2019-09-13 20:04:22 -07:00
|
|
|
DevFmtType FmtType{};
|
2018-11-20 22:47:24 -08:00
|
|
|
ALboolean IsHeadphones{AL_FALSE};
|
2019-09-13 20:04:22 -07:00
|
|
|
ALuint mAmbiOrder{0};
|
2016-07-31 07:46:38 -07:00
|
|
|
/* For DevFmtAmbi* output only, specifies the channel order and
|
|
|
|
* normalization.
|
|
|
|
*/
|
2018-11-20 22:47:24 -08:00
|
|
|
AmbiLayout mAmbiLayout{AmbiLayout::Default};
|
|
|
|
AmbiNorm mAmbiScale{AmbiNorm::Default};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2018-11-18 07:33:42 -08:00
|
|
|
ALCenum LimiterState{ALC_DONT_CARE_SOFT};
|
2018-10-03 13:48:04 -07:00
|
|
|
|
2018-11-18 18:45:45 -08:00
|
|
|
std::string DeviceName;
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2018-11-29 13:08:03 -08:00
|
|
|
// Device flags
|
2019-06-08 23:49:15 -07:00
|
|
|
al::bitfield<DeviceFlagsCount> Flags{};
|
2018-11-29 13:08:03 -08:00
|
|
|
|
|
|
|
std::string HrtfName;
|
|
|
|
al::vector<EnumeratedHrtf> HrtfList;
|
|
|
|
ALCenum HrtfStatus{ALC_FALSE};
|
|
|
|
|
2018-11-26 14:48:26 -08:00
|
|
|
std::atomic<ALCenum> LastError{ALC_NO_ERROR};
|
2009-12-28 23:19:13 -08:00
|
|
|
|
2007-11-13 18:02:18 -08:00
|
|
|
// Maximum number of sources that can be created
|
2018-11-18 07:33:42 -08:00
|
|
|
ALuint SourcesMax{};
|
2009-06-07 14:53:22 -07:00
|
|
|
// Maximum number of slots that can be created
|
2018-11-18 07:33:42 -08:00
|
|
|
ALuint AuxiliaryEffectSlotMax{};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2018-11-18 07:33:42 -08:00
|
|
|
ALCuint NumMonoSources{};
|
|
|
|
ALCuint NumStereoSources{};
|
2019-09-13 04:15:05 -07:00
|
|
|
ALCuint NumAuxSends{};
|
2009-07-06 03:09:01 -07:00
|
|
|
|
2010-05-01 19:59:41 -07:00
|
|
|
// Map of Buffers for this device
|
2018-11-26 22:06:53 -08:00
|
|
|
std::mutex BufferLock;
|
2018-12-27 10:25:09 -08:00
|
|
|
al::vector<BufferSubList> BufferList;
|
2009-08-15 09:14:08 -07:00
|
|
|
|
2010-05-18 17:41:06 -07:00
|
|
|
// Map of Effects for this device
|
2018-11-26 22:06:53 -08:00
|
|
|
std::mutex EffectLock;
|
2018-12-27 10:25:09 -08:00
|
|
|
al::vector<EffectSubList> EffectList;
|
2009-08-15 09:39:18 -07:00
|
|
|
|
2010-05-18 17:54:45 -07:00
|
|
|
// Map of Filters for this device
|
2018-11-26 22:06:53 -08:00
|
|
|
std::mutex FilterLock;
|
2018-12-27 10:25:09 -08:00
|
|
|
al::vector<FilterSubList> FilterList;
|
2009-08-15 09:39:18 -07:00
|
|
|
|
2016-02-26 21:48:03 -08:00
|
|
|
/* Rendering mode. */
|
2018-12-24 19:29:01 -08:00
|
|
|
RenderMode mRenderMode{NormalRender};
|
2016-02-26 21:48:03 -08:00
|
|
|
|
2019-07-06 18:39:26 -07:00
|
|
|
/* The average speaker distance as determined by the ambdec configuration,
|
|
|
|
* HRTF data set, or the NFC-HOA reference delay. Only used for NFC.
|
2018-11-29 13:08:03 -08:00
|
|
|
*/
|
|
|
|
ALfloat AvgSpeakerDist{0.0f};
|
2011-05-01 13:19:23 -07:00
|
|
|
|
2018-11-18 07:33:42 -08:00
|
|
|
ALuint SamplesDone{0u};
|
2018-11-22 12:53:16 -08:00
|
|
|
std::chrono::nanoseconds ClockBase{0};
|
|
|
|
std::chrono::nanoseconds FixedLatency{0};
|
2014-02-01 16:37:11 -08:00
|
|
|
|
2018-01-09 22:01:46 -08:00
|
|
|
/* Temp storage used for mixer processing. */
|
2019-09-28 14:35:42 -07:00
|
|
|
alignas(16) ALfloat SourceData[BUFFERSIZE + MAX_RESAMPLER_PADDING];
|
2019-03-02 23:41:26 -08:00
|
|
|
alignas(16) ALfloat ResampledData[BUFFERSIZE];
|
|
|
|
alignas(16) ALfloat FilteredData[BUFFERSIZE];
|
2019-03-28 09:29:20 -07:00
|
|
|
union {
|
|
|
|
alignas(16) ALfloat HrtfSourceData[BUFFERSIZE + HRTF_HISTORY_LENGTH];
|
|
|
|
alignas(16) ALfloat NfcSampleData[BUFFERSIZE];
|
|
|
|
};
|
2019-03-29 11:28:38 -07:00
|
|
|
alignas(16) float2 HrtfAccumData[BUFFERSIZE + HRIR_LENGTH];
|
2012-10-05 06:42:26 -07:00
|
|
|
|
2019-03-22 18:37:47 -07:00
|
|
|
/* Mixing buffer used by the Dry mix and Real output. */
|
2019-05-28 16:22:36 -07:00
|
|
|
al::vector<FloatBufferLine, 16> MixBuffer;
|
2018-11-19 06:22:09 -08:00
|
|
|
|
2016-03-09 23:43:57 -08:00
|
|
|
/* The "dry" path corresponds to the main output. */
|
2018-09-19 21:31:46 -07:00
|
|
|
MixParams Dry;
|
2019-06-05 23:00:28 -07:00
|
|
|
ALuint NumChannelsPerOrder[MAX_AMBI_ORDER+1]{};
|
2012-08-29 01:40:42 -07:00
|
|
|
|
2016-07-05 14:18:17 -07:00
|
|
|
/* "Real" output, which will be written to the device buffer. May alias the
|
|
|
|
* dry buffer.
|
|
|
|
*/
|
2018-01-11 03:45:23 -08:00
|
|
|
RealMixParams RealOut;
|
2016-03-09 22:57:38 -08:00
|
|
|
|
2018-11-29 13:08:03 -08:00
|
|
|
/* HRTF state and info */
|
|
|
|
std::unique_ptr<DirectHrtfState> mHrtfState;
|
2018-12-22 09:20:50 -08:00
|
|
|
HrtfEntry *mHrtf{nullptr};
|
2017-07-31 23:49:48 -07:00
|
|
|
|
2019-02-22 22:35:37 -08:00
|
|
|
/* Ambisonic-to-UHJ encoder */
|
2018-11-29 13:08:03 -08:00
|
|
|
std::unique_ptr<Uhj2Encoder> Uhj_Encoder;
|
2017-04-26 18:38:09 -07:00
|
|
|
|
2019-02-22 22:35:37 -08:00
|
|
|
/* Ambisonic decoder for speakers */
|
2018-11-29 13:08:03 -08:00
|
|
|
std::unique_ptr<BFormatDec> AmbiDecoder;
|
|
|
|
|
|
|
|
/* Stereo-to-binaural filter */
|
|
|
|
std::unique_ptr<bs2b> Bs2b;
|
|
|
|
|
2019-08-25 15:36:40 -07:00
|
|
|
using PostProc = void(ALCdevice::*)(const size_t SamplesToDo);
|
2019-08-07 11:43:53 -07:00
|
|
|
PostProc PostProcess{nullptr};
|
2018-11-29 13:08:03 -08:00
|
|
|
|
|
|
|
std::unique_ptr<FrontStablizer> Stablizer;
|
2017-03-10 04:35:32 -08:00
|
|
|
|
2018-12-24 07:30:01 -08:00
|
|
|
std::unique_ptr<Compressor> Limiter;
|
|
|
|
|
2017-02-19 22:47:59 -08:00
|
|
|
/* Delay buffers used to compensate for speaker distances. */
|
2018-11-21 05:06:31 -08:00
|
|
|
DistanceComp ChannelDelay;
|
2017-02-19 22:47:59 -08:00
|
|
|
|
2017-05-23 00:02:04 -07:00
|
|
|
/* Dithering control. */
|
2018-11-18 07:33:42 -08:00
|
|
|
ALfloat DitherDepth{0.0f};
|
|
|
|
ALuint DitherSeed{0u};
|
2017-05-23 00:02:04 -07:00
|
|
|
|
Keep track of the mix count
The purpose of this is to provide a safe way to be able to "swap" resources
used by the mixer from other threads without the need to block the mixer, as
well as a way to track when mixes have occurred. The idea is two-fold:
It provides a way to safely swap resources. If the mixer were to (atomically)
get a reference to an object to access it from, another thread would be able
allocate and prepare a new object then swap the reference to it with the stored
one. The other thread would then be able to wait until (count&1) is clear,
indicating the mixer is not running, before safely freeing the old object for
the mixer to use the new one.
It also provides a way to tell if the mixer has run. With this, a thread would
be able to read multiple values, which could be altered by the mixer, without
requiring a mixer lock. Comparing the before and after counts for inequality
would signify if the mixer has (started to) run, indicating the values may be
out of sync and should try getting them again. Of course, it will still need
something like a RWLock to ensure another (non-mixer) thread doesn't try to
write to the values at the same time.
Note that because of the possibility of overflow, the counter is not reliable
as an absolute count.
2014-03-19 19:00:54 -07:00
|
|
|
/* Running count of the mixer invocations, in 31.1 fixed point. This
|
|
|
|
* actually increments *twice* when mixing, first at the start and then at
|
|
|
|
* the end, so the bottom bit indicates if the device is currently mixing
|
|
|
|
* and the upper bits indicates how many mixes have been done.
|
|
|
|
*/
|
2018-11-18 07:33:42 -08:00
|
|
|
RefCount MixCount{0u};
|
Keep track of the mix count
The purpose of this is to provide a safe way to be able to "swap" resources
used by the mixer from other threads without the need to block the mixer, as
well as a way to track when mixes have occurred. The idea is two-fold:
It provides a way to safely swap resources. If the mixer were to (atomically)
get a reference to an object to access it from, another thread would be able
allocate and prepare a new object then swap the reference to it with the stored
one. The other thread would then be able to wait until (count&1) is clear,
indicating the mixer is not running, before safely freeing the old object for
the mixer to use the new one.
It also provides a way to tell if the mixer has run. With this, a thread would
be able to read multiple values, which could be altered by the mixer, without
requiring a mixer lock. Comparing the before and after counts for inequality
would signify if the mixer has (started to) run, indicating the values may be
out of sync and should try getting them again. Of course, it will still need
something like a RWLock to ensure another (non-mixer) thread doesn't try to
write to the values at the same time.
Note that because of the possibility of overflow, the counter is not reliable
as an absolute count.
2014-03-19 19:00:54 -07:00
|
|
|
|
2009-10-20 11:54:04 -07:00
|
|
|
// Contexts created on this device
|
2019-06-29 21:32:36 -07:00
|
|
|
std::atomic<al::FlexArray<ALCcontext*>*> mContexts{nullptr};
|
2007-11-13 18:02:18 -08:00
|
|
|
|
2018-12-30 21:38:42 -08:00
|
|
|
/* This lock protects the device state (format, update size, etc) from
|
|
|
|
* being from being changed in multiple threads, or being accessed while
|
|
|
|
* being changed. It's also used to serialize calls to the backend.
|
|
|
|
*/
|
|
|
|
std::mutex StateLock;
|
2018-12-29 02:16:16 -08:00
|
|
|
std::unique_ptr<BackendBase> Backend;
|
2018-11-18 07:33:42 -08:00
|
|
|
|
|
|
|
|
2019-01-01 18:13:33 -08:00
|
|
|
ALCdevice(DeviceType type);
|
|
|
|
ALCdevice(const ALCdevice&) = delete;
|
|
|
|
ALCdevice& operator=(const ALCdevice&) = delete;
|
|
|
|
~ALCdevice();
|
2018-11-18 07:33:42 -08:00
|
|
|
|
2019-09-13 14:29:25 -07:00
|
|
|
ALuint bytesFromFmt() const noexcept { return BytesFromDevFmt(FmtType); }
|
|
|
|
ALuint channelsFromFmt() const noexcept { return ChannelsFromDevFmt(FmtChans, mAmbiOrder); }
|
|
|
|
ALuint frameSizeFromFmt() const noexcept { return bytesFromFmt() * channelsFromFmt(); }
|
2018-12-19 03:13:15 -08:00
|
|
|
|
2019-08-25 15:36:40 -07:00
|
|
|
void ProcessHrtf(const size_t SamplesToDo);
|
|
|
|
void ProcessAmbiDec(const size_t SamplesToDo);
|
|
|
|
void ProcessUhj(const size_t SamplesToDo);
|
|
|
|
void ProcessBs2b(const size_t SamplesToDo);
|
2019-08-07 11:43:53 -07:00
|
|
|
|
2019-08-25 15:36:40 -07:00
|
|
|
inline void postProcess(const size_t SamplesToDo)
|
2019-08-07 11:43:53 -07:00
|
|
|
{ if LIKELY(PostProcess) (this->*PostProcess)(SamplesToDo); }
|
|
|
|
|
2018-11-18 07:33:42 -08:00
|
|
|
DEF_NEWDEL(ALCdevice)
|
2007-11-13 18:02:18 -08:00
|
|
|
};
|
|
|
|
|
2013-10-27 07:00:44 -07:00
|
|
|
/* Must be less than 15 characters (16 including terminating null) for
|
|
|
|
* compatibility with pthread_setname_np limitations. */
|
|
|
|
#define MIXER_THREAD_NAME "alsoft-mixer"
|
|
|
|
|
2014-12-21 10:38:40 -08:00
|
|
|
#define RECORD_THREAD_NAME "alsoft-record"
|
|
|
|
|
2013-10-27 07:00:44 -07:00
|
|
|
|
2018-01-11 20:17:02 -08:00
|
|
|
extern ALint RTPrioLevel;
|
2010-05-12 07:27:12 -07:00
|
|
|
void SetRTPriority(void);
|
2009-12-01 23:15:09 -08:00
|
|
|
|
2009-12-07 04:19:33 -08:00
|
|
|
void SetDefaultChannelOrder(ALCdevice *device);
|
|
|
|
void SetDefaultWFXChannelOrder(ALCdevice *device);
|
|
|
|
|
2018-12-19 03:13:15 -08:00
|
|
|
const ALCchar *DevFmtTypeString(DevFmtType type) noexcept;
|
|
|
|
const ALCchar *DevFmtChannelsString(DevFmtChannels chans) noexcept;
|
2011-05-15 04:03:15 -07:00
|
|
|
|
2018-01-11 03:45:23 -08:00
|
|
|
/**
|
|
|
|
* GetChannelIdxByName
|
|
|
|
*
|
2019-09-12 04:17:21 -07:00
|
|
|
* Returns the index for the given channel name (e.g. FrontCenter), or
|
|
|
|
* INVALID_CHANNEL_INDEX if it doesn't exist.
|
2018-01-11 03:45:23 -08:00
|
|
|
*/
|
2019-09-12 04:17:21 -07:00
|
|
|
inline ALuint GetChannelIdxByName(const RealMixParams &real, Channel chan) noexcept
|
2019-04-02 15:53:27 -07:00
|
|
|
{ return real.ChannelIndex[chan]; }
|
2019-09-12 04:17:21 -07:00
|
|
|
#define INVALID_CHANNEL_INDEX ~0u
|
2010-01-12 09:05:57 -08:00
|
|
|
|
2012-08-13 08:53:36 -07:00
|
|
|
|
2018-11-24 16:58:49 -08:00
|
|
|
al::vector<std::string> SearchDataFiles(const char *match, const char *subdir);
|
2007-11-13 18:02:18 -08:00
|
|
|
|
|
|
|
#endif
|