@@ -650,6 +650,7 @@ static int test_keyword_cmd(struct comp_dev *dev, int cmd, void *data,
650650 }
651651}
652652#endif /* CONFIG_IPC_MAJOR_4 */
653+ static int test_keyword_params (struct comp_dev * dev , struct sof_ipc_stream_params * params );
653654
654655static struct comp_dev * test_keyword_new (const struct comp_driver * drv ,
655656 const struct comp_ipc_config * config ,
@@ -749,6 +750,16 @@ static struct comp_dev *test_keyword_new(const struct comp_driver *drv,
749750 dev -> direction = SOF_IPC_STREAM_CAPTURE ;
750751 dev -> direction_set = true;
751752 dev -> state = COMP_STATE_READY ;
753+
754+ #if CONFIG_IPC_MAJOR_4
755+ struct sof_ipc_stream_params params ;
756+
757+ /* retrieve params based on base config for IPC4 */
758+ ret = test_keyword_params (dev , & params );
759+ if (ret < 0 )
760+ goto cd_fail ;
761+ #endif
762+
752763 return dev ;
753764
754765cd_fail :
@@ -816,30 +827,6 @@ static int test_keyword_params(struct comp_dev *dev,
816827
817828 cd -> sample_valid_bytes = params -> sample_valid_bytes ;
818829
819- /* keyword components will only ever have 1 source */
820- sourceb = comp_dev_get_first_data_producer (dev );
821- channels = audio_stream_get_channels (& sourceb -> stream );
822- frame_fmt = audio_stream_get_frm_fmt (& sourceb -> stream );
823- rate = audio_stream_get_rate (& sourceb -> stream );
824-
825- if (channels != 1 ) {
826- comp_err (dev , "test_keyword_params(): only single-channel supported" );
827- return - EINVAL ;
828- }
829-
830- if (!detector_is_sample_width_supported (frame_fmt )) {
831- comp_err (dev , "test_keyword_params(): only 16-bit format supported" );
832- return - EINVAL ;
833- }
834-
835- /* calculate the length of the preamble */
836- if (cd -> config .preamble_time ) {
837- cd -> keyphrase_samples = cd -> config .preamble_time *
838- (rate / 1000 );
839- } else {
840- cd -> keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH ;
841- }
842-
843830 /*
844831 * Threshold might be already set via IPC4_DETECT_TEST_SET_CONFIG,
845832 * otherwise apply default value.
@@ -855,6 +842,32 @@ static int test_keyword_params(struct comp_dev *dev,
855842 cd -> config .activation_threshold = err ;
856843 }
857844
845+ /* keyword components will only ever have 1 source */
846+ sourceb = comp_dev_get_first_data_producer (dev );
847+ if (sourceb ) {
848+ channels = audio_stream_get_channels (& sourceb -> stream );
849+ frame_fmt = audio_stream_get_frm_fmt (& sourceb -> stream );
850+ rate = audio_stream_get_rate (& sourceb -> stream );
851+
852+ if (channels != 1 ) {
853+ comp_err (dev , "test_keyword_params(): only single-channel supported" );
854+ return - EINVAL ;
855+ }
856+
857+ if (!detector_is_sample_width_supported (frame_fmt )) {
858+ comp_err (dev , "test_keyword_params(): only 16-bit format supported" );
859+ return - EINVAL ;
860+ }
861+
862+ /* calculate the length of the preamble */
863+ if (cd -> config .preamble_time ) {
864+ cd -> keyphrase_samples = cd -> config .preamble_time *
865+ (rate / 1000 );
866+ } else {
867+ cd -> keyphrase_samples = KEYPHRASE_DEFAULT_PREAMBLE_LENGTH ;
868+ }
869+ }
870+
858871#if CONFIG_AMS
859872 cd -> kpd_uuid_id = AMS_INVALID_MSG_TYPE ;
860873#endif /* CONFIG_AMS */
@@ -926,6 +939,7 @@ static int test_keyword_reset(struct comp_dev *dev)
926939static int test_keyword_prepare (struct comp_dev * dev )
927940{
928941 struct comp_data * cd = comp_get_drvdata (dev );
942+ struct sof_ipc_stream_params params ;
929943 uint16_t valid_bits = cd -> sample_valid_bytes * 8 ;
930944 uint16_t sample_width ;
931945 int ret ;
@@ -938,6 +952,12 @@ static int test_keyword_prepare(struct comp_dev *dev)
938952
939953 comp_info (dev , "test_keyword_prepare()" );
940954
955+ ret = test_keyword_params (dev , & params );
956+ if (ret < 0 ) {
957+ comp_err (dev , "test_keyword_prepare(): params config failed." );
958+ return ret ;
959+ }
960+
941961 /*
942962 * FIXME: this condition is always "false" for IPC4 as audio format cannot be changed
943963 * without component re-creation. Does this "if" makes sense for IPC3?
0 commit comments