Move some ambisonic-related macros to a separate header
[openal-soft.git] / Alc / mastering.h
blob141111308d22707fc33363bb65475a21314570f1
1 #ifndef MASTERING_H
2 #define MASTERING_H
4 #include "AL/al.h"
6 #include "almalloc.h"
7 /* For BUFFERSIZE. */
8 #include "alMain.h"
11 struct SlidingHold;
13 /* General topology and basic automation was based on the following paper:
15 * D. Giannoulis, M. Massberg and J. D. Reiss,
16 * "Parameter Automation in a Dynamic Range Compressor,"
17 * Journal of the Audio Engineering Society, v61 (10), Oct. 2013
19 * Available (along with supplemental reading) at:
21 * http://c4dm.eecs.qmul.ac.uk/audioengineering/compressors/
23 struct Compressor {
24 ALsizei NumChans;
25 ALuint SampleRate;
27 struct {
28 ALuint Knee : 1;
29 ALuint Attack : 1;
30 ALuint Release : 1;
31 ALuint PostGain : 1;
32 ALuint Declip : 1;
33 } Auto;
35 ALsizei LookAhead;
37 ALfloat PreGain;
38 ALfloat PostGain;
40 ALfloat Threshold;
41 ALfloat Slope;
42 ALfloat Knee;
44 ALfloat Attack;
45 ALfloat Release;
47 alignas(16) ALfloat SideChain[2*BUFFERSIZE];
48 alignas(16) ALfloat CrestFactor[BUFFERSIZE];
50 SlidingHold *Hold;
51 ALfloat (*Delay)[BUFFERSIZE];
52 ALsizei DelayIndex;
54 ALfloat CrestCoeff;
55 ALfloat GainEstimate;
56 ALfloat AdaptCoeff;
58 ALfloat LastPeakSq;
59 ALfloat LastRmsSq;
60 ALfloat LastRelease;
61 ALfloat LastAttack;
62 ALfloat LastGainDev;
64 DEF_PLACE_NEWDEL()
67 /* The compressor is initialized with the following settings:
69 * NumChans - Number of channels to process.
70 * SampleRate - Sample rate to process.
71 * AutoKnee - Whether to automate the knee width parameter.
72 * AutoAttack - Whether to automate the attack time parameter.
73 * AutoRelease - Whether to automate the release time parameter.
74 * AutoPostGain - Whether to automate the make-up (post) gain parameter.
75 * AutoDeclip - Whether to automate clipping reduction. Ignored when
76 * not automating make-up gain.
77 * LookAheadTime - Look-ahead time (in seconds).
78 * HoldTime - Peak hold-time (in seconds).
79 * PreGainDb - Gain applied before detection (in dB).
80 * PostGainDb - Make-up gain applied after compression (in dB).
81 * ThresholdDb - Triggering threshold (in dB).
82 * Ratio - Compression ratio (x:1). Set to INFINIFTY for true
83 * limiting. Ignored when automating knee width.
84 * KneeDb - Knee width (in dB). Ignored when automating knee
85 * width.
86 * AttackTimeMin - Attack time (in seconds). Acts as a maximum when
87 * automating attack time.
88 * ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
89 * automating release time.
91 Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
92 const ALboolean AutoKnee, const ALboolean AutoAttack,
93 const ALboolean AutoRelease, const ALboolean AutoPostGain,
94 const ALboolean AutoDeclip, const ALfloat LookAheadTime,
95 const ALfloat HoldTime, const ALfloat PreGainDb,
96 const ALfloat PostGainDb, const ALfloat ThresholdDb,
97 const ALfloat Ratio, const ALfloat KneeDb,
98 const ALfloat AttackTime, const ALfloat ReleaseTime);
100 void ApplyCompression(struct Compressor *Comp, const ALsizei SamplesToDo,
101 ALfloat (*RESTRICT OutBuffer)[BUFFERSIZE]);
103 ALsizei GetCompressorLookAhead(const struct Compressor *Comp);
105 #endif /* MASTERING_H */