pcm/Normalizer: eliminate struct CompressorConfig
This commit is contained in:
parent
d0dd035075
commit
d2f2dde2e1
@ -12,8 +12,9 @@
|
|||||||
#define BUCKETS 400 /*!< How long of a history to use by default */
|
#define BUCKETS 400 /*!< How long of a history to use by default */
|
||||||
|
|
||||||
struct Compressor {
|
struct Compressor {
|
||||||
//! The compressor's preferences
|
int target;
|
||||||
struct CompressorConfig prefs;
|
int maxgain;
|
||||||
|
int smooth;
|
||||||
|
|
||||||
//! History of the peak values
|
//! History of the peak values
|
||||||
int *peaks;
|
int *peaks;
|
||||||
@ -33,9 +34,9 @@ Compressor_new(unsigned int history) noexcept
|
|||||||
{
|
{
|
||||||
auto obj = new Compressor();
|
auto obj = new Compressor();
|
||||||
|
|
||||||
obj->prefs.target = TARGET;
|
obj->target = TARGET;
|
||||||
obj->prefs.maxgain = GAINMAX;
|
obj->maxgain = GAINMAX;
|
||||||
obj->prefs.smooth = GAINSMOOTH;
|
obj->smooth = GAINSMOOTH;
|
||||||
|
|
||||||
obj->peaks = obj->gain = obj->clipped = nullptr;
|
obj->peaks = obj->gain = obj->clipped = nullptr;
|
||||||
obj->bufsz = 0;
|
obj->bufsz = 0;
|
||||||
@ -61,17 +62,10 @@ Compressor_delete(struct Compressor *obj) noexcept
|
|||||||
delete obj;
|
delete obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CompressorConfig *
|
|
||||||
Compressor_getConfig(struct Compressor *obj) noexcept
|
|
||||||
{
|
|
||||||
return &obj->prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Compressor_Process_int16(struct Compressor *obj, int16_t *audio,
|
Compressor_Process_int16(struct Compressor *obj, int16_t *audio,
|
||||||
unsigned int count) noexcept
|
unsigned int count) noexcept
|
||||||
{
|
{
|
||||||
struct CompressorConfig *prefs = Compressor_getConfig(obj);
|
|
||||||
int16_t *ap;
|
int16_t *ap;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int *peaks = obj->peaks;
|
int *peaks = obj->peaks;
|
||||||
@ -109,15 +103,15 @@ Compressor_Process_int16(struct Compressor *obj, int16_t *audio,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! Determine target gain
|
//! Determine target gain
|
||||||
newGain = (1 << 10)*prefs->target/peakVal;
|
newGain = (1 << 10)*obj->target/peakVal;
|
||||||
|
|
||||||
//! Adjust the gain with inertia from the previous gain value
|
//! Adjust the gain with inertia from the previous gain value
|
||||||
newGain = (curGain*((1 << prefs->smooth) - 1) + newGain)
|
newGain = (curGain*((1 << obj->smooth) - 1) + newGain)
|
||||||
>> prefs->smooth;
|
>> obj->smooth;
|
||||||
|
|
||||||
//! Make sure it's no more than the maximum gain value
|
//! Make sure it's no more than the maximum gain value
|
||||||
if (newGain > (prefs->maxgain << 10))
|
if (newGain > (obj->maxgain << 10))
|
||||||
newGain = prefs->maxgain << 10;
|
newGain = obj->maxgain << 10;
|
||||||
|
|
||||||
//! Make sure it's no less than 1:1
|
//! Make sure it's no less than 1:1
|
||||||
if (newGain < (1 << 10))
|
if (newGain < (1 << 10))
|
||||||
|
@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
//! Configuration values for the compressor object
|
|
||||||
struct CompressorConfig {
|
|
||||||
int target;
|
|
||||||
int maxgain;
|
|
||||||
int smooth;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Compressor;
|
struct Compressor;
|
||||||
|
|
||||||
//! Create a new compressor (use history value of 0 for default)
|
//! Create a new compressor (use history value of 0 for default)
|
||||||
@ -23,10 +16,6 @@ Compressor_new(unsigned int history) noexcept;
|
|||||||
void
|
void
|
||||||
Compressor_delete(struct Compressor *) noexcept;
|
Compressor_delete(struct Compressor *) noexcept;
|
||||||
|
|
||||||
//! Get the configuration for a compressor
|
|
||||||
struct CompressorConfig *
|
|
||||||
Compressor_getConfig(struct Compressor *) noexcept;
|
|
||||||
|
|
||||||
//! Process 16-bit signed data
|
//! Process 16-bit signed data
|
||||||
void
|
void
|
||||||
Compressor_Process_int16(struct Compressor *, int16_t *data, unsigned int count) noexcept;
|
Compressor_Process_int16(struct Compressor *, int16_t *data, unsigned int count) noexcept;
|
||||||
|
Loading…
Reference in New Issue
Block a user