diff --git a/lmdk/libraries/module_example/module_example_mtl.toml b/lmdk/libraries/module_example/module_example_mtl.toml index 4adaa3a97e5f..33487dc3405b 100644 --- a/lmdk/libraries/module_example/module_example_mtl.toml +++ b/lmdk/libraries/module_example/module_example_mtl.toml @@ -44,7 +44,6 @@ length = "0x0" # calculated by rimage [signed_pkg] name = "ADSP" -partition_usage = "0x23" [[signed_pkg.module]] name = "ADSP.met" diff --git a/lmdk/modules/up_down_mixer/CMakeLists.txt b/lmdk/modules/up_down_mixer/CMakeLists.txt index c78b566b4ed7..a5be6b1449c9 100644 --- a/lmdk/modules/up_down_mixer/CMakeLists.txt +++ b/lmdk/modules/up_down_mixer/CMakeLists.txt @@ -12,7 +12,8 @@ target_compile_definitions(up_down_mixer PRIVATE __ZEPHYR__=1 CONFIG_IPC_MAJOR_4=1 CONFIG_LIBRARY=1 __ZEPHYR_RTOS_IDC_H__=1 - MODULE_PRIVAT=1) + MODULE_PRIVAT=1 + XCHAL_HAVE_HIFI3=1) message( ${LMDK_DIR}${SOF_SRC_DIR}../posix/include ) diff --git a/lmdk/modules/up_down_mixer/up_down_mixer_hifi3.c b/lmdk/modules/up_down_mixer/up_down_mixer_hifi3.c deleted file mode 100644 index d77b834c9fdd..000000000000 --- a/lmdk/modules/up_down_mixer/up_down_mixer_hifi3.c +++ /dev/null @@ -1,1915 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -// -// Copyright(c) 2022 Intel Corporation. All rights reserved. -// -// Author: Bartosz Kokoszko - -#include <../include/up_down_mixer.h> - -#include -#include -#include -#include -#include - -void upmix32bit_1_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - /* Only load the channel if it's present. */ - ae_int32 *output_left = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT) << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_CENTER) << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2)); - ae_int32 *output_left_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - ae_int32 *output_right_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LFE) << 2)); - - ae_int32 *in_ptr = (ae_int32 *)in_data; - - for (i = 0; i < (in_size >> 2); ++i) { - output_left[i * 6] = in_ptr[i]; - output_right[i * 6] = in_ptr[i]; - output_center[i * 6] = 0; - output_left_surround[i * 6] = in_ptr[i]; - output_right_surround[i * 6] = in_ptr[i]; - output_lfe[i * 6] = 0; - } -} - -void upmix16bit_1_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - /* Only load the channel if it's present. */ - ae_int32 *output_left = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT) << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_CENTER) << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2)); - ae_int32 *output_left_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - ae_int32 *output_right_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LFE) << 2)); - - ae_int16 *in_ptr = (ae_int16 *)in_data; - - for (i = 0; i < (in_size >> 1); ++i) { - output_left[i * 6] = AE_MOVINT32_FROMINT16(in_ptr[i]) << 16; - output_right[i * 6] = AE_MOVINT32_FROMINT16(in_ptr[i]) << 16; - output_center[i * 6] = 0; - output_left_surround[i * 6] = AE_MOVINT32_FROMINT16(in_ptr[i]) << 16; - output_right_surround[i * 6] = AE_MOVINT32_FROMINT16(in_ptr[i]) << 16; - output_lfe[i * 6] = 0; - } -} - -void upmix32bit_2_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT); - uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND); - uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND); - const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - if (left_surround_slot == CHANNEL_INVALID && right_surround_slot == CHANNEL_INVALID) { - left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32 *output_left = (ae_int32 *)(out_data + (left_slot << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + (center_slot << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + (right_slot << 2)); - ae_int32 *output_left_surround = (ae_int32 *)(out_data + (left_surround_slot << 2)); - ae_int32 *output_right_surround = (ae_int32 *)(out_data + (right_surround_slot << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + (lfe_slot << 2)); - - ae_int32 *in_left_ptr = (ae_int32 *)in_data; - ae_int32 *in_right_ptr = (ae_int32 *)(in_data + 4); - - for (i = 0; i < (in_size >> 3); ++i) { - output_left[i * 6] = in_left_ptr[i * 2]; - output_right[i * 6] = in_right_ptr[i * 2]; - output_center[i * 6] = 0; - output_left_surround[i * 6] = in_left_ptr[i * 2]; - output_right_surround[i * 6] = in_right_ptr[i * 2]; - output_lfe[i * 6] = 0; - } -} - -void upmix16bit_2_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT); - uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND); - uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND); - const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - if (left_surround_slot == CHANNEL_INVALID && right_surround_slot == CHANNEL_INVALID) { - left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32 *output_left = (ae_int32 *)(out_data + (left_slot << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + (center_slot << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + (right_slot << 2)); - ae_int32 *output_left_surround = (ae_int32 *)(out_data + (left_surround_slot << 2)); - ae_int32 *output_right_surround = (ae_int32 *)(out_data + (right_surround_slot << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + (lfe_slot << 2)); - - ae_int16 *in_left_ptr = (ae_int16 *)in_data; - ae_int16 *in_right_ptr = (ae_int16 *)(in_data + 2); - - for (i = 0; i < (in_size >> 2); ++i) { - output_left[i * 6] = AE_MOVINT32_FROMINT16(in_left_ptr[i * 2]) << 16; - output_right[i * 6] = AE_MOVINT32_FROMINT16(in_right_ptr[i * 2]) << 16; - output_center[i * 6] = 0; - output_left_surround[i * 6] = AE_MOVINT32_FROMINT16(in_left_ptr[i * 2]) << 16; - output_right_surround[i * 6] = AE_MOVINT32_FROMINT16(in_right_ptr[i * 2]) << 16; - output_lfe[i * 6] = 0; - } -} - -void upmix32bit_2_0_to_7_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - /* Only load the channel if it's present. */ - ae_int32 *output_left = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT) << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_CENTER) << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT) << 2)); - ae_int32 *output_left_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - ae_int32 *output_right_surround = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LFE) << 2)); - ae_int32 *output_left_side = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE) << 2)); - ae_int32 *output_right_side = (ae_int32 *)(out_data + - (get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE) << 2)); - - ae_int32 *in_left_ptr = (ae_int32 *)in_data; - ae_int32 *in_right_ptr = (ae_int32 *)(in_data + 4); - - for (i = 0; i < (in_size >> 3); ++i) { - output_left[i * 8] = in_left_ptr[i * 2]; - output_right[i * 8] = in_right_ptr[i * 2]; - output_center[i * 8] = 0; - output_left_surround[i * 8] = in_left_ptr[i * 2]; - output_right_surround[i * 8] = in_right_ptr[i * 2]; - output_lfe[i * 8] = 0; - output_left_side[i * 8] = 0; - output_right_side[i * 8] = 0; - } -} - -void shiftcopy32bit_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_p24f *in_ptr = (ae_p24f *)in_data; - ae_p24x2f *out_ptr = (ae_p24x2f *)out_data; - - for (i = 0; i < (in_size >> 2); ++i) - out_ptr[i] = in_ptr[i]; -} - -void shiftcopy32bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_p24x2f *in_ptr = (ae_p24x2f *)in_data; - ae_p24x2f *out_ptr = (ae_p24x2f *)out_data; - - for (i = 0; i < (in_size >> 3); ++i) - out_ptr[i] = in_ptr[i]; -} - -void downmix32bit_2_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_lfe; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_lfe_tmp = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_lfe = AE_SEL32_LL(P_coefficient_lfe_tmp, P_coefficient_lfe_tmp); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_lfe = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 2)); - - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_right; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - - while (input_left < end_input_left) { - /* update output left channel based on input left channel */ - AE_L32_IP(P_input_left, input_left, 12); - ae_f64 Q_tmp_left = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - /* update output right channel based on input right channel */ - AE_L32_IP(P_input_right, input_right, 12); - ae_f64 Q_tmp_right = AE_MULF32S_LL(P_input_right, P_coefficient_left_right); - - /* update output left and right channels based on input lfe channel */ - AE_L32_IP(P_input_lfe, input_lfe, 12); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_lfe); - AE_MULAF32S_LL(Q_tmp_right, P_input_lfe, P_coefficient_lfe); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * 4); - AE_S32_L_IP(P_output_right, output_right, 2 * 4); - } -} - -void downmix32bit_3_0(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center_tmp = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center = AE_SEL32_LL(P_coefficient_center_tmp, P_coefficient_center_tmp); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - - while (input_left < end_input_left) { - ae_f64 Q_tmp_left; - ae_f64 Q_tmp_right; - - /* update output left channel based on input left channel */ - AE_L32_IP(P_input_left, input_left, 3 * sizeof(ae_int32)); - Q_tmp_left = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - /* update output left and right channels based on input center channel */ - AE_L32_IP(P_input_center, input_center, 3 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_center, P_coefficient_center); - Q_tmp_right = AE_MULF32S_LH(P_input_center, P_coefficient_center); - - /* update output right channel based on input right channel */ - AE_L32_IP(P_input_right, input_right, 3 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix32bit_3_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_lfe; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_lfe = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 2)); - - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - - while (input_left < end_input_left) { - ae_f64 Q_tmp_left; - ae_f64 Q_tmp_right; - - AE_L32_IP(P_input_left, input_left, 4 * sizeof(ae_int32)); - Q_tmp_left = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_center, P_coefficient_center_lfe); - Q_tmp_right = AE_MULF32S_LH(P_input_center, P_coefficient_center_lfe); - - AE_L32_IP(P_input_right, input_right, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_lfe, input_lfe, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - AE_MULAF32S_LL(Q_tmp_right, P_input_lfe, P_coefficient_center_lfe); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix32bit(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - /* See what channels are available. */ - bool left = (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) != 0xF); - bool center = (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) != 0xF); - bool right = (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) != 0xF); - bool left_surround = - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) != 0xF); - bool right_surround = - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) != 0xF); - bool lfe = (get_channel_location(cd->in_channel_map, CHANNEL_LFE) != 0xF); - - /* Downmixer single load. */ - ae_int32 *input_left = NULL; - ae_int32 *input_center = NULL; - ae_int32 *input_right = NULL; - ae_int32 *input_left_surround = NULL; - ae_int32 *input_right_surround = NULL; - ae_int32 *input_lfe = NULL; - - /* Only load the channel if it's present. */ - if (left) { - input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - } - - if (center) { - input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - } - if (right) { - input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - } - if (left_surround) { - input_left_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - } - if (right_surround) { - input_right_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - } - if (lfe) { - input_lfe = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 2)); - } - - /** Calculate number of samples in a single channel. */ - uint32_t number_of_samples_in_one_channel = in_size / cd->in_channel_no; - - number_of_samples_in_one_channel >>= 2; - - /* Downmixer single store. */ - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - /* We will be using P & Q registers. */ - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - /* - * Calculating this outside of the loop is significant performance - * improvement. The value of this expression was reevaluated in each - * * iteration when placed inside loop. - */ - int sample_offset = cd->in_channel_no << 2; - - for (i = 0; i < number_of_samples_in_one_channel; i++) { - /* Zero-out the Q register first. */ - ae_f64 Q_tmp_left = AE_ZERO64(); - ae_f64 Q_tmp_right = AE_ZERO64(); - - /* Load one 24-bit value, replicate in two elements of register P. */ - if (left) { - P_input_left = AE_L32_X(input_left, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left, P_coefficient_left_right); - } - if (center) { - P_input_center = AE_L32_X(input_center, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_center, P_coefficient_center_lfe); - AE_MULAF32S_LH(Q_tmp_right, P_input_center, P_coefficient_center_lfe); - } - if (right) { - P_input_right = AE_L32_X(input_right, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - } - if (left_surround) { - P_input_left_surround = AE_L32_X(input_left_surround, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, - P_coefficient_left_s_right_s); - - if (cd->in_channel_config == IPC4_CHANNEL_CONFIG_4_POINT_0) { - AE_MULAF32S_LH(Q_tmp_right, - P_input_left_surround, - P_coefficient_left_s_right_s); - } - } - if (right_surround) { - P_input_right_surround = - AE_L32_X(input_right_surround, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_surround, - P_coefficient_left_s_right_s); - } - if (lfe) { - P_input_lfe = AE_L32_X(input_lfe, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - AE_MULAF32S_LL(Q_tmp_right, P_input_lfe, P_coefficient_center_lfe); - } - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - output_left[i * 2] = P_output_left; - output_right[i * 2] = P_output_right; - } -} - -void downmix32bit_4_0(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_left_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - - while (input_left < end_input_left) { - ae_f64 Q_tmp_left; - ae_f64 Q_tmp_right; - - AE_L32_IP(P_input_left, input_left, 4 * sizeof(ae_int32)); - Q_tmp_left = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_center, P_coefficient_center_lfe); - Q_tmp_right = AE_MULF32S_LH(P_input_center, P_coefficient_center_lfe); - - AE_L32_IP(P_input_right, input_right, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - /* for 4.0 left surround if propagated to both left and right output channels */ - AE_L32_IP(P_input_left_surround, input_left_surround, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, P_coefficient_left_s_right_s); - AE_MULAF32S_LH(Q_tmp_right, P_input_left_surround, P_coefficient_left_s_right_s); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix32bit_5_0_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_cs; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_cs = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER_SURROUND << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_cs = AE_SEL32_LL(P_coefficient_center, P_coefficient_cs); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_cs = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER_SURROUND) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_cs; - - ae_int32x2 P_output; - - const uint32_t channel_no = 5; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_IP(P_input_left, input_left, 5 * sizeof(ae_int32)); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 5 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp, P_input_center, P_coefficient_center_cs); - - AE_L32_IP(P_input_right, input_right, 5 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_cs, input_cs, 5 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_cs, P_coefficient_center_cs); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - const uint8_t left_slot = get_channel_location(cd->in_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(cd->in_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(cd->in_channel_map, CHANNEL_RIGHT); - uint8_t left_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND); - uint8_t right_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND); - const uint8_t lfe_slot = get_channel_location(cd->in_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - const bool surround_5_1_channel_map = (left_surround_slot == CHANNEL_INVALID) && - (right_surround_slot == CHANNEL_INVALID); - - if (surround_5_1_channel_map) { - left_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - if (surround_5_1_channel_map) { - P_coefficient_left_surround = AE_L32_X((ae_int32 *)cd->downmix_coefficients, - CHANNEL_LEFT_SIDE << 2); - P_coefficient_right_surround = AE_L32_X((ae_int32 *)cd->downmix_coefficients, - CHANNEL_RIGHT_SIDE << 2); - } - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - const ae_int32 *input_left = (ae_int32 *)(in_data + (left_slot << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + (center_slot << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + (right_slot << 2)); - const ae_int32 *input_left_surround = (ae_int32 *)(in_data + (left_surround_slot << 2)); - const ae_int32 *input_right_surround = (ae_int32 *)(in_data + (right_surround_slot << 2)); - const ae_int32 *input_lfe = (ae_int32 *)(in_data + (lfe_slot << 2)); - - /* Downmixer single store. */ - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - /* We will be using P & Q registers. */ - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - /* - * We don't need to initialize those registers in loop's body. - * Using non accumulating multiplication for the first left,rignt channels - * is more efficient. - * For non 5.1 version we cannot use this optimization, we don't know - * which channel is present and which multiplication should reset output - * accumulators. - */ - ae_f64 Q_tmp_left = AE_ZERO64(); - ae_f64 Q_tmp_right = AE_ZERO64(); - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - - while (input_left < end_input_left) { - /* Load one 24-bit value, replicate in two elements of register P. */ - AE_L32_IP(P_input_center, input_center, 6 * sizeof(ae_int32)); - Q_tmp_left = AE_MULF32S_LH(P_input_center, P_coefficient_center_lfe); - - AE_L32_IP(P_input_lfe, input_lfe, 6 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - - Q_tmp_right = Q_tmp_left; - - AE_L32_IP(P_input_left, input_left, 6 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_right, input_right, 6 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_left_surround, input_left_surround, 6 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, P_coefficient_left_s_right_s); - - AE_L32_IP(P_input_right_surround, input_right_surround, 6 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_surround, P_coefficient_left_s_right_s); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix32bit_7_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - ae_int32x2 P_coefficient_left_S_right_S; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - ae_int32x2 P_coefficient_left_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SIDE << 2); - ae_int32x2 P_coefficient_right_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SIDE << 2); - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - P_coefficient_left_S_right_S = AE_SEL32_LL(P_coefficient_left_side, - P_coefficient_right_side); - - /* Only load the channel if it's present. */ - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_left_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - const ae_int32 *input_right_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - const ae_int32 *input_lfe = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 2)); - const ae_int32 *input_left_side = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SIDE) << 2)); - const ae_int32 *input_right_side = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SIDE) << 2)); - - /* Downmixer single store. */ - ae_int32 *output_left = (ae_int32 *)(out_data); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - /* We will be using P & Q registers. */ - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_lfe; - ae_int32x2 P_input_left_side; - ae_int32x2 P_input_right_side; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - /* - * We don't need to initialize those registers in loop's body. - * Using non accumulating multiplication for the first left,rignt channels - * is more efficient. - * For non 5.1 version we cannot use this optimization, we don't know - * which channel is present and which multiplication should reset output - * accumulators. - */ - ae_f64 Q_tmp_left = AE_ZERO64(); - ae_f64 Q_tmp_right = AE_ZERO64(); - - const ae_int32 *const end_input_left = input_left + (in_size / (sizeof(ae_int32))); - const char cs = 8 * sizeof(ae_int32); - - while (input_left < end_input_left) { - /* Load one 24-bit value, replicate in two elements of register P. */ - AE_L32_XP(P_input_center, input_center, cs); - Q_tmp_left = AE_MULF32S_LH(P_input_center, P_coefficient_center_lfe); - - AE_L32_XP(P_input_lfe, input_lfe, cs); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - - Q_tmp_right = Q_tmp_left; - - AE_L32_XP(P_input_left, input_left, cs); - AE_MULAF32S_LH(Q_tmp_left, P_input_left, P_coefficient_left_right); - - AE_L32_XP(P_input_right, input_right, cs); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - AE_L32_XP(P_input_left_surround, input_left_surround, cs); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, P_coefficient_left_s_right_s); - - AE_L32_XP(P_input_right_surround, input_right_surround, cs); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_surround, P_coefficient_left_s_right_s); - - AE_L32_XP(P_input_left_side, input_left_side, cs); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_side, P_coefficient_left_S_right_S); - - AE_L32_XP(P_input_right_side, input_right_side, cs); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_side, P_coefficient_left_S_right_S); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - AE_S32_L_IP(P_output_left, output_left, 2 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_right, 2 * sizeof(ae_int32)); - } -} - -void shiftcopy16bit_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_int16 *in_ptrs = (ae_int16 *)in_data; - ae_int32x2 *out_ptrs = (ae_int32x2 *)out_data; - - for (i = 0; i < (in_size >> 1); ++i) - out_ptrs[i] = AE_MOVINT32_FROMINT16(in_ptrs[i]) << 16; -} - -void shiftcopy16bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_p16x2s *in_ptrs = (ae_p16x2s *)in_data; - ae_p24x2f *out_ptrs = (ae_p24x2f *)out_data; - ae_p24x2s in_regs = AE_ZEROP48(); - - for (i = 0; i < (in_size >> 2); ++i) { - in_regs = in_ptrs[i]; - AE_SP24X2F_X(in_regs, out_ptrs, i << 3); - } -} - -void downmix16bit(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - /* See what channels are available. */ - bool left = (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) != 0xF); - bool center = (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) != 0xF); - bool right = (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) != 0xF); - bool left_surround = - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) != 0xF); - bool right_surround = - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) != 0xF); - bool lfe = (get_channel_location(cd->in_channel_map, CHANNEL_LFE) != 0xF); - - /* Downmixer single load. */ - ae_p16s *input_left = NULL; - ae_p16s *input_center = NULL; - ae_p16s *input_right = NULL; - ae_p16s *input_left_surround = NULL; - ae_p16s *input_right_surround = NULL; - ae_p16s *input_lfe = NULL; - - /* Only load the channel if it's present. */ - if (left) { - input_left = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 1)); - } - if (center) { - input_center = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 1)); - } - if (right) { - input_right = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 1)); - } - if (left_surround) { - input_left_surround = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 1)); - } - if (right_surround) { - input_right_surround = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 1)); - } - if (lfe) { - input_lfe = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 1)); - } - - /** Calculate number of samples in a single channel. */ - uint32_t number_of_samples_in_one_channel = in_size / cd->in_channel_no; - - number_of_samples_in_one_channel >>= 1; - - /* Downmixer single store. */ - ae_int32 *output_left = (ae_int32 *)(out_data + 0); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - /* - * Calculating this outside of the loop is significant performance - * improvement. The value of this expression was reevaluated in each - * iteration when placed inside loop. - */ - int sample_offset = cd->in_channel_no << 1; - - for (i = 0; i < (number_of_samples_in_one_channel); i++) { - ae_f64 Q_tmp_left = AE_ZEROQ56(); - ae_f64 Q_tmp_right = AE_ZEROQ56(); - - /* Load one 24-bit value, replicate in two elements of register P. */ - if (left) { - P_input_left = AE_L16M_X(input_left, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left, P_coefficient_left_right); - } - if (center) { - P_input_center = AE_L16M_X(input_center, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_center, P_coefficient_center_lfe); - AE_MULAF32S_LH(Q_tmp_right, P_input_center, P_coefficient_center_lfe); - } - if (right) { - P_input_right = AE_L16M_X(input_right, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - } - if (left_surround) { - P_input_left_surround = AE_L16M_X(input_left_surround, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, - P_coefficient_left_s_right_s); - if (cd->in_channel_config == IPC4_CHANNEL_CONFIG_4_POINT_0) { - AE_MULAF32S_LH(Q_tmp_right, P_input_left_surround, - P_coefficient_left_s_right_s); - } - } - if (right_surround) { - P_input_right_surround = AE_L16M_X(input_right_surround, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_surround, - P_coefficient_left_s_right_s); - } - if (lfe) { - P_input_lfe = AE_L16M_X(input_lfe, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - AE_MULAF32S_LL(Q_tmp_right, P_input_lfe, P_coefficient_center_lfe); - } - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - output_left[i * 2] = AE_SLAI32(P_output_left, 2 * sizeof(ae_int32)); - output_right[i * 2] = AE_SLAI32(P_output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix16bit_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - /* Downmixer single load. */ - ae_p16s *input_left = NULL; - ae_p16s *input_center = NULL; - ae_p16s *input_right = NULL; - ae_p16s *input_left_surround = NULL; - ae_p16s *input_right_surround = NULL; - ae_p16s *input_lfe = NULL; - - /* Only load the channel if it's present. */ - input_left = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 1)); - input_center = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 1)); - input_right = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 1)); - input_left_surround = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 1)); - input_right_surround = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 1)); - input_lfe = (ae_p16s *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 1)); - - /** Calculate number of samples in a single channel. */ - uint32_t number_of_samples_in_one_channel = in_size / cd->in_channel_no; - - number_of_samples_in_one_channel >>= 1; - - /* Downmixer single store. */ - ae_int32 *output_left = (ae_int32 *)(out_data + 0); - ae_int32 *output_right = (ae_int32 *)(out_data + sizeof(ae_int32)); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - /* - * We don't need to initialize those registers in loop's body. - * Using non accumulating multiplication for the first left,rignt channels - * is more efficient. - * For non 5.1 version we cannot use this optimization, we don't know - * which channel is present and which multiplication should reset output - * accumulators. - */ - ae_f64 Q_tmp_left = AE_ZERO64(); - ae_f64 Q_tmp_right = AE_ZERO64(); - - /* - * Calculating this outside of the loop is significant performance - * improvement. The value of this expression was reevaluated in each - * iteration when placed inside loop. - */ - int sample_offset = cd->in_channel_no << 1; - /* 0.011xSR(k) MIPS */ - for (i = 0; i < (number_of_samples_in_one_channel); i++) { - /* Load one 16-bit value, replicate in two elements of register P. */ - P_input_center = AE_L16M_X(input_center, i * sample_offset); - Q_tmp_left = AE_MULF32S_LH(P_input_center, P_coefficient_center_lfe); - - P_input_lfe = AE_L16M_X(input_lfe, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_left, P_input_lfe, P_coefficient_center_lfe); - - Q_tmp_right = Q_tmp_left; - - P_input_left = AE_L16M_X(input_left, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left, P_coefficient_left_right); - - P_input_right = AE_L16M_X(input_right, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right, P_coefficient_left_right); - - P_input_left_surround = AE_L16M_X(input_left_surround, i * sample_offset); - AE_MULAF32S_LH(Q_tmp_left, P_input_left_surround, P_coefficient_left_s_right_s); - - P_input_right_surround = AE_L16M_X(input_right_surround, i * sample_offset); - AE_MULAF32S_LL(Q_tmp_right, P_input_right_surround, P_coefficient_left_s_right_s); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right); - - output_left[i * 2] = AE_SLAI32(P_output_left, 2 * sizeof(ae_int32)); - output_right[i * 2] = AE_SLAI32(P_output_right, 2 * sizeof(ae_int32)); - } -} - -void downmix16bit_4ch_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - uint32_t idx1 = get_channel_index(cd->in_channel_map, 0); - uint32_t idx2 = get_channel_index(cd->in_channel_map, 1); - uint32_t idx3 = get_channel_index(cd->in_channel_map, 2); - uint32_t idx4 = get_channel_index(cd->in_channel_map, 3); - - uint16_t coeffs[4] = {cd->downmix_coefficients[idx1], - cd->downmix_coefficients[idx2], - cd->downmix_coefficients[idx3], - cd->downmix_coefficients[idx4] - }; - - ae_int16x4 coeff = AE_L16X4_X((ae_int16x4 *)coeffs, 0); - - const ae_int16x4 *input_data = (const ae_int16x4 *)in_data; - ae_int16 *output_data = (ae_int16 *)out_data; - - ae_int16x4 P_input; - ae_int16x4 P_output; - - const uint32_t channel_no = 4; - - for (i = 0; i < in_size / (sizeof(int16_t)); i += channel_no) { - AE_L16X4_XP(P_input, input_data, sizeof(ae_int16) * channel_no); - ae_f32x2 Q_tmp = AE_MULF16SS_00(P_input, coeff); - - AE_MULAF16SS_11(Q_tmp, P_input, coeff); - AE_MULAF16SS_22(Q_tmp, P_input, coeff); - AE_MULAF16SS_33(Q_tmp, P_input, coeff); - - P_output = AE_ROUND16X4F32SSYM(Q_tmp, Q_tmp); - AE_S16_0_IP(P_output, output_data, sizeof(ae_int16)); - } -} - -void downmix32bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - uint32_t downmix_coefficient = 1073741568; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left_right = AE_L32_X((ae_int32 *)&downmix_coefficient, 0); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_right; - ae_int32x2 P_output; - - const ae_int32 *input_left = (ae_int32 *)in_data; - const ae_int32 *input_right = input_left + 1; - - ae_int32 *output = (ae_int32 *)(out_data); - - for (i = 0; i < (in_size >> 3); ++i) { - P_input_left = AE_L32_X(input_left, i * 2 * sizeof(ae_int32)); - ae_f64 Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - P_input_right = AE_L32_X(input_right, i * 2 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - output[i] = P_output; - } -} - -void downmix16bit_stereo(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t idx; - - /* TODO: optimize using Hifi3 */ - const uint16_t *in_data16 = (uint16_t *)in_data; - uint16_t *out_data16 = (uint16_t *)out_data; - - for (idx = 0; idx < (in_size / 4); ++idx) - out_data16[idx] = (in_data16[2 * idx] / 2) + (in_data16[2 * idx + 1] / 2); -} - -void downmix32bit_3_1_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_lfe; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_lfe = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LFE) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_lfe; - - ae_int32x2 P_output; - - const uint32_t channel_no = 4; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_IP(P_input_left, input_left, 4 * sizeof(ae_int32)); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp, P_input_center, P_coefficient_center_lfe); - - AE_L32_IP(P_input_right, input_right, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_lfe, input_lfe, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_lfe, P_coefficient_center_lfe); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_4_0_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_cs; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_cs = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER_SURROUND << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_cs = AE_SEL32_LL(P_coefficient_center, P_coefficient_cs); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_cs = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER_SURROUND) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_cs; - - ae_int32x2 P_output; - - const uint32_t channel_no = 4; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_IP(P_input_left, input_left, 4 * sizeof(ae_int32)); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp, P_input_center, P_coefficient_center_cs); - - AE_L32_IP(P_input_right, input_right, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_cs, input_cs, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_cs, P_coefficient_center_cs); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_quatro_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_ls_rs; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_ls = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_rs = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_ls_rs = AE_SEL32_LL(P_coefficient_ls, P_coefficient_rs); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_ls = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_rs = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_ls; - ae_int32x2 P_input_right; - ae_int32x2 P_input_rs; - - ae_int32x2 P_output; - - const uint32_t channel_no = 4; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_IP(P_input_left, input_left, 4 * sizeof(ae_int32)); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_ls, input_ls, 4 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp, P_input_ls, P_coefficient_ls_rs); - - AE_L32_IP(P_input_right, input_right, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_rs, input_rs, 4 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_rs, P_coefficient_ls_rs); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_5_1_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_cs; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_cs = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER_SURROUND << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_cs = AE_SEL32_LL(P_coefficient_center, P_coefficient_cs); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_cs = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER_SURROUND) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_cs; - - ae_int32x2 P_output; - - const uint32_t channel_no = 6; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_IP(P_input_left, input_left, 6 * sizeof(ae_int32)); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_IP(P_input_center, input_center, 6 * sizeof(ae_int32)); - AE_MULAF32S_LH(Q_tmp, P_input_center, P_coefficient_center_cs); - - AE_L32_IP(P_input_right, input_right, 6 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_IP(P_input_cs, input_cs, 6 * sizeof(ae_int32)); - AE_MULAF32S_LL(Q_tmp, P_input_cs, P_coefficient_center_cs); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_7_1_mono(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - size_t i; - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_center_cs; - - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_cs = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER_SURROUND << 2); - - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_center_cs = AE_SEL32_LL(P_coefficient_center, P_coefficient_cs); - - const ae_int32 *input_left = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT) << 2)); - const ae_int32 *input_center = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER) << 2)); - const ae_int32 *input_right = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT) << 2)); - const ae_int32 *input_cs = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER_SURROUND) << 2)); - - ae_int32 *output = (ae_int32 *)(out_data); - - ae_int32x2 P_input_left; - ae_int32x2 P_input_center; - ae_int32x2 P_input_right; - ae_int32x2 P_input_cs; - - ae_int32x2 P_output; - - const uint32_t channel_no = 8; - const size_t offset = sizeof(ae_int32) * channel_no; - - for (i = 0; i < in_size / (sizeof(ae_int32)); i += channel_no) { - ae_f64 Q_tmp; - - AE_L32_XP(P_input_left, input_left, offset); - Q_tmp = AE_MULF32S_LH(P_input_left, P_coefficient_left_right); - - AE_L32_XP(P_input_center, input_center, offset); - AE_MULAF32S_LH(Q_tmp, P_input_center, P_coefficient_center_cs); - - AE_L32_XP(P_input_right, input_right, offset); - AE_MULAF32S_LL(Q_tmp, P_input_right, P_coefficient_left_right); - - AE_L32_XP(P_input_cs, input_cs, offset); - AE_MULAF32S_LL(Q_tmp, P_input_cs, P_coefficient_center_cs); - - P_output = AE_ROUND32F64SSYM(Q_tmp); - - AE_S32_L_IP(P_output, output, sizeof(ae_int32)); - } -} - -void downmix32bit_7_1_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT); - uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND); - uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND); - const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - const bool surround_5_1_channel_map = (left_surround_slot == CHANNEL_INVALID) && - (right_surround_slot == CHANNEL_INVALID); - - if (surround_5_1_channel_map) { - left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32 *output_left_ptr = (ae_int32 *)(out_data + (left_slot << 2)); - ae_int32 *output_center_ptr = (ae_int32 *)(out_data + (center_slot << 2)); - ae_int32 *output_right_ptr = (ae_int32 *)(out_data + (right_slot << 2)); - ae_int32 *output_side_left_ptr = (ae_int32 *)(out_data + (left_surround_slot << 2)); - ae_int32 *output_side_right_ptr = (ae_int32 *)(out_data + (right_surround_slot << 2)); - ae_int32 *output_lfe_ptr = (ae_int32 *)(out_data + (lfe_slot << 2)); - - ae_int32 *in_left_ptr = (ae_int32 *)in_data; - ae_int32 *in_center_ptr = (ae_int32 *)(in_data + 4); - ae_int32 *in_right_ptr = (ae_int32 *)(in_data + 8); - ae_int32 *in_lfe_ptr = (ae_int32 *)(in_data + 20); - - for (i = 0; i < (in_size >> 5); ++i) { - output_left_ptr[i * 6] = in_left_ptr[i * 8]; - output_right_ptr[i * 6] = in_right_ptr[i * 8]; - output_center_ptr[i * 6] = in_center_ptr[i * 8]; - output_lfe_ptr[i * 6] = in_lfe_ptr[i * 8]; - } - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - ae_int32x2 P_coefficient_left_S_right_S; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - ae_int32x2 P_coefficient_left_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SIDE << 2); - ae_int32x2 P_coefficient_right_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SIDE << 2); - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - P_coefficient_left_S_right_S = AE_SEL32_LL(P_coefficient_left_side, - P_coefficient_right_side); - - const ae_int32 *input_left_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SURROUND) << 2)); - const ae_int32 *input_right_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SURROUND) << 2)); - const ae_int32 *input_left_side = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SIDE) << 2)); - const ae_int32 *input_right_side = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SIDE) << 2)); - - /* We will be using P & Q registers. */ - ae_int32x2 P_input_left_surround; - ae_int32x2 P_input_right_surround; - ae_int32x2 P_input_left_side; - ae_int32x2 P_input_right_side; - - ae_int32x2 P_output_left; - ae_int32x2 P_output_right; - - const ae_int32 *const end_input_left = input_left_surround + (in_size / (sizeof(ae_int32))); - const char cs = 8 * sizeof(ae_int32); - - while (input_left_surround < end_input_left) { - ae_f64 Q_tmp_right_side; - ae_f64 Q_tmp_left_side; - - /* Load one 24-bit value, replicate in two elements of register P. */ - AE_L32_XP(P_input_left_surround, input_left_surround, cs); - Q_tmp_left_side = AE_MULF32S_LH(P_input_left_surround, P_coefficient_left_right); - Q_tmp_right_side = AE_MULF32S_LL(P_input_left_surround, P_coefficient_left_S_right_S); - - AE_L32_XP(P_input_right_surround, input_right_surround, cs); - AE_MULAF32S_LH(Q_tmp_left_side, P_input_right_surround, P_coefficient_left_S_right_S); - AE_MULAF32S_LL(Q_tmp_right_side, P_input_right_surround, P_coefficient_left_right); - - AE_L32_XP(P_input_left_side, input_left_side, cs); - AE_MULAF32S_LH(Q_tmp_left_side, P_input_left_side, P_coefficient_left_right); - - AE_L32_XP(P_input_right_side, input_right_side, cs); - AE_MULAF32S_LL(Q_tmp_right_side, P_input_right_side, P_coefficient_left_right); - - P_output_left = AE_ROUND32F64SSYM(Q_tmp_left_side); - P_output_right = AE_ROUND32F64SSYM(Q_tmp_right_side); - - AE_S32_L_IP(P_output_left, output_side_left_ptr, 6 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right, output_side_right_ptr, 6 * sizeof(ae_int32)); - } -} - -void upmix32bit_4_0_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT); - uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND); - uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND); - const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - const bool surround_5_1_channel_map = (left_surround_slot == CHANNEL_INVALID) && - (right_surround_slot == CHANNEL_INVALID); - - if (surround_5_1_channel_map) { - left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32 *output_left = (ae_int32 *)(out_data + (left_slot << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + (center_slot << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + (right_slot << 2)); - ae_int32 *output_side_left = (ae_int32 *)(out_data + (left_surround_slot << 2)); - ae_int32 *output_side_right = (ae_int32 *)(out_data + (right_surround_slot << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + (lfe_slot << 2)); - - ae_int32 *in_left_ptr = (ae_int32 *)in_data; - ae_int32 *in_center_ptr = (ae_int32 *)(in_data + 4); - ae_int32 *in_right_ptr = (ae_int32 *)(in_data + 8); - - for (i = 0; i < (in_size >> 4); ++i) { - output_left[i * 6] = in_left_ptr[i * 4]; - output_right[i * 6] = in_right_ptr[i * 4]; - output_center[i * 6] = in_center_ptr[i * 4]; - output_lfe[i * 6] = 0; - } - - ae_int32x2 P_coefficient_left_right; - ae_int32x2 P_coefficient_left_s_right_s; - ae_int32x2 P_coefficient_center_lfe; - ae_int32x2 P_coefficient_left_S_right_S; - - /* Load the downmix coefficients. */ - ae_int32x2 P_coefficient_left = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT << 2); - ae_int32x2 P_coefficient_center = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_CENTER << 2); - ae_int32x2 P_coefficient_right = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT << 2); - ae_int32x2 P_coefficient_left_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SURROUND << 2); - ae_int32x2 P_coefficient_right_surround = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SURROUND << 2); - ae_int32x2 P_coefficient_lfe = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LFE << 2); - ae_int32x2 P_coefficient_left_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_LEFT_SIDE << 2); - ae_int32x2 P_coefficient_right_side = - AE_L32_X((ae_int32 *)cd->downmix_coefficients, CHANNEL_RIGHT_SIDE << 2); - - /* - * We have 6 coefficients (constant inside loop), 6 channels and only 8 - * AE_P registers. But each of those registers is 48bit or 2x24bit wide. - * Also many Hifi2 operations can use either lower or higher 24 bits from - * those registers. By combining 6 coefficients in pairs we save 3 AE_P - * registers. - */ - P_coefficient_left_right = AE_SEL32_LL(P_coefficient_left, P_coefficient_right); - P_coefficient_left_s_right_s = AE_SEL32_LL(P_coefficient_left_surround, - P_coefficient_right_surround); - P_coefficient_center_lfe = AE_SEL32_LL(P_coefficient_center, P_coefficient_lfe); - P_coefficient_left_S_right_S = AE_SEL32_LL(P_coefficient_left_side, - P_coefficient_right_side); - - const ae_int32 *input_center_surround = (ae_int32 *)(in_data + - (get_channel_location(cd->in_channel_map, CHANNEL_CENTER_SURROUND) << 2)); - - /* We will be using P & Q registers. */ - ae_int32x2 P_input_center_surround; - - ae_int32x2 P_output_left_side; - ae_int32x2 P_output_right_side; - - /* - * We don't need to initialize those registers in loop's body. - * Using non accumulating multiplication for the first left,rignt channels - * is more efficient. - * For non 5.1 version we cannot use this optimization, we don't know - * which channel is present and which multiplication should reset output - * accumulators. - */ - ae_f64 Q_tmp_right_side = AE_ZERO64(); - ae_f64 Q_tmp_left_side = AE_ZERO64(); - - const ae_int32 *const end_input_left = input_center_surround + (in_size / (sizeof(ae_int32))); - const char cs = 4 * sizeof(ae_int32); - - while (input_center_surround < end_input_left) { - /* Load one 24-bit value, replicate in two elements of register P. */ - AE_L32_XP(P_input_center_surround, input_center_surround, cs); - Q_tmp_left_side = AE_MULF32S_LH(P_input_center_surround, - P_coefficient_left_s_right_s); - Q_tmp_right_side = AE_MULF32S_LL(P_input_center_surround, - P_coefficient_left_s_right_s); - - P_output_left_side = AE_ROUND32F64SSYM(Q_tmp_left_side); - P_output_right_side = AE_ROUND32F64SSYM(Q_tmp_right_side); - - AE_S32_L_IP(P_output_left_side, output_side_left, 6 * sizeof(ae_int32)); - AE_S32_L_IP(P_output_right_side, output_side_right, 6 * sizeof(ae_int32)); - } -} - -void upmix32bit_quatro_to_5_1(struct up_down_mixer_data *cd, const uint8_t * const in_data, - const uint32_t in_size, uint8_t * const out_data) -{ - uint32_t i; - - channel_map out_channel_map = cd->out_channel_map; - - const uint8_t left_slot = get_channel_location(out_channel_map, CHANNEL_LEFT); - const uint8_t center_slot = get_channel_location(out_channel_map, CHANNEL_CENTER); - const uint8_t right_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT); - uint8_t right_surround_slot = get_channel_location(out_channel_map, CHANNEL_RIGHT_SURROUND); - uint8_t left_surround_slot = get_channel_location(out_channel_map, CHANNEL_LEFT_SURROUND); - const uint8_t lfe_slot = get_channel_location(out_channel_map, CHANNEL_LFE); - - /* Must support also 5.1 Surround */ - const bool surround_5_1_channel_map = (left_surround_slot == CHANNEL_INVALID) && - (right_surround_slot == CHANNEL_INVALID); - - if (surround_5_1_channel_map) { - left_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_LEFT_SIDE); - right_surround_slot = get_channel_location(cd->in_channel_map, CHANNEL_RIGHT_SIDE); - } - - ae_int32 *output_left = (ae_int32 *)(out_data + (left_slot << 2)); - ae_int32 *output_center = (ae_int32 *)(out_data + (center_slot << 2)); - ae_int32 *output_right = (ae_int32 *)(out_data + (right_slot << 2)); - ae_int32 *output_side_left = (ae_int32 *)(out_data + (left_surround_slot << 2)); - ae_int32 *output_side_right = (ae_int32 *)(out_data + (right_surround_slot << 2)); - ae_int32 *output_lfe = (ae_int32 *)(out_data + (lfe_slot << 2)); - - ae_int32 *in_left_ptr = (ae_int32 *)in_data; - ae_int32 *in_right_ptr = (ae_int32 *)(in_data + 4); - ae_int32 *in_left_sorround_ptr = (ae_int32 *)(in_data + 8); - ae_int32 *in_right_sorround_ptr = (ae_int32 *)(in_data + 12); - - for (i = 0; i < (in_size >> 4); ++i) { - output_left[i * 6] = in_left_ptr[i * 4]; - output_right[i * 6] = in_right_ptr[i * 4]; - output_center[i * 6] = 0; - output_side_left[i * 6] = in_left_sorround_ptr[i * 4]; - output_side_right[i * 6] = in_right_sorround_ptr[i * 4]; - output_lfe[i * 6] = 0; - } -} diff --git a/src/audio/up_down_mixer/up_down_mixer.c b/src/audio/up_down_mixer/up_down_mixer.c index 120241102b8c..1fe0b5e23ab0 100644 --- a/src/audio/up_down_mixer/up_down_mixer.c +++ b/src/audio/up_down_mixer/up_down_mixer.c @@ -15,21 +15,17 @@ #include "up_down_mixer_coef.h" #include "up_down_mixer.h" -//LOG_MODULE_REGISTER(up_down_mixer, CONFIG_SOF_LOG_LEVEL); -// -///* these ids aligns windows driver requirement to support windows driver */ -///* 42f8060c-832f-4dbf-b247-51e961997b34 */ -//DECLARE_SOF_RT_UUID("up_down_mixer", up_down_mixer_comp_uuid, 0x42f8060c, 0x832f, -// 0x4dbf, 0xb2, 0x47, 0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34); -// -//DECLARE_TR_CTX(up_down_mixer_comp_tr, SOF_UUID(up_down_mixer_comp_uuid), -// LOG_LEVEL_INFO); +#include +#include +#include +#include /* Logging is temporary disabled */ #define comp_err(...) #define comp_dbg(...) -static const struct native_system_agent* native_sys_agent; +static struct native_system_service_api* system_service; +uint32_t heap_mem[2048] __attribute__((section(".heap_mem"))) __attribute__((aligned(4096))); int32_t custom_coeffs[UP_DOWN_MIX_COEFFS_LENGTH]; @@ -43,7 +39,7 @@ static int set_downmix_coefficients(struct processing_module *mod, int ret; if (cd->downmix_coefficients) { - ret = memcpy_s(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients, + ret = system_service->safe_memcpy(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients, sizeof(int32_t) * UP_DOWN_MIX_COEFFS_LENGTH); if (ret < 0) @@ -321,9 +317,9 @@ static int up_down_mixer_free(struct processing_module *mod) { struct up_down_mixer_data *cd = module_get_private_data(mod); - rfree(cd->buf_in); - rfree(cd->buf_out); - rfree(cd); + free(cd->buf_in); + free(cd->buf_out); + free(cd); return 0; } @@ -337,16 +333,16 @@ static int up_down_mixer_init(struct processing_module *mod) struct up_down_mixer_data *cd; int ret; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = malloc(sizeof(struct up_down_mixer_data)); if (!cd) { - comp_free(dev); + free(dev); return -ENOMEM; } mod_data->private = cd; - cd->buf_in = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.ibs); - cd->buf_out = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.obs); + cd->buf_in = malloc(mod->priv.cfg.base_cfg.ibs); + cd->buf_out = malloc(mod->priv.cfg.base_cfg.obs); if (!cd->buf_in || !cd->buf_out) { ret = -ENOMEM; goto err; @@ -447,7 +443,7 @@ DECLARE_LOADABLE_MODULE_API_VERSION(udm); static void* entry_point(void* mod_cfg, void* parent_ppl, void** mod_ptr) { - native_sys_agent = *(const struct native_system_agent**)mod_ptr; + system_service = *(const struct native_system_agent**)mod_ptr; return &up_down_mixer_interface; } diff --git a/src/audio/up_down_mixer/up_down_mixer.toml b/src/audio/up_down_mixer/up_down_mixer.toml index 4adaa3a97e5f..33487dc3405b 100644 --- a/src/audio/up_down_mixer/up_down_mixer.toml +++ b/src/audio/up_down_mixer/up_down_mixer.toml @@ -44,7 +44,6 @@ length = "0x0" # calculated by rimage [signed_pkg] name = "ADSP" -partition_usage = "0x23" [[signed_pkg.module]] name = "ADSP.met" diff --git a/src/audio/up_down_mixer/up_down_mixer_hifi3.c b/src/audio/up_down_mixer/up_down_mixer_hifi3.c index 47a7d89749c7..bbf8fa638863 100644 --- a/src/audio/up_down_mixer/up_down_mixer_hifi3.c +++ b/src/audio/up_down_mixer/up_down_mixer_hifi3.c @@ -6,8 +6,7 @@ #include "up_down_mixer.h" -#if defined(__XCC__) && XCHAL_HAVE_HIFI3 || ~defined MODULE_PRIVAT - +#if defined(__XCC__) && XCHAL_HAVE_HIFI3 #include #include #include diff --git a/src/audio/up_down_mixer/up_down_mixer_ipc4.h b/src/audio/up_down_mixer/up_down_mixer_ipc4.h index 5300f5cb71d4..69dc67be4ab0 100644 --- a/src/audio/up_down_mixer/up_down_mixer_ipc4.h +++ b/src/audio/up_down_mixer/up_down_mixer_ipc4.h @@ -27,7 +27,9 @@ enum up_down_mix_coeff_select { #define UP_DOWN_MIX_COEFFS_LENGTH 8 #define IPC4_UP_DOWN_MIXER_MODULE_OUTPUT_PINS_COUNT 1 - +#ifndef __packed +#define __packed __attribute__((packed)) +#endif struct ipc4_up_down_mixer_module_cfg { struct ipc4_base_module_cfg base_cfg; diff --git a/src/include/ipc/topology.h b/src/include/ipc/topology.h index a12f8610f734..c9ddee97fbb9 100644 --- a/src/include/ipc/topology.h +++ b/src/include/ipc/topology.h @@ -77,6 +77,8 @@ struct sof_ipc_comp { /* * SOF memory capabilities, add new ones at the end */ +#define BIT(b) (1UL << (b)) + #define SOF_MEM_CAPS_RAM BIT(0) #define SOF_MEM_CAPS_ROM BIT(1) #define SOF_MEM_CAPS_EXT BIT(2) /**< external */ diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index cc143acd6532..a6dfaa4f69a9 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -20,8 +20,10 @@ #include #include #include +#ifndef MODULE_PRIVAT #include #include +#endif #include #include #include diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index e636771f9f93..614c1f6f91c5 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -7,7 +7,7 @@ #ifndef __SOF_AUDIO_BUFFER_H__ #define __SOF_AUDIO_BUFFER_H__ - +#ifndef MODULE_PRIVAT #include #include #include @@ -26,7 +26,7 @@ #include #include #include - +#endif #include #include #include diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 5c43c94b3434..b1c731ec9516 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -23,19 +23,57 @@ #include #include #include -#else #include #endif #include - +#include +#include #include - +#include struct comp_dev; struct sof_ipc_stream_posn; struct dai_hw_params; struct timestamp_data; struct dai_ts_data; +/* types of component */ +enum sof_comp_type { + SOF_COMP_NONE = 0, + SOF_COMP_HOST, + SOF_COMP_DAI, + SOF_COMP_SG_HOST, /**< scatter gather variant */ + SOF_COMP_SG_DAI, /**< scatter gather variant */ + SOF_COMP_VOLUME, + SOF_COMP_MIXER, + SOF_COMP_MUX, + SOF_COMP_SRC, + SOF_COMP_DEPRECATED0, /* Formerly SOF_COMP_SPLITTER */ + SOF_COMP_TONE, + SOF_COMP_DEPRECATED1, /* Formerly SOF_COMP_SWITCH */ + SOF_COMP_BUFFER, + SOF_COMP_EQ_IIR, + SOF_COMP_EQ_FIR, + SOF_COMP_KEYWORD_DETECT, + SOF_COMP_KPB, /* A key phrase buffer component */ + SOF_COMP_SELECTOR, /**< channel selector component */ + SOF_COMP_DEMUX, + SOF_COMP_ASRC, /**< Asynchronous sample rate converter */ + SOF_COMP_DCBLOCK, + SOF_COMP_SMART_AMP, /**< smart amplifier component */ + SOF_COMP_MODULE_ADAPTER, /**< module adapter */ + /* keep FILEREAD/FILEWRITE as the last ones */ + SOF_COMP_FILEREAD = 10000, /**< host test based file IO */ + SOF_COMP_FILEWRITE = 10001, /**< host test based file IO */ +}; + +/** + * Trace context. + */ +struct tr_ctx { + const struct sof_uuid_entry* uuid_p; /**< UUID pointer, use SOF_UUID() to init */ + uint32_t level; /**< Default log level */ +}; + /** \addtogroup component_api Component API * @{ */ diff --git a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h index ff328d84d789..9e0a16d1915e 100644 --- a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h +++ b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h @@ -11,8 +11,10 @@ #include #include -#ifdef __ZEPHYR__ && !defined MODULE_PRIVAT +#ifdef __ZEPHYR__ +#ifndef MODULE_PRIVAT #include +#endif #endif /* __ZEPHYR__ */ #ifdef __XTENSA__ diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index ca4c2123ed47..608cbebb637a 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -13,14 +13,15 @@ #ifndef __SOF_AUDIO_MODULE_GENERIC__ #define __SOF_AUDIO_MODULE_GENERIC__ -#ifndef MODULE_PRIVAT #include +#ifndef MODULE_PRIVAT #include #include +#include #endif //MODULE_PRIVAT #include #include -#include + #include "module_interface.h" #ifndef MODULE_PRIVAT #if CONFIG_INTEL_MODULES diff --git a/src/include/sof/audio/pipeline-trace.h b/src/include/sof/audio/pipeline-trace.h index d1f89583ad45..1224f9d5bab3 100644 --- a/src/include/sof/audio/pipeline-trace.h +++ b/src/include/sof/audio/pipeline-trace.h @@ -1,80 +1,81 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2016 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __SOF_AUDIO_PIPELINE_TRACE_H__ -#define __SOF_AUDIO_PIPELINE_TRACE_H__ - -#include -#include -#include -#include -#include -#include - -/* pipeline tracing */ -extern struct tr_ctx pipe_tr; - -#define trace_pipe_get_tr_ctx(pipe_p) (&(pipe_p)->tctx) -#define trace_pipe_get_id(pipe_p) ((pipe_p)->pipeline_id) -#define trace_pipe_get_subid(pipe_p) ((pipe_p)->comp_id) - -/* class (driver) level (no device object) tracing */ - -#define pipe_cl_err(__e, ...) \ - tr_err(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_warn(__e, ...) \ - tr_warn(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_info(__e, ...) \ - tr_info(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_dbg(__e, ...) \ - tr_dbg(&pipe_tr, __e, ##__VA_ARGS__) - -/* device tracing */ -#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) - -#if CONFIG_IPC_MAJOR_4 -#define __PIPE_FMT "pipe:%u %#x " -#else -#define __PIPE_FMT "pipe:%u.%u " -#endif - -#define pipe_err(pipe_p, __e, ...) LOG_ERR(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_warn(pipe_p, __e, ...) LOG_WRN(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_info(pipe_p, __e, ...) LOG_INF(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_dbg(pipe_p, __e, ...) LOG_DBG(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#else - -#define pipe_err(pipe_p, __e, ...) \ - trace_dev_err(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_warn(pipe_p, __e, ...) \ - trace_dev_warn(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_info(pipe_p, __e, ...) \ - trace_dev_info(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_dbg(pipe_p, __e, ...) \ - trace_dev_dbg(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#endif /* #if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) */ - -#endif +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2016 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __SOF_AUDIO_PIPELINE_TRACE_H__ +#define __SOF_AUDIO_PIPELINE_TRACE_H__ +#ifndef MODULE_PRIVAT +#include +#include +#include +#include +#endif +#include +#include + +/* pipeline tracing */ +extern struct tr_ctx pipe_tr; + +#define trace_pipe_get_tr_ctx(pipe_p) (&(pipe_p)->tctx) +#define trace_pipe_get_id(pipe_p) ((pipe_p)->pipeline_id) +#define trace_pipe_get_subid(pipe_p) ((pipe_p)->comp_id) + +/* class (driver) level (no device object) tracing */ + +#define pipe_cl_err(__e, ...) \ + tr_err(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_warn(__e, ...) \ + tr_warn(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_info(__e, ...) \ + tr_info(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_dbg(__e, ...) \ + tr_dbg(&pipe_tr, __e, ##__VA_ARGS__) + +/* device tracing */ +#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) + +#if CONFIG_IPC_MAJOR_4 +#define __PIPE_FMT "pipe:%u %#x " +#else +#define __PIPE_FMT "pipe:%u.%u " +#endif + +#define pipe_err(pipe_p, __e, ...) LOG_ERR(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_warn(pipe_p, __e, ...) LOG_WRN(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_info(pipe_p, __e, ...) LOG_INF(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_dbg(pipe_p, __e, ...) LOG_DBG(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#else + +#define pipe_err(pipe_p, __e, ...) \ + trace_dev_err(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_warn(pipe_p, __e, ...) \ + trace_dev_warn(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_info(pipe_p, __e, ...) \ + trace_dev_info(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_dbg(pipe_p, __e, ...) \ + trace_dev_dbg(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#endif /* #if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) */ + +#endif diff --git a/src/module/audio/sink_api.c b/src/module/audio/sink_api.c index 8bdfc99fcdc1..f79a7ce596c2 100644 --- a/src/module/audio/sink_api.c +++ b/src/module/audio/sink_api.c @@ -5,7 +5,7 @@ #include #include -#include +//#include /* This file contains public sink API functions that were too large to mark is as inline. */ @@ -24,7 +24,7 @@ int sink_get_buffer(struct sof_sink *sink, size_t req_size, sink->requested_write_frag_size = req_size; return ret; } -EXPORT_SYMBOL(sink_get_buffer); +//EXPORT_SYMBOL(sink_get_buffer); int sink_commit_buffer(struct sof_sink *sink, size_t commit_size) { @@ -46,7 +46,7 @@ int sink_commit_buffer(struct sof_sink *sink, size_t commit_size) sink->num_of_bytes_processed += commit_size; return ret; } -EXPORT_SYMBOL(sink_commit_buffer); +//EXPORT_SYMBOL(sink_commit_buffer); int sink_set_frm_fmt(struct sof_sink *sink, enum sof_ipc_frame frame_fmt) { diff --git a/src/module/audio/source_api.c b/src/module/audio/source_api.c index e36dbdf8a0ba..41e07992931c 100644 --- a/src/module/audio/source_api.c +++ b/src/module/audio/source_api.c @@ -3,10 +3,9 @@ * Copyright(c) 2023 Intel Corporation. All rights reserved. */ - #include #include -#include +//#include /* This file contains public source API functions that were too large to mark is as inline. */ @@ -24,7 +23,7 @@ int source_get_data(struct sof_source *source, size_t req_size, source->requested_read_frag_size = req_size; return ret; } -EXPORT_SYMBOL(source_get_data); +//EXPORT_SYMBOL(source_get_data); int source_release_data(struct sof_source *source, size_t free_size) { @@ -46,7 +45,7 @@ int source_release_data(struct sof_source *source, size_t free_size) source->num_of_bytes_processed += free_size; return ret; } -EXPORT_SYMBOL(source_release_data); +//EXPORT_SYMBOL(source_release_data); size_t source_get_frame_bytes(struct sof_source *source) { diff --git a/xtos/include/sof/lib/mailbox.h b/xtos/include/sof/lib/mailbox.h index 06e2659a5847..4e325fb3b3cc 100644 --- a/xtos/include/sof/lib/mailbox.h +++ b/xtos/include/sof/lib/mailbox.h @@ -12,8 +12,10 @@ #include #include #include +#ifndef MODULE_PRIVAT #include #include +#endif #include #include #include diff --git a/zephyr/include/rtos/alloc.h b/zephyr/include/rtos/alloc.h index 509c691e3964..41b7cb535064 100644 --- a/zephyr/include/rtos/alloc.h +++ b/zephyr/include/rtos/alloc.h @@ -5,12 +5,12 @@ #ifndef __ZEPHYR_RTOS_ALLOC_H__ #define __ZEPHYR_RTOS_ALLOC_H__ - +#ifndef MODULE_PRIVAT #include #include #include #include - +#endif #include #include diff --git a/zephyr/include/rtos/bit.h b/zephyr/include/rtos/bit.h index 133ca5424d87..4a49bc05229d 100644 --- a/zephyr/include/rtos/bit.h +++ b/zephyr/include/rtos/bit.h @@ -1,25 +1,25 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2018 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_BIT_H__ -#define __ZEPHYR_RTOS_BIT_H__ - -#include - -/* TODO: align with Zephyr BIT APIs */ - -#define MASK(b_hi, b_lo) \ - (((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo)) -#define SET_BIT(b, x) (((x) & 1) << (b)) -#define SET_BITS(b_hi, b_lo, x) \ - (((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo)) -#define GET_BIT(b, x) \ - (((x) & (1ULL << (b))) >> (b)) -#define GET_BITS(b_hi, b_lo, x) \ - (((x) & MASK(b_hi, b_lo)) >> (b_lo)) - -#endif /* __ZEPHYR_RTOS_BIT_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2018 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_BIT_H__ +#define __ZEPHYR_RTOS_BIT_H__ +#ifndef MODULE_PRIVAT +#include +#endif +/* TODO: align with Zephyr BIT APIs */ + +#define MASK(b_hi, b_lo) \ + (((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo)) +#define SET_BIT(b, x) (((x) & 1) << (b)) +#define SET_BITS(b_hi, b_lo, x) \ + (((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo)) +#define GET_BIT(b, x) \ + (((x) & (1ULL << (b))) >> (b)) +#define GET_BITS(b_hi, b_lo, x) \ + (((x) & MASK(b_hi, b_lo)) >> (b_lo)) + +#endif /* __ZEPHYR_RTOS_BIT_H__ */ diff --git a/zephyr/include/rtos/cache.h b/zephyr/include/rtos/cache.h index 576e1c5bea3d..246461c58a59 100644 --- a/zephyr/include/rtos/cache.h +++ b/zephyr/include/rtos/cache.h @@ -9,10 +9,10 @@ #define __SOF_LIB_CACHE_H__ #if !defined(__ASSEMBLER__) && !defined(LINKER) - +#ifndef MODULE_PRIVAT #include #include - +#endif #if defined(CONFIG_XTENSA) && defined(CONFIG_INTEL) /* definitions required by xtensa-based Intel platforms. diff --git a/zephyr/include/rtos/panic.h b/zephyr/include/rtos/panic.h index e065498a5ba5..f25907362b4e 100644 --- a/zephyr/include/rtos/panic.h +++ b/zephyr/include/rtos/panic.h @@ -1,25 +1,25 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright 2023 NXP - * Copyright(c) 2018 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_PANIC_H__ -#define __ZEPHYR_RTOS_PANIC_H__ - -#include - -#ifndef __ZEPHYR__ -#error "This file should only be included in Zephyr builds." -#endif /* __ZEPHYR__ */ - -#define sof_panic(x) k_panic() -#define assert(x) __ASSERT_NO_MSG(x) - -/* To print the asserted expression on failure: - * #define assert(x) __ASSERT(x, #x) - */ - -#endif /* __ZEPHYR_RTOS_PANIC_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright 2023 NXP + * Copyright(c) 2018 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_PANIC_H__ +#define __ZEPHYR_RTOS_PANIC_H__ +#ifndef MODULE_PRIVAT +#include +#endif +#ifndef __ZEPHYR__ +#error "This file should only be included in Zephyr builds." +#endif /* __ZEPHYR__ */ + +#define sof_panic(x) k_panic() +#define assert(x) __ASSERT_NO_MSG(x) + +/* To print the asserted expression on failure: + * #define assert(x) __ASSERT(x, #x) + */ + +#endif /* __ZEPHYR_RTOS_PANIC_H__ */ diff --git a/zephyr/include/rtos/task.h b/zephyr/include/rtos/task.h index 9fcc202c1e2e..c37f5f34c2d7 100644 --- a/zephyr/include/rtos/task.h +++ b/zephyr/include/rtos/task.h @@ -1,113 +1,116 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2016 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_TASK_H__ -#define __ZEPHYR_RTOS_TASK_H__ - -#include -#include -#include -#include -#include -#include - -struct comp_dev; -struct sof; - -/** \brief Predefined LL task priorities. */ -#define SOF_TASK_PRI_HIGH 0 /* priority level 0 - high */ -#define SOF_TASK_PRI_MED 4 /* priority level 4 - medium */ -#define SOF_TASK_PRI_LOW 9 /* priority level 9 - low */ - -/** \brief Predefined EDF task deadlines. */ -#define SOF_TASK_DEADLINE_IDLE UINT64_MAX -#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1) -#define SOF_TASK_DEADLINE_NOW 0 - -/** \brief Task counter initial value. */ -#define SOF_TASK_SKIP_COUNT 0xFFFFu - -/** \brief Task states. */ -enum task_state { - SOF_TASK_STATE_INIT = 0, - SOF_TASK_STATE_QUEUED, - SOF_TASK_STATE_PENDING, - SOF_TASK_STATE_RUNNING, - SOF_TASK_STATE_PREEMPTED, - SOF_TASK_STATE_COMPLETED, - SOF_TASK_STATE_FREE, - SOF_TASK_STATE_CANCEL, - SOF_TASK_STATE_RESCHEDULE, -}; - -/** \brief Task operations. */ -struct task_ops { - enum task_state (*run)(void *data); /**< task's main operation */ - void (*complete)(void *data); /**< executed on completion */ - uint64_t (*get_deadline)(void *data); /**< returns current deadline */ -}; - -/** \brief Task used by schedulers. */ -struct task { - uint64_t start; /**< start time in [ms] since now (LL only) */ - const struct sof_uuid_entry *uid; /**< Uuid */ - uint16_t type; /**< type of the task (LL or EDF) */ - uint16_t priority; /**< priority of the task (used by LL) */ - uint16_t core; /**< execution core */ - uint16_t flags; /**< custom flags */ - enum task_state state; /**< current state */ - void *data; /**< custom data passed to all ops */ - struct list_item list; /**< used by schedulers to hold tasks */ - void *priv_data; /**< task private data */ - struct task_ops ops; /**< task operations */ - struct k_work_delayable z_delayed_work; - uint32_t cycles_sum; - uint32_t cycles_max; - uint32_t cycles_cnt; -#if CONFIG_PERFORMANCE_COUNTERS - struct perf_cnt_data pcd; -#endif -}; - -static inline bool task_is_active(struct task *task) -{ - switch (task->state) { - case SOF_TASK_STATE_QUEUED: - case SOF_TASK_STATE_PENDING: - case SOF_TASK_STATE_RUNNING: - case SOF_TASK_STATE_PREEMPTED: - case SOF_TASK_STATE_RESCHEDULE: - return true; - default: - return false; - } -} - -static inline enum task_state task_run(struct task *task) -{ - assert(task->ops.run); - - return task->ops.run(task->data); -} - -static inline void task_complete(struct task *task) -{ - if (task->ops.complete) - task->ops.complete(task->data); -} - -static inline uint64_t task_get_deadline(struct task *task) -{ - assert(task->ops.get_deadline); - - return task->ops.get_deadline(task->data); -} - -int task_main_start(struct sof *sof); -int start_complete(void); - -#endif /* __ZEPHYR_RTOS_TASK_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2016 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_TASK_H__ +#define __ZEPHYR_RTOS_TASK_H__ +#ifndef MODULE_PRIVAT +#include +#endif +#include +#include +#include +#ifndef MODULE_PRIVAT +#include +#include +#endif + +struct comp_dev; +struct sof; + +/** \brief Predefined LL task priorities. */ +#define SOF_TASK_PRI_HIGH 0 /* priority level 0 - high */ +#define SOF_TASK_PRI_MED 4 /* priority level 4 - medium */ +#define SOF_TASK_PRI_LOW 9 /* priority level 9 - low */ + +/** \brief Predefined EDF task deadlines. */ +#define SOF_TASK_DEADLINE_IDLE UINT64_MAX +#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1) +#define SOF_TASK_DEADLINE_NOW 0 + +/** \brief Task counter initial value. */ +#define SOF_TASK_SKIP_COUNT 0xFFFFu + +/** \brief Task states. */ +enum task_state { + SOF_TASK_STATE_INIT = 0, + SOF_TASK_STATE_QUEUED, + SOF_TASK_STATE_PENDING, + SOF_TASK_STATE_RUNNING, + SOF_TASK_STATE_PREEMPTED, + SOF_TASK_STATE_COMPLETED, + SOF_TASK_STATE_FREE, + SOF_TASK_STATE_CANCEL, + SOF_TASK_STATE_RESCHEDULE, +}; + +/** \brief Task operations. */ +struct task_ops { + enum task_state (*run)(void *data); /**< task's main operation */ + void (*complete)(void *data); /**< executed on completion */ + uint64_t (*get_deadline)(void *data); /**< returns current deadline */ +}; + +/** \brief Task used by schedulers. */ +struct task { + uint64_t start; /**< start time in [ms] since now (LL only) */ + const struct sof_uuid_entry *uid; /**< Uuid */ + uint16_t type; /**< type of the task (LL or EDF) */ + uint16_t priority; /**< priority of the task (used by LL) */ + uint16_t core; /**< execution core */ + uint16_t flags; /**< custom flags */ + enum task_state state; /**< current state */ + void *data; /**< custom data passed to all ops */ + struct list_item list; /**< used by schedulers to hold tasks */ + void *priv_data; /**< task private data */ + struct task_ops ops; /**< task operations */ + struct k_work_delayable z_delayed_work; + uint32_t cycles_sum; + uint32_t cycles_max; + uint32_t cycles_cnt; +#if CONFIG_PERFORMANCE_COUNTERS + struct perf_cnt_data pcd; +#endif +}; + +static inline bool task_is_active(struct task *task) +{ + switch (task->state) { + case SOF_TASK_STATE_QUEUED: + case SOF_TASK_STATE_PENDING: + case SOF_TASK_STATE_RUNNING: + case SOF_TASK_STATE_PREEMPTED: + case SOF_TASK_STATE_RESCHEDULE: + return true; + default: + return false; + } +} + +static inline enum task_state task_run(struct task *task) +{ + assert(task->ops.run); + + return task->ops.run(task->data); +} + +static inline void task_complete(struct task *task) +{ + if (task->ops.complete) + task->ops.complete(task->data); +} + +static inline uint64_t task_get_deadline(struct task *task) +{ + assert(task->ops.get_deadline); + + return task->ops.get_deadline(task->data); +} + +int task_main_start(struct sof *sof); +int start_complete(void); + +#endif /* __ZEPHYR_RTOS_TASK_H__ */