EQ: Add equalizer control tool eqctl

This patch adds a simple control tool to setup during runtime (idle)
the IIR or FIR equalizer with new coefficients configuration. It is
useful in tuning of the equalizers. The tool also has capability to read
the EQ configuration from DSP.

Run "sof-eqctl -h" to see usage. The directory SOFT/tune/eq contains tool
to create EQ setup data.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
Seppo Ingalsuo 2018-09-24 19:01:39 +03:00
parent 918e401319
commit 1a1e1268ee
12 changed files with 261 additions and 1 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = logger rmbox topology
SUBDIRS = logger rmbox topology eqctl
TESTDIR = topology/test
tests:

View File

@ -3,6 +3,7 @@ AC_PREREQ([2.69])
AC_INIT([sof-tools], [1.0.1])
AM_INIT_AUTOMAKE([foreign])
AC_CONFIG_SRCDIR([rmbox/rmbox.c])
AC_CONFIG_SRCDIR([eqctl/eqctl.c])
AC_CONFIG_HEADERS([config.h])
AC_CHECK_HEADER([sof/uapi/abi.h])
AC_CHECK_PROG([XARGS], xargs, "yes", "no", [$PATH])
@ -19,6 +20,7 @@ AC_OUTPUT([
Makefile
logger/Makefile
rmbox/Makefile
eqctl/Makefile
topology/Makefile
topology/common/Makefile
topology/platform/Makefile

6
eqctl/Makefile.am Normal file
View File

@ -0,0 +1,6 @@
LDADD = -lasound
bin_PROGRAMS = sof-eqctl
sof_eqctl_SOURCES = \
eqctl.c

7
eqctl/README Normal file
View File

@ -0,0 +1,7 @@
How to use sof-eqctl tool
=========================
This tool helps to access the ext bytes or tlv bytes control of SOF
equalizer components eq_iir and eq_fir. Please find the documentation
in https://thesofproject.github.io/latest/getting_started/index.html
for more information.

1
eqctl/eq_fir_flat.txt Normal file
View File

@ -0,0 +1 @@
24,65538,0,4294901764,16384,0,

View File

@ -0,0 +1 @@
248,131076,65537,65537,4294901764,16384,0,108,3558500271,114559883,47710217,28574198,28836345,29032901,28180917,26280352,24510851,23200107,21954905,20578629,19136814,17891610,16843017,16122107,15335663,14549220,13762777,12976332,12124351,11337907,10551463,9896092,9175185,8585352,7995518,7405685,6815852,6291556,5767260,5308500,4849741,4456519,4063297,3735612,3473463,3145778,2883630,2687018,2424871,2228260,2031648,1835037,1638427,1507352,1376278,1179667,1048593,983056,851982,786444,720907,393225,

1
eqctl/eq_fir_mid.txt Normal file
View File

@ -0,0 +1 @@
192,65538,0,65624,1213426791,4254606209,3887459083,4018203428,4105564850,4147181068,4183947337,4217764461,4245486661,4267048379,4283170521,4294836140,7602239,12320925,14745811,15466729,14942442,13697244,11993285,10092713,8257676,6488176,4915287,3604544,2490414,1572895,917523,458762,65540,4294901759,4294770685,4294705147,4294639611,4294705146,4294705147,4294770683,4294836220,4294836221,4294901758,4294901758,4294967295,4294967295,65535,0,

View File

@ -0,0 +1 @@
84,2,1,0,0,2,2,3316150158,2048164275,513807534,3267352229,513807534,0,16384,3867454526,1191025347,38870735,77741469,38870735,4294967294,16458,

View File

@ -0,0 +1 @@
84,2,1,0,0,2,2,3227172081,2141520527,536653443,3221660410,536653443,0,16384,3260252783,2107733822,161646111,3961037800,172645501,4294967294,27910,

1
eqctl/eq_iir_flat.txt Normal file
View File

@ -0,0 +1 @@
56,2,1,0,0,1,1,0,0,0,0,538145694,0,32690,

View File

@ -0,0 +1 @@
156,4,2,1,1,1,1,1,1,0,0,0,0,538145694,0,32690,3,3,3237960220,2130690484,297056159,3694463533,303476880,0,16384,3302357025,2064935920,245217319,3776455865,274003881,0,16384,4106268671,4130185751,69182517,4179658584,365641401,4294967292,25468,

238
eqctl/eqctl.c Normal file
View File

@ -0,0 +1,238 @@
/*
* Copyright (c) 2018, 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@linux.intel.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <alsa/asoundlib.h>
#define SOF_CTRL_CMD_BINARY 3 /* TODO: From uapi ipc */
static void usage(char *name)
{
fprintf(stdout, "Usage %s <option(s)>\n", name);
fprintf(stdout, "Set example %s -Dhw:0 ", name);
fprintf(stdout, "-c \"numid=22,name=\\\"EQIIR1.0 EQIIR\\\"\" -s ");
fprintf(stdout, "iir.txt\n");
fprintf(stdout, "Set example %s -Dhw:0 -n 22 -s iir.txt\n", name);
fprintf(stdout, "Get example %s -Dhw:0 -n 22\n", name);
fprintf(stdout, "%s:\t \t\tControl SOF equalizers\n", name);
fprintf(stdout, "%s:\t -D <dev>\tUse device <dev>, defaults to hw:0\n",
name);
fprintf(stdout, "%s:\t -c <name>\tGet configuration for EQ <name>\n",
name);
fprintf(stdout, "%s:\t -n <number>\tGet configuration for ", name);
fprintf(stdout, "given numid\n");
fprintf(stdout, "%s:\t -s <file>\tSetup equalizer with data", name);
fprintf(stdout, "in <file>.\n");
fprintf(stdout, "\t\t\t\tThe ASCII text file must contain comma\n");
fprintf(stdout, "\t\t\t\tseparated unsigned integers.\n");
exit(0);
}
static int read_setup(unsigned int *data, char setup[], size_t smax)
{
FILE *fh;
int n = 0;
int n_max = smax / sizeof(unsigned int);
int separator;
fh = fopen(setup, "r");
while (fscanf(fh, "%u", &data[n]) != EOF && n < n_max) {
if (n > 0)
fprintf(stdout, ",");
fprintf(stdout, "%u", data[n]);
separator = fgetc(fh);
while (separator != ',' && separator != EOF)
separator = fgetc(fh);
n++;
}
fclose(fh);
fprintf(stdout, "\n");
return n;
}
int main(int argc, char *argv[])
{
snd_ctl_t *ctl;
snd_ctl_elem_id_t *id;
snd_ctl_elem_info_t *info;
snd_ctl_elem_value_t *value;
uint32_t *config;
unsigned int *user_data;
char nname[256];
int ret;
int ctrl_size;
int read;
int write;
int type;
int i;
char opt;
int n;
int buffer_size;
int mode = SND_CTL_NONBLOCK;
char *dev = "hw:0";
char *cname = NULL;
char *setup = NULL;
int set = 0;
while ((opt = getopt(argc, argv, "hD:c:s:n:")) != -1) {
switch (opt) {
case 'D':
dev = optarg;
break;
case 'c':
cname = optarg;
break;
case 'n':
sprintf(nname, "numid=%d", atoi(optarg));
cname = nname;
break;
case 's':
setup = optarg;
set = 1;
break;
case 'h':
usage(argv[0]);
exit(0);
break;
default:
usage(argv[0]);
exit(EXIT_FAILURE);
}
}
/* The control need to be defined. */
if (!cname) {
fprintf(stderr, "Error: No control was requested.\n");
usage(argv[0]);
exit(EXIT_FAILURE);
}
/* Open the device, mixer control and get read/write/type properties.
*/
ret = snd_ctl_open(&ctl, dev, mode);
if (ret) {
fprintf(stderr, "Error: Could not open device %s.\n", dev);
exit(ret);
}
/* Allocate buffers for pointers info, id, and value. */
snd_ctl_elem_info_alloca(&info);
snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_value_alloca(&value);
/* Get handle id for the ascii control name. */
ret = snd_ctl_ascii_elem_id_parse(id, cname);
if (ret) {
fprintf(stderr, "Error: Can't find %s.\n", cname);
exit(ret);
}
/* Get handle info from id. */
snd_ctl_elem_info_set_id(info, id);
ret = snd_ctl_elem_info(ctl, info);
if (ret) {
fprintf(stderr, "Error: Could not get elem info.\n");
exit(ret);
}
/* Get control attributes from info. */
ctrl_size = snd_ctl_elem_info_get_count(info);
read = snd_ctl_elem_info_is_tlv_readable(info);
write = snd_ctl_elem_info_is_tlv_writable(info);
type = snd_ctl_elem_info_get_type(info);
if (!read) {
fprintf(stderr, "Error: No read capability.\n");
exit(EXIT_FAILURE);
}
if (!write) {
fprintf(stderr, "Error: No write capability.\n");
exit(EXIT_FAILURE);
}
if (type != SND_CTL_ELEM_TYPE_BYTES) {
fprintf(stderr, "Error: control type has no bytes support.\n");
exit(EXIT_FAILURE);
}
/* Next allocate buffer for tlv write/read. The buffer needs a two
* words header with tag (SOF_CTRL_CMD_BINARY) and size in bytes.
*/
buffer_size = ctrl_size + 2 * sizeof(unsigned int);
user_data = calloc(1, buffer_size);
user_data[0] = SOF_CTRL_CMD_BINARY;
if (set) {
fprintf(stdout, "Applying configuration \"%s\" ", setup);
fprintf(stdout, "into device %s control %s.\n", dev, cname);
n = read_setup(&user_data[2], setup, ctrl_size);
if (n < 1) {
fprintf(stderr, "Error: failed data read from %s.\n",
setup);
free(user_data);
exit(EXIT_FAILURE);
}
user_data[1] = n * sizeof(unsigned int);
ret = snd_ctl_elem_tlv_write(ctl, id, user_data);
if (ret) {
fprintf(stderr, "Error: failed TLV write.\n");
free(user_data);
exit(ret);
}
fprintf(stdout, "Success.\n");
} else {
fprintf(stdout, "Retrieving configuration for ");
fprintf(stdout, "device %s control %s.\n", dev, cname);
user_data[1] = ctrl_size;
ret = snd_ctl_elem_tlv_read(ctl, id,
user_data, buffer_size);
if (ret) {
fprintf(stderr, "Error: failed TLV read.\n");
free(user_data);
exit(ret);
}
fprintf(stdout, "Success.\n");
/* Print the read EQ configuration data with similar syntax
* as the input file format.
*/
config = (uint32_t *) (user_data + 2);
n = config[0] / sizeof(uint32_t);
for (i = 0; i < n; i++) {
if (i == n - 1)
fprintf(stdout, "%u\n", config[i]);
else
fprintf(stdout, "%u,", config[i]);
}
}
free(user_data);
}