mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +01:00
get rid of compressor
This commit is contained in:
@@ -119,33 +119,4 @@ float voltage_to_voltage_db(float linear) {
|
|||||||
|
|
||||||
float voltage_to_power_db(float linear) {
|
float voltage_to_power_db(float linear) {
|
||||||
return 10.0f * log10f(fmaxf(linear, 1e-10f)); // Avoid log(0)
|
return 10.0f * log10f(fmaxf(linear, 1e-10f)); // Avoid log(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_compressor(Compressor *compressor, float attack, float release) {
|
|
||||||
compressor->attack = attack;
|
|
||||||
compressor->release = release;
|
|
||||||
compressor->max = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
float peak_compress(Compressor *compressor, float sample) {
|
|
||||||
float sample_abs = fabsf(sample);
|
|
||||||
if(sample_abs > compressor->max) {
|
|
||||||
compressor->max += (sample_abs - compressor->max) * compressor->attack;
|
|
||||||
} else {
|
|
||||||
compressor->max *= compressor->release;
|
|
||||||
}
|
|
||||||
return sample/(compressor->max+0.01);
|
|
||||||
}
|
|
||||||
|
|
||||||
float peak_compress_stereo(Compressor *compressor, float l, float r, float *output_r) {
|
|
||||||
float l_abs = fabsf(l);
|
|
||||||
float r_abs = fabsf(r);
|
|
||||||
float max = (l_abs > r_abs) ? l_abs : r_abs;
|
|
||||||
if(max > compressor->max) {
|
|
||||||
compressor->max += (max - compressor->max) / compressor->attack;
|
|
||||||
} else {
|
|
||||||
compressor->max *= compressor->release;
|
|
||||||
}
|
|
||||||
*output_r = r/(compressor->max+0.01);
|
|
||||||
return l/(compressor->max+0.01);
|
|
||||||
}
|
|
||||||
@@ -29,13 +29,4 @@ float hard_clip(float sample, float threshold);
|
|||||||
float voltage_db_to_voltage(float db);
|
float voltage_db_to_voltage(float db);
|
||||||
float power_db_to_voltage(float db);
|
float power_db_to_voltage(float db);
|
||||||
float voltage_to_voltage_db(float linear);
|
float voltage_to_voltage_db(float linear);
|
||||||
float voltage_to_power_db(float linear);
|
float voltage_to_power_db(float linear);
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float attack;
|
|
||||||
float release;
|
|
||||||
float max;
|
|
||||||
} Compressor;
|
|
||||||
void init_compressor(Compressor *compressor, float attack, float release);
|
|
||||||
float peak_compress(Compressor *compressor, float sample);
|
|
||||||
float peak_compress_stereo(Compressor *compressor, float l, float r, float *output_r);
|
|
||||||
11
src/fm95.c
11
src/fm95.c
@@ -34,7 +34,7 @@
|
|||||||
#include <pulse/error.h>
|
#include <pulse/error.h>
|
||||||
|
|
||||||
#define MASTER_VOLUME 1.0f // Volume of everything combined, for calibration
|
#define MASTER_VOLUME 1.0f // Volume of everything combined, for calibration
|
||||||
#define AUDIO_VOLUME 1.0f // Audio volume, before clipper
|
#define AUDIO_VOLUME 1.5f // Audio volume, before clipper
|
||||||
#define MONO_VOLUME 0.45f // L+R Signal
|
#define MONO_VOLUME 0.45f // L+R Signal
|
||||||
#define PILOT_VOLUME 0.09f // 19 KHz Pilot
|
#define PILOT_VOLUME 0.09f // 19 KHz Pilot
|
||||||
#define STEREO_VOLUME 0.45f // L-R signal, should be same as MONO
|
#define STEREO_VOLUME 0.45f // L-R signal, should be same as MONO
|
||||||
@@ -374,9 +374,6 @@ int main(int argc, char **argv) {
|
|||||||
BiquadFilter lpf_l, lpf_r;
|
BiquadFilter lpf_l, lpf_r;
|
||||||
init_lpf(&lpf_l, LPF_CUTOFF, 1.25f, SAMPLE_RATE);
|
init_lpf(&lpf_l, LPF_CUTOFF, 1.25f, SAMPLE_RATE);
|
||||||
init_lpf(&lpf_r, LPF_CUTOFF, 1.25f, SAMPLE_RATE);
|
init_lpf(&lpf_r, LPF_CUTOFF, 1.25f, SAMPLE_RATE);
|
||||||
|
|
||||||
Compressor comp;
|
|
||||||
init_compressor(&comp, 0.9995f, 0.8f);
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
@@ -417,10 +414,8 @@ int main(int argc, char **argv) {
|
|||||||
float current_mpx_in = mpx_in[i];
|
float current_mpx_in = mpx_in[i];
|
||||||
float current_sca_in = sca_in[i];
|
float current_sca_in = sca_in[i];
|
||||||
|
|
||||||
float ready_r;
|
float ready_l = apply_frequency_filter(&lpf_l, l_in);
|
||||||
float ready_l = peak_compress_stereo(&comp, l_in, r_in, &ready_r);
|
float ready_r = apply_frequency_filter(&lpf_r, r_in);
|
||||||
ready_l = apply_frequency_filter(&lpf_l, l_in);
|
|
||||||
ready_r = apply_frequency_filter(&lpf_r, r_in);
|
|
||||||
ready_l = apply_preemphasis(&preemp_l, ready_l)*4;
|
ready_l = apply_preemphasis(&preemp_l, ready_l)*4;
|
||||||
ready_r = apply_preemphasis(&preemp_r, ready_r)*4;
|
ready_r = apply_preemphasis(&preemp_r, ready_r)*4;
|
||||||
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
||||||
|
|||||||
Reference in New Issue
Block a user