mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 11:33:54 +01:00
some changes, again
This commit is contained in:
@@ -34,6 +34,7 @@ volatile sig_atomic_t to_run = 1;
|
|||||||
volatile sig_atomic_t playing_sequence = 0;
|
volatile sig_atomic_t playing_sequence = 0;
|
||||||
volatile int sequence_position = 0;
|
volatile int sequence_position = 0;
|
||||||
volatile int sequence_type = 0; // 0 = none, 1 = 29:56, 2 = 59:55
|
volatile int sequence_type = 0; // 0 = none, 1 = 29:56, 2 = 59:55
|
||||||
|
volatile time_t last_sequence_time = 0; // Track when we last played a sequence
|
||||||
|
|
||||||
static void stop(int signum) {
|
static void stop(int signum) {
|
||||||
(void)signum;
|
(void)signum;
|
||||||
@@ -44,19 +45,20 @@ static void stop(int signum) {
|
|||||||
void show_version() {
|
void show_version() {
|
||||||
printf("chimer95 (gts time signal encoder by radio95) version 1.0\n");
|
printf("chimer95 (gts time signal encoder by radio95) version 1.0\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_help(char *name) {
|
void show_help(char *name) {
|
||||||
printf(
|
printf(
|
||||||
"Usage: %s\n"
|
"Usage: %s\n"
|
||||||
" -o,--output Override output device [default: %s]\n"
|
" -o,--output Override output device [default: %s]\n"
|
||||||
" -F,--frequency GTS Frequency [default: %.1f]\n"
|
" -F,--frequency GTS Frequency [default: %.1f Hz]\n"
|
||||||
" -s,--samplerate Output Samplerate [default: %d]\n"
|
" -s,--samplerate Output Samplerate [default: %d]\n"
|
||||||
" -v,--volume Output volume [default: %.2f]\n"
|
" -v,--volume Output volume [default: %.2f]\n"
|
||||||
" -o,--offset GTS Offset [default: %d]\n"
|
" -t,--offset GTS Offset [default: %d s]\n"
|
||||||
,name
|
,name
|
||||||
,OUTPUT_DEVICE
|
,OUTPUT_DEVICE
|
||||||
,FREQ
|
,FREQ
|
||||||
,(int)SAMPLE_RATE
|
,SAMPLE_RATE
|
||||||
,MASTER_VOLUME,
|
,MASTER_VOLUME
|
||||||
,OFFSET
|
,OFFSET
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -68,19 +70,19 @@ int main(int argc, char **argv) {
|
|||||||
char audio_output_device[64] = OUTPUT_DEVICE;
|
char audio_output_device[64] = OUTPUT_DEVICE;
|
||||||
float master_volume = MASTER_VOLUME;
|
float master_volume = MASTER_VOLUME;
|
||||||
float freq = FREQ;
|
float freq = FREQ;
|
||||||
int sample_rate = (int)SAMPLE_RATE;
|
int sample_rate = SAMPLE_RATE;
|
||||||
int offset = OFFSET;
|
int offset = OFFSET;
|
||||||
|
|
||||||
// #region Parse Arguments
|
// #region Parse Arguments
|
||||||
int opt;
|
int opt;
|
||||||
const char *short_opt = "o:F:s:v:o:h";
|
const char *short_opt = "o:F:s:v:t:h";
|
||||||
struct option long_opt[] =
|
struct option long_opt[] =
|
||||||
{
|
{
|
||||||
{"output", required_argument, NULL, 'o'},
|
{"output", required_argument, NULL, 'o'},
|
||||||
{"frequency", required_argument, NULL, 'F'},
|
{"frequency", required_argument, NULL, 'F'},
|
||||||
{"samplerate", required_argument, NULL, 's'},
|
{"samplerate", required_argument, NULL, 's'},
|
||||||
{"volume", required_argument, NULL, 'v'},
|
{"volume", required_argument, NULL, 'v'},
|
||||||
{"offset", required_argument, NULL, 'o'},
|
{"offset", required_argument, NULL, 't'}, // Changed from 'o' to 't' to avoid duplicate
|
||||||
|
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
@@ -90,26 +92,34 @@ int main(int argc, char **argv) {
|
|||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'o': // Output Device
|
case 'o': // Output Device
|
||||||
memcpy(audio_output_device, optarg, 63);
|
memcpy(audio_output_device, optarg, 63);
|
||||||
|
audio_output_device[63] = '\0'; // Ensure null-termination
|
||||||
break;
|
break;
|
||||||
case 'F': // Frequency
|
case 'F': // Frequency
|
||||||
freq = strtof(optarg, NULL);
|
freq = strtof(optarg, NULL);
|
||||||
break;
|
break;
|
||||||
case 's': //Sample rate
|
case 's': // Sample rate
|
||||||
sample_rate = strtol(optarg, NULL, 10);
|
sample_rate = strtol(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 'v': // Volume
|
case 'v': // Volume
|
||||||
master_volume = strtof(optarg, NULL);
|
master_volume = strtof(optarg, NULL);
|
||||||
break;
|
break;
|
||||||
case 'o': // Offset
|
case 't': // Offset (changed from 'o' to 't')
|
||||||
offset = strtol(optarg, NULL, 10);
|
offset = strtol(optarg, NULL, 10);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
show_help(argv[0]);
|
show_help(argv[0]);
|
||||||
return 1;
|
return 0; // Return 0 for help, not 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
|
printf("Configuration:\n");
|
||||||
|
printf(" Output device: %s\n", audio_output_device);
|
||||||
|
printf(" Frequency: %.1f Hz\n", freq);
|
||||||
|
printf(" Sample rate: %d Hz\n", sample_rate);
|
||||||
|
printf(" Volume: %.2f\n", master_volume);
|
||||||
|
printf(" Time offset: %d seconds\n", offset);
|
||||||
|
|
||||||
// #region Setup devices
|
// #region Setup devices
|
||||||
|
|
||||||
// Define formats and buffer atributes
|
// Define formats and buffer atributes
|
||||||
@@ -164,6 +174,7 @@ int main(int argc, char **argv) {
|
|||||||
// Parameters for the time signals
|
// Parameters for the time signals
|
||||||
int elapsed_samples = 0;
|
int elapsed_samples = 0;
|
||||||
int total_sequence_samples = 0;
|
int total_sequence_samples = 0;
|
||||||
|
int sequence_completed = 0; // Flag to track if we've already reported completion
|
||||||
|
|
||||||
// For 29:56 - Play pip ... pip ... pip ... pip ... beep (4.5 seconds total)
|
// For 29:56 - Play pip ... pip ... pip ... pip ... beep (4.5 seconds total)
|
||||||
// Each pip is 0.1s with 0.9s pause, and beep is 0.5s
|
// Each pip is 0.1s with 0.9s pause, and beep is 0.5s
|
||||||
@@ -180,6 +191,9 @@ int main(int argc, char **argv) {
|
|||||||
int pause_samples = (int)((PIP_PAUSE / 1000.0) * sample_rate);
|
int pause_samples = (int)((PIP_PAUSE / 1000.0) * sample_rate);
|
||||||
int beep_samples = (int)((BEEP_DURATION / 1000.0) * sample_rate);
|
int beep_samples = (int)((BEEP_DURATION / 1000.0) * sample_rate);
|
||||||
|
|
||||||
|
printf("Ready to play time signals.\n");
|
||||||
|
printf("Will trigger at XX:29:%02d and XX:59:%02d\n", 56+offset, 55+offset);
|
||||||
|
|
||||||
while (to_run) {
|
while (to_run) {
|
||||||
// Clear the output buffer
|
// Clear the output buffer
|
||||||
memset(output, 0, sizeof(output));
|
memset(output, 0, sizeof(output));
|
||||||
@@ -190,18 +204,24 @@ int main(int argc, char **argv) {
|
|||||||
int second = utc_time->tm_sec;
|
int second = utc_time->tm_sec;
|
||||||
|
|
||||||
// Check if we need to start a time signal sequence
|
// Check if we need to start a time signal sequence
|
||||||
if (minute == 29 && second == 56+offset && !playing_sequence) {
|
// Only start a new sequence if we're not already playing one and
|
||||||
|
// if we haven't played this exact sequence already (using the timestamp check)
|
||||||
|
if (minute == 29 && second == (56+offset) && !playing_sequence && difftime(now, last_sequence_time) >= 1.0) {
|
||||||
printf("Starting 29:56 time signal sequence\n");
|
printf("Starting 29:56 time signal sequence\n");
|
||||||
playing_sequence = 1;
|
playing_sequence = 1;
|
||||||
sequence_type = 1; // 29:56 pattern
|
sequence_type = 1; // 29:56 pattern
|
||||||
elapsed_samples = 0;
|
elapsed_samples = 0;
|
||||||
total_sequence_samples = samples_29_56;
|
total_sequence_samples = samples_29_56;
|
||||||
} else if (minute == 59 && second == 55+offset && !playing_sequence) {
|
sequence_completed = 0;
|
||||||
|
last_sequence_time = now;
|
||||||
|
} else if (minute == 59 && second == (55+offset) && !playing_sequence && difftime(now, last_sequence_time) >= 1.0) {
|
||||||
printf("Starting 59:55 time signal sequence\n");
|
printf("Starting 59:55 time signal sequence\n");
|
||||||
playing_sequence = 1;
|
playing_sequence = 1;
|
||||||
sequence_type = 2; // 59:55 pattern
|
sequence_type = 2; // 59:55 pattern
|
||||||
elapsed_samples = 0;
|
elapsed_samples = 0;
|
||||||
total_sequence_samples = samples_59_55;
|
total_sequence_samples = samples_59_55;
|
||||||
|
sequence_completed = 0;
|
||||||
|
last_sequence_time = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're playing a sequence, generate the appropriate sounds
|
// If we're playing a sequence, generate the appropriate sounds
|
||||||
@@ -209,9 +229,12 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < BUFFER_SIZE; i++) {
|
for (int i = 0; i < BUFFER_SIZE; i++) {
|
||||||
if (elapsed_samples >= total_sequence_samples) {
|
if (elapsed_samples >= total_sequence_samples) {
|
||||||
// End of sequence
|
// End of sequence
|
||||||
|
if (!sequence_completed) {
|
||||||
|
printf("Time signal sequence completed\n");
|
||||||
|
sequence_completed = 1;
|
||||||
|
}
|
||||||
playing_sequence = 0;
|
playing_sequence = 0;
|
||||||
output[i] = 0;
|
output[i] = 0;
|
||||||
printf("Time signal sequence completed\n");
|
|
||||||
} else {
|
} else {
|
||||||
// Determine if we should be playing a pip, beep, or silence
|
// Determine if we should be playing a pip, beep, or silence
|
||||||
if (sequence_type == 1) { // 29:56 pattern: pip ... pip ... pip ... pip ... beep
|
if (sequence_type == 1) { // 29:56 pattern: pip ... pip ... pip ... pip ... beep
|
||||||
@@ -266,7 +289,14 @@ int main(int argc, char **argv) {
|
|||||||
to_run = 0;
|
to_run = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Small delay to prevent CPU hogging when idle
|
||||||
|
if (!playing_sequence) {
|
||||||
|
struct timespec ts = {0, 10000000}; // 10ms pause when not playing
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printf("Cleaning up...\n");
|
printf("Cleaning up...\n");
|
||||||
pa_simple_free(output_device);
|
pa_simple_free(output_device);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user