[Sound-open-firmware] [PATCH 3/3] [RFC]tune: add volume testbench
Ranjani Sridharan
ranjani.sridharan at linux.intel.com
Thu May 3 06:31:27 CEST 2018
This patch adds a volume testbench that enable reading samples from
an input file, processing them through a volume pipeline and
writing the processed samples to the output file.
Signed-off-by: Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
---
configure.ac | 1 +
tune/Makefile.am | 2 +-
tune/volume/Makefile.am | 17 +++++
tune/volume/volume_test.c | 160 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 179 insertions(+), 1 deletion(-)
create mode 100644 tune/volume/Makefile.am
create mode 100644 tune/volume/volume_test.c
diff --git a/configure.ac b/configure.ac
index d1c288d..6cc63bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,7 @@ AC_OUTPUT([
topology/test/Makefile
tune/Makefile
tune/common/Makefile
+ tune/volume/Makefile
])
echo "
diff --git a/tune/Makefile.am b/tune/Makefile.am
index e2e95a6..e7b9c0c 100644
--- a/tune/Makefile.am
+++ b/tune/Makefile.am
@@ -1 +1 @@
-SUBDIRS = common
+SUBDIRS = common volume
diff --git a/tune/volume/Makefile.am b/tune/volume/Makefile.am
new file mode 100644
index 0000000..2037802
--- /dev/null
+++ b/tune/volume/Makefile.am
@@ -0,0 +1,17 @@
+AUTOMAKE_OPTIONS = subdir-objects
+
+INCDIR1 = ../common
+INCDIR2 = $(prefix)/include/sof
+INCLUDE = -I$(INCDIR1) -I$(INCDIR2)
+DEFINE = -DDEBUG_PRINT
+
+AM_CPPFLAGS = $(INCLUDE) $(DEFINE)
+AM_CFLAGS = -g -Wall
+LDADD = \
+ ../common/libtb_common.a \
+ -lm -lsof -lsof_ipc -lsof_volume
+
+bin_PROGRAMS = volume_test
+
+volume_test_SOURCES = \
+ volume_test.c
diff --git a/tune/volume/volume_test.c b/tune/volume/volume_test.c
new file mode 100644
index 0000000..72fcb02
--- /dev/null
+++ b/tune/volume/volume_test.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2017, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the Intel Corporation nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Seppo Ingalsuo <seppo.ingalsuo at linux.intel.com>
+ * Ranjani Sridharan <ranjani.sridharan at linux.intel.com>
+ */
+
+#include <sof/ipc.h>
+#include <getopt.h>
+#include "common_test.h"
+#include "common_tplg.h"
+
+#define TESTBENCH_NCH 2 /* Stereo */
+
+/* main firmware context */
+static struct sof sof;
+static int fr_id; /* comp id for fileread */
+static int fw_id; /* comp id for filewrite */
+static int sched_id; /* comp id for scheduling comp */
+
+static void print_usage(char *executable)
+{
+ printf("Usage: %s -i <input_file> -o <output_file> -t <tplg_file> -b <input_format>\n",
+ executable);
+ printf("input_format should be s16le, s32le, s42le or float\n");
+}
+
+int main(int argc, char **argv)
+{
+ struct ipc_comp_dev *pcm_dev;
+ struct pipeline *p;
+ struct sof_ipc_pipe_new *ipc_pipe;
+ struct comp_dev *cd;
+ struct fileread_comp_data *frcd;
+ struct filewrite_comp_data *fwcd;
+ char *tplg_file = NULL, *input_file = NULL;
+ char *output_file = NULL, *bits_in = NULL;
+ clock_t tic, toc;
+ double c_realtime, t_exec;
+ int fs, n_in, n_out, ret;
+ int option = 0;
+
+ /* command line arguments*/
+ while ((option = getopt(argc, argv, "i:o:t:b:")) != -1) {
+ switch (option) {
+ case 'i':
+ input_file = malloc(strlen(optarg));
+ strcpy(input_file, optarg);
+ break;
+ case 'o':
+ output_file = malloc(strlen(optarg));
+ strcpy(output_file, optarg);
+ break;
+ case 't':
+ tplg_file = malloc(strlen(optarg));
+ strcpy(tplg_file, optarg);
+ break;
+ case 'b':
+ bits_in = malloc(strlen(optarg));
+ strcpy(bits_in, optarg);
+ break;
+ default:
+ print_usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (!bits_in || !tplg_file || !input_file || !output_file) {
+ print_usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ /* initialize ipc, pipeline and scheduler */
+ if (tb_pipeline_setup(&sof) < 0) {
+ printf("error: pipeline init\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* parse topology file and create pipeline */
+ if (parse_topology(tplg_file, &sof, &fr_id, &fw_id, &sched_id, bits_in,
+ input_file, output_file) < 0) {
+ printf("error: parsing topology\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Get pointers to fileread and filewrite */
+ pcm_dev = ipc_get_comp(sof.ipc, fw_id);
+ fwcd = comp_get_drvdata(pcm_dev->cd);
+ pcm_dev = ipc_get_comp(sof.ipc, fr_id);
+ frcd = comp_get_drvdata(pcm_dev->cd);
+
+ /* Run pipeline until EOF from fileread */
+ pcm_dev = ipc_get_comp(sof.ipc, sched_id);
+ p = pcm_dev->cd->pipeline;
+ ipc_pipe = &p->ipc_pipe;
+
+ fs = ipc_pipe->deadline * ipc_pipe->frames_per_sched;
+
+ /* set pipeline params and trigger start */
+ if (tb_pipeline_start(sof.ipc, TESTBENCH_NCH, bits_in, ipc_pipe) < 0) {
+ printf("error: pipeline params\n");
+ exit(EXIT_FAILURE);
+ }
+ cd = pcm_dev->cd;
+ tb_disable_trace(); /* Reduce print output */
+ tic = clock();
+
+ while (frcd->frs.reached_eof == 0)
+ pipeline_schedule_copy(p, 0);
+
+ /* reset and free pipeline */
+ toc = clock();
+ tb_enable_trace();
+ ret = pipeline_reset(p, cd);
+ if (ret < 0) {
+ printf("error: pipeline reset\n");
+ exit(EXIT_FAILURE);
+ }
+ pipeline_free(p);
+
+ n_in = frcd->frs.n;
+ n_out = fwcd->fws.n;
+ t_exec = (double) (toc - tic) / CLOCKS_PER_SEC;
+ c_realtime = (double) n_out / TESTBENCH_NCH / fs / t_exec;
+ /* print test summary */
+ printf("==============================================\n");
+ printf(" Test Summary\n");
+ printf("==============================================\n");
+ printf("Output written to file \"%s\"\n", output_file);
+ printf("Input sample count: %d\n", n_in);
+ printf("Output sample count: %d\n", n_out);
+ printf("Total execution time: %.2f us, %.2f x realtime\n",
+ 1e3 * t_exec, c_realtime);
+
+ return EXIT_SUCCESS;
+}
--
2.14.1
More information about the Sound-open-firmware
mailing list