Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to decode raw audio data from STDIN #110

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion acarsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] |");
Expand Down Expand Up @@ -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 audio stream on STDIN (sample rate: %d; sample format: F32)\n",INTRATE);

#ifdef WITH_ALSA
fprintf(stderr,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -501,6 +509,9 @@ int main(int argc, char **argv)
res = runSoapyClose();
break;
#endif
case 7:
runStdInSample();
break;
default:
res = -1;
}
Expand Down
2 changes: 2 additions & 0 deletions acarsdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions stdin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 <unistd.h>
#include <malloc.h>

#define MAX_SAMPLES 1024

int initStdIn(char **argv,int optind) {
nbch = 1;
channel[0].dm_buffer=malloc(sizeof(sample_t)*MAX_SAMPLES);
return 0;
}

int runStdInSample(void) {
ssize_t nbi;

do {
nbi = read(STDIN_FILENO, channel[0].dm_buffer, sizeof(sample_t) * MAX_SAMPLES);

if (nbi <= 0) {
return -1;
}

demodMSK(&(channel[0]), nbi / sizeof(sample_t));

} while (1);

return 0;
}