From 3a685a218aa91cdfab88906ea7d1e404dbfa3b5f Mon Sep 17 00:00:00 2001 From: Arkadiusz Cholewinski Date: Wed, 9 Jul 2025 13:59:26 +0200 Subject: [PATCH] Refactor format-to-bit-depth extraction, add FLOAT support Improved handling of standard formats (e.g., S16_LE) and added support for FLOAT types with defaulting to 32-bit when unspecified. Signed-off-by: Arkadiusz Cholewinski --- case-lib/lib.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index d60b9ca9..5cb486bc 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -774,9 +774,24 @@ parse_audio_device() { # There is passes PCM sample format while using ALSA tool (arecord) # While using TinyALSA (tinycap -b) we need to convert PCM sample fomrat to bits. extract_format_number() { - # (e.g., extracting '16' from 'S16_LE') - printf '%s' "$1" | grep '[0-9]\+' -o -} + local format_string="$1" + local extracted_num + + if [[ "$format_string" =~ ^[SU][0-9]+(_.*)?$ ]]; then + extracted_num=$(printf '%s' "${format_string}" | sed -E 's/^[SU]([0-9]+).*$/\1/') + printf '%s' "$extracted_num" + elif [[ "$format_string" =~ ^FLOAT[0-9]*$ ]]; then + extracted_num=$(printf '%s' "${format_string}" | sed -E 's/^FLOAT([0-9]*).*$/\1/') + # If extracted_num is empty (i.e., just "FLOAT"), default to 32 + if [[ -z "$extracted_num" ]]; then + printf '32' + else + printf '%s' "$extracted_num" + fi + else + die "Error: Unknown format: %s\n" + fi +} # Initialize the parameters using for audio testing. # shellcheck disable=SC2034