aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/mastering.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-09-30 12:08:01 -0700
committerChris Robinson <[email protected]>2018-09-30 12:08:01 -0700
commit1860b2ec8a1927ce98e516f498dbdf19419ae0a6 (patch)
tree85dab3bee6298b9c20cd6f1ca003b43fd56801cb /Alc/mastering.c
parent7ad4f753a42a4ff9c4ce2be0a848f8aaccb86454 (diff)
Make the Compressor struct opaque
Diffstat (limited to 'Alc/mastering.c')
-rw-r--r--Alc/mastering.c69
1 files changed, 66 insertions, 3 deletions
diff --git a/Alc/mastering.c b/Alc/mastering.c
index b92390bb..f443de37 100644
--- a/Alc/mastering.c
+++ b/Alc/mastering.c
@@ -7,8 +7,67 @@
#include "almalloc.h"
-extern inline ALsizei GetCompressorChannelCount(const Compressor *Comp);
-extern inline ALuint GetCompressorSampleRate(const Compressor *Comp);
+/* These structures assume BUFFERSIZE is a power of 2.
+ */
+typedef struct SlidingHold {
+ ALfloat Values[BUFFERSIZE];
+ ALsizei Expiries[BUFFERSIZE];
+ ALsizei LowerIndex;
+ ALsizei UpperIndex;
+ ALsizei Length;
+} SlidingHold;
+
+/* General topology and basic automation was based on the following paper:
+ *
+ * D. Giannoulis, M. Massberg and J. D. Reiss,
+ * "Parameter Automation in a Dynamic Range Compressor,"
+ * Journal of the Audio Engineering Society, v61 (10), Oct. 2013
+ *
+ * Available (along with supplemental reading) at:
+ *
+ * http://c4dm.eecs.qmul.ac.uk/audioengineering/compressors/
+ */
+typedef struct Compressor {
+ ALsizei NumChans;
+ ALuint SampleRate;
+
+ struct {
+ ALuint Knee : 1;
+ ALuint Attack : 1;
+ ALuint Release : 1;
+ ALuint PostGain : 1;
+ ALuint Declip : 1;
+ } Auto;
+
+ ALsizei LookAhead;
+
+ ALfloat PreGain;
+ ALfloat PostGain;
+
+ ALfloat Threshold;
+ ALfloat Slope;
+ ALfloat Knee;
+
+ ALfloat Attack;
+ ALfloat Release;
+
+ alignas(16) ALfloat SideChain[2*BUFFERSIZE];
+ alignas(16) ALfloat CrestFactor[BUFFERSIZE];
+
+ SlidingHold *Hold;
+ ALfloat (*Delay)[BUFFERSIZE];
+ ALsizei DelayIndex;
+
+ ALfloat CrestCoeff;
+ ALfloat GainEstimate;
+ ALfloat AdaptCoeff;
+
+ ALfloat LastPeakSq;
+ ALfloat LastRmsSq;
+ ALfloat LastRelease;
+ ALfloat LastAttack;
+ ALfloat LastGainDev;
+} Compressor;
/* This sliding hold follows the input level with an instant attack and a
@@ -342,7 +401,7 @@ static void SignalDelay(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*r
* ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
* automating release time.
*/
-Compressor* CompressorInit(const ALuint NumChans, const ALuint SampleRate,
+Compressor* CompressorInit(const ALsizei NumChans, const ALuint SampleRate,
const ALboolean AutoKnee, const ALboolean AutoAttack,
const ALboolean AutoRelease, const ALboolean AutoPostGain,
const ALboolean AutoDeclip, const ALfloat LookAheadTime,
@@ -463,3 +522,7 @@ void ApplyCompression(Compressor *Comp, const ALsizei SamplesToDo, ALfloat (*res
memmove(sideChain, sideChain+SamplesToDo, Comp->LookAhead*sizeof(ALfloat));
}
+
+
+ALsizei GetCompressorLookAhead(const Compressor *Comp)
+{ return Comp->LookAhead; }