diff --git a/.vscode/.server-controller-port.log b/.vscode/.server-controller-port.log index c8df33a..b506f6f 100644 --- a/.vscode/.server-controller-port.log +++ b/.vscode/.server-controller-port.log @@ -1,5 +1,5 @@ { "port": 13452, - "time": 1742659000234, + "time": 1742670994121, "version": "0.0.3" } \ No newline at end of file diff --git a/src/modulator.c b/src/modulator.c index a76977f..796a425 100644 --- a/src/modulator.c +++ b/src/modulator.c @@ -78,39 +78,47 @@ void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) { } } -float get_rds_sample(RDSModulator* rdsMod) { +float get_rds_sample(RDSModulator* rdsMod, uint8_t stream) { uint16_t idx; float *cur_waveform; float sample; - if (rdsMod->sample_count == SAMPLES_PER_BIT) { - if (rdsMod->bit_pos == BITS_PER_GROUP) { - get_rds_bits(rdsMod->enc, rdsMod->bit_buffer); - rdsMod->bit_pos = 0; + if (rdsMod->data[stream].sample_count == SAMPLES_PER_BIT) { + if (rdsMod->data[stream].bit_pos == BITS_PER_GROUP) { + get_rds_bits(rdsMod->enc, rdsMod->data[stream].bit_buffer); + rdsMod->data[stream].bit_pos = 0; } - rdsMod->cur_bit = rdsMod->bit_buffer[rdsMod->bit_pos++]; - rdsMod->prev_output = rdsMod->cur_output; - rdsMod->cur_output = rdsMod->prev_output ^ rdsMod->cur_bit; + rdsMod->data[stream].cur_bit = rdsMod->data[stream].bit_buffer[rdsMod->data[stream].bit_pos++]; + rdsMod->data[stream].prev_output = rdsMod->data[stream].cur_output; + rdsMod->data[stream].cur_output = rdsMod->data[stream].prev_output ^ rdsMod->data[stream].cur_bit; - idx = rdsMod->in_sample_index; - cur_waveform = waveform[rdsMod->cur_output]; + idx = rdsMod->data[stream].in_sample_index; + cur_waveform = waveform[rdsMod->data[stream].cur_output]; for (uint16_t i = 0; i < FILTER_SIZE; i++) { - rdsMod->sample_buffer[idx++] += *cur_waveform++; + rdsMod->data[stream].sample_buffer[idx++] += *cur_waveform++; if (idx == SAMPLE_BUFFER_SIZE) idx = 0; } - rdsMod->in_sample_index += SAMPLES_PER_BIT; - if (rdsMod->in_sample_index == SAMPLE_BUFFER_SIZE) rdsMod->in_sample_index = 0; + rdsMod->data[stream].in_sample_index += SAMPLES_PER_BIT; + if (rdsMod->data[stream].in_sample_index == SAMPLE_BUFFER_SIZE) rdsMod->data[stream].in_sample_index = 0; - rdsMod->sample_count = 0; + rdsMod->data[stream].sample_count = 0; } - rdsMod->sample_count++; + rdsMod->data[stream].sample_count++; - sample = rdsMod->sample_buffer[rdsMod->out_sample_index]; + sample = rdsMod->data[stream].sample_buffer[rdsMod->data[stream].out_sample_index]; - rdsMod->sample_buffer[rdsMod->out_sample_index++] = 0; - if (rdsMod->out_sample_index == SAMPLE_BUFFER_SIZE) - rdsMod->out_sample_index = 0; - return sample*rdsMod->params.level*rdsMod->params.rdsgen; + rdsMod->data[stream].sample_buffer[rdsMod->data[stream].out_sample_index++] = 0; + if (rdsMod->data[stream].out_sample_index == SAMPLE_BUFFER_SIZE) + rdsMod->data[stream].out_sample_index = 0; + uint8_t tooutput = 1; + if (rdsMod->params.rdsgen == 0) { + tooutput = 0; + } else { + if (stream == 1) { + tooutput = 0; + } + } + return sample*rdsMod->params.level*tooutput; } diff --git a/src/modulator.h b/src/modulator.h index 7d129ee..74507c7 100644 --- a/src/modulator.h +++ b/src/modulator.h @@ -3,6 +3,8 @@ #include "rds.h" #include "waveforms.h" +#define STREAMS 2 + #pragma pack(1) typedef struct { @@ -10,7 +12,8 @@ typedef struct uint8_t rdsgen : 2; } RDSModulatorParameters; -typedef struct { +typedef struct +{ uint8_t bit_buffer[BITS_PER_GROUP]; uint8_t bit_pos : 7; float sample_buffer[SAMPLE_BUFFER_SIZE]; @@ -20,6 +23,10 @@ typedef struct { uint8_t sample_count; uint16_t in_sample_index; uint16_t out_sample_index; +} RDSModulatorModulationData; + +typedef struct { + RDSModulatorModulationData data[STREAMS]; RDSModulatorParameters params; RDSEncoder* enc; } RDSModulator; @@ -29,4 +36,4 @@ void Modulator_saveToFile(RDSModulatorParameters *emp, const char *option); void Modulator_loadFromFile(RDSModulatorParameters *emp); int modulatorsaved(); void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc); -float get_rds_sample(RDSModulator* rdsMod); +float get_rds_sample(RDSModulator* rdsMod, uint8_t stream); diff --git a/src/rds.c b/src/rds.c index 8dcc631..6bae8d1 100644 --- a/src/rds.c +++ b/src/rds.c @@ -546,8 +546,9 @@ static uint8_t get_rds_custom_groups(RDSEncoder* enc, uint16_t *blocks) { return 0; } -static void get_rds_group(RDSEncoder* enc, uint16_t *blocks) { +static void get_rds_group(RDSEncoder* enc, uint16_t *blocks, uint8_t stream) { blocks[0] = enc->data[enc->program].pi; + if(stream != 0) blocks[0] = 0; blocks[1] = 0; blocks[2] = 0; blocks[3] = 0; @@ -726,9 +727,9 @@ group_coded: } } -void get_rds_bits(RDSEncoder* enc, uint8_t *bits) { +void get_rds_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream) { static uint16_t out_blocks[GROUP_LENGTH]; - get_rds_group(enc, out_blocks); + get_rds_group(enc, out_blocks, stream); add_checkwords(out_blocks, bits); } diff --git a/src/rds.h b/src/rds.h index 60bf685..8d347c9 100644 --- a/src/rds.h +++ b/src/rds.h @@ -333,7 +333,7 @@ int rdssaved(); void reset_rds_state(RDSEncoder* enc, uint8_t program); void set_rds_defaults(RDSEncoder* enc, uint8_t program); void init_rds_encoder(RDSEncoder* enc); -void get_rds_bits(RDSEncoder* enc, uint8_t *bits); +void get_rds_bits(RDSEncoder* enc, uint8_t *bits, uint8_t stream); void set_rds_rt1(RDSEncoder* enc, char *rt1); void set_rds_rt2(RDSEncoder* enc, char *rt2); void set_rds_dps1(RDSEncoder* enc, char *dps1); diff --git a/src/rds95.c b/src/rds95.c index 161f81c..5ec53cb 100644 --- a/src/rds95.c +++ b/src/rds95.c @@ -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; } \ No newline at end of file