2018-01-11 06:50:53 -08:00
|
|
|
#ifndef MASTERING_H
|
|
|
|
#define MASTERING_H
|
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
#include <memory>
|
|
|
|
|
2018-01-11 06:50:53 -08:00
|
|
|
#include "AL/al.h"
|
|
|
|
|
2019-05-28 16:22:36 -07:00
|
|
|
/* For FloatBufferLine/BUFFERSIZE. */
|
2019-07-28 18:33:29 -07:00
|
|
|
#include "alcmain.h"
|
2019-07-28 21:29:59 -07:00
|
|
|
#include "almalloc.h"
|
2018-11-14 04:15:44 -08:00
|
|
|
|
2018-11-21 16:46:52 -08:00
|
|
|
struct SlidingHold;
|
|
|
|
|
2019-07-28 21:29:59 -07:00
|
|
|
|
2018-11-21 16:46:52 -08:00
|
|
|
/* 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/
|
|
|
|
*/
|
|
|
|
struct Compressor {
|
2019-06-05 18:54:17 -07:00
|
|
|
ALuint mNumChans{0u};
|
2018-12-24 09:17:00 -08:00
|
|
|
ALuint mSampleRate{0u};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
|
|
|
struct {
|
2018-12-20 11:46:57 -08:00
|
|
|
bool Knee : 1;
|
|
|
|
bool Attack : 1;
|
|
|
|
bool Release : 1;
|
|
|
|
bool PostGain : 1;
|
|
|
|
bool Declip : 1;
|
2018-12-24 09:17:00 -08:00
|
|
|
} mAuto{};
|
|
|
|
|
|
|
|
ALsizei mLookAhead{0};
|
|
|
|
|
|
|
|
ALfloat mPreGain{0.0f};
|
|
|
|
ALfloat mPostGain{0.0f};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
ALfloat mThreshold{0.0f};
|
|
|
|
ALfloat mSlope{0.0f};
|
|
|
|
ALfloat mKnee{0.0f};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
ALfloat mAttack{0.0f};
|
|
|
|
ALfloat mRelease{0.0f};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
alignas(16) ALfloat mSideChain[2*BUFFERSIZE]{};
|
|
|
|
alignas(16) ALfloat mCrestFactor[BUFFERSIZE]{};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
SlidingHold *mHold{nullptr};
|
2019-05-28 17:18:22 -07:00
|
|
|
FloatBufferLine *mDelay{nullptr};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
ALfloat mCrestCoeff{0.0f};
|
|
|
|
ALfloat mGainEstimate{0.0f};
|
|
|
|
ALfloat mAdaptCoeff{0.0f};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
ALfloat mLastPeakSq{0.0f};
|
|
|
|
ALfloat mLastRmsSq{0.0f};
|
|
|
|
ALfloat mLastRelease{0.0f};
|
|
|
|
ALfloat mLastAttack{0.0f};
|
|
|
|
ALfloat mLastGainDev{0.0f};
|
2018-11-21 16:46:52 -08:00
|
|
|
|
|
|
|
|
2018-12-24 09:17:00 -08:00
|
|
|
~Compressor();
|
2019-05-28 16:22:36 -07:00
|
|
|
void process(const ALsizei SamplesToDo, FloatBufferLine *OutBuffer);
|
2018-12-24 09:17:00 -08:00
|
|
|
ALsizei getLookAhead() const noexcept { return mLookAhead; }
|
2018-11-21 16:46:52 -08:00
|
|
|
|
2018-11-22 07:06:42 -08:00
|
|
|
DEF_PLACE_NEWDEL()
|
2018-11-21 16:46:52 -08:00
|
|
|
};
|
2018-01-11 06:50:53 -08:00
|
|
|
|
2018-09-25 10:04:14 -07:00
|
|
|
/* The compressor is initialized with the following settings:
|
2018-01-11 06:50:53 -08:00
|
|
|
*
|
2018-09-25 10:04:14 -07:00
|
|
|
* NumChans - Number of channels to process.
|
|
|
|
* SampleRate - Sample rate to process.
|
|
|
|
* AutoKnee - Whether to automate the knee width parameter.
|
|
|
|
* AutoAttack - Whether to automate the attack time parameter.
|
|
|
|
* AutoRelease - Whether to automate the release time parameter.
|
|
|
|
* AutoPostGain - Whether to automate the make-up (post) gain parameter.
|
|
|
|
* AutoDeclip - Whether to automate clipping reduction. Ignored when
|
|
|
|
* not automating make-up gain.
|
|
|
|
* LookAheadTime - Look-ahead time (in seconds).
|
|
|
|
* HoldTime - Peak hold-time (in seconds).
|
2018-01-11 06:50:53 -08:00
|
|
|
* PreGainDb - Gain applied before detection (in dB).
|
2018-09-25 10:04:14 -07:00
|
|
|
* PostGainDb - Make-up gain applied after compression (in dB).
|
2018-01-11 06:50:53 -08:00
|
|
|
* ThresholdDb - Triggering threshold (in dB).
|
2018-09-25 10:04:14 -07:00
|
|
|
* Ratio - Compression ratio (x:1). Set to INFINIFTY for true
|
|
|
|
* limiting. Ignored when automating knee width.
|
|
|
|
* KneeDb - Knee width (in dB). Ignored when automating knee
|
|
|
|
* width.
|
|
|
|
* AttackTimeMin - Attack time (in seconds). Acts as a maximum when
|
|
|
|
* automating attack time.
|
|
|
|
* ReleaseTimeMin - Release time (in seconds). Acts as a maximum when
|
|
|
|
* automating release time.
|
2018-01-11 06:50:53 -08:00
|
|
|
*/
|
2019-06-05 18:54:17 -07:00
|
|
|
std::unique_ptr<Compressor> CompressorInit(const ALuint NumChans, const ALuint SampleRate,
|
|
|
|
const ALboolean AutoKnee, const ALboolean AutoAttack, const ALboolean AutoRelease,
|
|
|
|
const ALboolean AutoPostGain, const ALboolean AutoDeclip, const ALfloat LookAheadTime,
|
|
|
|
const ALfloat HoldTime, const ALfloat PreGainDb, const ALfloat PostGainDb,
|
|
|
|
const ALfloat ThresholdDb, const ALfloat Ratio, const ALfloat KneeDb, const ALfloat AttackTime,
|
|
|
|
const ALfloat ReleaseTime);
|
2018-01-11 06:50:53 -08:00
|
|
|
|
|
|
|
#endif /* MASTERING_H */
|