diff --git a/tools/testbench/README.md b/tools/testbench/README.md index 258888211888..ffe160881244 100644 --- a/tools/testbench/README.md +++ b/tools/testbench/README.md @@ -64,6 +64,37 @@ directions, use -p 1,2,3,4 and provide multiple input and output files separated with comma. Use e.g. -i i1.raw,i2.raw -o o1.raw,o2.raw. +### Apply controls to simulation + +The testbench supports shell script like amixer and sleep commands for +the controls. Create e.g. this script file as controls.sh: + +``` +#!/bin/sh + +# Example test sequence for DRC and volume components + +amixer -c0 cset name='Post Mixer Analog Playback DRC switch' off +amixer -c0 cset name='Post Mixer Analog Playback Volume' 40,30 +sleep 1 +amixer -c0 cset name='Post Mixer Analog Playback Volume' 0 +sleep 1 +amixer -c0 cset name='Post Mixer Analog Playback Volume' 45 +``` + +Then generarate sine wave (997 Hz, -3 dB level, 3 seconds) with sox +and check the impact to processed signal with next commands: + +``` +sox -n --encoding signed-integer -L -r 48000 -c 2 -b 32 in.raw synth 3 sine 997 norm -3 + +tools/testbench/build_testbench/install/bin/sof-testbench4 -r 48000 -c 2 -b S32_LE -p 1,2 \ + -t tools/build_tools/topology/topology2/production/sof-hda-generic.tplg \ +-i in.raw -o out.raw -s controls.sh + +sox --encoding signed-integer -L -r 48000 -c 2 -b 32 out.raw out.wav +``` + ### Run testbench with helper script The scripts/sof-testbench-helper.sh simplifies the task. See the help diff --git a/tools/testbench/file.c b/tools/testbench/file.c index 99c3f475a011..a6a768cf7355 100644 --- a/tools/testbench/file.c +++ b/tools/testbench/file.c @@ -632,8 +632,8 @@ static int file_init(struct processing_module *mod) /* set file comp mode */ cd->fs.mode = ipc_file->mode; - cd->rate = ipc_file->rate; - cd->channels = ipc_file->channels; + cd->fs.rate = ipc_file->rate; + cd->fs.channels = ipc_file->channels; cd->frame_fmt = ipc_file->frame_fmt; dev->direction = ipc_file->direction; dev->direction_set = true; @@ -859,8 +859,8 @@ static int file_get_hw_params(struct comp_dev *dev, tb_debug_print("file_hw_params()\n"); params->direction = dir; - params->rate = cd->rate; - params->channels = cd->channels; + params->rate = cd->fs.rate; + params->channels = cd->fs.channels; params->buffer_fmt = 0; params->frame_fmt = cd->frame_fmt; return 0; diff --git a/tools/testbench/include/testbench/file.h b/tools/testbench/include/testbench/file.h index 889649094429..c9552c5a4425 100644 --- a/tools/testbench/include/testbench/file.h +++ b/tools/testbench/include/testbench/file.h @@ -42,6 +42,8 @@ struct file_state { FILE *rfh, *wfh; /* read/write file handle */ char *fn; int copy_count; + int channels; + int rate; int n; enum file_mode mode; enum file_format f_format; @@ -56,8 +58,6 @@ struct file_comp_data; struct file_comp_data { struct file_state fs; enum sof_ipc_frame frame_fmt; - uint32_t channels; - uint32_t rate; int sample_container_bytes; int (*file_func)(struct file_comp_data *cd, struct audio_stream *sink, struct audio_stream *source, uint32_t frames); diff --git a/tools/testbench/include/testbench/topology_ipc4.h b/tools/testbench/include/testbench/topology_ipc4.h index 4a3d9ec96826..0f5d0699e08f 100644 --- a/tools/testbench/include/testbench/topology_ipc4.h +++ b/tools/testbench/include/testbench/topology_ipc4.h @@ -48,6 +48,10 @@ int tb_new_process(struct testbench_prm *tp); int tb_pipelines_set_state(struct testbench_prm *tp, int state, int dir); int tb_send_bytes_data(struct tb_mq_desc *ipc_tx, struct tb_mq_desc *ipc_rx, uint32_t module_id, uint32_t instance_id, struct sof_abi_hdr *abi); +int tb_send_volume_control(struct tb_mq_desc *ipc_tx, struct tb_mq_desc *ipc_rx, + struct tb_ctl *ctl, int *control_values, int num_values); +int tb_send_alsa_control(struct tb_mq_desc *ipc_tx, struct tb_mq_desc *ipc_rx, struct tb_ctl *ctl, + int *control_values, int num_values, int param_id); int tb_set_reset_state(struct testbench_prm *tp); int tb_set_running_state(struct testbench_prm *tp); int tb_set_up_pipeline(struct testbench_prm *tp, struct tplg_pipeline_info *pipe_info); diff --git a/tools/testbench/include/testbench/utils.h b/tools/testbench/include/testbench/utils.h index 9d11dcab2641..1d6df8faeeab 100644 --- a/tools/testbench/include/testbench/utils.h +++ b/tools/testbench/include/testbench/utils.h @@ -19,6 +19,10 @@ #define TB_MAX_INPUT_FILE_NUM 16 #define TB_MAX_OUTPUT_FILE_NUM 16 #define TB_MAX_PIPELINES_NUM 16 +#define TB_MAX_CMD_CHARS 256 +#define TB_MAX_CTL_NAME_CHARS 128 +#define TB_MAX_VOLUME_SIZE 120 +#define TB_MAX_BYTES_DATA_SIZE 8192 /* number of widgets types supported in testbench */ #define TB_NUM_WIDGETS_SUPPORTED 16 @@ -32,13 +36,34 @@ struct file_comp_lookup { struct file_state *state; }; +struct tb_ctl { + struct tplg_comp_info *comp_info; + unsigned int module_id; + unsigned int instance_id; + unsigned int type; + unsigned int volume_table[TB_MAX_VOLUME_SIZE]; + unsigned int index; + char *data; + char name[TB_MAX_CTL_NAME_CHARS]; + union { + struct snd_soc_tplg_mixer_control mixer_ctl; + struct snd_soc_tplg_enum_control enum_ctl; + struct snd_soc_tplg_bytes_control bytes_ctl; + }; +}; + +struct tb_glb_state { + char magic[8]; /* SOF_MAGIC */ + uint32_t num_ctls; /* number of ctls */ + size_t size; /* size of this structure in bytes */ + struct tb_ctl *ctl; +}; + #if CONFIG_IPC_MAJOR_4 #define TB_NAME_SIZE 256 #define TB_MAX_CONFIG_COUNT 2 #define TB_MAX_CONFIG_NAME_SIZE 64 -#define TB_MAX_VOLUME_SIZE 120 -#define TB_MAX_DATA_SIZE 512 #define TB_MAX_CTLS 16 struct tb_mq_desc { @@ -55,27 +80,6 @@ struct tb_config { int channels; unsigned long format; }; - -struct tb_ctl { - unsigned int module_id; - unsigned int instance_id; - unsigned int type; - unsigned int volume_table[TB_MAX_VOLUME_SIZE]; - unsigned int index; - char data[TB_MAX_DATA_SIZE]; - union { - struct snd_soc_tplg_mixer_control mixer_ctl; - struct snd_soc_tplg_enum_control enum_ctl; - struct snd_soc_tplg_bytes_control bytes_ctl; - }; -}; - -struct tb_glb_state { - char magic[8]; /* SOF_MAGIC */ - uint32_t num_ctls; /* number of ctls */ - size_t size; /* size of this structure in bytes */ - struct tb_ctl *ctl; -}; #endif /* @@ -93,6 +97,7 @@ struct testbench_prm { char *output_file[TB_MAX_OUTPUT_FILE_NUM]; /* output file names */ char *tplg_file; /* topology file to use */ char *bits_in; /* input bit format */ + char *control_file; int input_file_num; /* number of input files */ int output_file_num; /* number of output files */ int pipeline_num; @@ -100,8 +105,6 @@ struct testbench_prm { bool copy_check; int trace_level; int dynamic_pipeline_iterations; - int tick_period_us; - int pipeline_duration_ms; char *pipeline_string; int output_file_index; int input_file_index; @@ -125,6 +128,9 @@ struct testbench_prm { /* topology */ struct tplg_context tplg; + FILE *control_fh; + struct tb_glb_state glb_ctx; + #if CONFIG_IPC_MAJOR_4 struct list_item widget_list; struct list_item route_list; @@ -138,12 +144,12 @@ struct testbench_prm { struct tb_config config[TB_MAX_CONFIG_COUNT]; int num_configs; int period_frames; - struct tb_glb_state glb_ctx; #endif }; extern int debug; +int tb_decode_enum(struct snd_soc_tplg_enum_control *enum_ctl, char *token); int tb_find_file_components(struct testbench_prm *tp); int tb_free_all_pipelines(struct testbench_prm *tp); int tb_load_topology(struct testbench_prm *tp); @@ -152,7 +158,10 @@ int tb_pipeline_params(struct testbench_prm *tp, struct ipc *ipc, struct pipelin int tb_pipeline_reset(struct ipc *ipc, struct pipeline *p); int tb_pipeline_start(struct ipc *ipc, struct pipeline *p); int tb_pipeline_stop(struct ipc *ipc, struct pipeline *p); +int tb_read_controls(struct testbench_prm *tp, int64_t *sleep_ns); +int tb_set_enum_control(struct testbench_prm *tp, struct tb_ctl *ctl, char *control_params); int tb_set_reset_state(struct testbench_prm *tp); +int tb_set_mixer_control(struct testbench_prm *tp, struct tb_ctl *ctl, char *control_params); int tb_set_running_state(struct testbench_prm *tp); int tb_set_up_all_pipelines(struct testbench_prm *tp); int tb_setup(struct sof *sof, struct testbench_prm *tp); diff --git a/tools/testbench/testbench.c b/tools/testbench/testbench.c index be3e77ec918c..45c5c8843494 100644 --- a/tools/testbench/testbench.c +++ b/tools/testbench/testbench.c @@ -128,9 +128,8 @@ static void print_usage(char *executable) printf(" 4 shows debug traces and previous, plus other testbench debug messages\n"); printf(" -p \n"); printf(" -C \n"); - printf(" -D \n"); printf(" -P \n"); - printf(" -T \n\n"); + printf(" -s