From fd998e2bf73cc7cc8e1b0b16de111af2bfc7cf84 Mon Sep 17 00:00:00 2001 From: midnightmagic Date: Thu, 11 Sep 2014 03:32:22 -0700 Subject: [PATCH] libsndfile can be used to open a UNIX-style pipe on many platforms In specific, it can be used to read in data almost directly from Gqrx Currently, this will not function correctly using -i /dev/stdin on OS X because stdin is not seekable, and it is not actually a file; also, for ongoing raw data, there are no hints for libsndfile to identify the sample. So, we can use the UNIX-y '-' to do libsndfile-approved fd handle open. Tested with the dsd-samples wav after converting it to correct sampletype (stereo) -> sox p25_raw_unencrypted_edf.wav -c 2 ~/gqrx_last_recorded_filename.wav .. and then pressing 'play' in the Gqrx interface while running: socat udp-listen:7355 - | dsd -i - -o pa:2 .. in the background. And it decoded it nicely as many times as I played it, which was 5 or 10. --- dsd_audio.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dsd_audio.c b/dsd_audio.c index 2497919..993add2 100644 --- a/dsd_audio.c +++ b/dsd_audio.c @@ -465,7 +465,22 @@ void openAudioInDevice (dsd_opts * opts) { // get info of device/file - if(strncmp(opts->audio_in_dev, "pa:", 2) == 0) + if(strncmp(opts->audio_in_dev, "-", 1) == 0) + { + opts->audio_in_type = 1; + opts->audio_in_file_info = calloc(1, sizeof(SF_INFO)); + opts->audio_in_file_info->samplerate=48000; + opts->audio_in_file_info->channels=1; + opts->audio_in_file_info->seekable=0; + opts->audio_in_file_info->format=SF_FORMAT_RAW|SF_FORMAT_PCM_16|SF_ENDIAN_LITTLE; + opts->audio_in_file = sf_open_fd(fileno(stdin), SFM_READ, opts->audio_in_file_info, 0); + + if(opts->audio_in_file == NULL) { + printf ("Error, couldn't open stdin with libsndfile: %s\n", sf_strerror(NULL)); + exit(1); + } + } + else if(strncmp(opts->audio_in_dev, "pa:", 2) == 0) { opts->audio_in_type = 2; #ifdef USE_PORTAUDIO