mirror of
https://github.com/radio95-rnt/rds95.git
synced 2026-07-29 16:29:17 +02:00
refactor RDS modulator parameters and file handling; remove deprecated commands
This commit is contained in:
+62
-1
@@ -2,6 +2,61 @@
|
||||
|
||||
static float waveform[2][FILTER_SIZE];
|
||||
|
||||
void Modulator_saveToFile(RDSModulatorParameters *emp, const char *option) {
|
||||
char encoderPath[256];
|
||||
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsEncoder", getenv("HOME"));
|
||||
FILE *file;
|
||||
|
||||
RDSModulatorParameters tempEncoder;
|
||||
file = fopen(encoderPath, "rb");
|
||||
if (file != NULL) {
|
||||
fread(&tempEncoder, sizeof(RDSModulatorParameters), 1, file);
|
||||
fclose(file);
|
||||
} else {
|
||||
memcpy(&tempEncoder, emp, sizeof(RDSModulatorParameters));
|
||||
}
|
||||
|
||||
if (strcmp(option, "LEVL") == 0) {
|
||||
tempEncoder.level = emp->level;
|
||||
} else if (strcmp(option, "RDSGEN") == 0) {
|
||||
tempEncoder.rdsgen = emp->rdsgen;
|
||||
} else if (strcmp(option, "ALL") == 0) {
|
||||
tempEncoder.level = emp->level;
|
||||
tempEncoder.rdsgen = emp->rdsgen;
|
||||
}
|
||||
|
||||
file = fopen(encoderPath, "wb");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file");
|
||||
return;
|
||||
}
|
||||
fwrite(&tempEncoder, sizeof(RDSModulatorParameters), 1, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void Modulator_loadFromFile(RDSModulatorParameters *emp) {
|
||||
char encoderPath[256];
|
||||
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsModulator", getenv("HOME"));
|
||||
FILE *file = fopen(encoderPath, "rb");
|
||||
if (file == NULL) {
|
||||
perror("Error opening file");
|
||||
return;
|
||||
}
|
||||
fread(emp, sizeof(RDSModulatorParameters), 1, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
int modulatorsaved() {
|
||||
char encoderPath[256];
|
||||
snprintf(encoderPath, sizeof(encoderPath), "%s/.rdsModulator", getenv("HOME"));
|
||||
FILE *file = fopen(encoderPath, "rb");
|
||||
if (file) {
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) {
|
||||
memset(rdsMod, 0, sizeof(*rdsMod));
|
||||
rdsMod->level = 1.0f;
|
||||
@@ -15,6 +70,12 @@ void init_rds_modulator(RDSModulator* rdsMod, RDSEncoder* enc) {
|
||||
+waveform_biphase[j] : -waveform_biphase[j];
|
||||
}
|
||||
}
|
||||
|
||||
if(modulatorsaved()) {
|
||||
Modulator_loadFromFile(rdsMod->params);
|
||||
} else {
|
||||
Modulator_saveToFile(rdsMod->params, "ALL");
|
||||
}
|
||||
}
|
||||
|
||||
float get_rds_sample(RDSModulator* rdsMod) {
|
||||
@@ -51,5 +112,5 @@ float get_rds_sample(RDSModulator* rdsMod) {
|
||||
rdsMod->sample_buffer[rdsMod->out_sample_index++] = 0;
|
||||
if (rdsMod->out_sample_index == SAMPLE_BUFFER_SIZE)
|
||||
rdsMod->out_sample_index = 0;
|
||||
return sample*rdsMod->level*rdsMod->rdsgen;
|
||||
return sample*rdsMod->params.level*rdsMod->params.rdsgen;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user