Skip to content

ASoC: SOF: ipc-topology: Add float and 8-bit formats #5401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: topic/sof-dev
Choose a base branch
from

Conversation

singalsu
Copy link

@singalsu singalsu commented Apr 30, 2025

See commit messages for the changes.

@singalsu singalsu force-pushed the add_8bit_support branch from d4c44e7 to 7e3020c Compare May 6, 2025 12:15
@singalsu
Copy link
Author

singalsu commented May 8, 2025

SOFCI TEST

@singalsu singalsu force-pushed the add_8bit_support branch 2 times, most recently from 18cc681 to a742f2c Compare May 15, 2025 13:14
@singalsu
Copy link
Author

singalsu commented May 15, 2025

I combined all the patches, not sure if this can be split to preparation and feature enable.

I've tested this with script like below UPX i11 device with this kernel patch and firmware thesofproject/sof#9980. Then copied from DUT the nocodec loopback wav files and checked visually them with spectrogram in audio editor. The chirp should sound and look clean with all formats combinations.

#!/bin/bash

set -e

# Playback with 8bit
arecord -Dhw:0,0 -f S32_LE -c 2 -r 48000 -d 8 rec_play_s32.wav   & PID=$!; sleep 1; play_s32.sh   Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
arecord -Dhw:0,0 -f S32_LE -c 2 -r 48000 -d 8 rec_play_u8.wav    & PID=$!; sleep 1; play_u8.sh    Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
arecord -Dhw:0,0 -f S32_LE -c 2 -r 48000 -d 8 rec_play_alaw.wav  & PID=$!; sleep 1; play_alaw.sh  Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
arecord -Dhw:0,0 -f S32_LE -c 2 -r 48000 -d 8 rec_play_mulaw.wav & PID=$!; sleep 1; play_mulaw.sh Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID

# Capture with 8bit
arecord -Dhw:0,0 -f S32_LE -c 2 -r 48000 -d 8 rec_s32.wav & PID=$!; sleep 1; play_s32.sh   Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
arecord -Dhw:0,0 -f U8     -c 2 -r 48000 -d 8 rec_u8.wav  & PID=$!; sleep 1; play_s32.sh   Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID

# These neeed help from sox, arecord doesn't allow a/mu-law wav
arecord -Dhw:0,0 -f A_LAW -c 2 -r 48000 -d 8 -t raw /tmp/rec.raw & PID=$!; sleep 1; play_s32.sh Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
sox --encoding a-law -r 48000 -c 2 /tmp/rec.raw rec_alaw.wav
arecord -Dhw:0,0 -f MU_LAW -c 2 -r 48000 -d 8 -t raw /tmp/rec.raw & PID=$!; sleep 1; play_s32.sh Music/misc/chirp_lin_50Hz_15kHz_-3db_5s.wav; wait $PID
sox --encoding u-law -r 48000 -c 2 /tmp/rec.raw rec_mulaw.wav

@singalsu
Copy link
Author

No changes, just rebased and improved commit text to re-launch SOFCI.


_out_rate = fmt->sampling_frequency;
_out_channels = SOF_IPC4_AUDIO_FORMAT_CFG_CHANNELS_COUNT(fmt->fmt_cfg);
_out_valid_bits = SOF_IPC4_AUDIO_FORMAT_CFG_V_BIT_DEPTH(fmt->fmt_cfg);
_out_type = SOF_IPC4_AUDIO_FORMAT_CFG_SAMPLE_TYPE(fmt->fmt_cfg);
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is granted that the SOF_IPC4_AUDIO_FORMAT_CFG_SAMPLE_TYPE() for non 8 bit formats are always matching, right?
When used with older topologies where the type is not set.

Copy link
Author

Choose a reason for hiding this comment

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

It looks like the sample type was first set in this December 2021 patch. The error would be with sample type not set.

commit 663174320904c0bc045f2d60cbe62035147c9736 (HEAD)
Author: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Date:   Sat Dec 11 21:03:50 2021 -0800

    topology2: common: Add new class definition for audio_format
    
    Add definition for audio format class for defining the input and output
    audio formats for each components in cavs topology.
    
    Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>

