diff options
author | Chris Robinson <[email protected]> | 2017-05-27 03:36:34 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2017-05-27 03:36:34 -0700 |
commit | c4ef7399f84f4085ceb77f9897f9c9502d2cfd0d (patch) | |
tree | 5cd6863602b9c569c8aeb99a08fcfd00cb4f864c /OpenAL32 | |
parent | 653f0a1405b5dbceab6c2d8adc8fa246bdb5f607 (diff) |
Add a new compressor/limiter
This is just for the output limiter right now, but in the future can be used
for the compressor EFX effect. The parameters are also hardcoded, but can be
made configurable after 1.18.
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alMain.h | 32 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 22 |
2 files changed, 30 insertions, 24 deletions
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index 2ce98745..6e17651f 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -380,7 +380,7 @@ extern "C" { struct Hrtf; struct HrtfEntry; -struct OutputLimiter; +struct Compressor; #define DEFAULT_OUTPUT_RATE (44100) @@ -783,7 +783,7 @@ struct ALCdevice_struct ALsizei NumChannels; } RealOut; - struct OutputLimiter *Limiter; + struct Compressor *Limiter; /* The average speaker distance as determined by the ambdec configuration * (or alternatively, by the NFC-HOA reference delay). Only used for NFC. @@ -1047,6 +1047,34 @@ vector_al_string SearchDataFiles(const char *match, const char *subdir); typedef ALfloat ALfloatBUFFERSIZE[BUFFERSIZE]; typedef ALfloat ALfloat2[2]; + +/* 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. + */ +struct 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); + +ALuint GetCompressorSampleRate(const struct Compressor *Comp); + +void ApplyCompression(struct Compressor *Comp, const ALsizei NumChans, const ALsizei SamplesToDo, + ALfloat (*restrict OutBuffer)[BUFFERSIZE]); + #ifdef __cplusplus } #endif diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 8a56ddb2..0b3799c0 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -300,28 +300,6 @@ typedef struct ALvoice { void DeinitVoice(ALvoice *voice); -#define LIMITER_WINDOW_SIZE (1<<7) /* 128 */ -#define LIMITER_WINDOW_MASK (LIMITER_WINDOW_SIZE-1) -#define LIMITER_VALUE_MAX (1<<24) /* 16777216 */ -struct OutputLimiter { - /* RMS detection window, sum of values in the window, and the next write - * pos. Values are 16.16 fixed-point. - */ - ALuint Window[LIMITER_WINDOW_SIZE]; - ALuint SquaredSum; - ALsizei Pos; - - /* In milliseconds. */ - ALfloat AttackRate; - ALfloat ReleaseRate; - - /* The gain last used for limiting. */ - ALfloat Gain; -}; - -struct OutputLimiter *alloc_limiter(void); - - typedef void (*MixerFunc)(const ALfloat *data, ALsizei OutChans, ALfloat (*restrict OutBuffer)[BUFFERSIZE], ALfloat *CurrentGains, const ALfloat *TargetGains, ALsizei Counter, ALsizei OutPos, |