mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
bs412 lookahead
This commit is contained in:
@@ -21,13 +21,19 @@ void init_bs412(BS412Compressor* mpx, float mpx_deviation, float target_power, f
|
|||||||
mpx->target = target_power;
|
mpx->target = target_power;
|
||||||
mpx->gain = 1.0f;
|
mpx->gain = 1.0f;
|
||||||
mpx->max = max;
|
mpx->max = max;
|
||||||
|
memset(mpx->lookahead_samples, 0, BS412_LOOKAHEAD);
|
||||||
|
mpx->lookahead_samples = 0;
|
||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
debug_printf("Initialized MPX power measurement with sample rate: %d\n", sample_rate);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float bs412_compress(BS412Compressor* mpx, float sample) {
|
float bs412_compress(BS412Compressor* mpx, float sample) {
|
||||||
mpx->average += sample * sample * mpx->mpx_deviation * mpx->mpx_deviation;
|
if(mpx->lookahead_counter > BS412_LOOKAHEAD) mpx->lookahead_counter = 0;
|
||||||
|
float process_sample = mpx->lookahead_samples[BS412_LOOKAHEAD-mpx->lookahead_counter]; // get sample from the other end
|
||||||
|
mpx->lookahead_samples[mpx->lookahead_counter++] = sample; // write to the first end
|
||||||
|
|
||||||
|
mpx->average += process_sample * process_sample * mpx->mpx_deviation * mpx->mpx_deviation;
|
||||||
mpx->average_counter++;
|
mpx->average_counter++;
|
||||||
|
|
||||||
float avg_power = mpx->average / mpx->average_counter;
|
float avg_power = mpx->average / mpx->average_counter;
|
||||||
|
|||||||
@@ -5,10 +5,13 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
#ifdef BS412_DEBUG
|
#ifdef BS412_DEBUG
|
||||||
#include "../lib/debug.h"
|
#include "../lib/debug.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define BS412_LOOKAHEAD 2048 // samples
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int mpx_deviation;
|
int mpx_deviation;
|
||||||
@@ -20,6 +23,9 @@ typedef struct
|
|||||||
float max;
|
float max;
|
||||||
float gain;
|
float gain;
|
||||||
double average;
|
double average;
|
||||||
|
|
||||||
|
float lookahead_samples[BS412_LOOKAHEAD + 1];
|
||||||
|
int lookahead_counter;
|
||||||
} BS412Compressor;
|
} BS412Compressor;
|
||||||
|
|
||||||
float dbr_to_deviation(float dbr);
|
float dbr_to_deviation(float dbr);
|
||||||
|
|||||||
Reference in New Issue
Block a user