Skip to content

Add Cadence FLAC decoder support and configuration options - #11593

Merged
lgirdwood merged 5 commits into
thesofproject:mainfrom
ujfalusi:peter/pr/compr-flac-support
Dec 2, 2026
Merged

lgirdwood merged 5 commits into
thesofproject:mainfrom
ujfalusi:peter/pr/compr-flac-support

Conversation

@ujfalusi

@ujfalusi ujfalusi commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Adds the Cadence HiFi FLAC decoder (SND_AUDIOCODEC_FLAC) to the Cadence
codec module (IPC4), with an app overlay and a configurable decoder heap in
the compress topology.

  • The decoder output block size comes from the STREAMINFO max blocksize
    passed by the host in snd_codec.options.flac_d.max_blk_size. If it is
    not provided (0 or 65535), 4608 is assumed.
  • The channel count is set for the decoder, so the library no longer
    allocates its buffers for 8 channels.
  • COMPR_DECODER_HEAP makes the decoder heap configurable. The default
    stays at 192 KiB.

Supported configuration

Container native FLAC
Channels mono, stereo (the compress topology has no multichannel formats yet)
Sample rates 8 - 192 kHz, as listed in the compress topology
Bits per sample up to 24
Output 16 bit, or 24 bit in a 32 bit container
Max blocksize 4608 at <= 48 kHz, 16384 above 48 kHz (decoder limits)

With the default 192 KiB heap, stereo with 32 bit output handles blocks of
up to 4608 samples. Larger blocks above 48 kHz need a bigger heap, roughly
5 x blocksize x channels x 4 bytes: about 384 KiB for 8192 and about
704 KiB for 16384. Streams outside the decoder limits are rejected at
module init.

Testing

Tested on PTL with SoundWire: 48 kHz streams with 512, 1024, 2048 and 4096
sample blocks and a 96 kHz/24 bit stream with 4608 sample blocks play.
A 48 kHz stream with 8192 sample blocks is rejected cleanly.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unqualified header includes break IPC3 and non-Zephyr Cadence builds, and FLAC metadata spanning multiple buffers can trigger decoding before initialization completes.

2 open issues
What changed in this PR

Adds Cadence FLAC decoding to IPC4 compressed-audio playback, with host-provided block sizing and configurable decoder memory.

Changes:

  • Registers FLAC support and configures decoder channels, output depth, and block-size limits.
  • Adds build options, library linking, and application overlays.
  • Makes the compress-topology decoder heap configurable, retaining the 192 KiB default.
File Description
tools/​topology/​topology2/​platform/​intel/​compr.conf Applies configurable decoder heap sizing.
tools/​topology/​topology2/​platform/​intel/​compr-default.conf Defines the default heap and documents sizing estimates.
src/​include/​sof/​audio/​module_adapter/​module/​cadence.h Adds FLAC identifiers and block-size state.
src/​include/​sof/​audio/​cadence/​flac_dec/​xa_flac_dec_api.h Adds FLAC library API declarations.
src/​audio/​module_adapter/​module/​cadence.c Registers FLAC and handles its sizing and initialization status.
src/​audio/​module_adapter/​module/​cadence_ipc4.c Configures FLAC parameters and advertises decoder support.
src/​audio/​module_adapter/​Kconfig Adds FLAC decoder and library options.
src/​audio/​module_adapter/​CMakeLists.txt Links the configured FLAC library.
app/​compr/​README.txt Documents FLAC overlay availability.
app/​compr/​flac.conf Adds a dedicated FLAC overlay.
app/​compr/​all_codecs.conf Enables FLAC in the combined overlay.

Review effort: Balanced

ujfalusi and others added 5 commits December 2, 2026 16:00
Add the Cadence FLAC decoder API header with the FLAC specific
configuration parameters and error codes.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
…s done

The codec may need more than one input buffer to complete its
initialization, for example when the FLAC metadata blocks (like an
embedded cover picture) span multiple input buffers.

If enough input data is queued, cadence_codec_process() continues to
decode after a call to cadence_codec_init_process() even if the
initialization is not done yet, executing an uninitialized codec.

Return after the init step if the initialization is not complete, the
next process call will continue it.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add support for the Cadence FLAC decoder (SND_AUDIOCODEC_FLAC) with IPC4.

The decoder output buffer has to hold a complete decoded block, so the
OUTPUT_BLOCKSIZE of the library is configured from the STREAMINFO max
blocksize passed by the host in snd_codec.options.flac_d.max_blk_size.
If it is not provided (0 or 65535) the maximum supported blocksize for
<= 48kHz (4608) is used. Streams exceeding the blocksize limits of the
decoder (4608 for <= 48kHz, 16384 above) are rejected.

By default the library allocates its output buffer for the maximum
number of channels (8). Configure the channel count of the stream to
reduce the memory usage of the library and of the DP ring buffers,
which are sized based on the output buffer size of the codec.

The input buffer does not need to hold a whole frame as the library is
able to decode partial frames. While walking through the metadata blocks
(which can be large, like an embedded cover picture) the decoder returns
INSUFFICIENT_INPUT during init, log it as debug only.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Add flac.conf to enable the Cadence FLAC decoder and include it in
all_codecs.conf.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Add COMPR_DECODER_HEAP to set the heap_bytes_requirement of the Cadence
decoder widgets.

For FLAC the memory need scales with blocksize x channels x 4 bytes (U):
about 2 x U is needed by the library (output buffer and per channel
working memory) and 3 x U by the DP output ring buffer, plus small
buffers. The default is kept at 192 KiB, which fits the FLAC decoder
with up to 4608 samples per block (stereo, 32 bit output, ~185 KiB).

FLAC streams above 48kHz can use bigger blocks (up to 16384 samples),
which need a proportionally larger heap: ~384 KiB for 8192 and ~704 KiB
for 16384 samples per block.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi
ujfalusi force-pushed the peter/pr/compr-flac-support branch from b14e90b to 8e26c0b Compare December 2, 2026 14:05
@ujfalusi

ujfalusi commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Changes since v1:

  • New patch: module: cadence_ipc4: do not decode before the codec initialization is done.
    cadence_codec_process() no longer calls DO_EXECUTE while the codec
    initialization is incomplete. Initialization can take several input
    buffers, e.g. FLAC metadata with an embedded cover picture. This applies
    to all codecs. (Copilot)
  • FLAC header: use qualified <sof/audio/cadence/...> include paths,
    matching cadence.h. Fixes IPC3 and non-Zephyr builds, where cadence.c
    includes the header without the Cadence include directory on the path.
    (Copilot)
  • FLAC: the blocksize prints are now debug level, consistent with the
    other codecs. (Kai)

@intel-sofci

intel-sofci commented Dec 2, 2026 •

Copy link
Copy Markdown

PR 11593: test results

Run date: 2026-12-02 14:45 UTC

Tested commit: 8e26c0bc23053af644a1a65e58b56c2d971c8fc1

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood
lgirdwood merged commit ce77e3f into thesofproject:main Dec 2, 2026
44 of 47 checks passed
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.

5 participants