Skip to content

Conversation

@gbarkadiusz
Copy link
Contributor

@gbarkadiusz gbarkadiusz commented Jul 9, 2025

Expand ALSA text to bit depth conversion function with support for FLOAT_LE, U8, MU_LAW, and A_LAW.

Justification.
The check-capture test uses format that doesn't contain the digit. " e.g., FLOAT_LE".
As a result, the converting function returns an empty string, which the shell interprets as 0. This causes the tinycap command to fail with the following error:
tinycap /dev/null -D 0 -d 0 -c 2 -t 3 -r 48000 -b 0 bits is not supported.

@gbarkadiusz gbarkadiusz requested review from a team, golowanow, lgirdwood and marc-hb as code owners July 9, 2025 12:06
case-lib/lib.sh Outdated
FLOAT)
printf '32' # Assuming 32-bit float
;;
*)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are other format strings now also possible, e.g.

Device Information
        Name: hw:sofnocodec,0
        Card: sofnocodec[sof-nocodec]
        Device: Port0 (*)[]
        Stream: CAPTURE
        Format: ['U8', 'S16_LE', 'S24_LE', 'S32_LE', 'FLOAT_LE', 'MU_LAW', 'A_LAW']

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the above is just an example from one configuration, but there could be other
https://www.alsa-project.org/alsa-doc/alsa-lib/group___p_c_m.html#gaa14b7f26877a812acbb39811364177f8

ie. currently this test can handle '[0-9]+_BE`, but with this change it will not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think _[SU]([0-9])+_ and _FLOAT([0-9]+)_ should cover many formats and the rest (like 'FLOAT', '*_LAW') can be hardcoded.

Copy link
Contributor Author

@gbarkadiusz gbarkadiusz Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how about this one:

  case "$format_string" in
        # 8-bit formats (Signed/Unsigned)
        S8 | U8)
            printf '8'
            ;;
        # 16-bit formats (Signed/Unsigned, various endianness)
        S16_LE | S16_BE | U16_LE | U16_BE | S16 | U16)
            printf '16'
            ;;
        # 18-bit formats (3-byte container, various endianness)
        S18_3LE | S18_3BE | U18_3LE | U18_3BE)
            printf '18'
            ;;
        # 20-bit formats (in 4-byte or 3-byte containers, various endianness)
        S20_LE | S20_BE | U20_LE | U20_BE | S20 | U20 | \
        S20_3LE | S20_3BE | U20_3LE | U20_3BE)
            printf '20'
            ;;
        # 24-bit formats (in 4-byte or 3-byte containers, various endianness)
        S24_LE | S24_BE | U24_LE | U24_BE | S24 | U24 | \
        S24_3LE | S24_3BE | U24_3LE | U24_3BE)
            printf '24'
            ;;
        # 32-bit integer formats (Signed/Unsigned, various endianness)
        S32_LE | S32_BE | U32_LE | U32_BE | S32 | U32)
            printf '32'
            ;;
        # 32-bit Floating-point formats
        FLOAT_LE | FLOAT_BE | FLOAT)
            printf '32' # Standard single-precision float
            ;;
        # 64-bit Floating-point formats
        FLOAT64_LE | FLOAT64_BE | FLOAT64)
            printf '64' # Double-precision float
            ;;
        # Compressed / Encoded formats (typically handled as 8-bit for raw stream)
        MU_LAW | A_LAW | IMA_ADPCM | MPEG | GSM)
            printf '8' 
            ;;
        # IEC958 (S/PDIF) subframe formats
        IEC958_SUBFRAME_LE | IEC958_SUBFRAME_BE | IEC958_SUBFRAME)
            printf '24' # IEC958 commonly carries up to 24-bit audio data
            ;;
        # Formats without a direct, standard bit depth mapping or needing special handling
        UNKNOWN | SPECIAL) # Assuming 'UNKNOWN' corresponds to SND_PCM_FORMAT_UNKNOWN
            printf '' # No direct bit depth, or requires specific codec/driver handling
            ;;
        # Default case for any unlisted or unrecognized formats
        *)
            # echo "ERROR: Unrecognized format encountered: $format_string" >&2
            printf '' 
            ;;
    esac

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check against https://github.com/alsa-project/alsa-lib/blob/master/src/pcm/pcm_misc.c#L210
and squeeze it with patterns following the naming convention, whether possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: we are never going to encounter most of these formats (GSM, U/S18, *_BE)

I'm uncertain what is the meaning of bits in tiny-world...
S24_LE is 24bit audio in 32bit container, LSB aligned
S24_3LE s 24bit audio in 24bit container (sort of packed, no padding)
S32_LE + MSBITS_24 is 24bit audio in 32bit container, MSB aligned (we don't yet have support for this in SOF)

which of these -b24 will result? My guess is S24_LE, but I'm not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming that, I've confirmed that expanding the supported format list to allow FLOAT makes the test pass.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: we are never going to encounter most of these formats (GSM, U/S18, *_BE)

Let's implement it as explicit case selection for only these formats we use for validation.

Copy link
Member

@golowanow golowanow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please extend your commit's summary with more details, e.g.
Expand ALSA text to bit size format conversion function with FLOAT_LE and ....

@gbarkadiusz gbarkadiusz force-pushed the topic/tinyalsa/fix_format_converting branch from 9a64f81 to 71a15b4 Compare July 9, 2025 12:27
@golowanow golowanow added the P3 Low-impact bugs or features label Jul 10, 2025
@gbarkadiusz gbarkadiusz force-pushed the topic/tinyalsa/fix_format_converting branch from 71a15b4 to 4532d4f Compare July 10, 2025 11:53
@gbarkadiusz gbarkadiusz force-pushed the topic/tinyalsa/fix_format_converting branch from 4532d4f to 81f84fe Compare July 11, 2025 08:30
@golowanow
Copy link
Member

SOFCI TEST

@marc-hb marc-hb removed their request for review July 11, 2025 17:13
Copy link
Member

@golowanow golowanow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to update the commit message to what is actually done with refactoring other format's handling in addition to FLOAT.

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>
@gbarkadiusz gbarkadiusz force-pushed the topic/tinyalsa/fix_format_converting branch from 81f84fe to 3a685a2 Compare July 14, 2025 06:17
@golowanow golowanow merged commit 8df0f1a into thesofproject:main Jul 15, 2025
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-impact bugs or features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants