mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
stereoize rds2
This commit is contained in:
2
.vscode/.server-controller-port.log
vendored
2
.vscode/.server-controller-port.log
vendored
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"port": 13452,
|
"port": 13452,
|
||||||
"time": 1742563941525,
|
"time": 1742672637302,
|
||||||
"version": "0.0.3"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
80
src/fm95.c
80
src/fm95.c
@@ -70,8 +70,7 @@ void show_help(char *name) {
|
|||||||
" -i,--input Override input device [default: %s]\n"
|
" -i,--input Override input device [default: %s]\n"
|
||||||
" -o,--output Override output device [default: %s]\n"
|
" -o,--output Override output device [default: %s]\n"
|
||||||
" -M,--mpx Override MPX input device [default: %s]\n"
|
" -M,--mpx Override MPX input device [default: %s]\n"
|
||||||
" -r,--rds Override RDS input device [default: %s]\n"
|
" -r,--rds Override RDS95 input device [default: %s]\n"
|
||||||
" -T,--rds2 Override RDS2 input device [default: %s]\n"
|
|
||||||
" -C,--sca Override the SCA input device [default: %s]\n"
|
" -C,--sca Override the SCA input device [default: %s]\n"
|
||||||
" -f,--sca_freq Override the SCA frequency [default: %.1f]\n"
|
" -f,--sca_freq Override the SCA frequency [default: %.1f]\n"
|
||||||
" -F,--sca_dev Override the SCA deviation [default: %.2f]\n"
|
" -F,--sca_dev Override the SCA deviation [default: %.2f]\n"
|
||||||
@@ -122,7 +121,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
pa_simple *mpx_device = NULL;
|
pa_simple *mpx_device = NULL;
|
||||||
pa_simple *rds_device = NULL;
|
pa_simple *rds_device = NULL;
|
||||||
pa_simple *rds2_device = NULL;
|
|
||||||
pa_simple *sca_device = NULL;
|
pa_simple *sca_device = NULL;
|
||||||
|
|
||||||
pa_simple *input_device;
|
pa_simple *input_device;
|
||||||
@@ -148,11 +146,6 @@ int main(int argc, char **argv) {
|
|||||||
#else
|
#else
|
||||||
char audio_rds_device[64] = RDS_DEVICE;
|
char audio_rds_device[64] = RDS_DEVICE;
|
||||||
#endif
|
#endif
|
||||||
#ifndef RDS2_DEVICE
|
|
||||||
char audio_rds2_device[64] = "\0";
|
|
||||||
#else
|
|
||||||
char audio_rds2_device[64] = RDS2_DEVICE;
|
|
||||||
#endif
|
|
||||||
#ifndef SCA_DEVICE
|
#ifndef SCA_DEVICE
|
||||||
char audio_sca_device[64] = "\0";
|
char audio_sca_device[64] = "\0";
|
||||||
#else
|
#else
|
||||||
@@ -168,7 +161,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
// #region Parse Arguments
|
// #region Parse Arguments
|
||||||
int opt;
|
int opt;
|
||||||
const char *short_opt = "s::i:o:M:r:T:C:f:F:L:c:P::R:VA:v:h";
|
const char *short_opt = "s::i:o:M:r:C:f:F:L:c:P::R:VA:v:h";
|
||||||
struct option long_opt[] =
|
struct option long_opt[] =
|
||||||
{
|
{
|
||||||
{"stereo", optional_argument, NULL, 's'},
|
{"stereo", optional_argument, NULL, 's'},
|
||||||
@@ -176,7 +169,6 @@ int main(int argc, char **argv) {
|
|||||||
{"output", required_argument, NULL, 'o'},
|
{"output", required_argument, NULL, 'o'},
|
||||||
{"mpx", required_argument, NULL, 'M'},
|
{"mpx", required_argument, NULL, 'M'},
|
||||||
{"rds", required_argument, NULL, 'r'},
|
{"rds", required_argument, NULL, 'r'},
|
||||||
{"rds2", required_argument, NULL, 'T'},
|
|
||||||
{"sca", required_argument, NULL, 'C'},
|
{"sca", required_argument, NULL, 'C'},
|
||||||
{"sca_freq", required_argument, NULL, 'f'},
|
{"sca_freq", required_argument, NULL, 'f'},
|
||||||
{"sca_dev", required_argument, NULL, 'F'},
|
{"sca_dev", required_argument, NULL, 'F'},
|
||||||
@@ -213,9 +205,6 @@ int main(int argc, char **argv) {
|
|||||||
case 'r': // RDS in
|
case 'r': // RDS in
|
||||||
memcpy(audio_rds_device, optarg, 63);
|
memcpy(audio_rds_device, optarg, 63);
|
||||||
break;
|
break;
|
||||||
case 'T': // RDS2 in
|
|
||||||
memcpy(audio_rds2_device, optarg, 63);
|
|
||||||
break;
|
|
||||||
case 'C': //SCA in
|
case 'C': //SCA in
|
||||||
memcpy(audio_sca_device, optarg, 63);
|
memcpy(audio_sca_device, optarg, 63);
|
||||||
break;
|
break;
|
||||||
@@ -259,7 +248,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
int mpx_on = (strlen(audio_mpx_device) != 0);
|
int mpx_on = (strlen(audio_mpx_device) != 0);
|
||||||
int rds_on = (strlen(audio_rds_device) != 0);
|
int rds_on = (strlen(audio_rds_device) != 0);
|
||||||
int rds2_on = (rds_on && strlen(audio_rds2_device) != 0);
|
|
||||||
int sca_on = (strlen(audio_sca_device) != 0);
|
int sca_on = (strlen(audio_sca_device) != 0);
|
||||||
|
|
||||||
// #region Setup devices
|
// #region Setup devices
|
||||||
@@ -327,7 +315,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rds_on) {
|
if(rds_on) {
|
||||||
printf("Connecting to RDS device... (%s)\n", audio_rds_device);
|
printf("Connecting to RDS95 device... (%s)\n", audio_rds_device);
|
||||||
|
|
||||||
rds_device = pa_simple_new(
|
rds_device = pa_simple_new(
|
||||||
NULL,
|
NULL,
|
||||||
@@ -335,7 +323,7 @@ int main(int argc, char **argv) {
|
|||||||
PA_STREAM_RECORD,
|
PA_STREAM_RECORD,
|
||||||
audio_rds_device,
|
audio_rds_device,
|
||||||
"RDS Input",
|
"RDS Input",
|
||||||
&mono_format,
|
&stereo_format,
|
||||||
NULL,
|
NULL,
|
||||||
&input_buffer_atr,
|
&input_buffer_atr,
|
||||||
&opentime_pulse_error
|
&opentime_pulse_error
|
||||||
@@ -347,28 +335,7 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rds2_on) {
|
|
||||||
printf("Connecting to RDS2 device... (%s)\n", audio_rds2_device);
|
|
||||||
|
|
||||||
rds2_device = pa_simple_new(
|
|
||||||
NULL,
|
|
||||||
"fm95",
|
|
||||||
PA_STREAM_RECORD,
|
|
||||||
audio_rds2_device,
|
|
||||||
"RDS2 Input",
|
|
||||||
&mono_format,
|
|
||||||
NULL,
|
|
||||||
&input_buffer_atr,
|
|
||||||
&opentime_pulse_error
|
|
||||||
);
|
|
||||||
if (!rds2_device) {
|
|
||||||
fprintf(stderr, "Error: cannot open RDS device: %s\n", pa_strerror(opentime_pulse_error));
|
|
||||||
pa_simple_free(input_device);
|
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(sca_on) {
|
if(sca_on) {
|
||||||
printf("Connecting to SCA device... (%s)\n", audio_sca_device);
|
printf("Connecting to SCA device... (%s)\n", audio_sca_device);
|
||||||
|
|
||||||
@@ -388,7 +355,6 @@ int main(int argc, char **argv) {
|
|||||||
pa_simple_free(input_device);
|
pa_simple_free(input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) pa_simple_free(mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) pa_simple_free(rds_device);
|
||||||
if(rds2_on) pa_simple_free(rds2_device);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -411,7 +377,6 @@ int main(int argc, char **argv) {
|
|||||||
pa_simple_free(input_device);
|
pa_simple_free(input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) pa_simple_free(mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) pa_simple_free(rds_device);
|
||||||
if(rds2_on) pa_simple_free(rds2_device);
|
|
||||||
if(sca_on) pa_simple_free(sca_device);
|
if(sca_on) pa_simple_free(sca_device);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -440,7 +405,6 @@ int main(int argc, char **argv) {
|
|||||||
pa_simple_free(input_device);
|
pa_simple_free(input_device);
|
||||||
if(mpx_on) pa_simple_free(mpx_device);
|
if(mpx_on) pa_simple_free(mpx_device);
|
||||||
if(rds_on) pa_simple_free(rds_device);
|
if(rds_on) pa_simple_free(rds_device);
|
||||||
if(rds2_on) pa_simple_free(rds2_device);
|
|
||||||
if(sca_on) pa_simple_free(sca_device);
|
if(sca_on) pa_simple_free(sca_device);
|
||||||
pa_simple_free(output_device);
|
pa_simple_free(output_device);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -463,13 +427,15 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
int pulse_error;
|
int pulse_error;
|
||||||
|
|
||||||
static float audio_stereo_input[BUFFER_SIZE*2]; // Input from device, interleaved stereo
|
float audio_stereo_input[BUFFER_SIZE*2];
|
||||||
static float mpx_in[BUFFER_SIZE] = {0}; // Input from MPX device
|
float rds1_rds2_in[BUFFER_SIZE*2] = {0};
|
||||||
static float rds_in[BUFFER_SIZE] = {0}; // Input from RDS device
|
float rds1_in[BUFFER_SIZE] = {0};
|
||||||
static float rds2_in[BUFFER_SIZE] = {0}; // Input from RDS2 device
|
float rds2_in[BUFFER_SIZE] = {0};
|
||||||
static float sca_in[BUFFER_SIZE] = {0}; // Input from SCA device
|
|
||||||
static float left[BUFFER_SIZE], right[BUFFER_SIZE]; // Audio, same thing as in input but uninterleaved
|
float mpx_in[BUFFER_SIZE] = {0};
|
||||||
static float output[BUFFER_SIZE]; // MPX, this goes to the output
|
float sca_in[BUFFER_SIZE] = {0};
|
||||||
|
float left[BUFFER_SIZE], right[BUFFER_SIZE];
|
||||||
|
float output[BUFFER_SIZE];
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
if (pa_simple_read(input_device, audio_stereo_input, sizeof(audio_stereo_input), &pulse_error) < 0) {
|
if (pa_simple_read(input_device, audio_stereo_input, sizeof(audio_stereo_input), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from input device: %s\n", pa_strerror(pulse_error));
|
||||||
@@ -485,18 +451,12 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(rds_on) {
|
if(rds_on) {
|
||||||
if (pa_simple_read(rds_device, rds_in, sizeof(rds_in), &pulse_error) < 0) {
|
if (pa_simple_read(rds_device, rds1_rds2_in, sizeof(rds1_rds2_in), &pulse_error) < 0) {
|
||||||
fprintf(stderr, "Error reading from RDS device: %s\n", pa_strerror(pulse_error));
|
fprintf(stderr, "Error reading from RDS95 device: %s\n", pa_strerror(pulse_error));
|
||||||
to_run = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(rds2_on) {
|
|
||||||
if (pa_simple_read(rds2_device, rds2_in, sizeof(rds2_in), &pulse_error) < 0) {
|
|
||||||
fprintf(stderr, "Error reading from RDS2 device: %s\n", pa_strerror(pulse_error));
|
|
||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
uninterleave(rds1_rds2_in, rds1_in, rds2_in, BUFFER_SIZE*2);
|
||||||
}
|
}
|
||||||
if(sca_on) {
|
if(sca_on) {
|
||||||
if (pa_simple_read(sca_device, sca_in, sizeof(sca_in), &pulse_error) < 0) {
|
if (pa_simple_read(sca_device, sca_in, sizeof(sca_in), &pulse_error) < 0) {
|
||||||
@@ -510,7 +470,7 @@ int main(int argc, char **argv) {
|
|||||||
float l_in = left[i];
|
float l_in = left[i];
|
||||||
float r_in = right[i];
|
float r_in = right[i];
|
||||||
float current_mpx_in = mpx_in[i];
|
float current_mpx_in = mpx_in[i];
|
||||||
float current_rds_in = rds_in[i];
|
float current_rds_in = rds1_in[i];
|
||||||
float current_rds2_in = rds2_in[i];
|
float current_rds2_in = rds2_in[i];
|
||||||
float current_sca_in = sca_in[i];
|
float current_sca_in = sca_in[i];
|
||||||
|
|
||||||
@@ -519,10 +479,10 @@ int main(int argc, char **argv) {
|
|||||||
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
ready_l = hard_clip(ready_l*audio_volume, clipper_threshold);
|
||||||
ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);
|
ready_r = hard_clip(ready_r*audio_volume, clipper_threshold);
|
||||||
|
|
||||||
float mono = (ready_l + ready_r) / 2.0f; // Stereo to Mono
|
float mono = (ready_l + ready_r) / 2.0f;
|
||||||
output[i] = mono*MONO_VOLUME;
|
output[i] = mono*MONO_VOLUME;
|
||||||
if(stereo) {
|
if(stereo) {
|
||||||
float stereo = (ready_l - ready_r) / 2.0f; // Also Stereo to Mono but a bit diffrent
|
float stereo = (ready_l - ready_r) / 2.0f;
|
||||||
float stereo_carrier = get_oscillator_sin_multiplier_ni(&osc, polar_stereo ? 1 : 2);
|
float stereo_carrier = get_oscillator_sin_multiplier_ni(&osc, polar_stereo ? 1 : 2);
|
||||||
|
|
||||||
if(polar_stereo) {
|
if(polar_stereo) {
|
||||||
@@ -536,7 +496,7 @@ int main(int argc, char **argv) {
|
|||||||
if(rds_on && polar_stereo == 0) {
|
if(rds_on && polar_stereo == 0) {
|
||||||
float rds_carrier = get_oscillator_sin_multiplier_ni(&osc, 3);
|
float rds_carrier = get_oscillator_sin_multiplier_ni(&osc, 3);
|
||||||
output[i] += (current_rds_in*rds_carrier)*RDS_VOLUME;
|
output[i] += (current_rds_in*rds_carrier)*RDS_VOLUME;
|
||||||
if(rds2_on && !sca_on) {
|
if(!sca_on) {
|
||||||
float rds2_carrier_66 = get_oscillator_cos_multiplier_ni(&osc, 3.5f); // 66.5 KHz
|
float rds2_carrier_66 = get_oscillator_cos_multiplier_ni(&osc, 3.5f); // 66.5 KHz
|
||||||
output[i] += (current_rds2_in*rds2_carrier_66)*RDS2_VOLUME;
|
output[i] += (current_rds2_in*rds2_carrier_66)*RDS2_VOLUME;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user