From 6b5ccf89239eef1dcca1ed3e172d299ac3c4bfe2 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 17 Mar 2026 13:41:47 +0200 Subject: [PATCH 1/5] fcplay: Handle the buffer size and fragments command line parameters fcplay ignores the values set via -b and -f parameters, change the compress_open_and_prepare() to take these into account similarly as cplay does. Signed-off-by: Peter Ujfalusi --- src/utils-lgpl/fcplay.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils-lgpl/fcplay.c b/src/utils-lgpl/fcplay.c index 94276e9..72e7205 100644 --- a/src/utils-lgpl/fcplay.c +++ b/src/utils-lgpl/fcplay.c @@ -351,8 +351,8 @@ static int parse_file(const char *file, struct snd_codec *codec) static struct compress * compress_open_and_prepare(unsigned int card, unsigned int device, struct snd_codec *codec, unsigned long buffer_size, - const char *name, FILE *file, char **buffer_out, - int *size_out) + unsigned int frag, const char *name, FILE *file, + char **buffer_out, int *size_out) { struct compr_config config; struct compress *compress; @@ -361,6 +361,14 @@ compress_open_and_prepare(unsigned int card, unsigned int device, memset(&config, 0, sizeof(config)); + if ((buffer_size != 0) && (frag != 0)) { + config.fragment_size = buffer_size / frag; + config.fragments = frag; + } else { + /* use driver defaults */ + config.fragment_size = 0; + config.fragments = 0; + } config.codec = codec; compress = compress_open(card, device, COMPRESS_IN, &config); @@ -428,7 +436,7 @@ void play_samples(char **files, unsigned int card, unsigned int device, parse_file(name, &codec); compress = compress_open_and_prepare(card, device, &codec, buffer_size, - name, file, &buffer, &size); + frag, name, file, &buffer, &size); if (!compress) goto FILE_EXIT; @@ -486,7 +494,7 @@ void play_samples(char **files, unsigned int card, unsigned int device, parse_file(name, &codec); compress = compress_open_and_prepare(card, device, &codec, - buffer_size, name, + buffer_size, frag, name, file, &buffer, &size); if (!compress) goto FILE_EXIT; From 12ce56e40c171025b56feb51067ae92f2964c3a0 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 18 Mar 2026 13:54:04 +0200 Subject: [PATCH 2/5] cplay: Print out the number of fragments used in the buffer The number of fragments is useful information of the buffer allocation. Print it out alongside of the buffer size. Signed-off-by: Peter Ujfalusi --- src/utils/cplay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/cplay.c b/src/utils/cplay.c index b0d14a3..256df50 100644 --- a/src/utils/cplay.c +++ b/src/utils/cplay.c @@ -844,8 +844,8 @@ void play_samples(char *name, unsigned int card, unsigned int device, fprintf(stderr, "We wrote %d, DSP accepted %d\n", num_read, wrote); } } - printf("Playing file %s On Card %u device %u, with buffer of %d bytes\n", - name, card, device, size); + printf("Playing file %s On Card %u device %u, with buffer of %d bytes, %u fragments\n", + name, card, device, size, config.fragments); printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); From 9552e05b00c146ba3e446de7e2faefcd67c45a44 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 18 Mar 2026 13:56:26 +0200 Subject: [PATCH 3/5] fcplay: Fix the buffer size print and print out the number of fragments The code only printed out the buffer size which was passed as parameter - and ironically, it was ignored. Correct the code to print out the size of the allocated buffer. The number of fragments is useful information of the buffer allocation. Print it out alongside of the buffer size. Signed-off-by: Peter Ujfalusi --- src/utils-lgpl/fcplay.c | 45 +++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/utils-lgpl/fcplay.c b/src/utils-lgpl/fcplay.c index 72e7205..4fb4f90 100644 --- a/src/utils-lgpl/fcplay.c +++ b/src/utils-lgpl/fcplay.c @@ -352,11 +352,12 @@ static struct compress * compress_open_and_prepare(unsigned int card, unsigned int device, struct snd_codec *codec, unsigned long buffer_size, unsigned int frag, const char *name, FILE *file, - char **buffer_out, int *size_out) + char **buffer_out, unsigned long *total_size_out, + unsigned int *num_fragments_out) { struct compr_config config; struct compress *compress; - int size, num_read, wrote; + int fragment_size, num_read, wrote; char *buffer; memset(&config, 0, sizeof(config)); @@ -381,17 +382,17 @@ compress_open_and_prepare(unsigned int card, unsigned int device, if (verbose) printf("%s: Opened compress device\n", __func__); - size = config.fragment_size; - buffer = malloc(size * config.fragments); + fragment_size = config.fragment_size; + buffer = malloc(fragment_size * config.fragments); if (!buffer) { fprintf(stderr, "Unable to allocate %d bytes\n", - size * config.fragments); + fragment_size * config.fragments); compress_close(compress); return NULL; } /* write full buffer data initially */ - num_read = fread(buffer, 1, size * config.fragments, file); + num_read = fread(buffer, 1, fragment_size * config.fragments, file); if (num_read > 0) { if (verbose) printf("%s: Doing first buffer write of %d\n", __func__, num_read); @@ -410,7 +411,8 @@ compress_open_and_prepare(unsigned int card, unsigned int device, } *buffer_out = buffer; - *size_out = size; + *total_size_out = (unsigned long)fragment_size * config.fragments; + *num_fragments_out = config.fragments; return compress; } @@ -421,7 +423,9 @@ void play_samples(char **files, unsigned int card, unsigned int device, { struct compr_gapless_mdata mdata; struct compress *compress; - int size, num_read, wrote; + int fragment_size, num_read, wrote; + unsigned long allocated_buffer_size; + unsigned int num_fragments; unsigned int file_idx = 0; struct snd_codec codec; char *buffer, *name; @@ -436,17 +440,20 @@ void play_samples(char **files, unsigned int card, unsigned int device, parse_file(name, &codec); compress = compress_open_and_prepare(card, device, &codec, buffer_size, - frag, name, file, &buffer, &size); + frag, name, file, &buffer, + &allocated_buffer_size, &num_fragments); if (!compress) goto FILE_EXIT; + fragment_size = (int)(allocated_buffer_size / num_fragments); + if (pb_mode == PLAYBACK_MODE_GAPLESS) { memset(&mdata, 0, sizeof(mdata)); compress_set_gapless_metadata(compress, &mdata); } - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes\n", - name, card, device, buffer_size); + printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", + name, card, device, allocated_buffer_size, num_fragments); printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); @@ -462,8 +469,8 @@ void play_samples(char **files, unsigned int card, unsigned int device, goto TRACK_EXIT; if (verbose) - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes\n", - name, card, device, buffer_size); + printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", + name, card, device, allocated_buffer_size, num_fragments); if (pb_mode == PLAYBACK_MODE_GAPLESS) { int rc; @@ -495,12 +502,16 @@ void play_samples(char **files, unsigned int card, unsigned int device, parse_file(name, &codec); compress = compress_open_and_prepare(card, device, &codec, buffer_size, frag, name, - file, &buffer, &size); + file, &buffer, + &allocated_buffer_size, + &num_fragments); if (!compress) goto FILE_EXIT; - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes\n", - name, card, device, buffer_size); + fragment_size = num_fragments ? (int)(allocated_buffer_size / num_fragments) : 0; + + printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", + name, card, device, allocated_buffer_size, num_fragments); printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); @@ -511,7 +522,7 @@ void play_samples(char **files, unsigned int card, unsigned int device, } do { - num_read = fread(buffer, 1, size, file); + num_read = fread(buffer, 1, fragment_size, file); if (num_read > 0) { wrote = compress_write(compress, buffer, num_read); if (wrote < 0) { From 3cacca3ac6c4e2252321d8ce3e212b51724201e1 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 29 Apr 2026 15:40:57 +0300 Subject: [PATCH 4/5] src: lib: compress: add playback info helper Add compress_print_playback_info() to centralize playback configuration logging shared by cplay and fcplay. Signed-off-by: Peter Ujfalusi --- include/tinycompress/tinycompress.h | 5 +++++ src/lib/compress.c | 11 +++++++++++ src/utils-lgpl/fcplay.c | 13 +++++-------- src/utils/cplay.c | 6 ++---- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index c7b1b73..2ede072 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -332,6 +332,11 @@ int is_compress_ready(struct compress *compress); /* Returns a human readable reason for the last error */ const char *compress_get_error(struct compress *compress); +/* Prints basic stream details for playback diagnostics */ +void compress_print_playback_info(const char *name, unsigned int card, + unsigned int device, unsigned long buffer_size, + unsigned int num_fragments, const struct snd_codec *codec); + /* * compress_set_param: set codec config intended for next track * if DSP has support to switch CODEC config during gapless playback diff --git a/src/lib/compress.c b/src/lib/compress.c index c0b547b..d685f73 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -81,6 +81,17 @@ const char *compress_get_error(struct compress *compress) return compress->ops->get_error(compress->data); } +void compress_print_playback_info(const char *name, unsigned int card, + unsigned int device, unsigned long buffer_size, + unsigned int num_fragments, const struct snd_codec *codec) +{ + printf("Playing file %s On Card %u device %u\n", name, card, device); + printf(" Buffer size: %lu bytes, %u fragments, fragment size: %lu bytes\n", + buffer_size, num_fragments, buffer_size / num_fragments); + printf(" Format %u Channels %u, %u Hz, Bit Rate %d\n", + codec->id, codec->ch_in, codec->sample_rate, (int)codec->bit_rate); +} + int is_compress_running(struct compress *compress) { return compress->ops->is_compress_running(compress->data); diff --git a/src/utils-lgpl/fcplay.c b/src/utils-lgpl/fcplay.c index 4fb4f90..780301e 100644 --- a/src/utils-lgpl/fcplay.c +++ b/src/utils-lgpl/fcplay.c @@ -452,10 +452,8 @@ void play_samples(char **files, unsigned int card, unsigned int device, compress_set_gapless_metadata(compress, &mdata); } - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", - name, card, device, allocated_buffer_size, num_fragments); - printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", - codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); + compress_print_playback_info(name, card, device, allocated_buffer_size, + num_fragments, &codec); compress_start(compress); if (verbose) @@ -510,10 +508,9 @@ void play_samples(char **files, unsigned int card, unsigned int device, fragment_size = num_fragments ? (int)(allocated_buffer_size / num_fragments) : 0; - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", - name, card, device, allocated_buffer_size, num_fragments); - printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", - codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); + compress_print_playback_info(name, card, device, + allocated_buffer_size, + num_fragments, &codec); compress_start(compress); if (verbose) diff --git a/src/utils/cplay.c b/src/utils/cplay.c index 256df50..d96a7a1 100644 --- a/src/utils/cplay.c +++ b/src/utils/cplay.c @@ -844,10 +844,8 @@ void play_samples(char *name, unsigned int card, unsigned int device, fprintf(stderr, "We wrote %d, DSP accepted %d\n", num_read, wrote); } } - printf("Playing file %s On Card %u device %u, with buffer of %d bytes, %u fragments\n", - name, card, device, size, config.fragments); - printf("Format %u Channels %u, %u Hz, Bit Rate %d\n", - codec.id, codec.ch_in, codec.sample_rate, codec.bit_rate); + compress_print_playback_info(name, card, device, + (unsigned long)size, config.fragments, &codec); compress_start(compress); if (verbose) From 387062c781e5bb4c131f14d1f81705e24b39e739 Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Wed, 29 Apr 2026 16:07:26 +0300 Subject: [PATCH 5/5] src: lib: compress: print track index for playback wip Pass file_count and file_idx to compress_print_playback_info() so multi-file playback can show the current track number in the log while single-file playback keeps the same output format. Signed-off-by: Peter Ujfalusi --- include/tinycompress/tinycompress.h | 3 ++- src/lib/compress.c | 9 +++++++-- src/utils-lgpl/fcplay.c | 17 +++++++++++------ src/utils/cplay.c | 4 ++-- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/include/tinycompress/tinycompress.h b/include/tinycompress/tinycompress.h index 2ede072..7bd4738 100644 --- a/include/tinycompress/tinycompress.h +++ b/include/tinycompress/tinycompress.h @@ -334,7 +334,8 @@ const char *compress_get_error(struct compress *compress); /* Prints basic stream details for playback diagnostics */ void compress_print_playback_info(const char *name, unsigned int card, - unsigned int device, unsigned long buffer_size, + unsigned int device, unsigned int file_count, + unsigned int file_idx, unsigned long buffer_size, unsigned int num_fragments, const struct snd_codec *codec); /* diff --git a/src/lib/compress.c b/src/lib/compress.c index d685f73..3c57e65 100644 --- a/src/lib/compress.c +++ b/src/lib/compress.c @@ -82,10 +82,15 @@ const char *compress_get_error(struct compress *compress) } void compress_print_playback_info(const char *name, unsigned int card, - unsigned int device, unsigned long buffer_size, + unsigned int device, unsigned int file_count, + unsigned int file_idx, unsigned long buffer_size, unsigned int num_fragments, const struct snd_codec *codec) { - printf("Playing file %s On Card %u device %u\n", name, card, device); + if (file_count > 1) + printf("Playing file %u/%u %s On Card %u device %u\n", file_idx + 1, + file_count, name, card, device); + else + printf("Playing file %s On Card %u device %u\n", name, card, device); printf(" Buffer size: %lu bytes, %u fragments, fragment size: %lu bytes\n", buffer_size, num_fragments, buffer_size / num_fragments); printf(" Format %u Channels %u, %u Hz, Bit Rate %d\n", diff --git a/src/utils-lgpl/fcplay.c b/src/utils-lgpl/fcplay.c index 780301e..7b462b3 100644 --- a/src/utils-lgpl/fcplay.c +++ b/src/utils-lgpl/fcplay.c @@ -452,8 +452,8 @@ void play_samples(char **files, unsigned int card, unsigned int device, compress_set_gapless_metadata(compress, &mdata); } - compress_print_playback_info(name, card, device, allocated_buffer_size, - num_fragments, &codec); + compress_print_playback_info(name, card, device, file_count, file_idx, + allocated_buffer_size, num_fragments, &codec); compress_start(compress); if (verbose) @@ -466,10 +466,6 @@ void play_samples(char **files, unsigned int card, unsigned int device, if (!file) goto TRACK_EXIT; - if (verbose) - printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", - name, card, device, allocated_buffer_size, num_fragments); - if (pb_mode == PLAYBACK_MODE_GAPLESS) { int rc; @@ -491,6 +487,11 @@ void play_samples(char **files, unsigned int card, unsigned int device, rc = compress_partial_drain(compress); if (rc) fprintf(stderr, "ERR: partial drain\n"); + + compress_print_playback_info(name, card, device, + file_count, file_idx, + allocated_buffer_size, + num_fragments, &codec); } else if (pb_mode == PLAYBACK_MODE_RESTART) { /* restart: drain, close, and reopen for the new file */ compress_drain(compress); @@ -509,12 +510,16 @@ void play_samples(char **files, unsigned int card, unsigned int device, fragment_size = num_fragments ? (int)(allocated_buffer_size / num_fragments) : 0; compress_print_playback_info(name, card, device, + file_count, file_idx, allocated_buffer_size, num_fragments, &codec); compress_start(compress); if (verbose) printf("%s: You should hear audio NOW!!!\n", __func__); + } else if (verbose) { + printf("Playing file %s On Card %u device %u, with buffer of %lu bytes, %u fragments\n", + name, card, device, allocated_buffer_size, num_fragments); } } diff --git a/src/utils/cplay.c b/src/utils/cplay.c index d96a7a1..9e1175d 100644 --- a/src/utils/cplay.c +++ b/src/utils/cplay.c @@ -844,8 +844,8 @@ void play_samples(char *name, unsigned int card, unsigned int device, fprintf(stderr, "We wrote %d, DSP accepted %d\n", num_read, wrote); } } - compress_print_playback_info(name, card, device, - (unsigned long)size, config.fragments, &codec); + compress_print_playback_info(name, card, device, 1, 0, (unsigned long)size, + config.fragments, &codec); compress_start(compress); if (verbose)