From b2d7a40cb4b7d5d5dbeda444c47814ab6616d058 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 8 Sep 2023 16:45:56 +0200 Subject: [PATCH 1/4] add a simple stdin-based implementation --- CMakeLists.txt | 2 +- acarsdec.c | 13 +++++++++++- acarsdec.h | 2 ++ stdin.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 stdin.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 33c5f02..a08bd89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project (acarsdec C) add_compile_options(-Ofast -march=native) -add_executable(acarsdec acars.c acarsdec.c cJSON.c label.c msk.c output.c netout.c fileout.c ) +add_executable(acarsdec acars.c acarsdec.c cJSON.c label.c msk.c output.c netout.c fileout.c stdin.c ) find_package(PkgConfig) if(PKG_CONFIG_FOUND) diff --git a/acarsdec.c b/acarsdec.c index e96581d..277490c 100644 --- a/acarsdec.c +++ b/acarsdec.c @@ -97,6 +97,8 @@ static void usage(void) #ifdef HAVE_LIBACARS fprintf(stderr, " [--skip-reassembly] "); #endif + fprintf(stderr, + "-s |"); #ifdef WITH_MQTT fprintf(stderr, " [ -M mqtt_url"); fprintf(stderr, " [-T mqtt_topic] |"); @@ -159,6 +161,8 @@ static void usage(void) fprintf(stderr, " -P mqtt_passwd\t\t: Optional MQTT password\n"); #endif fprintf(stderr, "\n"); + fprintf(stderr, + " -s\t\t\t: decode from a raw IQ data stream on STDIN (sample rate: %d)\n",INTRATE); #ifdef WITH_ALSA fprintf(stderr, @@ -262,6 +266,10 @@ int main(int argc, char **argv) skip_reassembly = 1; break; #endif + case 's': + res = initStdIn(argv, optind); + inmode = 7; + break; #ifdef WITH_ALSA case 'a': res = initAlsa(argv, optind); @@ -391,7 +399,7 @@ int main(int argc, char **argv) } if (inmode == 0) { - fprintf(stderr, "Need at least one of -a|-f|-r|-R|-d options\n"); + fprintf(stderr, "Need at least one of -s|-a|-f|-r|-R|-d options\n"); usage(); } @@ -501,6 +509,9 @@ int main(int argc, char **argv) res = runSoapyClose(); break; #endif + case 7: + runStdInSample(); + break; default: res = -1; } diff --git a/acarsdec.h b/acarsdec.h index e0b6428..2147654 100644 --- a/acarsdec.h +++ b/acarsdec.h @@ -149,6 +149,8 @@ extern int initOutput(char*,char *); #ifdef HAVE_LIBACARS extern int skip_reassembly; #endif +extern int initStdIn(char **argv,int optind); +extern int runStdInSample(void); #ifdef WITH_ALSA extern int initAlsa(char **argv,int optind); extern int runAlsaSample(void); diff --git a/stdin.c b/stdin.c new file mode 100644 index 0000000..20929c7 --- /dev/null +++ b/stdin.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 Jakob Ketterl + * + * + * This code is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License version 2 + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "acarsdec.h" +#include +#include +#include + +#define MAX_SAMPLES 1024 + +int initStdIn(char **argv,int optind) { + nbch = 1; + channel[0].dm_buffer=malloc(sizeof(float)*MAX_SAMPLES); + return 0; +} + +int runStdInSample(void) { + ssize_t nbi; + int i, samples; + sample_t buffer[MAX_SAMPLES * 2]; + + do { + nbi = read(STDIN_FILENO, buffer, sizeof(sample_t) * MAX_SAMPLES * 2); + + if (nbi <= 0) { + return -1; + } + + samples = nbi / (sizeof(sample_t) * 2); + + for (i = 0; i < samples; i++) + channel[0].dm_buffer[i]=hypotf(buffer[i * 2], buffer[i * 2 + 1]); + + demodMSK(&(channel[0]),samples); + + } while (1); + return 0; +} From e80c90464bfa2963891201b210f3689bdef49fa6 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 21 Sep 2023 16:19:24 +0200 Subject: [PATCH 2/4] change from IQ to raw audio --- acarsdec.c | 2 +- stdin.c | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/acarsdec.c b/acarsdec.c index 277490c..0da8c1c 100644 --- a/acarsdec.c +++ b/acarsdec.c @@ -162,7 +162,7 @@ static void usage(void) #endif fprintf(stderr, "\n"); fprintf(stderr, - " -s\t\t\t: decode from a raw IQ data stream on STDIN (sample rate: %d)\n",INTRATE); + " -s\t\t\t: decode from a raw audio stream on STDIN (sample rate: %d; sample format: F32)\n",INTRATE); #ifdef WITH_ALSA fprintf(stderr, diff --git a/stdin.c b/stdin.c index 20929c7..777557c 100644 --- a/stdin.c +++ b/stdin.c @@ -20,35 +20,28 @@ #include "acarsdec.h" #include #include -#include #define MAX_SAMPLES 1024 int initStdIn(char **argv,int optind) { nbch = 1; - channel[0].dm_buffer=malloc(sizeof(float)*MAX_SAMPLES); + channel[0].dm_buffer=malloc(sizeof(sample_t)*MAX_SAMPLES); return 0; } int runStdInSample(void) { ssize_t nbi; - int i, samples; - sample_t buffer[MAX_SAMPLES * 2]; do { - nbi = read(STDIN_FILENO, buffer, sizeof(sample_t) * MAX_SAMPLES * 2); + nbi = read(STDIN_FILENO, channel[0].dm_buffer, sizeof(sample_t) * MAX_SAMPLES); if (nbi <= 0) { return -1; } - samples = nbi / (sizeof(sample_t) * 2); - - for (i = 0; i < samples; i++) - channel[0].dm_buffer[i]=hypotf(buffer[i * 2], buffer[i * 2 + 1]); - - demodMSK(&(channel[0]),samples); + demodMSK(&(channel[0]), nbi / sizeof(sample_t)); } while (1); + return 0; } From 813a2df36b8b6a900b690496d68cfd6d539e76af Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 21 Sep 2023 16:22:39 +0200 Subject: [PATCH 3/4] fix indentation --- acarsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acarsdec.c b/acarsdec.c index 0da8c1c..2d204e1 100644 --- a/acarsdec.c +++ b/acarsdec.c @@ -98,7 +98,7 @@ static void usage(void) fprintf(stderr, " [--skip-reassembly] "); #endif fprintf(stderr, - "-s |"); + "-s |"); #ifdef WITH_MQTT fprintf(stderr, " [ -M mqtt_url"); fprintf(stderr, " [-T mqtt_topic] |"); From c4d747d424623d94eb7187a73bfa2524b3e6728b Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 21 Sep 2023 16:23:35 +0200 Subject: [PATCH 4/4] more indentation --- acarsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acarsdec.c b/acarsdec.c index 2d204e1..c290774 100644 --- a/acarsdec.c +++ b/acarsdec.c @@ -162,7 +162,7 @@ static void usage(void) #endif fprintf(stderr, "\n"); fprintf(stderr, - " -s\t\t\t: decode from a raw audio stream on STDIN (sample rate: %d; sample format: F32)\n",INTRATE); + " -s\t\t\t: decode from a raw audio stream on STDIN (sample rate: %d; sample format: F32)\n",INTRATE); #ifdef WITH_ALSA fprintf(stderr,