Compandor: Remove unused option for unaffected level
This commit is contained in:
parent
d058927e2d
commit
393e54b817
|
@ -32,7 +32,7 @@
|
||||||
#define EXPAND_ATTACK_FACTOR 1.145 /* about 0.57 after 6 dB step up */
|
#define EXPAND_ATTACK_FACTOR 1.145 /* about 0.57 after 6 dB step up */
|
||||||
#define EXPAND_RECOVERY_FACTOR 0.753 /* about 1.51 after 6 dB step down */
|
#define EXPAND_RECOVERY_FACTOR 0.753 /* about 1.51 after 6 dB step down */
|
||||||
|
|
||||||
/* Minimum level value to keep state */
|
/* Minimum level value to keep state (-60 dB) */
|
||||||
#define ENVELOPE_MIN 0.001
|
#define ENVELOPE_MIN 0.001
|
||||||
|
|
||||||
/* Maximum level, to prevent sqrt_tab to overflow */
|
/* Maximum level, to prevent sqrt_tab to overflow */
|
||||||
|
@ -46,7 +46,7 @@ static double sqrt_tab[10000];
|
||||||
* Hopefully this is correct
|
* Hopefully this is correct
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms, double unaffected_level)
|
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -60,8 +60,6 @@ void init_compandor(compandor_t *state, double samplerate, double attack_ms, dou
|
||||||
state->c.step_down = pow(COMPRESS_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
state->c.step_down = pow(COMPRESS_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
||||||
state->e.step_up = pow(EXPAND_ATTACK_FACTOR, 1000.0 / attack_ms / samplerate);
|
state->e.step_up = pow(EXPAND_ATTACK_FACTOR, 1000.0 / attack_ms / samplerate);
|
||||||
state->e.step_down = pow(EXPAND_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
state->e.step_down = pow(EXPAND_RECOVERY_FACTOR, 1000.0 / recovery_ms / samplerate);
|
||||||
state->c.unaffected = unaffected_level;
|
|
||||||
state->e.unaffected = unaffected_level;
|
|
||||||
|
|
||||||
// FIXME: make global, not at instance
|
// FIXME: make global, not at instance
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
|
@ -70,19 +68,17 @@ void init_compandor(compandor_t *state, double samplerate, double attack_ms, dou
|
||||||
|
|
||||||
void compress_audio(compandor_t *state, sample_t *samples, int num)
|
void compress_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
{
|
{
|
||||||
double value, peak, envelope, step_up, step_down, unaffected;
|
double value, peak, envelope, step_up, step_down;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
step_up = state->c.step_up;
|
step_up = state->c.step_up;
|
||||||
step_down = state->c.step_down;
|
step_down = state->c.step_down;
|
||||||
peak = state->c.peak;
|
peak = state->c.peak;
|
||||||
envelope = state->c.envelope;
|
envelope = state->c.envelope;
|
||||||
unaffected = state->c.unaffected;
|
|
||||||
|
|
||||||
// printf("envelope=%.4f\n", envelope);
|
// printf("envelope=%.4f\n", envelope);
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
/* normalize sample value to unaffected level */
|
value = *samples;
|
||||||
value = *samples / unaffected;
|
|
||||||
|
|
||||||
/* 'peak' is the level that raises directly with the signal
|
/* 'peak' is the level that raises directly with the signal
|
||||||
* level, but falls with specified recovery rate. */
|
* level, but falls with specified recovery rate. */
|
||||||
|
@ -101,11 +97,9 @@ void compress_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
if (envelope > ENVELOPE_MAX)
|
if (envelope > ENVELOPE_MAX)
|
||||||
envelope = ENVELOPE_MAX;
|
envelope = ENVELOPE_MAX;
|
||||||
|
|
||||||
value = value / sqrt_tab[(int)(envelope / 0.001)];
|
*samples++ = value / sqrt_tab[(int)(envelope / 0.001)];
|
||||||
//if (i > 47000.0 && i < 48144)
|
//if (i > 47000.0 && i < 48144)
|
||||||
//printf("time=%.4f envelope=%.4fdb, value=%.4f\n", (double)i/48000.0, 20*log10(envelope), value);
|
//printf("time=%.4f envelope=%.4fdb, value=%.4f\n", (double)i/48000.0, 20*log10(envelope), value);
|
||||||
|
|
||||||
*samples++ = value * unaffected;
|
|
||||||
}
|
}
|
||||||
//exit(0);
|
//exit(0);
|
||||||
|
|
||||||
|
@ -115,18 +109,16 @@ void compress_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
|
|
||||||
void expand_audio(compandor_t *state, sample_t *samples, int num)
|
void expand_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
{
|
{
|
||||||
double value, peak, envelope, step_up, step_down, unaffected;
|
double value, peak, envelope, step_up, step_down;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
step_up = state->e.step_up;
|
step_up = state->e.step_up;
|
||||||
step_down = state->e.step_down;
|
step_down = state->e.step_down;
|
||||||
peak = state->e.peak;
|
peak = state->e.peak;
|
||||||
envelope = state->e.envelope;
|
envelope = state->e.envelope;
|
||||||
unaffected = state->e.unaffected;
|
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
/* normalize sample value to 0 DB level */
|
value = *samples;
|
||||||
value = *samples / unaffected;
|
|
||||||
|
|
||||||
/* for comments: see compress_audio() */
|
/* for comments: see compress_audio() */
|
||||||
if (fabs(value) > peak)
|
if (fabs(value) > peak)
|
||||||
|
@ -140,9 +132,7 @@ void expand_audio(compandor_t *state, sample_t *samples, int num)
|
||||||
if (envelope < ENVELOPE_MIN)
|
if (envelope < ENVELOPE_MIN)
|
||||||
envelope = ENVELOPE_MIN;
|
envelope = ENVELOPE_MIN;
|
||||||
|
|
||||||
value = value * envelope;
|
*samples++ = value * envelope;
|
||||||
|
|
||||||
*samples++ = value * unaffected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
state->e.envelope = envelope;
|
state->e.envelope = envelope;
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
|
|
||||||
typedef struct compandor {
|
typedef struct compandor {
|
||||||
struct {
|
struct {
|
||||||
double unaffected;
|
|
||||||
double step_up;
|
double step_up;
|
||||||
double step_down;
|
double step_down;
|
||||||
double peak;
|
double peak;
|
||||||
double envelope;
|
double envelope;
|
||||||
} c;
|
} c;
|
||||||
struct {
|
struct {
|
||||||
double unaffected;
|
|
||||||
double step_up;
|
double step_up;
|
||||||
double step_down;
|
double step_down;
|
||||||
double peak;
|
double peak;
|
||||||
|
@ -16,7 +14,7 @@ typedef struct compandor {
|
||||||
} e;
|
} e;
|
||||||
} compandor_t;
|
} compandor_t;
|
||||||
|
|
||||||
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms, double unaffected_level);
|
void init_compandor(compandor_t *state, double samplerate, double attack_ms, double recovery_ms);
|
||||||
void compress_audio(compandor_t *state, sample_t *samples, int num);
|
void compress_audio(compandor_t *state, sample_t *samples, int num);
|
||||||
void expand_audio(compandor_t *state, sample_t *samples, int num);
|
void expand_audio(compandor_t *state, sample_t *samples, int num);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue