From b2109aadba5c960a01bce80e58f56c0d9d84f473 Mon Sep 17 00:00:00 2001 From: jens1608 <47902940+jens1608@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:53:43 +0100 Subject: [PATCH] Turn off output on idle (#25) * Update main.c Trying to disable PCM while waiting for data * Update main.c Made disabling PCM during underrun configurable * Update main.c Added debug log messages * Fix formatting * Update README --------- Co-authored-by: Tucker Kern --- README.md | 1 + source/main.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 83ec1f1..c44b8c8 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ Check `raspdif --help` for additional optional arguments to tweak behavior. ``` Usage: raspdif [OPTION...] + -d, --disable-pcm-on-idle Disable PCM during underrun. -f, --format=FORMAT Set audio sample format to s16le or s24le. Default: s16le -i, --input=INPUT_FILE Read data from file instead of stdin. diff --git a/source/main.c b/source/main.c index b6012dd..2c7e67c 100644 --- a/source/main.c +++ b/source/main.c @@ -34,6 +34,7 @@ typedef struct raspdif_arguments_t const char* file; bool verbose; bool keep_alive; + bool pcm_disable; double sample_rate; raspdif_format_t format; } raspdif_arguments_t; @@ -45,6 +46,7 @@ static struct argp_option options[] = { {"rate", 'r', "RATE", 0, "Set audio sample rate. Default: 44.1 kHz"}, {"format", 'f', "FORMAT", 0, "Set audio sample format to s16le or s24le. Default: s16le"}, {"no-keep-alive", 'k', 0, 0, "Don't send silent noise during underrun."}, + {"disable-pcm-on-idle", 'd', 0, 0, "Disable PCM during underrun."}, {"verbose", 'v', 0, 0, "Enable debug messages."}, {0}, }; @@ -91,6 +93,10 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state) arguments->keep_alive = false; break; + case 'd': + arguments->pcm_disable = true; + break; + default: return ARGP_ERR_UNKNOWN; } @@ -526,12 +532,24 @@ int main(int argc, char* argv[]) // Zero fill the sample buffers for silence raspdif_fill_buffers(buffer_index, &block, arguments.format, arguments.sample_rate, arguments.keep_alive); + if (arguments.pcm_disable) + { + bcm283x_pcm_enable(false, false); + LOGD(TAG, "PCM disabled."); + } + // Wait for file to be readable struct pollfd poll_list; poll_list.fd = fileno(file); poll_list.events = POLLIN; poll(&poll_list, 1, -1); + if (arguments.pcm_disable) + { + bcm283x_pcm_enable(true, false); + LOGD(TAG, "PCM enabled."); + } + // Resume read loop LOGD(TAG, "Data available."); continue;