aboutsummaryrefslogtreecommitdiffstats
path: root/Alc
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-11 06:50:53 -0800
committerChris Robinson <[email protected]>2018-01-11 06:50:53 -0800
commit9b9ec2c21a7f0992a6ca64ac9cb2a03838e11cd7 (patch)
tree94a959806234d4b3699eb8c676732021c0718cf7 /Alc
parentf3c9bc114cb1d136fce4e790d6d2721430eb30dc (diff)
Move the compressor/limiter declarations to their own header
Diffstat (limited to 'Alc')
-rw-r--r--Alc/ALc.c1
-rw-r--r--Alc/ALu.c1
-rw-r--r--Alc/mastering.c31
-rw-r--r--Alc/mastering.h57
4 files changed, 63 insertions, 27 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index cca88a8f..3de59521 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -37,6 +37,7 @@
#include "alBuffer.h"
#include "alAuxEffectSlot.h"
#include "alError.h"
+#include "mastering.h"
#include "bformatdec.h"
#include "alu.h"
diff --git a/Alc/ALu.c b/Alc/ALu.c
index a4e9c1a4..bd1bf79a 100644
--- a/Alc/ALu.c
+++ b/Alc/ALu.c
@@ -34,6 +34,7 @@
#include "alu.h"
#include "bs2b.h"
#include "hrtf.h"
+#include "mastering.h"
#include "uhjfilter.h"
#include "bformatdec.h"
#include "static_assert.h"
diff --git a/Alc/mastering.c b/Alc/mastering.c
index 9de5fd5f..91267d83 100644
--- a/Alc/mastering.c
+++ b/Alc/mastering.c
@@ -2,37 +2,19 @@
#include <math.h>
+#include "mastering.h"
#include "alu.h"
#include "almalloc.h"
+
+extern inline ALuint GetCompressorSampleRate(const Compressor *Comp);
+
#define RMS_WINDOW_SIZE (1<<7)
#define RMS_WINDOW_MASK (RMS_WINDOW_SIZE-1)
#define RMS_VALUE_MAX (1<<24)
-#define LOOKAHEAD_SIZE (1<<13)
-#define LOOKAHEAD_MASK (LOOKAHEAD_SIZE-1)
-
static_assert(RMS_VALUE_MAX < (UINT_MAX / RMS_WINDOW_SIZE), "RMS_VALUE_MAX is too big");
-typedef struct Compressor {
- ALfloat PreGain;
- ALfloat PostGain;
- ALboolean SummedLink;
- ALfloat AttackMin;
- ALfloat AttackMax;
- ALfloat ReleaseMin;
- ALfloat ReleaseMax;
- ALfloat Ratio;
- ALfloat Threshold;
- ALfloat Knee;
- ALuint SampleRate;
-
- ALuint RmsSum;
- ALuint *RmsWindow;
- ALsizei RmsIndex;
- ALfloat Envelope[BUFFERSIZE];
- ALfloat EnvLast;
-} Compressor;
/* Multichannel compression is linked via one of two modes:
*
@@ -209,11 +191,6 @@ Compressor *CompressorInit(const ALfloat PreGainDb, const ALfloat PostGainDb,
return Comp;
}
-ALuint GetCompressorSampleRate(const Compressor *Comp)
-{
- return Comp->SampleRate;
-}
-
void ApplyCompression(Compressor *Comp, const ALsizei NumChans, const ALsizei SamplesToDo,
ALfloat (*restrict OutBuffer)[BUFFERSIZE])
{
diff --git a/Alc/mastering.h b/Alc/mastering.h
new file mode 100644
index 00000000..0a7b4901
--- /dev/null
+++ b/Alc/mastering.h
@@ -0,0 +1,57 @@
+#ifndef MASTERING_H
+#define MASTERING_H
+
+#include "AL/al.h"
+
+/* For BUFFERSIZE. */
+#include "alMain.h"
+
+typedef struct Compressor {
+ ALfloat PreGain;
+ ALfloat PostGain;
+ ALboolean SummedLink;
+ ALfloat AttackMin;
+ ALfloat AttackMax;
+ ALfloat ReleaseMin;
+ ALfloat ReleaseMax;
+ ALfloat Ratio;
+ ALfloat Threshold;
+ ALfloat Knee;
+ ALuint SampleRate;
+
+ ALuint RmsSum;
+ ALuint *RmsWindow;
+ ALsizei RmsIndex;
+ ALfloat Envelope[BUFFERSIZE];
+ ALfloat EnvLast;
+} Compressor;
+
+/* The compressor requires the following information for proper
+ * initialization:
+ *
+ * PreGainDb - Gain applied before detection (in dB).
+ * PostGainDb - Gain applied after compression (in dB).
+ * SummedLink - Whether to use summed (true) or maxed (false) linking.
+ * RmsSensing - Whether to use RMS (true) or Peak (false) sensing.
+ * AttackTimeMin - Minimum attack time (in seconds).
+ * AttackTimeMax - Maximum attack time. Automates when min != max.
+ * ReleaseTimeMin - Minimum release time (in seconds).
+ * ReleaseTimeMax - Maximum release time. Automates when min != max.
+ * Ratio - Compression ratio (x:1). Set to 0 for true limiter.
+ * ThresholdDb - Triggering threshold (in dB).
+ * KneeDb - Knee width (below threshold; in dB).
+ * SampleRate - Sample rate to process.
+ */
+Compressor *CompressorInit(const ALfloat PreGainDb, const ALfloat PostGainDb,
+ const ALboolean SummedLink, const ALboolean RmsSensing, const ALfloat AttackTimeMin,
+ const ALfloat AttackTimeMax, const ALfloat ReleaseTimeMin, const ALfloat ReleaseTimeMax,
+ const ALfloat Ratio, const ALfloat ThresholdDb, const ALfloat KneeDb,
+ const ALuint SampleRate);
+
+void ApplyCompression(struct Compressor *Comp, const ALsizei NumChans, const ALsizei SamplesToDo,
+ ALfloat (*restrict OutBuffer)[BUFFERSIZE]);
+
+inline ALuint GetCompressorSampleRate(const Compressor *Comp)
+{ return Comp->SampleRate; }
+
+#endif /* MASTERING_H */