Implement a "fast" bsinc path
[openal-soft.git] / alc / mastering.h
blob851381e96c8305bcdfcd7677bb27130e27e1d11c
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 ALuint 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 ALfloat mPreGain{0.0f};
39 ALfloat mPostGain{0.0f};
41 ALfloat mThreshold{0.0f};
42 ALfloat mSlope{0.0f};
43 ALfloat mKnee{0.0f};
45 ALfloat mAttack{0.0f};
46 ALfloat mRelease{0.0f};
48 alignas(16) ALfloat mSideChain[2*BUFFERSIZE]{};
49 alignas(16) ALfloat mCrestFactor[BUFFERSIZE]{};
51 SlidingHold *mHold{nullptr};
52 FloatBufferLine *mDelay{nullptr};
54 ALfloat mCrestCoeff{0.0f};
55 ALfloat mGainEstimate{0.0f};
56 ALfloat mAdaptCoeff{0.0f};
58 ALfloat mLastPeakSq{0.0f};
59 ALfloat mLastRmsSq{0.0f};
60 ALfloat mLastRelease{0.0f};
61 ALfloat mLastAttack{0.0f};
62 ALfloat 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()
72 /* The compressor is initialized with the following settings:
74 * NumChans - Number of channels to process.
75 * SampleRate - Sample rate to process.
76 * AutoKnee - Whether to automate the knee width parameter.
77 * AutoAttack - Whether to automate the attack time parameter.
78 * AutoRelease - Whether to automate the release time parameter.
79 * AutoPostGain - Whether to automate the make-up (post) gain parameter.
80 * AutoDeclip - Whether to automate clipping reduction. Ignored when
81 * not automating make-up gain.
82 * LookAheadTime - Look-ahead time (in seconds).
83 * HoldTime - Peak hold-time (in seconds).
84 * PreGainDb - Gain applied before detection (in dB).
85 * PostGainDb - Make-up gain applied after compression (in dB).
86 * ThresholdDb - Triggering threshold (in dB).
87 * Ratio - Compression ratio (x:1). Set to INFINIFTY for true
88 * limiting. Ignored when automating knee width.
89 * KneeDb - Knee width (in dB). Ignored when automating knee
90 * width.
91 * AttackTimeMin - Attack time (in seconds). Acts as a maximum when
92 * automating attack time.
93 * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
94 * automating release time.
96 std::unique_ptr<Compressor> CompressorInit(const ALuint NumChans, const ALfloat SampleRate,
97 const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease,
98 const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime,
99 const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb,
100 const ALfloat ThresholdDb, const ALfloat Ratio, const ALfloat KneeDb, const ALfloat AttackTime,
101 const ALfloat ReleaseTime);
103 #endif /* MASTERING_H */