Skip to content

Commit 3a685a2

Browse files
committed
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 <arkadiuszx.cholewinski@intel.com>
1 parent 4a5a1d9 commit 3a685a2

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

case-lib/lib.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,24 @@ parse_audio_device() {
774774
# There is passes PCM sample format while using ALSA tool (arecord)
775775
# While using TinyALSA (tinycap -b) we need to convert PCM sample fomrat to bits.
776776
extract_format_number() {
777-
# (e.g., extracting '16' from 'S16_LE')
778-
printf '%s' "$1" | grep '[0-9]\+' -o
779-
}
777+
local format_string="$1"
778+
local extracted_num
779+
780+
if [[ "$format_string" =~ ^[SU][0-9]+(_.*)?$ ]]; then
781+
extracted_num=$(printf '%s' "${format_string}" | sed -E 's/^[SU]([0-9]+).*$/\1/')
782+
printf '%s' "$extracted_num"
783+
elif [[ "$format_string" =~ ^FLOAT[0-9]*$ ]]; then
784+
extracted_num=$(printf '%s' "${format_string}" | sed -E 's/^FLOAT([0-9]*).*$/\1/')
785+
# If extracted_num is empty (i.e., just "FLOAT"), default to 32
786+
if [[ -z "$extracted_num" ]]; then
787+
printf '32'
788+
else
789+
printf '%s' "$extracted_num"
790+
fi
791+
else
792+
die "Error: Unknown format: %s\n"
793+
fi
794+
}
780795

781796
# Initialize the parameters using for audio testing.
782797
# shellcheck disable=SC2034

0 commit comments

Comments
 (0)