Skip to content

Commit ab79b4e

Browse files
committed
Audio: Volume: Set align constraints for source only
This patch modifies the frame align request to match the gain loop samples unroll number. In HiFi5 four s32 samples or eight s16 are processed per iteration. In HiFi3, HiFi4 and generic C two s32 samples or four s16 samples are processed per iteration. The equation frame_align_req = n / gcd(n, channels) with n = 8 or n = 4 for HiFi5 for s16 or s32 n = 4 or 4 = 2 for other builds for s16 or s32 ensures that every aligned frame count is multiple of gain loop unroll amount. The equation for byte_align is same as earlier but the unnecessary SOF_USE_HIFI() are removed. The code wasn't wrong for HiFi5 but it was confusing. The check for 6ch wasn't done because the SOF_FRAME_BYTE_ALIGN value was the same as VOLUME_HIFI3_HIFI4_FRAME_BYTE_ALIGN_6CH. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 531c255 commit ab79b4e

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

src/audio/volume/volume.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -639,30 +639,37 @@ static vol_zc_func vol_get_zc_function(struct comp_dev *dev,
639639
/**
640640
* \brief Set volume frames alignment limit.
641641
* \param[in,out] source Structure pointer of source.
642-
* \param[in,out] sink Structure pointer of sink.
643642
*/
644-
static void volume_set_alignment(struct audio_stream *source,
645-
struct audio_stream *sink)
643+
static void volume_set_alignment(struct audio_stream *source)
646644
{
647-
/* Both source and sink buffer in HiFi5 processing version,
648-
* xtensa intrinsics ask for 16-byte aligned.
645+
const int channels = audio_stream_get_channels(source);
646+
647+
/* The source buffer in HiFi5 processing version needs 16 bytes alignment. The
648+
* macro SOF_FRAME_BYTE_ALIGN is set in common.h to the requirement align.
649+
* The VOLUME_HIFI3_HIFI4_FRAME_BYTE_ALIGN_6CH also has the value 16 and the
650+
* same align for 5.1 channels works for HiFi5 too.
649651
*
650-
* Both source and sink buffer in HiFi3 or HiFi4 processing version,
651-
* xtensa intrinsics ask for 8-byte aligned. 5.1 format SSE audio
652-
* requires 16-byte aligned.
652+
* In HiFi4 processing version the source align requirement is 8 bytes. While
653+
* the 5.1 format SSE audio requires 16 bytes alignment.
654+
*/
655+
const uint32_t byte_align =
656+
(channels == 6) ? VOLUME_HIFI3_HIFI4_FRAME_BYTE_ALIGN_6CH : SOF_FRAME_BYTE_ALIGN;
657+
658+
/* On HiFi5 the number of samples to process must be multiple of four for s24/s32
659+
* and multiple of eight for s16. For HiFi4 and HiFi3 the number of samples
660+
* need to be multiple of two for s32 and multiple of four for s16.
661+
* E.g. for s32 format for channels counts of 1, 2, 4, 6, ... the
662+
* frame align need to be 4, 2, 1, 2, ...
653663
*/
654-
#if SOF_USE_HIFI(3, VOLUME) || SOF_USE_HIFI(4, VOLUME)
655-
const uint32_t byte_align = audio_stream_get_channels(source) == 6 ?
656-
VOLUME_HIFI3_HIFI4_FRAME_BYTE_ALIGN_6CH : SOF_FRAME_BYTE_ALIGN;
664+
#if SOF_USE_HIFI(5, VOLUME)
665+
const int n = (audio_stream_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 8 : 4;
657666
#else
658-
const uint32_t byte_align = SOF_FRAME_BYTE_ALIGN;
667+
const int n = (audio_stream_get_valid_fmt(source) == SOF_IPC_FRAME_S16_LE) ? 4 : 2;
659668
#endif
660669

661-
/*There is no limit for frame number, so both source and sink set it to be 1*/
662-
const uint32_t frame_align_req = 1;
670+
const uint32_t frame_align_req = (uint32_t)(n / gcd(n, channels));
663671

664672
audio_stream_set_align(byte_align, frame_align_req, source);
665-
audio_stream_set_align(byte_align, frame_align_req, sink);
666673
}
667674

668675
/**
@@ -698,7 +705,7 @@ static int volume_prepare(struct processing_module *mod,
698705

699706
ret = volume_peak_prepare(cd, mod);
700707

701-
volume_set_alignment(&sourceb->stream, &sinkb->stream);
708+
volume_set_alignment(&sourceb->stream);
702709

703710
/* get sink period bytes */
704711
sink_period_bytes = audio_stream_period_bytes(&sinkb->stream,

0 commit comments

Comments
 (0)