It looks like the risk of encountering such topology is very low, only own tplg builds can be such. SOF v2.7 was first release for IPC4 and it was September 2023.

if (params_format(fe_params) == SNDRV_PCM_FORMAT_S16_LE)
pipeline->msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_SCS_MASK;

/* Set SCS bit for 8 and 16 bit formats */
switch (params_format(fe_params)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if (params_physical_width(fe_params) <= 16)
	pipeline->msg.primary |= SOF_IPC4_GLB_CHAIN_DMA_SCS_MASK;

Copy link
Author

Choose a reason for hiding this comment

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

Yep, much better that way.

return SOF_IPC4_TYPE_LSB_INTEGER;
default:
dev_err(sdev->dev, "invalid pcm sample type %d\n", params_format(params));
return -EINVAL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

HDMI supports IEC958_SUBFRAME_LE, that should be not an error.

Copy link
Author

Choose a reason for hiding this comment

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

I guess I'll add case SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE: to return SOF_IPC4_TYPE_LSB_INTEGER though it isn't exactly right. I need to get his somehow tested, maybe with my TV and HDMI.

Copy link
Author

@singalsu singalsu May 28, 2025

Choose a reason for hiding this comment

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

@ujfalusi This seems to be called only for capture. I was never able to get SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE, since HDMI is only for playback. What do you think, should I remove the added case since it doesn't get executed?

As alternative way, this function could return by default SOF_IPC4_TYPE_LSB_INTEGER and only warn if ALSA PCM format is unknown. I don't know really what to do other than this conversion from ALSA to IPC4 needs to be done for 8-bit and next to-be-added float sample type.

singalsu added 2 commits June 5, 2025 11:19
This patch enables use of 8-bit unsigned, A-law, and mu-law
sample formats with IPC4 SOF.

The ipc4-topology.h is updated with IPC4 sample types. The
purpose is to to convert ALSA types to IPC4 types.

The functions of_ipc4_update_hw_params(), sof_ipc4_get_valid_bits(),
and new function sof_ipc4_get_sample_type() are updated to handle
the sample type conversions.

The function sof_ipc4_prepare_copier_module() is updated to set
the DMA SCS bit for all non 32 bits sample types.

The change to function sof_ipc4_get_valid_bits() returns 8 bits
for these ALSA formats.

The change to function sof_ipc4_prepare_copier_module() is
needed to handle properly all non 32-bit formats with SCS
bit set.

To support playback with new 8 bits types, the
sof_ipc4_init_input_audio_fmt() function is updated to get
the sample type and use it in search for copier input pin
format.

To support capture, the sof_ipc4_init_output_audio_fmt()
is updated similarly. Since the function uses separate
out_ref_type argument, instead of single parameters struct,
the out_ref_type needs to be added to every user of the
function. Therefore functions sof_ipc4_prepare_copier_module(),
sof_ipc4_prepare_gain_module(), sof_ipc4_prepare_mixer_module(),
sof_ipc4_prepare_src_module(), and sof_ipc4_prepare_process_module()
are updated to set the out_ref_type.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This patch adds support for FLOAT_LE ALSA type for playback and
capture for IPC4 systems. Functions sof_ipc4_update_hw_params(),
sof_ipc4_get_valid_bits() and sof_ipc4_get_sample_type()
are updated to handle SOF_IPC4_TYPE_FLOAT and
SNDRV_PCM_FORMAT_FLOAT_LE.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu singalsu force-pushed the add_8bit_support branch from 1ae4f3f to 9b13ced Compare June 5, 2025 08:20
@singalsu singalsu changed the title ASoC: SOF: ipc-topology: Add 8-bit formats ASoC: SOF: ipc-topology: Add float and 8-bit formats Jun 5, 2025
@singalsu singalsu requested a review from ujfalusi June 5, 2025 08:22
@singalsu
Copy link
Author

singalsu commented Jun 5, 2025

I combined the float format add into this patch. Please review @ranj063 and @ujfalusi .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants