kgoba-ft8_lib/gen_ft8.c

50 wiersze
1.4 KiB
C
Czysty Zwykły widok Historia

2021-08-05 11:07:31 +00:00
#include <stdlib.h>
#include <stdbool.h>
2021-11-08 20:44:37 +00:00
#include <string.h>
2018-10-18 07:42:43 +00:00
2021-11-08 20:44:37 +00:00
#include "ft8.h"
2018-11-02 12:03:28 +00:00
#include "common/wave.h"
#include "common/debug.h"
2021-08-16 17:02:52 +00:00
2021-11-08 20:44:37 +00:00
#define FT4_SLOT_TIME 7.0f // total length of output waveform in seconds
#define FT8_SLOT_TIME 15.0f // total length of output waveform in seconds
2021-08-16 17:02:52 +00:00
2021-11-08 20:44:37 +00:00
int main(int argc, char **argv)
{
2021-11-08 20:44:37 +00:00
int sample_rate = 8000;
// Expect two command-line arguments
if (argc ==3 || argc == 4)
2021-08-05 10:56:35 +00:00
{
2021-11-08 20:44:37 +00:00
float frequency = 1000.0;
bool is_ft4 = (argc > 4) && (0 == strcmp(argv[4], "-ft4"));
int num_samples = sample_rate * (is_ft4 ? FT4_SLOT_TIME : FT8_SLOT_TIME);
float signal[num_samples];
2021-11-08 20:44:37 +00:00
if (argc > 3)
2021-08-05 10:56:35 +00:00
{
2021-11-08 20:44:37 +00:00
frequency = atof(argv[3]);
}
2021-11-08 20:44:37 +00:00
int rc = is_ft4 ? ft4_encode(argv[1], signal, num_samples, frequency, sample_rate) : ft8_encode(argv[1], signal, num_samples, 1000.0, 8000.0);
if (rc == 0) {
save_wav(signal, num_samples, sample_rate, argv[2]);
}
else
{
LOG(LOG_ERROR, "Could not generate signal, rc = %d\n", rc);
}
return rc;
}
2021-11-08 20:44:37 +00:00
// wrong number of arguments
2018-10-18 08:16:21 +00:00
printf("Generate a 15-second WAV file encoding a given message.\n");
printf("Usage:\n");
printf("\n");
printf("gen_ft8 MESSAGE WAV_FILE [FREQUENCY]\n");
2018-10-18 08:16:21 +00:00
printf("\n");
printf("(Note that you might have to enclose your message in quote marks if it contains spaces)\n");
2021-11-08 20:44:37 +00:00
return -1;
2018-10-18 08:43:51 +00:00
}