From 642de0654dde7ea6e3d110521ed91a585c62b594 Mon Sep 17 00:00:00 2001 From: Steve Markgraf Date: Tue, 9 Sep 2025 20:52:45 +0200 Subject: [PATCH] add aux/headswitch support --- src/format_convert.c | 16 +++++++++++++++- src/hsdaoh_file.c | 37 +++++++++++++++---------------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/format_convert.c b/src/format_convert.c index 2fc6ffd..212a62a 100644 --- a/src/format_convert.c +++ b/src/format_convert.c @@ -236,6 +236,7 @@ void hsdaoh_unpack_pio_10bit_iq(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data_info void hsdaoh_unpack_pio_pcm1802_audio(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data_info) { + unsigned int i; uint32_t *in = (uint32_t *)data_info->buf; size_t inlen = data_info->len / sizeof(uint32_t); @@ -243,7 +244,7 @@ void hsdaoh_unpack_pio_pcm1802_audio(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data uint8_t *out = malloc(inlen * 3); int j = 0; - for (unsigned int i = 0; i < inlen; i += 2) { + for (i = 0; i < inlen; i += 2) { out[j++] = in[i+1] & 0xff; out[j++] = (in[i+1] >> 8) & 0xff; out[j++] = (in[i+1] >> 16) & 0xff; @@ -259,6 +260,19 @@ void hsdaoh_unpack_pio_pcm1802_audio(hsdaoh_dev_t *dev, hsdaoh_data_info_t *data data_info->is_signed = true; data_info->is_float = false; dev->cb(data_info); + + /* extract aux info/headswitch signal */ + for (i = 0; i < inlen; i++) + out[i] = in[i] & (1 << 25) ? 0xff : 0; + + data_info->stream_id += 2; + data_info->srate *= 2; + data_info->len = inlen; + data_info->bits_per_samp = 8; + data_info->nchans = 1; + data_info->is_signed = false; + dev->cb(data_info); + free(out); } diff --git a/src/hsdaoh_file.c b/src/hsdaoh_file.c index 719fe09..c85089b 100644 --- a/src/hsdaoh_file.c +++ b/src/hsdaoh_file.c @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef _WIN32 #include @@ -40,7 +41,7 @@ #include "hsdaoh.h" -#define FD_NUMS 4 +#define FD_NUMS 6 static bool do_exit = false; static hsdaoh_dev_t *dev = NULL; @@ -65,7 +66,7 @@ void usage(void) #ifdef FLAC__STREAM_ENCODER_SET_NUM_THREADS_OK "\t[-t number of threads for FLAC encoding (default: 4)]\n" #endif - "\t[-0 to -3 filename of stream 0 to stream 3 (a '-' dumps samples to stdout)]\n" + "\t[-0 to -5 filename of stream 0 to stream 5 (a '-' dumps samples to stdout)]\n" "\tfilename (of stream 0) (a '-' dumps samples to stdout)\n\n" "\tFilenames with the extension .flac will enable FLAC encoding\n\n"); exit(1); @@ -232,7 +233,17 @@ int main(int argc, char **argv) bool fname0_used = false; bool have_file = false; - while ((opt = getopt(argc, argv, "0:1:2:3:d:b:l:t:")) != -1) { + while ((opt = getopt(argc, argv, "0:1:2:3:4:5:d:b:l:t:")) != -1) { + if (isdigit(opt)) { + int num = opt - 0x30; + have_file = true; + filenames[num] = optarg; + if (num == 0) + fname0_used = true; + + continue; + } + switch (opt) { case 'd': dev_index = (uint32_t)atoi(optarg); @@ -246,23 +257,6 @@ int main(int argc, char **argv) case 't': flac_nthreads = atoi(optarg); break; - case '0': - fname0_used = true; - have_file = true; - filenames[0] = optarg; - break; - case '1': - have_file = true; - filenames[1] = optarg; - break; - case '2': - have_file = true; - filenames[2] = optarg; - break; - case '3': - have_file = true; - filenames[3] = optarg; - break; default: usage(); break; @@ -273,9 +267,8 @@ int main(int argc, char **argv) if (argc <= optind) { if (!have_file) usage(); - } else { + } else filenames[0] = argv[optind]; - } } if (dev_index < 0)