mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-26 19:23:51 +01:00
damn it
This commit is contained in:
@@ -31,26 +31,6 @@ float apply_biquad(BiquadFilter* filter, float input) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_upsampler(Upsampler* up, int ratio, float sample_rate) {
|
|
||||||
up->i = 0;
|
|
||||||
up->ratio = ratio;
|
|
||||||
init_lpf(&up->lpf, sample_rate*ratio, 0.70710678f, sample_rate);
|
|
||||||
}
|
|
||||||
|
|
||||||
float upsample(Upsampler* up, float sample) {
|
|
||||||
float output = 0.0f;
|
|
||||||
|
|
||||||
if (up->i == 0) {
|
|
||||||
output = sample;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = apply_biquad(&up->lpf, output);
|
|
||||||
|
|
||||||
up->i++;
|
|
||||||
if(up->i >= up->ratio) up->i = 0;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
float hard_clip(float sample, float threshold) {
|
float hard_clip(float sample, float threshold) {
|
||||||
if (sample > threshold) {
|
if (sample > threshold) {
|
||||||
|
|||||||
@@ -23,15 +23,6 @@ typedef struct {
|
|||||||
void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate);
|
void init_lpf(BiquadFilter* filter, float cutoffFreq, float qFactor, float sampleRate);
|
||||||
float apply_biquad(BiquadFilter* filter, float input);
|
float apply_biquad(BiquadFilter* filter, float input);
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int ratio;
|
|
||||||
BiquadFilter lpf;
|
|
||||||
} Upsampler;
|
|
||||||
void init_upsampler(Upsampler* up, int ratio, float sample_rate);
|
|
||||||
float upsample(Upsampler *up, float sample);
|
|
||||||
|
|
||||||
float hard_clip(float sample, float threshold);
|
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);
|
||||||
|
|||||||
17
src/fm95.c
17
src/fm95.c
@@ -21,7 +21,6 @@
|
|||||||
#include "../lib/filters.h"
|
#include "../lib/filters.h"
|
||||||
#include "../lib/fm_modulator.h"
|
#include "../lib/fm_modulator.h"
|
||||||
|
|
||||||
#define INPUT_SAMPLE_RATE 32000 // make sure that the output is a multiple of this
|
|
||||||
#define SAMPLE_RATE 192000
|
#define SAMPLE_RATE 192000
|
||||||
|
|
||||||
#define INPUT_DEVICE "FM_Audio.monitor"
|
#define INPUT_DEVICE "FM_Audio.monitor"
|
||||||
@@ -239,12 +238,6 @@ int main(int argc, char **argv) {
|
|||||||
.channels = 1,
|
.channels = 1,
|
||||||
.rate = SAMPLE_RATE
|
.rate = SAMPLE_RATE
|
||||||
};
|
};
|
||||||
pa_sample_spec main_input_format = {
|
|
||||||
.format = PA_SAMPLE_FLOAT32NE,
|
|
||||||
.channels = 2,
|
|
||||||
.rate = INPUT_SAMPLE_RATE
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
pa_buffer_attr input_buffer_atr = {
|
pa_buffer_attr input_buffer_atr = {
|
||||||
.maxlength = buffer_maxlength,
|
.maxlength = buffer_maxlength,
|
||||||
@@ -266,7 +259,7 @@ int main(int argc, char **argv) {
|
|||||||
PA_STREAM_RECORD,
|
PA_STREAM_RECORD,
|
||||||
audio_input_device,
|
audio_input_device,
|
||||||
"Main Audio Input",
|
"Main Audio Input",
|
||||||
&main_input_format,
|
&stereo_format,
|
||||||
NULL,
|
NULL,
|
||||||
&input_buffer_atr,
|
&input_buffer_atr,
|
||||||
&opentime_pulse_error
|
&opentime_pulse_error
|
||||||
@@ -382,10 +375,6 @@ int main(int argc, char **argv) {
|
|||||||
BiquadFilter lpf_l, lpf_r;
|
BiquadFilter lpf_l, lpf_r;
|
||||||
init_lpf(&lpf_l, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE);
|
init_lpf(&lpf_l, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE);
|
||||||
init_lpf(&lpf_r, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE);
|
init_lpf(&lpf_r, LPF_CUTOFF, 0.70710678f, SAMPLE_RATE);
|
||||||
|
|
||||||
Upsampler upsampler_l, upsampler_r;
|
|
||||||
init_upsampler(&upsampler_l, SAMPLE_RATE/INPUT_SAMPLE_RATE, SAMPLE_RATE);
|
|
||||||
init_upsampler(&upsampler_r, SAMPLE_RATE/INPUT_SAMPLE_RATE, SAMPLE_RATE);
|
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
signal(SIGINT, stop);
|
signal(SIGINT, stop);
|
||||||
@@ -421,8 +410,8 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < BUFFER_SIZE; i++) {
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
float l_in = upsample(&upsampler_l, left[i]);
|
float l_in = left[i];
|
||||||
float r_in = upsample(&upsampler_r, right[i]);
|
float r_in = right[i];
|
||||||
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];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user