Skip to content

Commit

Permalink
[rffft] Add filename parameter parsing for SatDump .wav files
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Herren (HB9FXX) <[email protected]>
  • Loading branch information
MartinHerren authored and cbassa committed Dec 16, 2024
1 parent f993466 commit 3ba9260
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ It is also possible to read WAV files. This is compatible with any WAV file, 16

./rffft -i recording.wav -f 97400000 -s 48000 -F wav -T "YYYY-MM-DDTHH:MM:SS"

For WAV files exported from SatDump the `-P` options will automatically extract the correct parameters from the filename.

The output spectrograms can be viewed and analysed using `rfplot`.
2 changes: 1 addition & 1 deletion rffft.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int main(int argc,char *argv[])
wav_reader = sox_open_read(infname, NULL, NULL, NULL);

if (wav_reader == NULL) {
fprintf(stderr, "Error opening file %s", infile);
fprintf(stderr, "Error opening file %s", infname);
exit(-1);
}

Expand Down
9 changes: 8 additions & 1 deletion rffft_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
// - 2023-08-05_08-02-00_16000000SPS_2274000000Hz.s8
// - 2023-08-05_18-02-45-534_16000000SPS_2284000000Hz.s16
// - 2023-08-05_18-02-45-1691258565.534000_16000000SPS_2284000000Hz.f32
// - 2023-08-07_16-36-47-1691426207.749000_2400000SPS_100000000Hz.wav
// s8: char, s16 short int, f32 float.
// SatDump also supports .wav and compressed versions of s8/s16/f32 with .ziq
// SatDump also supports a compressed versions of s8/s16/f32 with .ziq
// extension. Those are not yet supported
// timestamp can have an added milliseconds field, configurable. This feature
// was broken during some time so files with this convention still exists.
Expand Down Expand Up @@ -56,6 +57,8 @@ int rffft_params_from_filename(char * filename, double * samplerate, double * fr
*format = 'i';
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) {
*format = 'f';
} else if ((strlen(p_format) == 3) && (strncmp("wav", p_format, 3) == 0)) {
*format = 'w';
} else {
printf("Unsupported SatDump format %s\n", p_format);
return -1;
Expand Down Expand Up @@ -91,6 +94,8 @@ int rffft_params_from_filename(char * filename, double * samplerate, double * fr
*format = 'i';
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) {
*format = 'f';
} else if ((strlen(p_format) == 3) && (strncmp("wav", p_format, 3) == 0)) {
*format = 'w';
} else {
printf("Unsupported SatDump format %s\n", p_format);
return -1;
Expand Down Expand Up @@ -125,6 +130,8 @@ int rffft_params_from_filename(char * filename, double * samplerate, double * fr
*format = 'i';
} else if ((strlen(p_format) == 3) && (strncmp("f32", p_format, 3) == 0)) {
*format = 'f';
} else if ((strlen(p_format) == 3) && (strncmp("wav", p_format, 3) == 0)) {
*format = 'w';
} else {
printf("Unsupported SatDump format %s\n", p_format);
return -1;
Expand Down
2 changes: 1 addition & 1 deletion rffft_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" {
// output:
// samplerate: parsed samplerate
// frequency: parsed frequency
// format: parsed sample format: char: 'c', int: 'i', float: 'f'
// format: parsed sample format: char: 'c', int: 'i', float: 'f', wav: 'w'
// starttime: parsed start time string formatted YYYY-MM-DDTHH:MM:SS.sss
int rffft_params_from_filename(char * filename, double * samplerate, double * frequency, char * format, char * starttime);

Expand Down
8 changes: 8 additions & 0 deletions tests/tests_rffft_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ void rffft_internal_parse_satdump_filenames(void **state) {
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-05T18:02:45.534", starttime);

// wav file with milliseconds
ref_format = 'w';
assert_int_equal(0, rffft_params_from_filename("2023-08-07_16-36-47-749_2400000SPS_100000000Hz.wav", &samplerate, &frequency, &format, starttime));
assert_float_equal(2.4e6, samplerate, 1e-12);
assert_float_equal(100e6, frequency, 1e-12);
assert_memory_equal(&ref_format, &format, 1);
assert_string_equal("2023-08-07T16:36:47.749", starttime);

assert_int_equal(-1, rffft_params_from_filename("2023-08-05-19:59:30_16000000SPS_402000000Hz.f32", &samplerate, &frequency, &format, starttime));
}

Expand Down

0 comments on commit 3ba9260

Please sign in to comment.