Avoid class templates for the POPCNT64/CTZ64 macros
[openal-soft.git] / alc / mastering.h
blob92c25fee2169b3417437bdb40150c1574e4f790d
1 #ifndef MASTERING_H
2 #define MASTERING_H
4 #include <memory>
6 #include "AL/al.h"
8 /* For FloatBufferLine/BUFFERSIZE. */
9 #include "alcmain.h"
10 #include "almalloc.h"
12 struct SlidingHold;
15 /* General topology and basic automation was based on the following paper:
17 * D. Giannoulis, M. Massberg and J. D. Reiss,
18 * "Parameter Automation in a Dynamic Range Compressor,"
19 * Journal of the Audio Engineering Society, v61 (10), Oct. 2013
21 * Available (along with supplemental reading) at:
23 * http://c4dm.eecs.qmul.ac.uk/audioengineering/compressors/
25 struct Compressor {
26 size_t mNumChans{0u};
28 struct {
29 bool Knee : 1;
30 bool Attack : 1;
31 bool Release : 1;
32 bool PostGain : 1;
33 bool Declip : 1;
34 } mAuto{};
36 ALuint mLookAhead{0};
38 float mPreGain{0.0f};
39 float mPostGain{0.0f};
41 float mThreshold{0.0f};
42 float mSlope{0.0f};
43 float mKnee{0.0f};
45 float mAttack{0.0f};
46 float mRelease{0.0f};
48 alignas(16) float mSideChain[2*BUFFERSIZE]{};
49 alignas(16) float mCrestFactor[BUFFERSIZE]{};
51 SlidingHold *mHold{nullptr};
52 FloatBufferLine *mDelay{nullptr};
54 float mCrestCoeff{0.0f};
55 float mGainEstimate{0.0f};
56 float mAdaptCoeff{0.0f};
58 float mLastPeakSq{0.0f};
59 float mLastRmsSq{0.0f};
60 float mLastRelease{0.0f};
61 float mLastAttack{0.0f};
62 float mLastGainDev{0.0f};
65 ~Compressor();
66 void process(const ALuint SamplesToDo, FloatBufferLine *OutBuffer);
67 ALsizei getLookAhead() const noexcept { return static_cast<ALsizei>(mLookAhead); }
69 DEF_PLACE_NEWDEL()
71 /**
72 * The compressor is initialized with the following settings:
74 * \param NumChans Number of channels to process.
75 * \param SampleRate Sample rate to process.
76 * \param AutoKnee Whether to automate the knee width parameter.
77 * \param AutoAttack Whether to automate the attack time parameter.
78 * \param AutoRelease Whether to automate the release time parameter.
79 * \param AutoPostGain Whether to automate the make-up (post) gain
80 * parameter.
81 * \param AutoDeclip Whether to automate clipping reduction. Ignored
82 * when not automating make-up gain.
83 * \param LookAheadTime Look-ahead time (in seconds).
84 * \param HoldTime Peak hold-time (in seconds).
85 * \param PreGainDb Gain applied before detection (in dB).
86 * \param PostGainDb Make-up gain applied after compression (in dB).
87 * \param ThresholdDb Triggering threshold (in dB).
88 * \param Ratio Compression ratio (x:1). Set to INFINIFTY for true
89 * limiting. Ignored when automating knee width.
90 * \param KneeDb Knee width (in dB). Ignored when automating knee
91 * width.
92 * \param AttackTime Attack time (in seconds). Acts as a maximum when
93 * automating attack time.
94 * \param ReleaseTime Release time (in seconds). Acts as a maximum when
95 * automating release time.
97 static std::unique_ptr<Compressor> Create(const size_t NumChans, const float SampleRate,
98 const bool AutoKnee, const bool AutoAttack, const bool AutoRelease,
99 const bool AutoPostGain, const bool AutoDeclip, const float LookAheadTime,
100 const float HoldTime, const float PreGainDb, const float PostGainDb,
101 const float ThresholdDb, const float Ratio, const float KneeDb, const float AttackTime,
102 const float ReleaseTime);
105 #endif /* MASTERING_H */