Skip to content

Commit

Permalink
Turn off output on idle (#25)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jens1608 and mill1000 authored Mar 27, 2024
1 parent b292500 commit b2109aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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},
};
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b2109aa

Please sign in to comment.