try to do rds2, again

This commit is contained in:
2025-03-22 20:29:06 +01:00
parent 8ace0112a7
commit e581cf20c2
6 changed files with 81 additions and 28 deletions
+38 -1
View File
@@ -12,6 +12,7 @@
#include "ascii_cmd.h"
#define RDS_DEVICE "RDS"
#define RDS2_DEVICE "RDS2"
#define NUM_MPX_FRAMES 512
@@ -55,6 +56,9 @@ int main(int argc, char **argv) {
char control_pipe[51] = "\0";
pa_simple *rds1_device;
#ifdef RDS2_DEVICE
pa_simple *rds2_device;
#endif
pa_sample_spec format;
pa_buffer_attr buffer;
@@ -114,6 +118,24 @@ int main(int argc, char **argv) {
goto exit;
}
#ifdef RDS2_DEVICE
rds2_device = pa_simple_new(
NULL,
"rds95",
PA_STREAM_PLAYBACK,
RDS2_DEVICE,
"RDS2 Generator",
&format,
NULL,
&buffer,
NULL
);
if (rds2_device == NULL) {
fprintf(stderr, "Error: cannot open sound device.\n");
goto exit;
}
#endif
RDSEncoder rdsEncoder;
RDSModulator rdsModulator;
init_rds_encoder(&rdsEncoder);
@@ -140,16 +162,28 @@ int main(int argc, char **argv) {
int pulse_error;
float rds1_buffer[NUM_MPX_FRAMES];
#ifdef RDS2_DEVICE
float rds2_buffer[NUM_MPX_FRAMES];
#endif
while(!stop_rds) {
for (uint16_t i = 0; i < NUM_MPX_FRAMES; i++) {
rds1_buffer[i] = get_rds_sample(&rdsModulator);
rds1_buffer[i] = get_rds_sample(&rdsModulator, 0);
#ifdef RDS2_DEVICE
rds2_buffer[i] = get_rds_sample(&rdsModulator, 1);
#endif
}
if (pa_simple_write(rds1_device, rds1_buffer, sizeof(rds1_buffer), &pulse_error) != 0) {
fprintf(stderr, "Error: could not play audio. (%s : %d)\n", pa_strerror(pulse_error), pulse_error);
break;
}
#ifdef RDS2_DEVICE
if (pa_simple_write(rds2_device, rds2_buffer, sizeof(rds2_buffer), &pulse_error) != 0) {
fprintf(stderr, "Error: could not play audio. (%s : %d)\n", pa_strerror(pulse_error), pulse_error);
break;
}
#endif
}
exit:
@@ -160,6 +194,9 @@ exit:
pthread_attr_destroy(&attr);
pa_simple_free(rds1_device);
#ifdef RDS2_DEVICE
pa_simple_free(rds2_device);
#endif
return 0;
}