diff --git a/scripts/README.docker b/scripts/README.docker index 468ae251fb77..76b727f67041 100644 --- a/scripts/README.docker +++ b/scripts/README.docker @@ -26,8 +26,8 @@ To build for baytrail: or (may need password test0000 for rimage install) ./scripts/docker-run.sh ./scripts/xtensa-build-all.sh byt -To rebuild the topology in soft.git: -./scripts/docker-run.sh ./scripts/build-soft.sh +To rebuild the topology and logger: +./scripts/docker-run.sh ./scripts/build-tools.sh An incremental sof.git build: ./scripts/docker-run.sh make diff --git a/scripts/build-soft.sh b/scripts/build-tools.sh similarity index 63% rename from scripts/build-soft.sh rename to scripts/build-tools.sh index 0756cc54ba38..e6fbae078ce2 100755 --- a/scripts/build-soft.sh +++ b/scripts/build-tools.sh @@ -1,6 +1,6 @@ #!/bin/sh -cd ../soft.git +cd tools ./autogen.sh ./configure make -j$(nproc) -cd ../sof.git +cd ../ diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 000000000000..27a4118a27e9 --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1,23 @@ +*.o +*.in +*~ +autom4te* +*.Po +*.swp +Makefile +config.* +configure +depcomp +install-sh +missing +stamp-h1 +aclocal.m4 +compile +ltmain.sh +rimage/rimage +rwav/rwav +*.tplg +topology/*.conf +topology/test/*.conf +eqctl/sof-eqctl +logger/sof-logger diff --git a/tools/.travis.yml b/tools/.travis.yml new file mode 100644 index 000000000000..58c664662cc0 --- /dev/null +++ b/tools/.travis.yml @@ -0,0 +1,14 @@ +sudo: required + +language: c + +services: + - docker + +before_install: + - docker pull xiulipan/sof + - echo -e '#!/bin/bash \n./autogen.sh && ./configure && make && make tests 1>/dev/null' > quickbuild.sh + - chmod 755 quickbuild.sh + +script: + - docker run -it -v `pwd`:/home/sof/work/sof.git --user `id -u` xiulipan/sof ./quickbuild.sh diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 000000000000..da48543f1672 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = logger topology eqctl +TESTDIR = test/topology + +tests: + $(MAKE) -C $(TESTDIR) diff --git a/tools/README b/tools/README new file mode 100644 index 000000000000..07e9777d67a8 --- /dev/null +++ b/tools/README @@ -0,0 +1,133 @@ +Sound Open Firmware Tools +========================= + +This is a collection of open source tools used to develop open source audio +DSP firmwares for ALSA. + +Building and Installing +======================= + +./autogen.sh (only needed first time) +./configure +make +make install + + +rimage +====== + +rimage is used to convert ELF executable firmware files to the firmware file +formats used by the kernel drivers. + +e.g. + +rimage -i elf_file -o kernel_file -m machine + +rimage can also convert kernel firmware formats to flat binaries formats to +assist in debugging :- + +e.g. convert to flat binary, then ELF then dissasemble + +rimage -i /lib/firmware/intel/reef-byt.ri -o image.bin -b -m byt + +xtensa-byt-elf-objcopy -I binary -O elf32-xtensa-le -B xtensa image.bin image.bin.elf + +xtensa-byt-elf-objdump -D image.bin.elf > image.dis.txt + + +sof-logger +====== + +sof-logger is used to print logs delivered from FW dma_trace mechanism, by searching log +entries in *.ldc file generated by rimage. + +Every entry declared in FW is placed in elf output file (e.g. sof-apl) in +.static_log_entries section in a form of struct defined in sof/src/include/sof/trace.h +in sof fw repo. + +*.ldc file contains snd_sof_logs_header (defined in rmbox/logger_convert.c) +following by .static_log_entries section incorporated from FW elf file (e.g. sof-apl). +snd_sof_logs_header contains basic information about .static_log_entries section +like base_address and data_length. + +sof-logger works by reading entry parameters value and entries addresses from FW +dma_trace mechanism and searching suitable entry in *.ldc file by its address. + +Usage sof-logger + Display mailbox contents +-h help +-l *.ldc_file Specify the *.ldc file +-i in_file Get traces from in_file, instead of the default + "/sys/kernel/debug/sof/etrace" +-o out_file Specify the output file, instead of default stdout +-t Get traces from "/sys/kernel/debug/sof/trace", instead + of the default "/sys/kernel/debug/sof/etrace" +-p Get traces from stdin, instead of the default + "/sys/kernel/debug/sof/etrace" +-c Set timestamp clock in MHz +-e Enable checking firmware version with default verification file + "/sys/kernel/debug/sof/fw_version" +-v ver_file Enable checking firmware version with ver_file file, + instead of default: "/sys/kernel/debug/sof/fw_version" +-s Take a snapshot of state + + +Examples: + +- Get traces from "/sys/kernel/debug/sof/etrace" file, verifies fw_version with + "/sys/kernel/debug/sof/fw_version" and prints logs to stdout + + $ sof-logger -l ldc_file -e + +- Get traces from "/sys/kernel/debug/sof/etrace" file, verifies fw_version with + ver_file file and prints logs to stdout + + $ sof-logger -l ldc_file -v ver_file + +- Get traces from "/sys/kernel/debug/sof/etrace" file and prints logs to stdout + + $ sof-logger -l ldc_file + +- Get traces from "/sys/kernel/debug/sof/etrace" file and prints logs to + out_file file + + $ sof-logger -l ldc_file -o out_file + +- Get traces from "/sys/kernel/debug/sof/trace" file and prints logs to stdout + + $ sof-logger -l ldc_file -t + +- Get traces from "/sys/kernel/debug/sof/trace" file and prints logs to + out_file file + + $ sof-logger -l ldc_file -t -o out_file + +- Get traces from stdin and prints logs to stdout + + $ sof-logger -l ldc_file -p + +- Get traces from stdin and prints logs to out_file file + + $ sof-logger -l ldc_file -p -o out_file + +- Get traces from trace_dump file and prints logs to stdout + + $ sof-logger -l ldc_file -i trace_dump + +- Get traces from trace_dump file and prints logs to out_file file + + $ sof-logger -l ldc_file -i trace_dump -o out_file + +- c flag is intented for defining clock value (in MHz) used to format log + timestamps. By default clock value is set to 19.2 (MHz). Below example + set clock value to 19.9 (MHz). + + $ sof-logger -l ldc_file -i trace_dump -o out_file -c 19.9 + + +tests +===== + +To generate all test configuration files: + +make tests \ No newline at end of file diff --git a/tools/autogen.sh b/tools/autogen.sh new file mode 100755 index 000000000000..3b379b6014f2 --- /dev/null +++ b/tools/autogen.sh @@ -0,0 +1,6 @@ +#!/bin/bash +libtoolize -c --force +aclocal -I m4 --install +autoconf -Wall +autoheader +automake -a --copy --foreign --add-missing diff --git a/tools/configure.ac b/tools/configure.ac new file mode 100644 index 000000000000..829937a699b0 --- /dev/null +++ b/tools/configure.ac @@ -0,0 +1,38 @@ + +AC_PREREQ([2.69]) +AC_INIT([sof-tools], [1.0.1]) +AM_INIT_AUTOMAKE([foreign]) +AC_CONFIG_SRCDIR([logger/logger.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]) +AM_CONDITIONAL(XARGS, test "$XARGS" = "yes") + +AC_CANONICAL_HOST + +dnl Initialize maintainer mode +AM_MAINTAINER_MODE([enable]) + +AC_PROG_CC + +AC_OUTPUT([ + Makefile + logger/Makefile + eqctl/Makefile + topology/Makefile + topology/common/Makefile + topology/platform/Makefile + topology/platform/intel/Makefile + topology/platform/common/Makefile + topology/m4/Makefile + topology/sof/Makefile + test/topology/Makefile +]) + +echo " + +prefix: ${prefix} +Compiler: ${CC} +CFLAGS: ${CFLAGS} +" diff --git a/tools/coredumper/sof-coredump-reader.py b/tools/coredumper/sof-coredump-reader.py new file mode 100755 index 000000000000..33aa628e5b68 --- /dev/null +++ b/tools/coredumper/sof-coredump-reader.py @@ -0,0 +1,569 @@ +#!/usr/bin/env python3 + +# Tool for processing FW stack dumps. +# For more detailed useage, use --help option. + +from __future__ import print_function +import argparse +import struct +import os +import sys +import itertools +import re +import shutil +from ctypes import LittleEndianStructure, BigEndianStructure, c_uint32, c_char +from collections import namedtuple +from operator import attrgetter +from functools import partial + +def stderr_print(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + +try: + from sty import fg, bg, ef, rs, Rule, Render + CAN_COLOUR=True +except ImportError: + CAN_COLOUR=False + +ArchDefinition = namedtuple('ArchDefinition', ['name', 'bitness', 'endianness']) +VALID_ARCHS = {} +[VALID_ARCHS.update({archdef.name : archdef}) + for archdef in [ArchDefinition(*tup) for tup in + [ + ( 'LE32bit', + 32, + LittleEndianStructure, ), + ( 'LE64bit', + 64, + LittleEndianStructure, ), +# ( 'BE32bit', #untested, treat as not implemented +# 32, +# BigEndianStructure, ), +# ( 'BE64bit', #untested, treat as not implemented +# 64, +# BigEndianStructure, ), + ]] +] + +def valid_archs_print(): + archs = ''.join("{0}, ".format(x) for x in VALID_ARCHS) + archs = archs[:len(archs)-2] + return "{0}.".format(archs) + +TERM_SIZE = shutil.get_terminal_size((120, 20)) +AR_WINDOW_WIDTH = 4 +IS_COLOUR=False + +class argparse_readable_file( argparse.Action): + def raise_error(self, filepath, reason): + raise argparse.ArgumentTypeError( + "is_readable_file:{0} {1}".format( + filepath, + reason + )) + def is_readable_file(self, filepath): + if not os.path.isfile(filepath): + self.raise_error(filepath, "is not a valid path") + if os.access(filepath, os.R_OK): + return True + else: + self.raise_error(filepath, "is not a readable file") + return False + def __call__(self, parser, namespace, values, option_string=None): + filepath = values[0] + if (self.is_readable_file(filepath)): + setattr(namespace, self.dest, filepath) + +class argparse_writeable_file(argparse.Action): + def raise_error(self, filepath, reason): + raise argparse.ArgumentTypeError( + "is_writeable_file:{0} {1}".format( + filepath, + reason + )) + def is_writeable_file(self, filepath): + absdir = os.path.abspath(os.path.dirname(filepath)) + if os.path.isdir(absdir) and not os.path.exists(filepath): + return True + else: + if not os.path.isfile(filepath): + self.raise_error(filepath, "is not a valid path") + if os.access(filepath, os.W_OK): + return True + else: + self.raise_error(filepath, "is not a writeable file") + return False + def __call__(self, parser, namespace, values, option_string=None): + filepath = values[0] + if (self.is_writeable_file(filepath)): + setattr(namespace, self.dest, filepath) + else: + self.raise_error( + filepath, + "failed to determine whether file is writeable" + ) + +class argparse_architecture( argparse.Action): + def raise_error(self, value, reason): + raise argparse.ArgumentTypeError( + "architecture: {0} {1}".format( + value, + reason + )) + def is_valid_architecture(self, value): + if value in VALID_ARCHS: + return True + return False + def __call__(self, parser, namespace, values, option_string=None): + value = values[0] + if (self.is_valid_architecture(value)): + setattr(namespace, self.dest, VALID_ARCHS[value]) + else: + self.raise_error( + value, + "is invalid architecture. Valid architectures are: {0}".format(valid_archs_print()) + ) + +def parse_params(): + parser = argparse.ArgumentParser( + description="Tool for processing FW stack dumps." + +" In verbose mode it prints DSP registers, and function call" + +" addresses in stack up to that which caused core dump." + +" It then prints either to file or to stdin all gdb" + +" commands unwrapping those function call addresses to" + +" function calls in human readable format." + ) + ArgTuple = namedtuple('ArgTuple', ['name', 'optionals', 'parent']) + ArgTuple.__new__.__defaults__ = ((), {}, parser) + + # below cannot be empty once declared + outputMethod = parser.add_mutually_exclusive_group(required=True) + inputMethod = parser.add_mutually_exclusive_group() + [parent.add_argument(*name, **optionals) + for name, optionals, parent in sorted([ArgTuple(*x) for x in + [ + ( ( '-a', '--arch' , ), { + 'type' : str, + 'help' :'determine architecture of dump file; valid archs are: {0}' + .format(valid_archs_print()), + 'action' : argparse_architecture, + 'nargs' : 1, + 'default': VALID_ARCHS['LE64bit'], + },), + ( ( '-v', '--verbose' , ), { + 'help' :'increase output verbosity', + 'action':'store_true', + },), + ( ( '--stdin' , ), { + 'help' :'input is from stdin', + 'action' : 'store_true', + }, + inputMethod), + ( ( '-o', '--outfile' , ), { + 'type' : str, + 'help' :'output is to FILE', + 'action' : argparse_writeable_file, + 'nargs' : 1, + }, + outputMethod), + ( ( '--stdout' , ), { + 'help' :'output is to stdout', + 'action' :'store_true', + }, + outputMethod), + ( ( '-c', '--colour', ), { + 'help' :'set output to be colourful!', + 'action':'store_true', + },), + ( ( '-l', '--columncount', ), { + 'type' : int, + 'help' :'set how many colums to group the output in', + 'action':'store', + 'nargs' : 1, + },), + # below makes it impossible to have input file while getting stdin from pipe + ] + ([] if not sys.stdin.isatty() else [ + ( ( '-i', '--infile' , ), { + 'type' : str, + 'help' :'path to sys dump bin', + 'action' : argparse_readable_file, + 'nargs' : 1, + }, + inputMethod), + ])], + key=lambda argtup: (argtup.parent.__hash__(), argtup.name) + ) + ] + + parsed = parser.parse_args() + if not sys.stdin.isatty(): + parsed.stdin = True + + return parsed + +def chunks(l, n): + return [l[i:i + n] for i in range(0, len(l), n)] + +def flaten(l): + return [item for sublist in l for item in sublist] + +def raiseIfArchNotValid(arch): + if arch not in VALID_ARCHS.values(): + raise ValueError( + "CoreDumpFactory: {0} not in valid architectures: {1}" + .format(arch, valid_archs_print()) + ) + endiannesses = [arch.endianness for arch in VALID_ARCHS.values()] + if arch.endianness not in endiannesses: + raise ValueError( + "CoreDumpFactory: {0} not in valid endiannesses: {1}" + .format(endianness, endiannesses) + ) + +def FileInfoFactory(arch, filename_length): + raiseIfArchNotValid(arch) + class FileInfo(arch.endianness): + _fields_ = [ + ("filename", filename_length * c_char), + ("line_no", c_uint32) + ] + def __str__(self): + return "{}:{:d}".format(self.filename.decode(), self.line_no) + if FileInfo is None: + raise RuntimeError( + "FileInfoFactory: failed to produce FileInfo({0})" + .format(arch.name) + ) + return FileInfo + +class Colorer(): + #TODO: Add detection of 8bit/24bit terminal + # Add 8bit/24bit colours (with flag, maybe --colour=24bit) + # Use this below as fallback only + __print = partial(stderr_print) + __style = { + 'o' : fg.red, + 'O' : fg.yellow, + 'y' : fg.blue, + 'Y' : fg.cyan, + 'D' : fg.white + bg.red, + } + def __init__(self): + self.matchings = [ + ( + lambda x: self.enstyleNumHex(x.group()), + re.compile(r'\b([a-f0-9]{8})\b') + ), + ( + lambda x: self.enstyleNumBin(x.group()), + re.compile(r'\b(b[01]+)\b') + ), + ( + r'\1' + + r'\2' + + self.enstyle( fg.green , r'\3') , + re.compile(r'(\|)(ar)([0-9]+)\b') + ), + ( + self.enstyle(bg.green + fg.black , r'\1') + + r'\2' + + self.enstyle( fg.green , r'\3') , + re.compile(r'(\#)(ar)([0-9]+)\b') + ), + ] + + def toGroup(self, txt): + return [ (label, sum(1 for _ in group)) + for label, group in itertools.groupby(txt) ] + + def leadingZero(self, txt, char): + result = "" + groups = self.toGroup(txt) + lead = 0 + if groups[0][0] == '0': + lead = min(4, groups[0][1]) + result += char.lower() * lead + result += char.upper() * (4-lead) + return result + + def findSub(self, txt, mask, sub, char): + pos = txt.find(sub) + if pos >= 0: + return mask[:pos] + char * len(sub) + mask[(len(sub)+pos):] + else: + return mask + + def enstyleNumBin(self, txt): + result = rs.all + bg.magenta + "b" + prev = "" + for c in txt[1:]: + if prev != c: + prev = c + result += rs.all + if c == "0": + result += fg.red + result += c + result += rs.all + return result + + def enstyleNumHex(self, txt): + p1 = 'o' + p2 = 'y' + if txt == "00000000": + styleMask = p1 * 8 + elif txt.lower() == "deadbeef": + styleMask = "DDDDDDDD" + else: + styleMask = "".join( + [self.leadingZero(string, style) + for string, style in [ + (txt[:4], p1), + (txt[4:], p2), + ]]) + styleMask = "".join( + [self.findSub(txt, styleMask, string, style) + for string, style in [ + ('dead', 'D'), + ]]) + + result = "" + thisstyle = '' + for iter, style in enumerate(styleMask): + if thisstyle != style: + thisstyle = style + result += rs.all + self.__style[thisstyle] + result += txt[iter] + result += rs.all + return result + + def enstyle(self, style, txt): + return style + txt + rs.all + + def print(self, word): + result = word + for repl, regex in self.matchings: + result = re.sub(regex, repl, result) + self.__print(result) + +def CoreDumpFactory(arch): + raiseIfArchNotValid(arch) + class CoreDump(arch.endianness): + _fields_ = [(x, c_uint32) for x in + [ + "exccause", + "excvaddr", + "ps" + ] + + ["epc" + str(x) for x in range(1,7+1)] + + ["eps" + str(x) for x in range(2,7+1)] + + [ + "depc", + "intenable", + "interrupt", + "sar", + "debugcause", + "windowbase", + "windowstart", + "excsave1" # to + ] + ] + [ + ("a", arch.bitness * c_uint32) + ] + + def __init__(self, columncount): + self.arch = arch + self._fields_ + # below: smart column count + self._longest_field = len(max([x[0] for x in self._fields_], key=len)) + if columncount is not None: + self.columncount = max (1, int(columncount[0])) + else: + self.columncount = max(1, + int(TERM_SIZE[0]/(self._longest_field + 2 + 2 * AR_WINDOW_WIDTH + 2)) + ) + self.columncount_ar = ( + self.columncount + if self.columncount <= AR_WINDOW_WIDTH else + AR_WINDOW_WIDTH * int(self.columncount/AR_WINDOW_WIDTH) + ) + + def __windowbase_shift(self, iter, direction): + return (iter + self.windowbase * AR_WINDOW_WIDTH * direction) % self.arch.bitness + def windowbase_shift_left(self, iter): + return self.__windowbase_shift(iter, -1) + def windowbase_shift_right(self, iter): + return self.__windowbase_shift(iter, 1) + + def reg_from_string(self, string): + if string.startswith("ar"): + return self.a[self.windowbase_shift_left(int(string[2:]))] + else: + return self.__getattribute__(string) + + def __str__(self): + string = "" + string += "exccause" + return string + + def to_string(self, is_gdb): + # flatten + chunk enable to smartly print in N columns + string = ''.join([self.fmt(is_gdb, x) + for x in flaten( + [chunks(word, self.columncount) for word in [ + ["exccause", "excvaddr","ps"], + ["epc" + str(x) for x in range(1,7+1)], + ["eps" + str(x) for x in range(2,7+1)], + ["depc", "intenable", "interrupt", "sar", "debugcause"], + ["windowbase", "windowstart"], + ["excsave1"], + ]] +\ + [chunks(word, self.columncount_ar) for word in [ + ["ar" + str(x) for x in itertools.chain( + range( self.windowbase * AR_WINDOW_WIDTH, self.arch.bitness), + range(0, self.windowbase * AR_WINDOW_WIDTH), + )] + ]] + ) + ]) + if not is_gdb: + string += "\n" + return string + + def fmt_gdb_command(self): + return "set ${}=0x{:08x}\n" + + def fmt_pretty_form(self, separator = "|"): + return separator + "{:" + str(self._longest_field) + "} {:08x} " + + def fmt_separator(self, name): + separator = "|" + if name.startswith("ar") and int(name[2:]) % AR_WINDOW_WIDTH == 0 : + separator = "#" + return separator + + def fmt_pretty_auto(self, name): + return self.fmt_pretty_form(self.fmt_separator(name)) + + def fmt(self, is_gdb, names): + if is_gdb: + fmtr = lambda name: self.fmt_gdb_command() + else: + fmtr = lambda name: self.fmt_pretty_auto(name) + + string = "" + for name in names: + string += fmtr(name).format( + name, self.reg_from_string(name) + ) + if not is_gdb: + string += "\n" + return string + + def windowstart_process(self): + string = "" + binary = "b{0:b}".format(self.windowstart) + fnc_num = 0 + header = " " + for it, c in enumerate(binary[1:]): + if c != "0": + header += str(fnc_num) + fnc_num += 1 + else: + header += " " + string += " {0}\n".format(header) + string += "windowstart: {0}\n".format(binary) + + fnc_num = 0 + for iter, digit in enumerate(binary[1:]): + if (digit == '1'): + reg = "ar{0}".format( + self.windowbase_shift_right(AR_WINDOW_WIDTH * iter) + ) + string += "{0:2d} ".format(++fnc_num) + string += self.fmt_pretty_auto(reg).format( + reg, self.reg_from_string(reg) + ) + "\n" + fnc_num += 1 + return string + + if CoreDump is None: + raise RuntimeError( + "CoreDumpFactory: failed to produce CoreDump({0})" + .format(arch.name) + ) + return CoreDump + +class CoreDumpReader(object): + def __init__(self, args): + self.core_dump = CoreDumpFactory(args.arch)( + args.columncount + ) + self.file_info = FileInfoFactory(args.arch, 32)() + + if args.verbose: + if IS_COLOUR: + colorer = Colorer() + verbosePrint = colorer.print + else: + verbosePrint = stderr_print + else: + verbosePrint = lambda *discard_this: None + + if args.stdout: + stdoutPrint = print + stdoutClose = lambda : None + else: + outFile = open(args.outfile, "w") + stdoutPrint = outFile.write + stdoutClose = outFile.close + + if args.stdin or not sys.stdin.isatty(): + inStream = lambda : sys.stdin.buffer + else: + inStream = lambda : open(args.infile, "rb") + + with inStream() as cd_file: + [cd_file.readinto(x) for x in [ + self.core_dump, + self.file_info + ]] + self.stack = cd_file.read() + + verbosePrint(self.core_dump.to_string(0)) + + verbosePrint(self.core_dump.windowstart_process()) + + verbosePrint("Location: " + str(self.file_info)); + stack_base = self.core_dump.a[1] + 16 + stack_dw_num = int(len(self.stack)/AR_WINDOW_WIDTH) + verbosePrint("Stack dumped from {:08x} dwords num {:d}" + .format(stack_base, stack_dw_num)) + + stdoutPrint("break *0xbefe0000\nrun\n") + stdoutPrint(self.core_dump.to_string(1)) + + #TODO: make this elegant + for dw, addr in [( + struct.unpack("I", self.stack[i*AR_WINDOW_WIDTH : (i+1)*AR_WINDOW_WIDTH])[0], + stack_base + i*AR_WINDOW_WIDTH + ) for i in range(0, stack_dw_num)]: + stdoutPrint("set *0x{:08x}=0x{:08x}\n" + .format(addr, dw)) + + # TODO: if excsave1 is not empty, pc should be set to that value + # (exception mode, not forced panic mode) + # dodac sobie przyklad + # ustawiac pc z + stdoutPrint("set $pc=&arch_dump_regs_a\nbacktrace\n") + + stdoutClose() + +if __name__ == "__main__": + args = parse_params() + if args.colour: + if CAN_COLOUR: + IS_COLOUR=True + else: + stderr_print("Cannot color the output: module 'sty' not found!") + CoreDumpReader(args) + diff --git a/tools/coredumper/sof-coredump-to-gdb.sh b/tools/coredumper/sof-coredump-to-gdb.sh new file mode 100755 index 000000000000..a35c86f245d0 --- /dev/null +++ b/tools/coredumper/sof-coredump-to-gdb.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# Exemplatory usage of sof-coredump-reader.py ($reader_name) +# We read from dump file into sof-coredump-reader.py, then we pipe its output +# to xt-gdb, which operates on given elf-file. + +THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +elf="${1}" +dump="${2}" + +reader_name="sof-coredump-reader.py" # in case it is changed +reader_output="$(${THIS_SCRIPT_DIR}/${reader_name} -vc -i ${dump} --stdout -l 4)" +reader_result="$?" # if $reader_name script fails, running xt-gdb is pointless +if [[ ${reader_result} -ne 0 ]] ; then + echo "${reader_name} failed!" + exit ${reader_result} +else + xt-gdb "${elf}" < <(echo "${reader_output}") +fi diff --git a/tools/eqctl/Makefile.am b/tools/eqctl/Makefile.am new file mode 100644 index 000000000000..c1759c05b65a --- /dev/null +++ b/tools/eqctl/Makefile.am @@ -0,0 +1,6 @@ +LDADD = -lasound + +bin_PROGRAMS = sof-eqctl + +sof_eqctl_SOURCES = \ + eqctl.c diff --git a/tools/eqctl/README b/tools/eqctl/README new file mode 100644 index 000000000000..49762054eeb4 --- /dev/null +++ b/tools/eqctl/README @@ -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. diff --git a/tools/eqctl/eq_fir_flat.txt b/tools/eqctl/eq_fir_flat.txt new file mode 100644 index 000000000000..ee630d924f80 --- /dev/null +++ b/tools/eqctl/eq_fir_flat.txt @@ -0,0 +1 @@ +24,65538,0,4294901764,16384,0, diff --git a/tools/eqctl/eq_fir_loudness.txt b/tools/eqctl/eq_fir_loudness.txt new file mode 100644 index 000000000000..71788fc4e944 --- /dev/null +++ b/tools/eqctl/eq_fir_loudness.txt @@ -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, diff --git a/tools/eqctl/eq_fir_mid.txt b/tools/eqctl/eq_fir_mid.txt new file mode 100644 index 000000000000..1cdab1f8c326 --- /dev/null +++ b/tools/eqctl/eq_fir_mid.txt @@ -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, diff --git a/tools/eqctl/eq_iir_bandpass.txt b/tools/eqctl/eq_iir_bandpass.txt new file mode 100644 index 000000000000..3a097b9f215b --- /dev/null +++ b/tools/eqctl/eq_iir_bandpass.txt @@ -0,0 +1 @@ +84,2,1,0,0,2,2,3316150158,2048164275,513807534,3267352229,513807534,0,16384,3867454526,1191025347,38870735,77741469,38870735,4294967294,16458, diff --git a/tools/eqctl/eq_iir_bassboost.txt b/tools/eqctl/eq_iir_bassboost.txt new file mode 100644 index 000000000000..ae30294c3d07 --- /dev/null +++ b/tools/eqctl/eq_iir_bassboost.txt @@ -0,0 +1 @@ +84,2,1,0,0,2,2,3227172081,2141520527,536653443,3221660410,536653443,0,16384,3260252783,2107733822,161646111,3961037800,172645501,4294967294,27910, diff --git a/tools/eqctl/eq_iir_flat.txt b/tools/eqctl/eq_iir_flat.txt new file mode 100644 index 000000000000..59c75db9dca7 --- /dev/null +++ b/tools/eqctl/eq_iir_flat.txt @@ -0,0 +1 @@ +56,2,1,0,0,1,1,0,0,0,0,538145694,0,32690, diff --git a/tools/eqctl/eq_iir_loudness.txt b/tools/eqctl/eq_iir_loudness.txt new file mode 100644 index 000000000000..6bb76ad48f86 --- /dev/null +++ b/tools/eqctl/eq_iir_loudness.txt @@ -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, diff --git a/tools/eqctl/eqctl.c b/tools/eqctl/eqctl.c new file mode 100644 index 000000000000..8963c5cb47b7 --- /dev/null +++ b/tools/eqctl/eqctl.c @@ -0,0 +1,252 @@ +/* + * 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 + */ + +#include +#include +#include +#include +#include + +#define SOF_CTRL_CMD_BINARY 3 /* TODO: From uapi ipc */ + +static void usage(char *name) +{ + fprintf(stdout, "Usage %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 \tUse device , defaults to hw:0\n", + name); + fprintf(stdout, "%s:\t -c \tGet configuration for EQ \n", + name); + fprintf(stdout, "%s:\t -n \tGet configuration for ", name); + fprintf(stdout, "given numid\n"); + fprintf(stdout, "%s:\t -s \tSetup equalizer with data", name); + fprintf(stdout, "in .\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; + + /* open input file */ + fh = fopen(setup, "r"); + if (!fh) { + fprintf(stderr, "error: %s\n", strerror(errno)); + return -errno; + } + + 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); + if (!user_data) { + fprintf(stderr, + "Error: Failed to allocate buffer for user data.\n"); + exit(EXIT_FAILURE); + } + + 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); + return 0; +} diff --git a/tools/kmod_scripts/sof_bootloop.sh b/tools/kmod_scripts/sof_bootloop.sh new file mode 100755 index 000000000000..da9296dbe23d --- /dev/null +++ b/tools/kmod_scripts/sof_bootloop.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +MAXLOOPS=100 +COUNTER=0 + +while [ $COUNTER -lt $MAXLOOPS ]; do + echo "test $COUNTER" + ./sof_bootone.sh + dmesg > boot_$COUNTER.bootlog + let COUNTER+=1 +done diff --git a/tools/kmod_scripts/sof_bootone.sh b/tools/kmod_scripts/sof_bootone.sh new file mode 100755 index 000000000000..92071fab7152 --- /dev/null +++ b/tools/kmod_scripts/sof_bootone.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +dmesg -C +./sof_remove.sh +./sof_insert.sh +sleep 1 + +unset FW_BOOT +unset ERROR +FW_BOOT=$(dmesg | grep sof-audio | grep "boot complete") +ERROR=$(dmesg | grep sof-audio | grep -v "DSP trace buffer overflow" | grep "error") +TIMEOUT=$(dmesg | grep sof-audio | grep "ipc timed out") + +if [ ! -z "$ERROR" ] || [ -z "$FW_BOOT" ] || [ ! -z "$TIMEOUT" ] +then + dmesg > boot_fail.log + echo "boot failed, see boot_fail.log for details" + exit 1 +else + echo "boot success" +fi + diff --git a/tools/kmod_scripts/sof_insert.sh b/tools/kmod_scripts/sof_insert.sh new file mode 100755 index 000000000000..60753107fba6 --- /dev/null +++ b/tools/kmod_scripts/sof_insert.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +modprobe snd_soc_rt5670 +modprobe snd_soc_rt5645 +modprobe snd_soc_rt5651 +modprobe snd_soc_rt5640 +modprobe snd_soc_da7213 +modprobe snd_soc_pcm512x_i2c +modprobe snd_soc_tdf8532 +modprobe snd_soc_rt274 + +modprobe sof_acpi_dev +modprobe sof_pci_dev + + diff --git a/tools/kmod_scripts/sof_remove.sh b/tools/kmod_scripts/sof_remove.sh new file mode 100755 index 000000000000..8f0b49cbd162 --- /dev/null +++ b/tools/kmod_scripts/sof_remove.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +remove_module() { + + MODULE="$1" + + if lsmod | grep "$MODULE" &> /dev/null ; then + echo "Removing $MODULE" + rmmod $MODULE + else + echo "skipping $MODULE, not loaded" + fi +} + +remove_module sof_pci_dev +remove_module sof_acpi_dev +remove_module snd_soc_acpi_intel_match +remove_module snd_sof_intel_byt +remove_module snd_sof_intel_hsw +remove_module snd_sof_intel_bdw +remove_module snd_sof_intel_hda_common +remove_module snd_sof_xtensa_dsp + +remove_module snd_soc_sst_bytcr_rt5640 +remove_module snd_soc_sst_bytcr_rt5651 +remove_module snd_soc_sst_cht_bsw_rt5645 +remove_module snd_soc_sst_cht_bsw_rt5670 +remove_module snd_soc_sst_byt_cht_da7213 +remove_module snd_soc_sst_bxt_pcm512x +remove_module snd_soc_sst_bxt_tdf8532 +remove_module snd_soc_cnl_rt274 +remove_module snd_sof_nocodec +remove_module snd_sof + +remove_module snd_soc_rt5670 +remove_module snd_soc_rt5645 +remove_module snd_soc_rt5651 +remove_module snd_soc_rt5640 +remove_module snd_soc_rl6231 +remove_module snd_soc_da7213 +remove_module snd_soc_pcm512x_i2c +remove_module snd_soc_pcm512x +remove_module snd_soc_tdf8532 +remove_module snd_soc_rt274 +remove_module snd_soc_acpi diff --git a/tools/logger/Makefile.am b/tools/logger/Makefile.am new file mode 100644 index 000000000000..b938dfd44b66 --- /dev/null +++ b/tools/logger/Makefile.am @@ -0,0 +1,9 @@ +bin_PROGRAMS = sof-logger + +sof_logger_SOURCES = \ + logger.c \ + convert.c + +sof_logger_CFLAGS = \ + -Wall \ + -Werror diff --git a/tools/logger/convert.c b/tools/logger/convert.c new file mode 100644 index 000000000000..29f1e1b3147a --- /dev/null +++ b/tools/logger/convert.c @@ -0,0 +1,343 @@ +/* + * debug log converter, using new logger format. + * + * Copyright (c) 2018, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "convert.h" + +#define CEIL(a, b) ((a+b-1)/b) + +#define TRACE_MAX_PARAMS_COUNT 4 +#define TRACE_MAX_TEXT_LEN 1024 +#define TRACE_MAX_FILENAME_LEN 128 +#define TRACE_MAX_IDS_STR 10 +#define TRACE_IDS_MASK ((1 << TRACE_ID_LENGTH) - 1) + +/* logs file signature */ +#define SND_SOF_LOGS_SIG_SIZE 4 +#define SND_SOF_LOGS_SIG "Logs" + +/* +* Logs dictionary file header. +*/ +struct snd_sof_logs_header { + unsigned char sig[SND_SOF_LOGS_SIG_SIZE]; /* "Logs" */ + uint32_t base_address; /* address of log entries section */ + uint32_t data_length; /* amount of bytes following this header */ + uint32_t data_offset; /* offset to first entry in this file */ + struct sof_ipc_fw_version version; +}; + +struct ldc_entry_header { + uint32_t level; + uint32_t component_class; + uint32_t has_ids; + uint32_t params_num; + uint32_t line_idx; + uint32_t file_name_len; + uint32_t text_len; +}; + +struct ldc_entry { + struct ldc_entry_header header; + char *file_name; + char *text; + uint32_t *params; +}; + +static double to_usecs(uint64_t time, double clk) +{ + /* trace timestamp uses CPU system clock at default 25MHz ticks */ + // TODO: support variable clock rates + return (double)time / clk; +} + + +static inline void print_table_header(FILE *out_fd) +{ + fprintf(out_fd, "%5s %6s %12s %7s %16s %16s %24s\t%s\n", + "CORE", + "LEVEL", + "COMP_ID", + "", + "TIMESTAMP", + "DELTA", + "FILE_NAME", + "CONTENT"); + fflush(out_fd); +} + +#define CASE(x) \ + case(TRACE_CLASS_##x): return #x + +static const char * get_component_name(uint32_t component_id) { + switch (component_id) { + CASE(IRQ); + CASE(IPC); + CASE(PIPE); + CASE(HOST); + CASE(DAI); + CASE(DMA); + CASE(SSP); + CASE(COMP); + CASE(WAIT); + CASE(LOCK); + CASE(MEM); + CASE(MIXER); + CASE(BUFFER); + CASE(VOLUME); + CASE(SWITCH); + CASE(MUX); + CASE(SRC); + CASE(TONE); + CASE(EQ_FIR); + CASE(EQ_IIR); + CASE(SA); + CASE(DMIC); + CASE(POWER); + default: return "unknown"; + } +} + +static void print_entry_params(FILE *out_fd, struct log_entry_header dma_log, + struct ldc_entry entry, uint64_t last_timestamp, double clock) +{ + char ids[TRACE_MAX_IDS_STR]; + float dt = to_usecs(dma_log.timestamp - last_timestamp, clock); + + if (dt < 0 || dt > 1000.0 * 1000.0 * 1000.0) + dt = NAN; + + if (entry.header.has_ids) + sprintf(ids, "%d.%d", (dma_log.id_0 & TRACE_IDS_MASK), + (dma_log.id_1 & TRACE_IDS_MASK)); + + fprintf(out_fd, "%s%5u %6u %12s %-7s %16.6f %16.6f %20s:%-4u\t", + entry.header.level == LOG_LEVEL_CRITICAL ? KRED : KNRM, + dma_log.core_id, + entry.header.level, + get_component_name(entry.header.component_class), + entry.header.has_ids ? ids : "", + to_usecs(dma_log.timestamp, clock), + dt, + entry.file_name, + entry.header.line_idx); + + switch (entry.header.params_num) { + case 0: + fprintf(out_fd, "%s", entry.text); + break; + case 1: + fprintf(out_fd, entry.text, entry.params[0]); + break; + case 2: + fprintf(out_fd, entry.text, entry.params[0], entry.params[1]); + break; + case 3: + fprintf(out_fd, entry.text, entry.params[0], entry.params[1], + entry.params[2]); + break; + case 4: + fprintf(out_fd, entry.text, entry.params[0], entry.params[1], + entry.params[2], entry.params[3]); + break; + } + fprintf(out_fd, "%s\n", KNRM); + fflush(out_fd); +} + +static int fetch_entry(struct convert_config *config, uint32_t base_address, + uint32_t data_offset, struct log_entry_header dma_log, uint64_t *last_timestamp) +{ + struct ldc_entry entry; + uint32_t entry_offset; + + int ret; + + entry.file_name = NULL; + entry.text = NULL; + entry.params = NULL; + + /* evaluate entry offset in input file */ + entry_offset = dma_log.log_entry_address - base_address; + + /* set file position to beginning of processed entry */ + fseek(config->ldc_fd, entry_offset + data_offset, SEEK_SET); + + /* fetching elf header params */ + ret = fread(&entry.header, sizeof(entry.header), 1, config->ldc_fd); + if (!ret) { + ret = -ferror(config->ldc_fd); + goto out; + } + if (entry.header.file_name_len > TRACE_MAX_FILENAME_LEN) { + fprintf(stderr, "Error: Invalid filename length. \n"); + ret = -EINVAL; + goto out; + } + entry.file_name = (char *)malloc(entry.header.file_name_len); + + if (!entry.file_name) { + fprintf(stderr, "error: can't allocate %d byte for " + "entry.file_name\n", entry.header.file_name_len); + ret = -ENOMEM; + goto out; + } + + ret = fread(entry.file_name, sizeof(char), entry.header.file_name_len, + config->ldc_fd); + if (ret != entry.header.file_name_len) { + ret = -ferror(config->ldc_fd); + goto out; + } + + /* fetching text */ + if (entry.header.text_len > TRACE_MAX_TEXT_LEN) { + fprintf(stderr, "Error: Invalid text length. \n"); + ret = -EINVAL; + goto out; + } + entry.text = (char *)malloc(entry.header.text_len); + if (entry.text == NULL) { + fprintf(stderr, "error: can't allocate %d byte for " + "entry.text\n", entry.header.text_len); + ret = -ENOMEM; + goto out; + } + ret = fread(entry.text, sizeof(char), entry.header.text_len, config->ldc_fd); + if (ret != entry.header.text_len) { + ret = -ferror(config->ldc_fd); + goto out; + } + + /* fetching entry params from dma dump */ + if (entry.header.params_num > TRACE_MAX_PARAMS_COUNT) { + fprintf(stderr, "Error: Invalid number of parameters. \n"); + ret = -EINVAL; + goto out; + } + entry.params = (uint32_t *)malloc(sizeof(uint32_t) * + entry.header.params_num); + if (entry.params == NULL) { + fprintf(stderr, "error: can't allocate %d byte for " + "entry.params\n", (int)(sizeof(uint32_t) * + entry.header.params_num)); + ret = -ENOMEM; + goto out; + } + ret = fread(entry.params, sizeof(uint32_t), entry.header.params_num, + config->in_fd); + if (ret != entry.header.params_num) { + ret = -ferror(config->in_fd); + goto out; + } + + /* printing entry content */ + print_entry_params(config->out_fd, dma_log, entry, *last_timestamp, + config->clock); + *last_timestamp = dma_log.timestamp; + + /* set f_ldc file position to the beginning */ + rewind(config->ldc_fd); + + ret = 0; +out: + /* free alocated memory */ + free(entry.params); + free(entry.text); + free(entry.file_name); + + return ret; +} + +static int logger_read(struct convert_config *config, + struct snd_sof_logs_header *snd) +{ + struct log_entry_header dma_log; + int ret = 0; + print_table_header(config->out_fd); + uint64_t last_timestamp = 0; + + while (!feof(config->in_fd)) { + /* getting entry parameters from dma dump */ + ret = fread(&dma_log, sizeof(dma_log), 1, config->in_fd); + if (!ret) { + return -ferror(config->in_fd); + } + + /* checking if received trace address is located in + * entry section in elf file. + */ + if ((dma_log.log_entry_address < snd->base_address) || + dma_log.log_entry_address > snd->base_address + snd->data_length) { + /* in case the address is not correct input fd should be + * move forward by one DWORD, not entire struct dma_log + */ + fseek(config->in_fd, -(sizeof(dma_log) - sizeof(uint32_t)), SEEK_CUR); + continue; + } + + /* fetching entry from elf dump */ + ret = fetch_entry(config, snd->base_address, snd->data_offset, + dma_log, &last_timestamp); + if (ret) + break; + } + + return ret; +} + +int convert(struct convert_config *config) { + struct snd_sof_logs_header snd; + int count, ret = 0; + + count = fread(&snd, sizeof(snd), 1, config->ldc_fd); + if (!count) { + fprintf(stderr, "Error while reading %s. \n", config->ldc_file); + return -ferror(config->ldc_fd); + } + + if (strncmp((char *) snd.sig, SND_SOF_LOGS_SIG, SND_SOF_LOGS_SIG_SIZE)) { + fprintf(stderr, "Error: Invalid ldc file signature. \n"); + return -EINVAL; + } + + /* fw verification */ + if (config->version_fd) { + struct sof_ipc_fw_version ver; + + /* here fw verification should be exploited */ + count = fread(&ver, sizeof(ver), 1, config->version_fd); + if (!count) { + fprintf(stderr, "Error while reading %s. \n", config->version_file); + return -ferror(config->version_fd); + } + + ret = memcmp(&ver, &snd.version, sizeof(struct sof_ipc_fw_version)); + if (ret) { + fprintf(stderr, "Error: fw version in %s file " + "does not coincide with fw version in " + "%s file. \n", config->ldc_file, config->version_file); + return -EINVAL; + } + } + + return logger_read(config, &snd); +} diff --git a/tools/logger/convert.h b/tools/logger/convert.h new file mode 100644 index 000000000000..16e3c3be7640 --- /dev/null +++ b/tools/logger/convert.h @@ -0,0 +1,36 @@ +/* +* debug log converter interface. +* +* Copyright (c) 2018, Intel Corporation. +* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +*/ +#include +#include + +#define KNRM "\x1B[0m" +#define KRED "\x1B[31m" + +struct convert_config { + const char *out_file; + const char *in_file; + FILE *out_fd; + FILE *in_fd; + double clock; + int trace; + const char *ldc_file; + FILE* ldc_fd; + int input_std; + int version_fw; + char *version_file; + FILE *version_fd; +}; + +int convert(struct convert_config *config); diff --git a/tools/logger/logger.c b/tools/logger/logger.c new file mode 100644 index 000000000000..b888d01e19c5 --- /dev/null +++ b/tools/logger/logger.c @@ -0,0 +1,236 @@ +/* + * mbox dump to debug log convertor. + * + * Copyright (c) 2015, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ +#include +#include +#include +#include +#include +#include +#include "convert.h" + +#define APP_NAME "sof-logger" + +#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) + +static const char *debugfs[] = { + "dmac0", "dmac1", "ssp0", "ssp1", + "ssp2", "iram", "dram", "shim", + "mbox", "etrace", +}; + +static void usage(void) +{ + fprintf(stdout, "Usage %s \n", APP_NAME); + fprintf(stdout, "%s:\t \t\t\tDisplay mailbox contents\n", APP_NAME); + fprintf(stdout, "%s:\t -i infile -o outfile\tDump infile contents to outfile\n", APP_NAME); + fprintf(stdout, "%s:\t -l *.ldc_file\t\t*.ldc files generated by rimage\n", APP_NAME); + fprintf(stdout, "%s:\t -p \t\t\tInput from stdin\n", APP_NAME); + fprintf(stdout, "%s:\t -e \t\t\tEnable checking firmware version with default verification file\n", APP_NAME); + fprintf(stdout, "%s:\t -v ver_file\t\tEnable checking firmware version with ver_file file\n", APP_NAME); + fprintf(stdout, "%s:\t -c\t\t\tSet timestamp clock in MHz\n", APP_NAME); + fprintf(stdout, "%s:\t -s\t\t\tTake a snapshot of state\n", APP_NAME); + fprintf(stdout, "%s:\t -t\t\t\tDisplay trace data\n", APP_NAME); + exit(0); +} + +static int snapshot(const char *name) +{ + const char *path = "/sys/kernel/debug/sof"; + uint32_t val, addr; + char pinname[64], poutname[64], buffer[128]; + FILE *in_fd, *out_fd; + int i, count; + + if (name == NULL) { + fprintf(stderr, "error: need snapshot name\n"); + return -EINVAL; + } + + for (i = 0; i < ARRAY_SIZE(debugfs); i++) { + + sprintf(pinname, "%s/%s", path, debugfs[i]); + sprintf(poutname, "%s.%s.txt", name, debugfs[i]); + + /* open debugfs for reading */ + in_fd = fopen(pinname, "r"); + if (in_fd == NULL) { + fprintf(stderr, "error: unable to open %s for reading %d\n", + pinname, errno); + continue; + } + + /* open outfile for reading */ + out_fd = fopen(poutname, "w"); + if (out_fd == NULL) { + fprintf(stderr, "error: unable to open %s for writing %d\n", + poutname, errno); + fclose(in_fd); + continue; + } + + fprintf(stdout, "processing %s...\n", pinname); + addr = 0; + + while (1) { + count = fread(&val, 1, 4, in_fd); + if (count != 4) + break; + + sprintf(buffer, "0x%6.6x: 0x%8.8x\n", addr, val); + + count = fwrite(buffer, 1, strlen(buffer), out_fd); + + addr += 4; + } + + fclose(in_fd); + fclose(out_fd); + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + struct convert_config config; + int opt, ret = 0; + + config.trace = 0; + config.clock = 19.2; + config.in_file = NULL; + config.out_file = NULL; + config.out_fd = NULL; + config.in_fd = NULL; + config.ldc_file = NULL; + config.ldc_fd = NULL; + config.input_std = 0; + /* checking fw version is disabled by default */ + config.version_file = NULL; + config.version_fd = NULL; + config.version_fw = 0; + + while ((opt = getopt(argc, argv, "ho:i:l:ps:m:c:tev:")) != -1) { + switch (opt) { + case 'o': + config.out_file = optarg; + break; + case 'i': + config.in_file = optarg; + break; + case 't': + config.trace = 1; + break; + case 'c': + config.clock = atof(optarg); + break; + case 's': + return snapshot(optarg); + case 'l': + config.ldc_file = optarg; + break; + case 'p': + config.input_std = 1; + break; + case 'e': + /* enabling checking fw version with default verification + * file + */ + config.version_fw = 1; + config.version_file = "/sys/kernel/debug/sof/fw_version"; + break; + case 'v': + /* enabling checking fw version with ver_file file */ + config.version_fw = 1; + config.version_file = optarg; + break; + case 'h': + default: /* '?' */ + usage(); + } + } + + if (!config.ldc_file) { + fprintf(stderr, "error: Missing ldc file\n"); + usage(); + } + + config.ldc_fd = fopen(config.ldc_file, "r"); + if (!config.ldc_fd) { + fprintf(stderr, "error: Unable to open ldc file %s\n", + config.ldc_file); + ret = -errno; + goto out; + } + + if (config.version_fw) { + config.version_fd = fopen(config.version_file, "r"); + if (!config.version_fd) { + fprintf(stderr, "error: Unable to open ver file %s\n", + config.version_file); + ret = -errno; + goto out; + } + } + + if (config.out_file) { + config.out_fd = fopen(config.out_file, "w"); + if (!config.out_fd) { + fprintf(stderr, "error: Unable to open out file %s\n", + config.out_file); + ret = -errno; + goto out; + } + } else { + config.out_fd = stdout; + } + + /* trace requested ? */ + if (config.trace) + config.in_file = "/sys/kernel/debug/sof/trace"; + + /* default option with no infile is to dump errors/debug data */ + if (!config.in_file) + config.in_file = "/sys/kernel/debug/sof/etrace"; + + if (config.input_std) { + config.in_fd = stdin; + } else { + config.in_fd = fopen(config.in_file, "r"); + if (!config.in_fd) { + fprintf(stderr, "error: Unable to open in file %s\n", + config.in_file); + ret = -errno; + goto out; + } + } + + convert(&config); + +out: + /* close files */ + if (config.out_fd) + fclose(config.out_fd); + + if (config.in_fd) + fclose(config.in_fd); + + if (config.ldc_fd) + fclose(config.ldc_fd); + + if (config.version_fd) + fclose(config.version_fd); + + return ret; +} diff --git a/tools/logger/sof/uapi/abi.h b/tools/logger/sof/uapi/abi.h new file mode 100644 index 000000000000..118ea64d4686 --- /dev/null +++ b/tools/logger/sof/uapi/abi.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016, 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: Liam Girdwood + */ + +/** + * \file include/uapi/abi.h + * \brief ABI definitions + * \author Liam Girdwood + */ + +#ifndef __INCLUDE_UAPI_ABI_H__ +#define __INCLUDE_UAPI_ABI_H__ + +/** \brief SOF ABI version number. */ +#define SOF_ABI_VER(major, minor, micro) \ + (((major)<<8)|((minor)<<4)|(micro)) +#define SOF_ABI_VERSION_MAJOR(version) (((version)>>8) & 0xff) +#define SOF_ABI_VERSION_MINOR(version) (((version)>>4) & 0xf) +#define SOF_ABI_VERSION_MICRO(version) ((version) & 0xf) +#define SOF_ABI_VERSION_INCOMPATIBLE(sof_ver, client_ver) \ + (SOF_ABI_VERSION_MAJOR(sof_ver) != SOF_ABI_VERSION_MAJOR(client_ver) ||\ + (SOF_ABI_VERSION_MAJOR(sof_ver) == SOF_ABI_VERSION_MAJOR(client_ver) &&\ + SOF_ABI_VERSION_MINOR(sof_ver) != SOF_ABI_VERSION_MINOR(client_ver))) + +#define SOF_ABI_MAJOR 1 +#define SOF_ABI_MINOR 0 +#define SOF_ABI_MICRO 0 + +#define SOF_ABI_VERSION SOF_ABI_VER(SOF_ABI_MAJOR, SOF_ABI_MINOR, SOF_ABI_MICRO) + +/** \brief SOF ABI magic number "SOF\0". */ +#define SOF_ABI_MAGIC 0x00464F53 + +/** + * \brief Header for all non IPC ABI data. + * + * Identifies data type, size and ABI. + * Used by any bespoke component data structures or binary blobs. + */ +struct sof_abi_hdr { + uint32_t magic; /**< 'S', 'O', 'F', '\0' */ + uint32_t type; /**< component specific type */ + uint32_t size; /**< size in bytes of data excl. this struct */ + uint32_t abi; /**< SOF ABI version */ + uint32_t comp_abi; /**< component specific ABI version */ + char data[0]; /**< data */ +} __attribute__((packed)); + +#endif + diff --git a/tools/logger/sof/uapi/ipc.h b/tools/logger/sof/uapi/ipc.h new file mode 100644 index 000000000000..e9883acb0cd7 --- /dev/null +++ b/tools/logger/sof/uapi/ipc.h @@ -0,0 +1,1020 @@ +/* + * Copyright (c) 2016, 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: Liam Girdwood + * Keyon Jie + */ + +/** + * \file include/uapi/ipc.h + * \brief IPC definitions + * \author Liam Girdwood + * \author Keyon Jie + */ + +#ifndef __INCLUDE_UAPI_IPC_H__ +#define __INCLUDE_UAPI_IPC_H__ + +#include + +/** \addtogroup sof_uapi uAPI + * SOF uAPI specification. + * @{ + */ + +/* + * IPC messages have a prefixed 32 bit identifier made up as follows :- + * + * 0xGCCCNNNN where + * G is global cmd type (4 bits) + * C is command type (12 bits) + * I is the ID number (16 bits) - monotonic and overflows + * + * This is sent at the start of the IPM message in the mailbox. Messages should + * not be sent in the doorbell (special exceptions for firmware . + */ + +/* Global Message - Generic */ +#define SOF_GLB_TYPE_SHIFT 28 +#define SOF_GLB_TYPE_MASK (0xf << SOF_GLB_TYPE_SHIFT) +#define SOF_GLB_TYPE(x) ((x) << SOF_GLB_TYPE_SHIFT) + +/* Command Message - Generic */ +#define SOF_CMD_TYPE_SHIFT 16 +#define SOF_CMD_TYPE_MASK (0xfff << SOF_CMD_TYPE_SHIFT) +#define SOF_CMD_TYPE(x) ((x) << SOF_CMD_TYPE_SHIFT) + +/* Global Message Types */ +#define SOF_IPC_GLB_REPLY SOF_GLB_TYPE(0x1U) +#define SOF_IPC_GLB_COMPOUND SOF_GLB_TYPE(0x2U) +#define SOF_IPC_GLB_TPLG_MSG SOF_GLB_TYPE(0x3U) +#define SOF_IPC_GLB_PM_MSG SOF_GLB_TYPE(0x4U) +#define SOF_IPC_GLB_COMP_MSG SOF_GLB_TYPE(0x5U) +#define SOF_IPC_GLB_STREAM_MSG SOF_GLB_TYPE(0x6U) +#define SOF_IPC_FW_READY SOF_GLB_TYPE(0x7U) +#define SOF_IPC_GLB_DAI_MSG SOF_GLB_TYPE(0x8U) +#define SOF_IPC_GLB_TRACE_MSG SOF_GLB_TYPE(0x9U) + +/* + * DSP Command Message Types + */ + +/* topology */ +#define SOF_IPC_TPLG_COMP_NEW SOF_CMD_TYPE(0x001) +#define SOF_IPC_TPLG_COMP_FREE SOF_CMD_TYPE(0x002) +#define SOF_IPC_TPLG_COMP_CONNECT SOF_CMD_TYPE(0x003) +#define SOF_IPC_TPLG_PIPE_NEW SOF_CMD_TYPE(0x010) +#define SOF_IPC_TPLG_PIPE_FREE SOF_CMD_TYPE(0x011) +#define SOF_IPC_TPLG_PIPE_CONNECT SOF_CMD_TYPE(0x012) +#define SOF_IPC_TPLG_PIPE_COMPLETE SOF_CMD_TYPE(0x013) +#define SOF_IPC_TPLG_BUFFER_NEW SOF_CMD_TYPE(0x020) +#define SOF_IPC_TPLG_BUFFER_FREE SOF_CMD_TYPE(0x021) + +/* PM */ +#define SOF_IPC_PM_CTX_SAVE SOF_CMD_TYPE(0x001) +#define SOF_IPC_PM_CTX_RESTORE SOF_CMD_TYPE(0x002) +#define SOF_IPC_PM_CTX_SIZE SOF_CMD_TYPE(0x003) +#define SOF_IPC_PM_CLK_SET SOF_CMD_TYPE(0x004) +#define SOF_IPC_PM_CLK_GET SOF_CMD_TYPE(0x005) +#define SOF_IPC_PM_CLK_REQ SOF_CMD_TYPE(0x006) +#define SOF_IPC_PM_CORE_ENABLE SOF_CMD_TYPE(0x007) + +/* component runtime config - multiple different types */ +#define SOF_IPC_COMP_SET_VALUE SOF_CMD_TYPE(0x001) +#define SOF_IPC_COMP_GET_VALUE SOF_CMD_TYPE(0x002) +#define SOF_IPC_COMP_SET_DATA SOF_CMD_TYPE(0x003) +#define SOF_IPC_COMP_GET_DATA SOF_CMD_TYPE(0x004) + +/* DAI messages */ +#define SOF_IPC_DAI_CONFIG SOF_CMD_TYPE(0x001) +#define SOF_IPC_DAI_LOOPBACK SOF_CMD_TYPE(0x002) + +/* stream */ +#define SOF_IPC_STREAM_PCM_PARAMS SOF_CMD_TYPE(0x001) +#define SOF_IPC_STREAM_PCM_PARAMS_REPLY SOF_CMD_TYPE(0x002) +#define SOF_IPC_STREAM_PCM_FREE SOF_CMD_TYPE(0x003) +#define SOF_IPC_STREAM_TRIG_START SOF_CMD_TYPE(0x004) +#define SOF_IPC_STREAM_TRIG_STOP SOF_CMD_TYPE(0x005) +#define SOF_IPC_STREAM_TRIG_PAUSE SOF_CMD_TYPE(0x006) +#define SOF_IPC_STREAM_TRIG_RELEASE SOF_CMD_TYPE(0x007) +#define SOF_IPC_STREAM_TRIG_DRAIN SOF_CMD_TYPE(0x008) +#define SOF_IPC_STREAM_TRIG_XRUN SOF_CMD_TYPE(0x009) +#define SOF_IPC_STREAM_POSITION SOF_CMD_TYPE(0x00a) +#define SOF_IPC_STREAM_VORBIS_PARAMS SOF_CMD_TYPE(0x010) +#define SOF_IPC_STREAM_VORBIS_FREE SOF_CMD_TYPE(0x011) + +/* trace and debug */ +#define SOF_IPC_TRACE_DMA_PARAMS SOF_CMD_TYPE(0x001) +#define SOF_IPC_TRACE_DMA_POSITION SOF_CMD_TYPE(0x002) + +/* Get message component id */ +#define SOF_IPC_MESSAGE_ID(x) ((x) & 0xffff) + +/* maximum message size for mailbox Tx/Rx */ +#define SOF_IPC_MSG_MAX_SIZE 384 + +/* + * SOF panic codes + */ +#define SOF_IPC_PANIC_MAGIC 0x0dead000 +#define SOF_IPC_PANIC_MAGIC_MASK 0x0ffff000 +#define SOF_IPC_PANIC_CODE_MASK 0x00000fff +#define SOF_IPC_PANIC_MEM (SOF_IPC_PANIC_MAGIC | 0x0) +#define SOF_IPC_PANIC_WORK (SOF_IPC_PANIC_MAGIC | 0x1) +#define SOF_IPC_PANIC_IPC (SOF_IPC_PANIC_MAGIC | 0x2) +#define SOF_IPC_PANIC_ARCH (SOF_IPC_PANIC_MAGIC | 0x3) +#define SOF_IPC_PANIC_PLATFORM (SOF_IPC_PANIC_MAGIC | 0x4) +#define SOF_IPC_PANIC_TASK (SOF_IPC_PANIC_MAGIC | 0x5) +#define SOF_IPC_PANIC_EXCEPTION (SOF_IPC_PANIC_MAGIC | 0x6) +#define SOF_IPC_PANIC_DEADLOCK (SOF_IPC_PANIC_MAGIC | 0x7) +#define SOF_IPC_PANIC_STACK (SOF_IPC_PANIC_MAGIC | 0x8) +#define SOF_IPC_PANIC_IDLE (SOF_IPC_PANIC_MAGIC | 0x9) +#define SOF_IPC_PANIC_WFI (SOF_IPC_PANIC_MAGIC | 0xa) + +/* + * SOF memory capabilities, add new ones at the end + */ +#define SOF_MEM_CAPS_RAM (1 << 0) +#define SOF_MEM_CAPS_ROM (1 << 1) +#define SOF_MEM_CAPS_EXT (1 << 2) /* external */ +#define SOF_MEM_CAPS_LP (1 << 3) /* low power */ +#define SOF_MEM_CAPS_HP (1 << 4) /* high performance */ +#define SOF_MEM_CAPS_DMA (1 << 5) /* DMA'able */ +#define SOF_MEM_CAPS_CACHE (1 << 6) /* cacheable */ +#define SOF_MEM_CAPS_EXEC (1 << 7) /* executable */ + +/* + * Command Header - Header for all IPC. Identifies IPC message. + * The size can be greater than the structure size and that means there is + * extended bespoke data beyond the end of the structure including variable + * arrays. + */ + +struct sof_ipc_hdr { + uint32_t cmd; /* SOF_IPC_GLB_ + cmd */ + uint32_t size; /* size of structure */ +} __attribute__((packed)); + +/* + * Generic reply message. Some commands override this with their own reply + * types that must include this at start. + */ +struct sof_ipc_reply { + struct sof_ipc_hdr hdr; + int32_t error; /* negative error numbers */ +} __attribute__((packed)); + +/* + * Compound commands - SOF_IPC_GLB_COMPOUND. + * + * Compound commands are sent to the DSP as a single IPC operation. The + * commands are split into blocks and each block has a header. This header + * identifies the command type and the number of commands before the next + * header. + */ + +struct sof_ipc_compound_hdr { + struct sof_ipc_hdr hdr; + uint32_t count; /* count of 0 means end of compound sequence */ +} __attribute__((packed)); + +/* + * DAI Configuration. + * + * Each different DAI type will have it's own structure and IPC cmd. + */ + +#define SOF_DAI_FMT_I2S 1 /* I2S mode */ +#define SOF_DAI_FMT_RIGHT_J 2 /* Right Justified mode */ +#define SOF_DAI_FMT_LEFT_J 3 /* Left Justified mode */ +#define SOF_DAI_FMT_DSP_A 4 /* L data MSB after FRM LRC */ +#define SOF_DAI_FMT_DSP_B 5 /* L data MSB during FRM LRC */ +#define SOF_DAI_FMT_PDM 6 /* Pulse density modulation */ + +#define SOF_DAI_FMT_CONT (1 << 4) /* continuous clock */ +#define SOF_DAI_FMT_GATED (0 << 4) /* clock is gated */ + +#define SOF_DAI_FMT_NB_NF (0 << 8) /* normal bit clock + frame */ +#define SOF_DAI_FMT_NB_IF (2 << 8) /* normal BCLK + inv FRM */ +#define SOF_DAI_FMT_IB_NF (3 << 8) /* invert BCLK + nor FRM */ +#define SOF_DAI_FMT_IB_IF (4 << 8) /* invert BCLK + FRM */ + +#define SOF_DAI_FMT_CBM_CFM (0 << 12) /* codec clk & FRM master */ +#define SOF_DAI_FMT_CBS_CFM (2 << 12) /* codec clk slave & FRM master */ +#define SOF_DAI_FMT_CBM_CFS (3 << 12) /* codec clk master & frame slave */ +#define SOF_DAI_FMT_CBS_CFS (4 << 12) /* codec clk & FRM slave */ + +#define SOF_DAI_FMT_FORMAT_MASK 0x000f +#define SOF_DAI_FMT_CLOCK_MASK 0x00f0 +#define SOF_DAI_FMT_INV_MASK 0x0f00 +#define SOF_DAI_FMT_MASTER_MASK 0xf000 + + /* ssc1: TINTE */ +#define SOF_DAI_INTEL_SSP_QUIRK_TINTE (1 << 0) + /* ssc1: PINTE */ +#define SOF_DAI_INTEL_SSP_QUIRK_PINTE (1 << 1) + /* ssc2: SMTATF */ +#define SOF_DAI_INTEL_SSP_QUIRK_SMTATF (1 << 2) + /* ssc2: MMRATF */ +#define SOF_DAI_INTEL_SSP_QUIRK_MMRATF (1 << 3) + /* ssc2: PSPSTWFDFD */ +#define SOF_DAI_INTEL_SSP_QUIRK_PSPSTWFDFD (1 << 4) + /* ssc2: PSPSRWFDFD */ +#define SOF_DAI_INTEL_SSP_QUIRK_PSPSRWFDFD (1 << 5) + /* here is the possibility to define others aux macros */ + +#define SOF_DAI_INTEL_SSP_FRAME_PULSE_WIDTH_MAX 38 +#define SOF_DAI_INTEL_SSP_SLOT_PADDING_MAX 31 + +/* SSP clocks control settings + * + * Macros for clks_control field in sof_ipc_dai_ssp_params struct. + */ + +/* mclk 0 disable */ +#define SOF_DAI_INTEL_SSP_MCLK_0_DISABLE BIT(0) +/* mclk 1 disable */ +#define SOF_DAI_INTEL_SSP_MCLK_1_DISABLE BIT(1) +/* mclk keep active */ +#define SOF_DAI_INTEL_SSP_CLKCTRL_MCLK_KA BIT(2) +/* bclk keep active */ +#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_KA BIT(3) +/* fs keep active */ +#define SOF_DAI_INTEL_SSP_CLKCTRL_FS_KA BIT(4) +/* bclk idle */ +#define SOF_DAI_INTEL_SSP_CLKCTRL_BCLK_IDLE_HIGH BIT(5) + +/** \brief Types of DAI */ +enum sof_ipc_dai_type { + SOF_DAI_INTEL_NONE = 0, /**< None */ + SOF_DAI_INTEL_SSP, /**< Intel SSP */ + SOF_DAI_INTEL_DMIC, /**< Intel DMIC */ + SOF_DAI_INTEL_HDA, /**< Intel HD/A */ +}; + +/* SSP Configuration Request - SOF_IPC_DAI_SSP_CONFIG */ +struct sof_ipc_dai_ssp_params { + uint16_t mode; // FIXME: do we need this? + uint16_t mclk_id; + + uint32_t mclk_rate; /* mclk frequency in Hz */ + uint32_t fsync_rate; /* fsync frequency in Hz */ + uint32_t bclk_rate; /* bclk frequency in Hz */ + + /* TDM */ + uint32_t tdm_slots; + uint32_t rx_slots; + uint32_t tx_slots; + + /* data */ + uint32_t sample_valid_bits; + uint16_t tdm_slot_width; + uint16_t reserved2; /* alignment */ + + /* MCLK */ + uint32_t mclk_direction; + + uint16_t frame_pulse_width; + uint16_t tdm_per_slot_padding_flag; + uint32_t clks_control; + uint32_t quirks; // FIXME: is 32 bits enough ? + /* private data, e.g. for quirks */ + //uint32_t pdata[10]; // FIXME: would really need ~16 u32 +} __attribute__((packed)); + +/* HDA Configuration Request - SOF_IPC_DAI_HDA_CONFIG */ +struct sof_ipc_dai_hda_params { + struct sof_ipc_hdr hdr; + /* TODO */ +} __attribute__((packed)); + +/* DMIC Configuration Request - SOF_IPC_DAI_DMIC_CONFIG */ + +/* This struct is defined per 2ch PDM controller available in the platform. + * Normally it is sufficient to set the used microphone specific enables to 1 + * and keep other parameters as zero. The customizations are: + * + * 1. If a device mixes different microphones types with different polarity + * and/or the absolute polarity matters the PCM signal from a microphone + * can be inverted with the controls. + * + * 2. If the microphones in a stereo pair do not appear in captured stream + * in desired order due to board schematics choises they can be swapped with + * the clk_edge parameter. + * + * 3. If PDM bit errors are seen in capture (poor quality) the skew parameter + * that delays the sampling time of data by half cycles of DMIC source clock + * can be tried for improvement. However there is no guarantee for this to fix + * data integrity problems. + */ +struct sof_ipc_dai_dmic_pdm_ctrl { + uint16_t id; /* PDM controller ID */ + uint16_t enable_mic_a; /* Use A (left) channel mic (0 or 1)*/ + uint16_t enable_mic_b; /* Use B (right) channel mic (0 or 1)*/ + uint16_t polarity_mic_a; /* Optionally invert mic A signal (0 or 1) */ + uint16_t polarity_mic_b; /* Optionally invert mic B signal (0 or 1) */ + uint16_t clk_edge; /* Optionally swap data clock edge (0 or 1) */ + uint16_t skew; /* Adjust PDM data sampling vs. clock (0..15) */ + uint16_t pad; /* Make sure the total size is 4 bytes aligned */ +} __attribute__((packed)); + +/* This struct contains the global settings for all 2ch PDM controllers. The + * version number used in configuration data is checked vs. version used by + * device driver src/drivers/dmic.c need to match. It is incremented from + * initial value 1 if updates done for the to driver would alter the operation + * of the microhone. + * + * Note: The microphone clock (pdmclk_min, pdmclk_max, duty_min, duty_max) + * parameters need to be set as defined in microphone data sheet. E.g. clock + * range 1.0 - 3.2 MHz is usually supported microphones. Some microphones are + * multi-mode capable and there may be denied mic clock frequencies between + * the modes. In such case set the clock range limits of the desired mode to + * avoid the driver to set clock to an illegal rate. + * + * The duty cycle could be set to 48-52% if not known. Generally these + * parameters can be altered within data sheet specified limits to match + * required audio application performance power. + * + * The microphone clock needs to be usually about 50-80 times the used audio + * sample rate. With highest sample rates above 48 kHz this can relaxed + * somewhat. + */ +struct sof_ipc_dai_dmic_params { + uint32_t driver_ipc_version; /* Version (1..N) */ + uint32_t pdmclk_min; /* Minimum microphone clock in Hz (100000..N) */ + uint32_t pdmclk_max; /* Maximum microphone clock in Hz (min...N) */ + uint32_t fifo_fs_a; /* FIFO A sample rate in Hz (8000..96000) */ + uint32_t fifo_fs_b; /* FIFO B sample rate in Hz (8000..96000) */ + uint16_t fifo_bits_a; /* FIFO A word length (16 or 32) */ + uint16_t fifo_bits_b; /* FIFO B word length (16 or 32) */ + uint16_t duty_min; /* Min. mic clock duty cycle in % (20..80) */ + uint16_t duty_max; /* Max. mic clock duty cycle in % (min..80) */ + uint32_t num_pdm_active; /* Number of active pdm controllers */ + /* variable number of pdm controller config */ + struct sof_ipc_dai_dmic_pdm_ctrl pdm[0]; +} __attribute__((packed)); + +/* general purpose DAI configuration */ +struct sof_ipc_dai_config { + struct sof_ipc_hdr hdr; + enum sof_ipc_dai_type type; + uint32_t dai_index; /* index of this type dai */ + + /* physical protocol and clocking */ + uint16_t format; /* SOF_DAI_FMT_ */ + uint16_t reserved; /* alignment */ + + /* HW specific data */ + union { + struct sof_ipc_dai_ssp_params ssp; + struct sof_ipc_dai_hda_params hda; + struct sof_ipc_dai_dmic_params dmic; + }; +}; + +/* + * Stream configuration. + */ + +#define SOF_IPC_MAX_CHANNELS 8 + +/* channel positions - uses same values as ALSA */ +enum sof_ipc_chmap { + SOF_CHMAP_UNKNOWN = 0, + SOF_CHMAP_NA, /* N/A, silent */ + SOF_CHMAP_MONO, /* mono stream */ + SOF_CHMAP_FL, /* front left */ + SOF_CHMAP_FR, /* front right */ + SOF_CHMAP_RL, /* rear left */ + SOF_CHMAP_RR, /* rear right */ + SOF_CHMAP_FC, /* front centre */ + SOF_CHMAP_LFE, /* LFE */ + SOF_CHMAP_SL, /* side left */ + SOF_CHMAP_SR, /* side right */ + SOF_CHMAP_RC, /* rear centre */ + SOF_CHMAP_FLC, /* front left centre */ + SOF_CHMAP_FRC, /* front right centre */ + SOF_CHMAP_RLC, /* rear left centre */ + SOF_CHMAP_RRC, /* rear right centre */ + SOF_CHMAP_FLW, /* front left wide */ + SOF_CHMAP_FRW, /* front right wide */ + SOF_CHMAP_FLH, /* front left high */ + SOF_CHMAP_FCH, /* front centre high */ + SOF_CHMAP_FRH, /* front right high */ + SOF_CHMAP_TC, /* top centre */ + SOF_CHMAP_TFL, /* top front left */ + SOF_CHMAP_TFR, /* top front right */ + SOF_CHMAP_TFC, /* top front centre */ + SOF_CHMAP_TRL, /* top rear left */ + SOF_CHMAP_TRR, /* top rear right */ + SOF_CHMAP_TRC, /* top rear centre */ + SOF_CHMAP_TFLC, /* top front left centre */ + SOF_CHMAP_TFRC, /* top front right centre */ + SOF_CHMAP_TSL, /* top side left */ + SOF_CHMAP_TSR, /* top side right */ + SOF_CHMAP_LLFE, /* left LFE */ + SOF_CHMAP_RLFE, /* right LFE */ + SOF_CHMAP_BC, /* bottom centre */ + SOF_CHMAP_BLC, /* bottom left centre */ + SOF_CHMAP_BRC, /* bottom right centre */ + SOF_CHMAP_LAST = SOF_CHMAP_BRC, +}; + +/* common sample rates for use in masks */ +#define SOF_RATE_8000 (1 << 0) /* 8000Hz */ +#define SOF_RATE_11025 (1 << 1) /* 11025Hz */ +#define SOF_RATE_12000 (1 << 2) /* 12000Hz */ +#define SOF_RATE_16000 (1 << 3) /* 16000Hz */ +#define SOF_RATE_22050 (1 << 4) /* 22050Hz */ +#define SOF_RATE_24000 (1 << 5) /* 24000Hz */ +#define SOF_RATE_32000 (1 << 6) /* 32000Hz */ +#define SOF_RATE_44100 (1 << 7) /* 44100Hz */ +#define SOF_RATE_48000 (1 << 8) /* 48000Hz */ +#define SOF_RATE_64000 (1 << 9) /* 64000Hz */ +#define SOF_RATE_88200 (1 << 10) /* 88200Hz */ +#define SOF_RATE_96000 (1 << 11) /* 96000Hz */ +#define SOF_RATE_176400 (1 << 12) /* 176400Hz */ +#define SOF_RATE_192000 (1 << 13) /* 192000Hz */ + +/* continuous and non-standard rates for flexibility */ +#define SOF_RATE_CONTINUOUS (1 << 30) /* range */ +#define SOF_RATE_KNOT (1 << 31) /* non-continuous */ + +/* stream PCM frame format */ +enum sof_ipc_frame { + SOF_IPC_FRAME_S16_LE = 0, + SOF_IPC_FRAME_S24_4LE, + SOF_IPC_FRAME_S32_LE, + SOF_IPC_FRAME_FLOAT, + /* other formats here */ +}; + +/* stream buffer format */ +enum sof_ipc_buffer_format { + SOF_IPC_BUFFER_INTERLEAVED, + SOF_IPC_BUFFER_NONINTERLEAVED, + /* other formats here */ +}; + +/* stream direction */ +enum sof_ipc_stream_direction { + SOF_IPC_STREAM_PLAYBACK = 0, + SOF_IPC_STREAM_CAPTURE, +}; + +/* stream ring info */ +struct sof_ipc_host_buffer { + uint32_t phy_addr; + uint32_t pages; + uint32_t size; + uint32_t offset; +} __attribute__((packed)); + +struct sof_ipc_stream_params { + struct sof_ipc_host_buffer buffer; + enum sof_ipc_stream_direction direction; + enum sof_ipc_frame frame_fmt; + enum sof_ipc_buffer_format buffer_fmt; + uint32_t host_dma_ch; + uint32_t be_dma_ch; + uint32_t rate; + uint32_t channels; + uint32_t sample_valid_bytes; + uint32_t sample_container_bytes; + /* for notifying host period has completed - 0 means no period IRQ */ + uint32_t host_period_bytes; + enum sof_ipc_chmap chmap[SOF_IPC_MAX_CHANNELS]; /* channel map */ +} __attribute__((packed)); + +/* PCM params info - SOF_IPC_STREAM_PCM_PARAMS */ +struct sof_ipc_pcm_params { + struct sof_ipc_hdr hdr; + uint32_t comp_id; + struct sof_ipc_stream_params params; +} __attribute__((packed)); + +/* PCM params info reply - SOF_IPC_STREAM_PCM_PARAMS_REPLY */ +struct sof_ipc_pcm_params_reply { + struct sof_ipc_reply rhdr; + uint32_t comp_id; + uint32_t posn_offset; +} __attribute__((packed)); + +/* compressed vorbis params - SOF_IPC_STREAM_VORBIS_PARAMS */ +struct sof_ipc_vorbis_params { + struct sof_ipc_hdr hdr; + uint32_t comp_id; + struct sof_ipc_stream_params params; + /* TODO */ +} __attribute__((packed)); + +/* free stream - SOF_IPC_STREAM_PCM_PARAMS */ +struct sof_ipc_stream { + struct sof_ipc_hdr hdr; + uint32_t comp_id; +} __attribute__((packed)); + +/* flags indicating which time stamps are in sync with each other */ +#define SOF_TIME_HOST_SYNC (1 << 0) +#define SOF_TIME_DAI_SYNC (1 << 1) +#define SOF_TIME_WALL_SYNC (1 << 2) +#define SOF_TIME_STAMP_SYNC (1 << 3) + +/* flags indicating which time stamps are valid */ +#define SOF_TIME_HOST_VALID (1 << 8) +#define SOF_TIME_DAI_VALID (1 << 9) +#define SOF_TIME_WALL_VALID (1 << 10) +#define SOF_TIME_STAMP_VALID (1 << 11) + +/* flags indicating time stamps are 64bit else 3use low 32bit */ +#define SOF_TIME_HOST_64 (1 << 16) +#define SOF_TIME_DAI_64 (1 << 17) +#define SOF_TIME_WALL_64 (1 << 18) +#define SOF_TIME_STAMP_64 (1 << 19) + +struct sof_ipc_stream_posn { + struct sof_ipc_reply rhdr; + uint32_t comp_id; /* host component ID */ + uint32_t flags; /* SOF_TIME_ */ + uint32_t wallclock_hz; /* frequency of wallclock in Hz */ + uint32_t timestamp_ns; /* resolution of timestamp in ns */ + uint64_t host_posn; /* host DMA position in bytes */ + uint64_t dai_posn; /* DAI DMA position in bytes */ + uint64_t comp_posn; /* comp position in bytes */ + uint64_t wallclock; /* audio wall clock */ + uint64_t timestamp; /* system time stamp */ + uint32_t xrun_comp_id; /* comp ID of XRUN component */ + int32_t xrun_size; /* XRUN size in bytes */ +} __attribute__((packed)); + +/* + * Component Mixers and Controls + */ + +/* control data type and direction */ +enum sof_ipc_ctrl_type { + /* per channel data - uses struct sof_ipc_ctrl_value_chan */ + SOF_CTRL_TYPE_VALUE_CHAN_GET = 0, + SOF_CTRL_TYPE_VALUE_CHAN_SET, + /* component data - uses struct sof_ipc_ctrl_value_comp */ + SOF_CTRL_TYPE_VALUE_COMP_GET, + SOF_CTRL_TYPE_VALUE_COMP_SET, + /* bespoke data - struct struct sof_abi_hdr */ + SOF_CTRL_TYPE_DATA_GET, + SOF_CTRL_TYPE_DATA_SET, +}; + +/* control command type */ +enum sof_ipc_ctrl_cmd { + SOF_CTRL_CMD_VOLUME = 0, /* maps to ALSA volume style controls */ + SOF_CTRL_CMD_ENUM, /* maps to ALSA enum style controls */ + SOF_CTRL_CMD_SWITCH, /* maps to ALSA switch style controls */ + SOF_CTRL_CMD_BINARY, /* maps to ALSA binary style controls */ +}; + +/* generic channel mapped value data */ +struct sof_ipc_ctrl_value_chan { + enum sof_ipc_chmap channel; + uint32_t value; +} __attribute__((packed)); + +/* generic component mapped value data */ +struct sof_ipc_ctrl_value_comp { + uint32_t index; /* component source/sink/control index in control */ + union { + uint32_t uvalue; + int32_t svalue; + }; +} __attribute__((packed)); + +/* generic control data */ +struct sof_ipc_ctrl_data { + struct sof_ipc_reply rhdr; + uint32_t comp_id; + + /* control access and data type */ + enum sof_ipc_ctrl_type type; + enum sof_ipc_ctrl_cmd cmd; + uint32_t index; /* control index for comps > 1 control */ + + /* control data - can either be appended or DMAed from host */ + struct sof_ipc_host_buffer buffer; + uint32_t num_elems; /* in array elems or bytes */ + + /* control data - add new types if needed */ + union { + /* channel values can be used by volume type controls */ + struct sof_ipc_ctrl_value_chan chanv[0]; + /* component values used by routing controls like mux, mixer */ + struct sof_ipc_ctrl_value_comp compv[0]; + /* data can be used by binary controls */ + struct sof_abi_hdr data[0]; + }; +} __attribute__((packed)); + +/* + * Component + */ + +/* 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_SPLITTER, + SOF_COMP_TONE, + SOF_COMP_SWITCH, + SOF_COMP_BUFFER, + SOF_COMP_EQ_IIR, + SOF_COMP_EQ_FIR, + SOF_COMP_FILEREAD, /* host test based file IO */ + SOF_COMP_FILEWRITE, /* host test based file IO */ +}; + +/* XRUN action for component */ +#define SOF_XRUN_STOP 1 /* stop stream */ +#define SOF_XRUN_UNDER_ZERO 2 /* send 0s to sink */ +#define SOF_XRUN_OVER_NULL 4 /* send data to NULL */ + +/* create new generic component - SOF_IPC_TPLG_COMP_NEW */ +struct sof_ipc_comp { + struct sof_ipc_hdr hdr; + uint32_t id; + enum sof_comp_type type; + uint32_t pipeline_id; +} __attribute__((packed)); + +/* + * Component Buffers + */ + +/* create new component buffer - SOF_IPC_TPLG_BUFFER_NEW */ +struct sof_ipc_buffer { + struct sof_ipc_comp comp; + uint32_t size; /* buffer size in bytes */ + uint32_t caps; /* SOF_MEM_CAPS_ */ +} __attribute__((packed)); + +/* generic component config data - must always be after struct sof_ipc_comp */ +struct sof_ipc_comp_config { + uint32_t periods_sink; /* 0 means variable */ + uint32_t periods_source; /* 0 means variable */ + uint32_t preload_count; /* how many periods to preload */ + enum sof_ipc_frame frame_fmt; + uint32_t xrun_action; +} __attribute__((packed)); + +/* generic host component */ +struct sof_ipc_comp_host { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + enum sof_ipc_stream_direction direction; + uint32_t no_irq; /* don't send periodic IRQ to host/DSP */ + uint32_t dmac_config; /* DMA engine specific */ +} __attribute__((packed)); + +/* generic DAI component */ +struct sof_ipc_comp_dai { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + enum sof_ipc_stream_direction direction; + uint32_t dai_index; /* index of this type dai */ + enum sof_ipc_dai_type type; + uint32_t dmac_config; /* DMA engine specific */ +} __attribute__((packed)); + +/* generic mixer component */ +struct sof_ipc_comp_mixer { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* volume ramping types */ +enum sof_volume_ramp { + SOF_VOLUME_LINEAR = 0, + SOF_VOLUME_LOG, + SOF_VOLUME_LINEAR_ZC, + SOF_VOLUME_LOG_ZC, +}; + +/* generic volume component */ +struct sof_ipc_comp_volume { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + uint32_t channels; + uint32_t min_value; + uint32_t max_value; + enum sof_volume_ramp ramp; + uint32_t initial_ramp; /* ramp space in ms */ +} __attribute__((packed)); + +/* generic SRC component */ +struct sof_ipc_comp_src { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + /* either source or sink rate must be non zero */ + uint32_t source_rate; /* source rate or 0 for variable */ + uint32_t sink_rate; /* sink rate or 0 for variable */ + uint32_t rate_mask; /* SOF_RATE_ supported rates */ +} __attribute__((packed)); + +/* generic MUX component */ +struct sof_ipc_comp_mux { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; +} __attribute__((packed)); + +/* generic tone generator component */ +struct sof_ipc_comp_tone { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + int32_t sample_rate; + int32_t frequency; + int32_t amplitude; + int32_t freq_mult; + int32_t ampl_mult; + int32_t length; + int32_t period; + int32_t repeats; + int32_t ramp_step; +} __attribute__((packed)); + +/* FIR equalizer component */ +struct sof_ipc_comp_eq_fir { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + uint32_t size; + unsigned char data[0]; +} __attribute__((packed)); + +/* IIR equalizer component */ +struct sof_ipc_comp_eq_iir { + struct sof_ipc_comp comp; + struct sof_ipc_comp_config config; + uint32_t size; + unsigned char data[0]; +} __attribute__((packed)); + +/** \brief Types of EFFECT */ +enum sof_ipc_effect_type { + SOF_EFFECT_NONE = 0, /**< None */ + SOF_EFFECT_INTEL_EQFIR, /**< Intel FIR */ + SOF_EFFECT_INTEL_EQIIR, /**< Intel IIR */ +}; + +/* frees components, buffers and pipelines + * SOF_IPC_TPLG_COMP_FREE, SOF_IPC_TPLG_PIPE_FREE, SOF_IPC_TPLG_BUFFER_FREE + */ +struct sof_ipc_free { + struct sof_ipc_hdr hdr; + uint32_t id; +} __attribute__((packed)); + +struct sof_ipc_comp_reply { + struct sof_ipc_reply rhdr; + uint32_t id; + uint32_t offset; +} __attribute__((packed)); + +/* + * Pipeline + */ + +/* new pipeline - SOF_IPC_TPLG_PIPE_NEW */ +struct sof_ipc_pipe_new { + struct sof_ipc_hdr hdr; + uint32_t comp_id; /* component id for pipeline */ + uint32_t pipeline_id; /* pipeline id */ + uint32_t sched_id; /* sheduling component id */ + uint32_t core; /* core we run on */ + uint32_t deadline; /* execution completion deadline in us*/ + uint32_t priority; /* priority level 0 (low) to 10 (max) */ + uint32_t mips; /* worst case instruction count per period */ + uint32_t frames_per_sched;/* output frames of pipeline, 0 is variable */ + uint32_t xrun_limit_usecs; /* report xruns greater than limit */ + + /* non zero if timer scheduled, otherwise DAI DMA irq scheduled */ + uint32_t timer_delay; +} __attribute__((packed)); + +/* pipeline construction complete - SOF_IPC_TPLG_PIPE_COMPLETE */ +struct sof_ipc_pipe_ready { + struct sof_ipc_hdr hdr; + uint32_t comp_id; +} __attribute__((packed)); + +struct sof_ipc_pipe_free { + struct sof_ipc_hdr hdr; + uint32_t comp_id; +} __attribute__((packed)); + +/* connect two components in pipeline - SOF_IPC_TPLG_COMP_CONNECT */ +struct sof_ipc_pipe_comp_connect { + struct sof_ipc_hdr hdr; + uint32_t source_id; + uint32_t sink_id; +} __attribute__((packed)); + +/* + * PM + */ + +/* PM context element */ +struct sof_ipc_pm_ctx_elem { + uint32_t type; + uint32_t size; + uint64_t addr; +} __attribute__((packed)); + +/* + * PM context - SOF_IPC_PM_CTX_SAVE, SOF_IPC_PM_CTX_RESTORE, + * SOF_IPC_PM_CTX_SIZE + */ +struct sof_ipc_pm_ctx { + struct sof_ipc_hdr hdr; + struct sof_ipc_host_buffer buffer; + uint32_t num_elems; + uint32_t size; + struct sof_ipc_pm_ctx_elem elems[]; +}; + +/* enable or disable cores - SOF_IPC_PM_CORE_ENABLE */ +struct sof_ipc_pm_core_config { + struct sof_ipc_hdr hdr; + uint32_t enable_mask; +}; + +/* + * Firmware boot and version + */ + +#define SOF_IPC_MAX_ELEMS 16 + +/* extended data types that can be appended onto end of sof_ipc_fw_ready */ +enum sof_ipc_ext_data { + SOF_IPC_EXT_DMA_BUFFER = 0, + SOF_IPC_EXT_WINDOW, +}; + +/* FW version - SOF_IPC_GLB_VERSION */ +struct sof_ipc_fw_version { + uint16_t major; + uint16_t minor; + uint16_t build; + uint8_t date[12]; + uint8_t time[10]; + uint8_t tag[6]; + uint16_t abi_version; + /* Make sure the total size is 4 bytes aligned */ +} __attribute__((packed)); + +/* FW ready Message - sent by firmware when boot has completed */ +struct sof_ipc_fw_ready { + struct sof_ipc_hdr hdr; + uint32_t dspbox_offset; /* dsp initiated IPC mailbox */ + uint32_t hostbox_offset; /* host initiated IPC mailbox */ + uint32_t dspbox_size; + uint32_t hostbox_size; + struct sof_ipc_fw_version version; +} __attribute__((packed)); + +/* + * Extended Firmware data. All optional, depends on platform/arch. + */ + +enum sof_ipc_region { + SOF_IPC_REGION_DOWNBOX = 0, + SOF_IPC_REGION_UPBOX, + SOF_IPC_REGION_TRACE, + SOF_IPC_REGION_DEBUG, + SOF_IPC_REGION_STREAM, + SOF_IPC_REGION_REGS, + SOF_IPC_REGION_EXCEPTION, +}; + +struct sof_ipc_ext_data_hdr { + struct sof_ipc_hdr hdr; + enum sof_ipc_ext_data type; /* SOF_IPC_EXT_ */ +}; + +struct sof_ipc_dma_buffer_elem { + enum sof_ipc_region type; + uint32_t id; /* platform specific - used to map to host memory */ + struct sof_ipc_host_buffer buffer; +}; + +/* extended data DMA buffers for IPC, trace and debug */ +struct sof_ipc_dma_buffer_data { + struct sof_ipc_ext_data_hdr ext_hdr; + uint32_t num_buffers; + /* host files in buffer[n].buffer */ + struct sof_ipc_dma_buffer_elem buffer[]; +} __attribute__((packed)); + +struct sof_ipc_window_elem { + enum sof_ipc_region type; + uint32_t id; /* platform specific - used to map to host memory */ + uint32_t flags; /* R, W, RW, etc - to define */ + uint32_t size; /* size of region in bytes */ + /* offset in window region as windows can be partitioned */ + uint32_t offset; +}; + +/* extended data memory windows for IPC, trace and debug */ +struct sof_ipc_window { + struct sof_ipc_ext_data_hdr ext_hdr; + uint32_t num_windows; + struct sof_ipc_window_elem window[]; +} __attribute__((packed)); + +/* + * DMA for Trace + */ + +/* DMA for Trace params info - SOF_IPC_DEBUG_DMA_PARAMS */ +struct sof_ipc_dma_trace_params { + struct sof_ipc_hdr hdr; + struct sof_ipc_host_buffer buffer; + uint32_t stream_tag; +} __attribute__((packed)); + +/* DMA for Trace params info - SOF_IPC_DEBUG_DMA_PARAMS */ +struct sof_ipc_dma_trace_posn { + struct sof_ipc_reply rhdr; + uint32_t host_offset; /* Offset of DMA host buffer */ + uint32_t overflow; /* overflow bytes if any */ + uint32_t messages; /* total trace messages */ +} __attribute__((packed)); + +/* + * Architecture specific debug + */ + +/* Xtensa Firmware Oops data */ +struct sof_ipc_dsp_oops_xtensa { + uint32_t exccause; + uint32_t excvaddr; + uint32_t ps; + uint32_t epc1; + uint32_t epc2; + uint32_t epc3; + uint32_t epc4; + uint32_t epc5; + uint32_t epc6; + uint32_t epc7; + uint32_t eps2; + uint32_t eps3; + uint32_t eps4; + uint32_t eps5; + uint32_t eps6; + uint32_t eps7; + uint32_t depc; + uint32_t intenable; + uint32_t interrupt; + uint32_t sar; + uint32_t stack; +} __attribute__((packed)); + +/* + * Commom debug + */ + +/* panic info include filename and line number */ +struct sof_ipc_panic_info { + char filename[32]; + uint32_t linenum; +} __attribute__((packed)); + +/** @}*/ + +#endif diff --git a/tools/logger/sof/uapi/logging.h b/tools/logger/sof/uapi/logging.h new file mode 100644 index 000000000000..c5423fc111a5 --- /dev/null +++ b/tools/logger/sof/uapi/logging.h @@ -0,0 +1,119 @@ +/* + * 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: Bartosz Kokoszko + * Artur Kloniecki + */ + +#ifndef __INCLUDE_LOGGING__ +#define __INCLUDE_LOGGING__ + +#include + +/* + * Host system time. + * + * This property is used by the driver to pass down information about + * current system time. It is expressed in us. + * FW translates timestamps (in log entries, probe pockets) to this time + * domain. + * + * (cavs: SystemTime). + */ +struct system_time { + uint32_t val_l; /* Lower dword of current host time value */ + uint32_t val_u; /* Upper dword of current host time value */ +}; + +/* trace event classes - high 8 bits*/ +#define TRACE_CLASS_IRQ (1 << 24) +#define TRACE_CLASS_IPC (2 << 24) +#define TRACE_CLASS_PIPE (3 << 24) +#define TRACE_CLASS_HOST (4 << 24) +#define TRACE_CLASS_DAI (5 << 24) +#define TRACE_CLASS_DMA (6 << 24) +#define TRACE_CLASS_SSP (7 << 24) +#define TRACE_CLASS_COMP (8 << 24) +#define TRACE_CLASS_WAIT (9 << 24) +#define TRACE_CLASS_LOCK (10 << 24) +#define TRACE_CLASS_MEM (11 << 24) +#define TRACE_CLASS_MIXER (12 << 24) +#define TRACE_CLASS_BUFFER (13 << 24) +#define TRACE_CLASS_VOLUME (14 << 24) +#define TRACE_CLASS_SWITCH (15 << 24) +#define TRACE_CLASS_MUX (16 << 24) +#define TRACE_CLASS_SRC (17 << 24) +#define TRACE_CLASS_TONE (18 << 24) +#define TRACE_CLASS_EQ_FIR (19 << 24) +#define TRACE_CLASS_EQ_IIR (20 << 24) +#define TRACE_CLASS_SA (21 << 24) +#define TRACE_CLASS_DMIC (22 << 24) +#define TRACE_CLASS_POWER (23 << 24) +#define TRACE_CLASS_IDC (24 << 24) +#define TRACE_CLASS_CPU (25 << 24) + +#define LOG_ENABLE 1 /* Enable logging */ +#define LOG_DISABLE 0 /* Disable logging */ + +#define LOG_LEVEL_CRITICAL 1 /* (FDK fatal) */ +#define LOG_LEVEL_VERBOSE 2 + +/* + * Layout of a log fifo. + */ +struct log_buffer_layout { + uint32_t read_ptr; /*read pointer */ + uint32_t write_ptr; /* write pointer */ + uint32_t buffer[0]; /* buffer */ +}; + +/* + * Log buffer status reported by FW. + */ +struct log_buffer_status { + uint32_t core_id; /* ID of core that logged to other half */ +}; + +#define TRACE_ID_LENGTH 12 + +/* + * Log entry header. + * + * The header is followed by an array of arguments (uint32_t[]). + * Number of arguments is specified by the params_num field of log_entry, + * and is 0-based value (entry_len=0 means there is 1 argument). + */ +struct log_entry_header { + uint32_t id_0 : TRACE_ID_LENGTH; /* Pipeline ID */ + uint32_t id_1 : TRACE_ID_LENGTH; /* Component ID */ + uint32_t core_id : 8; /* Reporting core's id */ + + uint64_t timestamp; /* Timestamp (in dsp ticks) */ + uint32_t log_entry_address; /* Address of log entry in ELF */ +} __attribute__((__packed__)); + +#endif //#ifndef __INCLUDE_LOGGING__ diff --git a/tools/rimage/keys/Makefile.am b/tools/rimage/keys/Makefile.am new file mode 100644 index 000000000000..06fe3071317a --- /dev/null +++ b/tools/rimage/keys/Makefile.am @@ -0,0 +1,9 @@ +install-data-local: + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(PEM_KEY_PREFIX); + $(INSTALL_DATA) otc_private_key.pem $(PEM_KEY_PREFIX) + $(INSTALL_DATA) otc_public_key.pem $(PEM_KEY_PREFIX) + +EXTRA_DIST = \ + otc_private_key.pem \ + otc_public_key.pem \ No newline at end of file diff --git a/tools/rimage/keys/README b/tools/rimage/keys/README new file mode 100644 index 000000000000..3ece70cad290 --- /dev/null +++ b/tools/rimage/keys/README @@ -0,0 +1,34 @@ +About +===== + +Firmware binary signing is for audio DSP is mandatory on Intel products from +Skylake onwards. i.e. no code signing on Baytrail, Cherrytrail, Braswell, +Haswell and Broadwell but mandatory on Skylake, Kabylake, Apollolake and +Cannonlake. + +rimage can now sign firmware binaries for Apollolake and Cannonlake targets. +This is done automatically as part of the "make bin" part of the build. + + +Key Pairs +========= + +The key included here is the Intel OTC (Opensource Technology Center) community +development key. It can be freely used by anyone and is intended for reference +board makers and firmware developers. + +** This key is NOT intended for locking down firmware on end user production +devices since the "private" key has been published here. A new key pair must +be genrated for securing firmware ! ** + +RSA Private and Public keys are generated as follows :- + +openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048 +openssl rsa -pubout -in private_key.pem -out public_key.pem + +The public key needs to be programmed into the OEM Key manifest (cavsManifest0) +within the BIOS in order to verify code signed with the private key. +Intel supplies tools to board makers to stitch the public key into the BIOS. + +The private key is used by rimage to sign the SOF binary. It should be kept +secret and secure for production signing. \ No newline at end of file diff --git a/tools/rimage/keys/otc_private_key.pem b/tools/rimage/keys/otc_private_key.pem new file mode 100644 index 000000000000..03ad749260b7 --- /dev/null +++ b/tools/rimage/keys/otc_private_key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC5Q68ZJyiWWrXb +TSjlj4I/UmgusmIfv5+MCtinahekLPasIvoBhmEAr/TBizlfhj2/VN4FKNsqy7HR +QGn+iLhqnVrzpEVug4EQIpkFxTnycKMQPSDvpIqq8VL9pUCvKokSMub0oTCwoxjJ +V81wJy+NE2AnamjtnuJEXqim9U5CGjsnVNSktv/YPbso/LYFjH658Fz5QGgWfbgi +BPNFwMvemSFOIXw2J2B91ayP9ZJeI2tLyEP9EMeQqU3Gd8T5LfHIUmibpPFe1JDM +s4HmIEs7Iay03EfwjEWLVd0P/fxv9I9YNTZAi+7o8IyrTNRHDsH55efW7V58GwfS +66po4QCFAgMBAAECggEBALf7IlktTR47iRv2/WUz5hnyQWoWVmHHD6+oWc2wCzhM +Os9pkLOQ+qYPF1ZZZ6mYi5uFsVKYZ0aRsM3oVRqkNdgS2m7YtObyC2q1oRdc7JX6 +C8Wlnx69XcQzEcK4qIsMB8Gd8UQBC3RvE79nxanaEFveYP/jqb5IqdVR19SuCYCU +EZurwwAnYeLg0VSSdVQHSGVMlHkDwhgVAvp5NryPXhml51pT0gzUwnvJOsUcrc0m +tqUa2yu7/Qju1/JtFL98RgW4x3mSo4TZO3B/d664pWPOxL72zCt7bD9s06ILZmga +z1oMLMwTaNaeYIBaRvjmssKOqLXmDvfc415V82SwMYUCgYEA2p2At6acrD8Xx5GO +GeCeUbZzm0Ke9zql1W+Diq89UroFX/i9XO9Mb/ZfwouC+5n3iLjyCG7jIaIwYAyV +2qim9sINeieepM54HqYz0235nX5CqLHPDobYLn5tsbNYvXYBWiyjRppG+cnprMBk +O6vLNXNc4sRemgbcmwT3sEYLLo8CgYEA2PInWZx0JoEXriEgefv/IZeyCjpaS9uH +OOaPVAJTJPaaZhazA4ANV2bzrQAigiXbOgzPkXyldy7T7d/gHfVYnHbyhGwMEa6u +WMnj5qFXPI0hYOOrJbqXofbfGkKC996eoQybnvE0WdIwscySIki1zAenE/5nVdCJ +HLwK9xXMKasCgYA/ZxSQrsqbjgTYhVdgG+vuqOqoac7uxtyXpSrSSvaPCpJKfjp1 +PJW/lwW4x3tqewH2biUL2xUWiRJcmOnRK76YrDj6Z4k0JQljYjJ/rFKLobW1dTQm +82a5PUOVGP2wnQvRWkbUUCQrh6q0xmuLfsyFqPqUbf090KWkc/Fd90KA8wKBgG6C +q9jSAbi7ebyR02FQJJ6QD3l2UBjkMvWhPNGmfYQOuofWeEoIKMOlBevSbcGuVwYz +EGkj/YXArOQ3borUN9c8ID2kbGF1ggpojVcmSLHnkmEwmDYX3rX6c5uE1gI9vMB9 +E6jbZbd7gqKPesFMGI9eNpXQugLUv4OLpmpHCEERAoGAMF5P9jSe3JirlZ7WaH7A +I1I23L3oZfkmrcxP7B860k1ZLHDtx/MtWLkb609fq1Q2lqRuvdoaur1kW+Rv9IHS +Db8cznu9jIz3OzmJ735lHDpomylzt0+nxL5rrUnoTyMsDK0kIWs03JhPYc0+S2Ip +lkkvYQHB1eUUCxMnTgzWRr4= +-----END PRIVATE KEY----- diff --git a/tools/rimage/keys/otc_public_key.pem b/tools/rimage/keys/otc_public_key.pem new file mode 100644 index 000000000000..b8662bda0192 --- /dev/null +++ b/tools/rimage/keys/otc_public_key.pem @@ -0,0 +1,9 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUOvGScollq1200o5Y+C +P1JoLrJiH7+fjArYp2oXpCz2rCL6AYZhAK/0wYs5X4Y9v1TeBSjbKsux0UBp/oi4 +ap1a86RFboOBECKZBcU58nCjED0g76SKqvFS/aVAryqJEjLm9KEwsKMYyVfNcCcv +jRNgJ2po7Z7iRF6opvVOQho7J1TUpLb/2D27KPy2BYx+ufBc+UBoFn24IgTzRcDL +3pkhTiF8NidgfdWsj/WSXiNrS8hD/RDHkKlNxnfE+S3xyFJom6TxXtSQzLOB5iBL +OyGstNxH8IxFi1XdD/38b/SPWDU2QIvu6PCMq0zURw7B+eXn1u1efBsH0uuqaOEA +hQIDAQAB +-----END PUBLIC KEY----- diff --git a/tools/scripts/pretty-macro.sh b/tools/scripts/pretty-macro.sh new file mode 100755 index 000000000000..c01b4453dfcb --- /dev/null +++ b/tools/scripts/pretty-macro.sh @@ -0,0 +1,123 @@ +#!/bin/bash +# Simple script for printing preprocessor output in human-readable fashion +# Mostly useful for debugging macro metaprogramming +# For more detailed useage, use --h option. +enstyle(){ + awk \ + -v style="${1}" \ + -v regex="${2}" \ +'{\ + gsub(\ + regex,\ + "\033["style"m&\033[0m"\ + );\ + print;\ +}' +} +styleUserRegexp() +{ + if [[ "${USER_REGEXP}" != "" ]] ; then + enstyle "7;33" "${USER_REGEXP}" + else + tee # pipe that does nothing, just pass input to output + fi +} +styleAll(){ + if [[ "${COLORISE}" == "1" ]] ; then + enstyle "33" '[{}()\\[\\],;]'\ + | enstyle "1;31" '->|\\.|&'\ + | enstyle "1;35" '\\s(if|while|do|for|return|exit|panic)'\ + | enstyle "1;36" '(u?int(32|64)_t|void|struct|const|char|volatile|static|unsigned|long)\\s*\\**'\ + | enstyle "32" '0x[A-Za-z0-9]+'\ + | styleUserRegexp + else + tee # pipe that does nothing, just pass input to output + fi +} + +pretty_macro(){ + params="${1}" + infile="${2}" + + gcc_params="${params} -E -dD ${infile}" + if [[ "${SHOW_ERR}" == "0" ]] ; then + gcc_params+=" 2>/dev/null" + fi + cmd="gcc ${gcc_params}" + if [[ "${VERBOSE}" == "1" ]] ; then + echo "params are: [${params}]" + echo "infile is: [${infile}]" + echo "cmd is: [${cmd}]" + fi + + bash -c "$cmd" \ + | sed\ + -e 's/;\ /;\n\t/g'\ + -e 's/{\ /\n{\n\t/g'\ + -e 's/}[\ ]*/\n}\n/g'\ + | styleAll +} + +VERBOSE=0 +SHOW_ERR=0 +COLORISE=0 +gcc_params="" +USER_REGEXP="" +while getopts ":f:I:u:hevc" opt; do + case ${opt} in + h) #usage + echo \ +"usage: $0 [-hevc] (-f IN_FILE) [-I INCLUDE_DIR] [-u USER_REGEXP] + +Expands c macroes in files given with -f flag and prints them prettily. + +mandatory arguments: + -f IN_FILE input file to gcc +optional arguments: + -h show this help message and exit + -e don't redirect gcc errors to /dev/null + -v show verbose output + -c color the output + -u USER_REGEXP highlights user defined regular expression + -I INCLUDE_DIR pass INCLUDE_DIR to gcc with -I option +" + exit 0 + ;; + u) + USER_REGEXP="${OPTARG}" + ;; + e) + SHOW_ERR=1 + ;; + v) + VERBOSE=1 + ;; + c) + COLORISE=1 + ;; + I) + gcc_params+=" -I ${OPTARG}" + ;; + f) + infiles+=("${OPTARG}") + ;; + \?) + echo "Invalid option: -${OPTARG}" >&2 + exit 1 + ;; + :) + echo "Option -${OPTARG} requires an argument." >&2 + exit 1 + ;; + esac +done +if [[ "${VERBOSE}" == "1" ]] ; then + echo "gcc_params are: [${gcc_params}]" + echo "infiles are: [${infiles[@]}]" + echo "user regexp is: [${USER_REGEXP}]" +fi +for file in ${infiles[@]} ; do + pretty_macro "${gcc_params}" "${file}" +done +exit 0 + diff --git a/tools/test/audio/README b/tools/test/audio/README new file mode 100644 index 000000000000..488005a190a0 --- /dev/null +++ b/tools/test/audio/README @@ -0,0 +1,64 @@ +SOF Audio Processing Components Tests +===================================== + +This is a set of test scripts to test that performance requirements +are met. The tests are currently for measured audio objective quality +parameters. The used criteria for performance is only an initial +assumption and need to be adjusted for various applications needs. + +The scripts support currently support the next list of objective +quality parameters. The test scripts need Matlab(R) [2] or GNU Octave +scientific programming language [3]. + + - Gain + - Frequency Response + - THD+N vs. Frequency + - Dynamic Range + - Attenuation of Alias Products + - Attenuation of Image Products + +Note: The metric is an effort to follow AES17 [1] recommendation for +parameters and test procedures. This was created to help developers to +quickly check their work but has not been verified to be +compliant. Professional equipment and formal calibration process is +recommended for professional applications where both accurate absolute +and relative metric is needed. + +Note: The test bench uses by default raw binary data files. It is +possible to convert with SoX (v14.4.1) [4] the raw data to e.g. wav +format for other audio tools and subjective listening. + +$ sox -b 32 -c 2 -r 48000 -L -e signed-integer fr_test_out.raw fr_test_out.wav + +For debugging purposes it is possible to switch from test scripts the +test vectors format to txt for easy manual data creation and +inspection. + + +Tests for component SRC +----------------------- + +The top level shell script to launch tests is src_test.sh. See script +src_run.sh for assumed install location of SOF host test bench +executable and component libraries. Exit code 0 indicates success and +exit code 1 indicates failed test cases. + +The default in/out rates matrix to test is defined in the beginning of +script src_test.m. The matrix can be also passed from calling function +src_test_top.m if need. + +The key objective quality parameters requiremements are in the +beginning of script src_test.m as well under comment Generic test +pass/fail criteria. + +Test run creates plots into directory "plots". Brief text format +reports are placed to directory "reports". + + +References +---------- + +[1] AES17-1015 standard, http://www.aes.org/publications/standards/search.cfm?docID=21 +[2] Matlab(R), https://www.mathworks.com/products/matlab.html +[3] GNU Octave, https://www.gnu.org/software/octave/ +[4] SoX - Sound eXchange, http://sox.sourceforge.net/ diff --git a/tools/test/audio/src_run.sh b/tools/test/audio/src_run.sh new file mode 100755 index 000000000000..41fb8c98fd86 --- /dev/null +++ b/tools/test/audio/src_run.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# SRC specifics +COMP=src +BITS_IN=$1 +BITS_OUT=$2 +FS1=$3 +FS2=$4 +FN_IN=$5 +FN_OUT=$6 + +# The HOST_ROOT path need to be retrived from SOFT .configure command +HOST_ROOT=../../../host-root +HOST_EXE=$HOST_ROOT/bin/testbench +HOST_LIB=$HOST_ROOT/lib + +# Topology +INFMT=s${BITS_IN}le +OUTFMT=s${BITS_IN}le +MCLK=24576k +TPLG=../../topology/test/test-playback-ssp2-mclk-0-I2S-${COMP}-${INFMT}-${OUTFMT}-48k-${MCLK}-nocodec.tplg + +# If binary test vectors +if [ ${FN_IN: -4} == ".raw" ]; then + CMDFMT="-b S${BITS_IN}_LE" +else + CMDFMT="" +fi + +# Run command +CMD0=$HOST_EXE +CMD1="-d -r $FS1 -R $FS2 -i $FN_IN -o $FN_OUT -t $TPLG -a src=libsof_${COMP}.so $CMDFMT" +CMD="$CMD0 $CMD1" +export LD_LIBRARY_PATH=$HOST_LIB + +# Run test bench +echo "Command: $CMD0" +echo "Arg: $CMD1" +$CMD diff --git a/tools/test/audio/src_test.m b/tools/test/audio/src_test.m new file mode 100644 index 000000000000..7e503a557d06 --- /dev/null +++ b/tools/test/audio/src_test.m @@ -0,0 +1,609 @@ +function [n_fail, n_pass, n_na] = src_test(bits_in, bits_out, fs_in_list, fs_out_list) + +%% +% src_test - test with SRC test bench objective audio quality parameters +% +% src_test(bits_in, bits_out, fs_in, fs_out) +% +% bits_in - input word length +% bits_out - output word length +% fs_in - vector of rates in +% fs_out - vector of rates out +% +% A default in-out matrix with 32 bits data is tested if the +% paremeters are omitted. +% + +%% +% Copyright (c) 2016, 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 +% + +addpath('std_utils'); +addpath('test_utils'); +addpath('../../tune/src'); +mkdir_check('plots'); +mkdir_check('reports'); + +%% Defaults for call parameters +if nargin < 1 + bits_in = 32; +end +if nargin < 2 + bits_out = 32; +end +if nargin < 3 + fs_in_list = [8e3 11025 12e3 16e3 18900 22050 24e3 32e3 44100 48e3 ... + 64e3 88.2e3 96e3 176400 192e3]; +end +if nargin < 4 + fs_out_list = [8e3 11025 12e3 16e3 18900 22050 24e3 32e3 44100 48e3]; +end + +%% Generic test pass/fail criteria +% Note that AAP and AIP are relaxed a bit from THD+N due to inclusion +% of point Fs/2 to test. The stopband of kaiser FIR is not equiripple +% and there's sufficient amount of attnuation at higher frequencies to +% meet THD+N requirement. +t.g_db_tol = 0.1; +t.thdnf_db_max = -80; +t.dr_db_min = 100; +t.aap_db_max = -60; +t.aip_db_max = -60; + +%% Defaults for test +t.fmt = 'raw'; % Can be 'raw' (fast binary) or 'txt' (debug) +t.nch = 2; % Number of channels +t.ch = 0; % 1..nch. With value 0 test a randomly selected channel. +t.bits_in = bits_in; % Input word length +t.bits_out = bits_out; % Output word length +t.full_test = 1; % 0 is quick check only, 1 is full set + +%% Show graphics or not. With visible plot windows Octave may freeze if too +% many windows are kept open. As workaround setting close windows to +% 1 shows only flashing windows while the test proceeds. With +% visibility set to to 0 only console text is seen. The plots are +% exported into plots directory in png format and can be viewed from +% there. +t.close_plot_windows = 0; % Workaround for visible windows if Octave hangs +t.visible = 'off'; % Use off for batch tests and on for interactive +t.delete = 1; % Set to 0 to inspect the audio data files + +%% Init for test loop +n_test = 7; % We have next seven test cases for SRC +n_fsi = length(fs_in_list); +n_fso = length(fs_out_list); +r.fs_in_list = fs_in_list; +r.fs_out_list = fs_out_list; +r.g = NaN(n_fsi, n_fso); +r.dr = NaN(n_fsi, n_fso); +r.fr_db = NaN(n_fsi, n_fso); +r.fr_hz = NaN(n_fsi, n_fso, 2); +r.fr3db_hz = NaN(n_fsi, n_fso); +r.thdnf = NaN(n_fsi, n_fso); +r.aap = NaN(n_fsi, n_fso); +r.aip = NaN(n_fsi, n_fso); +r.pf = NaN(n_fsi, n_fso, n_test); +r.n_fail = 0; +r.n_pass = 0; +r.n_skipped = 0; +r.n_na = 0; +%% Loop all modes to test +for b = 1:n_fso + for a = 1:n_fsi + v = -ones(n_test,1); % Set pass/fail test verdict to not executed + tn = 1; + t.fs1 = fs_in_list(a); + t.fs2 = fs_out_list(b); + v(1) = chirp_test(t); + if v(1) ~= -1 && t.full_test == 1 + %% Chirp was processed so this in/out Fs is supported + [v(2), r.g(a,b)] = g_test(t); + [v(3), r.fr_db(a,b), r.fr_hz(a,b,:), r.fr3db_hz(a,b)] = fr_test(t); + [v(4), r.thdnf(a,b)] = thdnf_test(t); + [v(5), r.dr(a,b)] = dr_test(t); + [v(6), r.aap(a,b)] = aap_test(t); + [v(7), r.aip(a,b)] = aip_test(t); + end + %% Done, store pass/fail + r.pf(a, b, :) = v; + if v(1) ~= -1 + idx = find(v > 0); + r.n_fail = r.n_fail + length(idx); + idx = find(v == 0); + r.n_pass = r.n_pass + length(idx); + idx = find(v == -1); + r.n_skipped = r.n_skipped + length(idx); + idx = find(v == -2); + r.n_na = r.n_na + length(idx); + end + end +end + +%% Print table with test summary: Gain +fn = 'reports/g_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.g, r.pf, 'Gain dB'); + +%% Print table with test summary: FR +fn = 'reports/fr_src.txt'; +print_fr(fn, fs_in_list, fs_out_list, r.fr_db, r.fr_hz, r.pf); + +%% Print table with test summary: FR +fn = 'reports/fr_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.fr3db_hz/1e3, r.pf, ... + 'Frequency response -3 dB 0 - X kHz'); + +%% Print table with test summary: THD+N vs. frequency +fn = 'reports/thdnf_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.thdnf, r.pf, ... + 'Worst-case THD+N vs. frequency'); + +%% Print table with test summary: DR +fn = 'reports/dr_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.dr, r.pf, ... + 'Dynamic range dB (CCIR-RMS)'); + +%% Print table with test summary: AAP +fn = 'reports/aap_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.aap, r.pf, ... + 'Attenuation of alias products dB'); + +%% Print table with test summary: AIP +fn = 'reports/aip_src.txt'; +print_val(fn, fs_in_list, fs_out_list, r.aip, r.pf, ... + 'Attenuation of image products dB'); + + +%% Print table with test summary: pass/fail +fn = 'reports/pf_src.txt'; +print_pf(fn, fs_in_list, fs_out_list, r.pf); + +fprintf('\n'); +fprintf('Number of passed tests = %d\n', r.n_pass); +fprintf('Number of failed tests = %d\n', r.n_fail); +fprintf('Number of non-applicable tests = %d\n', r.n_na); +fprintf('Number of skipped tests = %d\n', r.n_skipped); + + +if r.n_fail > 0 || r.n_pass < 1 + fprintf('\nERROR: TEST FAILED!!!\n'); +else + fprintf('\nTest passed.\n'); +end + +n_fail = r.n_fail; +n_pass = r.n_pass; +n_na = r.n_na; + +end + + +%% +%% Test execution with help of common functions +%% + +function [fail, g_db] = g_test(t) + +%% Reference: AES17 6.2.2 Gain +test = test_defaults_src(t); +prm = src_param(t.fs1, t.fs2, test.coef_bits); +test.fu = prm.c_pb*min(t.fs1,t.fs2); +test.g_db_tol = t.g_db_tol; +test.g_db_expect = 0; + +%% Create input file +test = g_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test = g_test_measure(test); + +%% Get output parameters +fail = test.fail; +g_db = test.g_db; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +end + +function [fail, pm_range_db, range_hz, fr3db_hz] = fr_test(t) + +%% Reference: AES17 6.2.3 Frequency response +test = test_defaults_src(t); +prm = src_param(t.fs1, t.fs2, test.coef_bits); + +test.rp_max = prm.rp_tot; % Max. ripple +/- dB allowed +test.f_lo = 20; % For response reporting, measure from 20 Hz +test.f_hi = min(t.fs1,t.fs2)*prm.c_pb; % to designed filter upper frequency +test.f_max = min(t.fs1/2, t.fs2/2); % Measure up to Nyquist frequency + +%% Create input file +test = fr_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test = fr_test_measure(test); + +fail = test.fail; +pm_range_db = test.rp; +range_hz = [test.f_lo test.f_hi]; +fr3db_hz = test.fr3db_hz; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +%% Print +src_test_result_print(t, 'Frequency response', 'FR', test.ph); + +end + +function [fail, thdnf] = thdnf_test(t) + +%% Reference: AES17 6.3.2 THD+N ratio vs. frequency +test = test_defaults_src(t); + +prm = src_param(t.fs1, t.fs2, test.coef_bits); +test.f_start = 20; +test.f_end = prm.c_pb*min(t.fs1, t.fs2); +test.fu = prm.c_pb*min(t.fs1, t.fs2); +%test.f_end = 0.4535*min(t.fs1, t.fs2); +%test.fu = 0.4535*min(t.fs1, t.fs2); + +%% Create input file +test = thdnf_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test.thdnf_max = t.thdnf_db_max; +test = thdnf_test_measure(test); +thdnf = max(max(test.thdnf)); +fail = test.fail; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +%% Print +src_test_result_print(t, 'THD+N ratio vs. frequency', 'THDNF'); + +end + +function [fail, dr_db] = dr_test(t) + +%% Reference: AES17 6.4.1 Dynamic range +test = test_defaults_src(t); +test.dr_db_min = t.dr_db_min; + +%% Create input file +test = dr_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test = dr_test_measure(test); + +%% Get output parameters +fail = test.fail; +dr_db = test.dr_db; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +end + + +function [fail, aap_db] = aap_test(t) + +%% Reference: AES17 6.6.6 Attenuation of alias products +test = test_defaults_src(t); +test.aap_max = t.aap_db_max; + +if t.fs1 <= t.fs2 + %% Internal rate must be lower than input + fail = -2; + aap_db = NaN; + return; +end + +test.f_start = 0.5*t.fs1; +test.f_end = 0.5*t.fs2; + +%% Create input file +test = aap_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test = aap_test_measure(test); +aap_db = test.aap; +fail = test.fail; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +%% Print +src_test_result_print(t, 'Attenuation of alias products', 'AAP'); + +end + +function [fail, aip_db] = aip_test(t) + +%% Reference: AES17 6.6.7 Attenuation of image products +test = test_defaults_src(t); +test.aip_max = t.aip_db_max; +if t.fs1 >= t.fs2 + %% Internal rate must be higher than input + fail = -2; + aip_db = NaN; + return; +%% +end + +%% Create input file +test.f_end = t.fs1/2; +test = aip_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Measure +test.fs = t.fs2; +test = aip_test_measure(test); +aip_db = test.aip; +fail = test.fail; +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +%% Print +src_test_result_print(t, 'Attenuation of image products', 'AIP'); + +end + +%% Chirp spectrogram test. This is a visual check only. Aliasing is visible +% in the plot as additional freqiencies than main linear up sweep. The aliasing +% can be a line, few lines, or lattice pattern depending the SRC conversion +% to test. The main sweep line should be steady level and extend from near +% zero freqeuncy to near Nyquist (Fs/2). + +function fail = chirp_test(t) + +fprintf('Spectrogram test %d -> %d ...\n', t.fs1, t.fs2); + +%% Create input file +test = test_defaults_src(t); +test = chirp_test_input(test); + +%% Run test +test = test_run_src(test, t); + +%% Analyze +test.fs = t.fs2; +test = chirp_test_analyze(test); +src_test_result_print(t, 'Chirp', 'chirpf'); + +% Delete files unless e.g. debugging and need data to run +delete_check(t.delete, test.fn_in); +delete_check(t.delete, test.fn_out); + +fail = test.fail; +end + + +%% Some SRC test specific utility functions +%% + +function test = test_defaults_src(t) +test.fmt = t.fmt; +test.bits_in = t.bits_in; +test.bits_out = t.bits_out; +test.nch = t.nch; +test.ch = t.ch; +test.fs = t.fs1; +test.fs1 = t.fs1; +test.fs2 = t.fs2; +test.mask_f = []; +test.mask_lo = []; +test.mask_hi = []; +test.coef_bits = 24; % No need to use actual word length in test +test.visible = t.visible; +end + +function test = test_run_src(test, t) +test.ex = './src_run.sh'; +test.arg = { num2str(t.bits_in), num2str(t.bits_out), num2str(t.fs1), num2str(t.fs2), test.fn_in, test.fn_out}; +delete_check(1, test.fn_out); +test = test_run(test); +end + +function src_test_result_print(t, testverbose, testacronym, ph) +tstr = sprintf('%s SRC %d, %d', testverbose, t.fs1, t.fs2); +if nargin > 3 + title(ph, tstr); +else + title(tstr); +end +pfn = sprintf('plots/%s_src_%d_%d.png', testacronym, t.fs1, t.fs2); +% The print command caused a strange error with __osmesa_print__ +% so disable it for now until solved. +%print(pfn, '-dpng'); +if t.close_plot_windows + close all; +end +end + +%% The next are results printing functions + +function print_val(fn, fs_in_list, fs_out_list, val, pf, valstr) +n_fsi = length(fs_in_list); +n_fso = length(fs_out_list); +fh = fopen(fn,'w'); +fprintf(fh,'\n'); +fprintf(fh,'SRC test result: %s\n', valstr); +fprintf(fh,'%8s, ', 'in \ out'); +for a = 1:n_fso-1 + fprintf(fh,'%8.1f, ', fs_out_list(a)/1e3); +end +fprintf(fh,'%8.1f', fs_out_list(n_fso)/1e3); +fprintf(fh,'\n'); +for a = 1:n_fsi + fprintf(fh,'%8.1f, ', fs_in_list(a)/1e3); + for b = 1:n_fso + if pf(a,b,1) < 0 + cstr = 'x'; + else + if isnan(val(a,b)) + cstr = '-'; + else + cstr = sprintf('%8.2f', val(a,b)); + end + end + if b < n_fso + fprintf(fh,'%8s, ', cstr); + else + fprintf(fh,'%8s', cstr); + end + end + fprintf(fh,'\n'); +end +fclose(fh); +type(fn); +end + +function print_fr(fn, fs_in_list, fs_out_list, fr_db, fr_hz, pf) +n_fsi = length(fs_in_list); +n_fso = length(fs_out_list); +fh = fopen(fn,'w'); +fprintf(fh,'\n'); +fprintf(fh,'SRC test result: Frequency response +/- X.XX dB (YY.Y kHz) \n'); +fprintf(fh,'%8s, ', 'in \ out'); +for a = 1:n_fso-1 + fprintf(fh,'%12.1f, ', fs_out_list(a)/1e3); +end +fprintf(fh,'%12.1f', fs_out_list(n_fso)/1e3); +fprintf(fh,'\n'); +for a = 1:n_fsi + fprintf(fh,'%8.1f, ', fs_in_list(a)/1e3); + for b = 1:n_fso + if pf(a,b,1) < 0 + cstr = 'x'; + else + cstr = sprintf('%4.2f (%4.1f)', fr_db(a,b), fr_hz(a,b,2)/1e3); + end + if b < n_fso + fprintf(fh,'%12s, ', cstr); + else + fprintf(fh,'%12s', cstr); + end + end + fprintf(fh,'\n'); +end +fclose(fh); +type(fn); +end + +function print_fr3db(fn, fs_in_list, fs_out_list, fr3db_hz, pf) +n_fsi = length(fs_in_list); +n_fso = length(fs_out_list); +fh = fopen(fn,'w'); +fprintf(fh,'\n'); +fprintf(fh,'SRC test result: Frequency response -3dB 0 - X.XX kHz\n'); +fprintf(fh,'%8s, ', 'in \ out'); +for a = 1:n_fso-1 + fprintf(fh,'%8.1f, ', fs_out_list(a)/1e3); +end +fprintf(fh,'%8.1f', fs_out_list(n_fso)/1e3); +fprintf(fh,'\n'); +for a = 1:n_fsi + fprintf(fh,'%8.1f, ', fs_in_list(a)/1e3); + for b = 1:n_fso + if pf(a,b,1) < 0 + cstr = 'x'; + else + cstr = sprintf('%4.1f', fr3db_hz(a,b)/1e3); + end + if b < n_fso + fprintf(fh,'%8s, ', cstr); + else + fprintf(fh,'%8s', cstr); + end + end + fprintf(fh,'\n'); +end +fclose(fh); +type(fn); +end + + +function print_pf(fn, fs_in_list, fs_out_list, pf) +n_fsi = length(fs_in_list); +n_fso = length(fs_out_list); +fh = fopen(fn,'w'); +fprintf(fh,'\n'); +fprintf(fh,'SRC test result: Fails\n'); +fprintf(fh,'%8s, ', 'in \ out'); +for a = 1:n_fso-1 + fprintf(fh,'%14.1f, ', fs_out_list(a)/1e3); +end +fprintf(fh,'%14.1f', fs_out_list(n_fso)/1e3); +fprintf(fh,'\n'); +spf = size(pf); +npf = spf(3); +for a = 1:n_fsi + fprintf(fh,'%8.1f, ', fs_in_list(a)/1e3); + for b = 1:n_fso + if pf(a,b,1) < 0 + cstr = 'x'; + else + cstr = sprintf('%d', pf(a,b,1)); + for n=2:npf + if pf(a,b,n) < 0 + cstr = sprintf('%s/x', cstr); + else + cstr = sprintf('%s/%d', cstr,pf(a,b,n)); + end + end + end + if b < n_fso + fprintf(fh,'%14s, ', cstr); + else + fprintf(fh,'%14s', cstr); + end + end + fprintf(fh,'\n'); +end +fclose(fh); +type(fn); +end diff --git a/tools/test/audio/src_test.sh b/tools/test/audio/src_test.sh new file mode 100755 index 000000000000..84e88c91dfe6 --- /dev/null +++ b/tools/test/audio/src_test.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# 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 +# + +octave --no-gui src_test_top.m +if [ $? -eq 0 ]; then + echo "Test passed." + exit 0 +else + echo "Test failed." >&2 + exit 1 +fi diff --git a/tools/test/audio/src_test_top.m b/tools/test/audio/src_test_top.m new file mode 100644 index 000000000000..a0bf826245d4 --- /dev/null +++ b/tools/test/audio/src_test_top.m @@ -0,0 +1,42 @@ +%% +% 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 +% + +[n_fail, n_pass] = src_test(24, 24); +if n_fail > 0 || n_pass < 1 + fprintf('Error: SRC test with 24 bits data failed.\n'); + quit(1) +end +[n_fail, n_pass] = src_test(32, 32); +if n_fail > 0 || n_pass < 1 + fprintf('Error: SRC test with 32 bits data failed.\n'); + quit(1) +end + +fprintf('Success: SRC test with 24 and 32 bits data passed.\n'); diff --git a/tools/test/audio/std_utils/aap_test_input.m b/tools/test/audio/std_utils/aap_test_input.m new file mode 100644 index 000000000000..0a969c62a99f --- /dev/null +++ b/tools/test/audio/std_utils/aap_test_input.m @@ -0,0 +1,103 @@ +function test = aap_test_input(test) + +%% t = aap_test_input(t) +% +% Create frequency sweep data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.f_start - start frequency +% t.f_end - end frequency +% t.fs - sample rate +% t.bits_in - number of bits in signal +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - frequencies in sweep +% t.nf - number of frequencies +% t.tl - tone length in seconds +% t.ts - tone start times +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% 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 +% + +%% Reference: AES17 6.6.6 Attenuation of alias products +% http://www.aes.org/publications/standards/ + +if nargin < 1 + error('This function must be called with argunment.'); +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fstart=%d Hz, Fend=%d Hz, Fs=%.1f kHz, bits_in=%d, ch=%d, nch=%d\n', ... + test.f_start, test.f_end, test.fs, test.bits_in, test.ch, test.nch); + + +test.fn_in = sprintf('aap_test_in.%s', test.fmt); +test.fn_out = sprintf('aap_test_out.%s', test.fmt); +f_first = 997; +f_max = max(test.f_start, test.f_end); +f_min = min(test.f_start, test.f_end); +n_third = ceil(log(f_max/f_min)/log(2)*3); % max 1/3 octave step +steps = max(n_third, 50); % Min 50 steps +test.f = [f_first logspace(log10(test.f_start), log10(test.f_end), steps) ]; + +%% Tone sweep parameters +test.is = 20e-3; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.3; % Error if marker positions delta is greater than 0.3s +test.tc = 20; % Min. 20 cycles of sine wave for a frequency +t_min = 0.2; +test.a_db = -20; +test.a = 10^(test.a_db/20); +% Use t_min or min cycles count as tone length +test.tl = max(test.tc*1/min(test.f),t_min); + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/aap_test_measure.m b/tools/test/audio/std_utils/aap_test_measure.m new file mode 100644 index 000000000000..a61dadf30653 --- /dev/null +++ b/tools/test/audio/std_utils/aap_test_measure.m @@ -0,0 +1,77 @@ +function test = aap_test_measure(test) + +%% +% 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 +% + +%% Reference: AES17 6.6.6 Attenuation of alias products +% http://www.aes.org/publications/standards/ + +%% Load output file +[x, nx] = load_test_output(test); +if nx == 0 + test.fail = 1; + return +end + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(x, test); + +%% Measure +win = hamming(nt_use); +m0 = zeros(test.nf,1); +for n=1:test.nf + fprintf('Measuring %.0f Hz ...\n', test.f(n)); + i1 = d+(n-1)*nt+nt_skip; + i2 = i1+nt_use-1; + m0(n) = level_dbfs(x(i1:i2).*win); +end + +%% Calculate levels relative to first 997 Hz frequency, +% remove it from result, sort to ascinding order for plot +m_ref = m0(1); +test.m = m0(2:end)-m0(1); +[test.f, idx] = sort(test.f(2:end)); +test.m = test.m(idx); +test.aap = max(test.m); % Worst-case + +if test.aap > test.aap_max + test.fail = 1; +else + test.fail = 0; +end + +test.fh = figure('visible', test.visible); +semilogx(test.f, test.m); +grid on; +xlabel('Frequency (Hz)'); +ylabel('Relative level (dB)'); +grid on; + +end diff --git a/tools/test/audio/std_utils/aip_test_input.m b/tools/test/audio/std_utils/aip_test_input.m new file mode 100644 index 000000000000..a946c9680145 --- /dev/null +++ b/tools/test/audio/std_utils/aip_test_input.m @@ -0,0 +1,101 @@ +function test = aip_test_input(test) + +%% t = aap_test_input(t) +% +% Create frequency sweep data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.f_start - start frequency +% t.f_end - end frequency +% t.fs - sample rate +% t.bits_in - number of bits in signal +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - frequencies in sweep +% t.nf - number of frequencies +% t.tl - tone length in seconds +% t.ts - tone start times +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% 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 +% + +%% Reference: AES17 6.6.7 Attenuation of image products +% http://www.aes.org/publications/standards/ + +if nargin < 1 + error('This function must be called with argument.'); +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fend=%d Hz, Fs=%.1f kHz, bits_in=%d, ch=%d, nch=%d\n', ... + test.f_end, test.fs, test.bits_in, test.ch, test.nch); + +test.fn_in = sprintf('aip_test_in.%s', test.fmt); +test.fn_out = sprintf('aip_test_out.%s', test.fmt); +f_first = 997; +test.f_start = 20; +f_min = min(test.f_start, test.f_end); +f_max = max(test.f_start, test.f_end); +test.fu = f_max; +n_thirdoct = ceil(log(f_max/f_min)/log(2)*3); % max 1/3 octave step +steps = n_thirdoct; +test.f = [f_first logspace(log10(test.f_start), log10(test.f_end), steps) ]; + +%% Tone sweep parameters +test.is = 20e-3; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.1; % Error if marker positions delta is greater than 0.1s +test.tl = 3; +test.a_db = -20; +test.a = 10^(test.a_db/20); + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/aip_test_measure.m b/tools/test/audio/std_utils/aip_test_measure.m new file mode 100644 index 000000000000..56aee93b9125 --- /dev/null +++ b/tools/test/audio/std_utils/aip_test_measure.m @@ -0,0 +1,84 @@ +function test = aip_test_measure(test) + +%% +% 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 +% + +%% Reference: AES17 6.6.7 Attenuation of image products +% http://www.aes.org/publications/standards/ + +%% Load output file +[x, nx] = load_test_output(test); +if nx == 0 + test.g_db = NaN; + test.fail = 1; + return +end + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(x, test); + +%% Measure all test frequencies +t_skip = 1.0; +ml = zeros(test.nf,1); +mn = zeros(test.nf,1); +b_lpf = stdlpf_get(test.fu, test.fs); % Get LPF coef +b_hpf = stdhpf_get(test.fu, test.fs); % Get HPF coef +for n=1:test.nf + fprintf('Measuring %.0f Hz ...\n', test.f(n)); + % Get notch coef for this frequency + [b_notch, a_notch] = stdnotch_get(test.f(n), test.fs); + i1 = d+(n-1)*nt+nt_skip; + i2 = i1+nt_use-1; + x_lpf = filter(b_lpf, 1, x(i1:i2)); % Standard LPF, need for 997 Hz only + x_notch = filter(b_notch, a_notch, x(i1:i2)); % Standard notch + x_hpf = filter(b_hpf, 1, x_notch); % Standard HPF + ml(n) = level_dbfs(x_lpf(round(t_skip*test.fs):end)); + mn(n) = level_dbfs(x_hpf(round(t_skip*test.fs):end)); +end + +%% Calculate levels relative to first 997 Hz frequency, +% remove it from result, sort to ascinding order for plot +test.f = test.f(2:end); +test.m = mn(2:end)-ml(1); +test.aip = max(test.m); % Worst-case +if test.aip > test.aip_max + test.fail = 1; +else + test.fail = 0; +end + +test.fh = figure('visible', test.visible); +semilogx(test.f, test.m); +grid on; +xlabel('Frequency (Hz)'); +ylabel('Relative level (dB)'); +grid on; + +end diff --git a/tools/test/audio/std_utils/dr_test_input.m b/tools/test/audio/std_utils/dr_test_input.m new file mode 100644 index 000000000000..396d7d09036d --- /dev/null +++ b/tools/test/audio/std_utils/dr_test_input.m @@ -0,0 +1,91 @@ +function test = dr_test_input(test) + +%% t = dr_test_input(t) +% +% Create tone data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.fs - sample rate +% t.bits_in - signal word length +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - test signal frequency +% t.tl - tone length in seconds +% t.ts - tone start time +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% Copyright (c) 2016, 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 +% + +%% Reference: AES17 6.2.3 Frequency response + +if nargin < 1 + fprintf('Warning, using default parameters!\n'); + test.fs = 48e3; test.bits_in=32; test.ch=1; test.nch=1; +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fs=%.1f, bits=%d, ch=%d, Nch=%d\n', ... + test.fs/1e3, test.bits_in, test.ch, test.nch ); + +%% Test tone parameters +test.fn_in = sprintf('dr_test_in.%s', test.fmt); +test.fn_out = sprintf('dr_test_out.%s', test.fmt); +test.f = 997; +test.a_db = -60; +test.a = 10^(test.a_db/20); +test.is = 1.0; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.3; % Error if marker positions delta is greater than 0.3s +test.tc = 25; % Min. 20 cycles of sine wave for a frequency +test.tl = 3; % 3 seconds tone + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/dr_test_measure.m b/tools/test/audio/std_utils/dr_test_measure.m new file mode 100644 index 000000000000..6e8634fb90d8 --- /dev/null +++ b/tools/test/audio/std_utils/dr_test_measure.m @@ -0,0 +1,76 @@ +function test = dr_test_measure(test) + +%% +% 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 +% + +%% Load output file +[x, nx] = load_test_output(test); +if nx == 0 + test.dr_db = NaN; + test.fail = 1; + return +end + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(x, test); + +%% Notch filter +y0n = stdnotch(x, test.f, test.fs); + +%% CCIR-RMS weighting filter +y0w = stdweight(y0n, test.fs); + +%% Trim sample by removing first 1s to let the notch to apply +i1 = d+nt_skip; +i2 = i1+nt_use-1; +y = x(i1:i2); +y_n = y0w(i1:i2); + +%% Gain, SNR +level_in = test.a_db; +level_out = level_dbfs(y); +level_final = level_dbfs(y_n); +test.dr_db = level_out-level_final-test.a_db; +fprintf('DR = %5.1f dB\n', test.dr_db); +if 0 + plot(y); + hold on + plot(y_n,'g'); + hold off +end + +%% Check pass/fail +test.fail = 0; +if test.dr_db < test.dr_db_min + fprintf('Failed DR %f dB (min %f dB)\n', test.dr_db, test.dr_db_min); + test.fail = 1; +end + +end diff --git a/tools/test/audio/std_utils/fr_test_input.m b/tools/test/audio/std_utils/fr_test_input.m new file mode 100644 index 000000000000..5471bf7c4698 --- /dev/null +++ b/tools/test/audio/std_utils/fr_test_input.m @@ -0,0 +1,123 @@ +function test = fr_test_input(test) + +%% t = fr_test_input(t) +% +% Create frequency sweep data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.f_max - maximum frequency of sweep, set e.g. to 0.99*fs/2 +% t.fs - sample rate +% t.bits_in - number of bits in signal +% t.ch - mix test signal to channel ch, e.g. set to [1 2] to measure +% two channels +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - Created input file name +% t.fn_out - Proposed output file name for captured output +% t.f_ref - Reference frequency used to report deviation (997 Hz) +% t.f_min - Sweep start frequency +% t.f - Frequencies in sweep +% t.is - Ignore signal from tone start +% t.ie - Ignore signal from tone end +% t.tr - tone gain ramp length in seconds +% t.sm - Seek start marker this time length from start +% t.em - Seek end marker this time length from end +% t.mt - Error if marker positions delta is greater than this +% t.tc - Min cycles of sine wave per frequency +% t.tl - Tone length in seconds +% t.a_db - Tone amplitude (dB) +% t.a - Tone amplitude (lin) +% t.nt - Number of samples per tone +% t.nf - Number of frequencies +% t.na - Number of amplitudes +% t.mark_t - Length of marker tone in seconds +% t.mark_a - Amplitude max of marker tone (lin) +% t.mark_a_db - Amplitude max of marker tone (dB) +% t.ts - Tone start times +% +% E.g. +% t.fs=48e3; t.f_max=20e3; t.bits_in=16; t.ch=1; t.nch=2; t = fr_test_input(t); +% + +%% +% Copyright (c) 2016, 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 +% + +%% Reference: AES17 6.2.3 Frequency response +% http://www.aes.org/publications/standards/ + +if nargin < 1 + fprintf('Warning, using default parameters!\n'); + test.fs = 48e3; test.f_max = 0.99*test.fs/2; test.ch=1; test.nch=1; + test.bits_in=32; +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fmax=%.1f kHz, Fs=%.1f, ch=%d, Nch=%d, bits_in=%d\n', ... + test.f_max/1e3, test.fs/1e3, test.ch, test.nch, test.bits_in); + +test.fn_in = sprintf('fr_test_in.%s', test.fmt); +test.fn_out = sprintf('fr_test_out.%s', test.fmt); +test.f_ref = 997; +test.f_min = 20; + +%% Use a dense frequency grid to see -3 dB point well +n_oct = ceil(log(test.f_max/test.f_ref)/log(2)*35); +f = logspace(log10(test.f_ref), log10(test.f_max), n_oct); +c = f(1)/f(2); +f_next = test.f_ref*c; +while (f_next > test.f_min) + f = [f_next f]; + f_next = f_next*c; +end +test.f = f; + +%% Tone sweep parameters +test.is = 20e-3; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.1; % Error if marker positions delta is greater than 0.1s +test.tc = 10; % Min. 10 cycles of sine wave for a frequency +t_min = 0.2; +% Use t_min or min cycles count as tone length +test.tl = max(test.tc*1/min(f),t_min); +test.a_db = -20; +test.a = 10.^(test.a_db/20); + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/fr_test_measure.m b/tools/test/audio/std_utils/fr_test_measure.m new file mode 100644 index 000000000000..e7156fede631 --- /dev/null +++ b/tools/test/audio/std_utils/fr_test_measure.m @@ -0,0 +1,173 @@ +function test = fr_test_measure(test) + +%% t = fr_test_measure(t) +% +% Measure frequency response from captured frequency sweep created by +% fr_test_input() that sets most of the input struct fiels. The output +% is read from file t.fn_out. +% +% Input parameters +% t.f_lo - Measure ripple start frequency +% t.f_hi - Measure ripple end frequency +% t.rp_max - Max. ripple +/- dB +% t.mask_f - Frequencies for mask +% t.mask_lo - Upper limits of mask +% t.mask_hi - Lower limits of mask +% +% Output parameters +% t.m - Measured frequency response +% t.rp - Measured ripple +/- dB +% t.fr3db_hz - Bandwidth in Hz for -3 dB attenuated response +% t.fail - Returns zero for passed +% t.fh - Figure handle +% t.ph - Plot handle +% +% E.g. +% t.fs=48e3; t.f_max=20e3; t.bits_out=16; t.ch=1; t.nch=2; t=fr_test_input(t); +% t.fn_out=t.fn_in; t.f_lo=20; t.f_hi=20e3; t.rp_max=[]; t.mask_f=[]; +% t=fr_test_measure(t); +% + +%% +% 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 +% + +%% Reference: AES17 6.2.3 Frequency response +% http://www.aes.org/publications/standards/ + +[x, nx] = load_test_output(test); + +j = 1; +for channel = test.ch + + if nx == 0 + test.rp(j) = NaN; + test.fr3db_hz(j) = NaN; + test.fail = 1; + return + end + + %% Find sync + [d, nt, nt_use, nt_skip] = find_test_signal(x(:,j), test); + + win = hamming(nt_use); + m0 = zeros(test.nf,1); + for n=1:test.nf + fprintf('Measuring %.0f Hz ...\n', test.f(n)); + i1 = d+(n-1)*nt+nt_skip; + i2 = i1+nt_use-1; + m0(n) = level_dbfs(x(i1:i2,j).*win) -test.a_db; + end + + %% Scale 997 Hz point as 0 dB + df = test.f - test.f_ref; + [~,i997] = min(abs(df)); + m_offs = m0(i997); + test.m(:,j) = m0 - m_offs; + + %% Check pass/fail + idx0 = find(test.f < test.f_hi); + idx1 = find(test.f(idx0) > test.f_lo); + range_db = max(test.m(idx1,j))-min(test.m(idx1,j)); + test.rp(j) = range_db/2; + test.fail = 0; + if ~isempty(test.rp_max) + if test.rp > test.rp_max + fprintf('Failed response +/- %f dBpp (max +/- %f dB)\n', ... + test.rp, test.rp_max); + test.fail = 1; + end + end + + %% Find frequency response 3 dB 0-X Hz + idx3 = find(test.m(:,j) > -3); + test.fr3db_hz(j) = test.f(idx3(end)); + + %% Interpolate mask in logaritmic frequencies, check + if ~isempty(test.mask_f) + f_log = log(test.f); + mask_hi = interp1(log(test.mask_f), test.mask_hi(:,j), ... + f_log, 'linear'); + mask_lo = interp1(log(test.mask_f), test.mask_lo(:,j), ... + f_log, 'linear'); + over_mask = test.m(:,j)-mask_hi'; + under_mask = mask_lo'-test.m(:,j); + idx = find(isnan(over_mask) == 0); + [m_over_mask, io] = max(over_mask(idx)); + idx = find(isnan(under_mask) == 0); + [m_under_mask, iu] = max(under_mask(idx)); + if m_over_mask > 0 + fprintf('Failed upper response mask around %.0f Hz\n', ... + test.f(io)); + test.fail = 1; + end + if m_under_mask > 0 + fprintf('Failed lower response mask around %.0f Hz\n', ... + test.f(iu)); + test.fail = 1; + end + end + + test.fh(j) = figure('visible', test.visible); + subplot(1,1,1); + test.ph(j) = subplot(1,1,1); + %semilogx(test.f, test.m(:,j)); + plot(test.f, test.m(:,j)); + grid on; + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + if length(test.mask_f) > 0 + hold on; + plot(test.f, mask_hi, 'r--'); + plot(test.f, mask_lo, 'r--'); + hold off; + end + ax = axis(); + axis([ax(1:2) -4 1]); + if max(max(test.m(idx1,j))-min(test.m(idx1,j))) < 1 + axes('Position', [ 0.2 0.2 0.4 0.2]); + box on; + plot(test.f(idx1), test.m(idx1,j)); + if ~isempty(test.rp_max) + hold on; + plot([test.f_lo test.f_hi], ... + [-test.rp_max/2 -test.rp_max/2], 'r--'); + plot([test.f_lo test.f_hi], ... + [ test.rp_max/2 test.rp_max/2], 'r--'); + hold off; + end + grid on; + axis([0 test.f_hi -0.1 0.1]); + end + + %% Next channel to measure + j=j+1; +end + +end diff --git a/tools/test/audio/std_utils/g_test_input.m b/tools/test/audio/std_utils/g_test_input.m new file mode 100644 index 000000000000..bc0e19b04f92 --- /dev/null +++ b/tools/test/audio/std_utils/g_test_input.m @@ -0,0 +1,97 @@ +function test = g_test_input(test) + +%% t = dr_test_input(t) +% +% Create tone data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.fs - sample rate +% t.bits_in - signal word length +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - test signal frequency +% t.tl - tone length in seconds +% t.ts - tone start time +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% Copyright (c) 2016, 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 +% + +%% Reference: AES17 6.2.2 Gain +% http://www.aes.org/publications/standards/ + + +if nargin < 1 + fprintf('Warning, using default parameters!\n'); + test.fs = 48e3; test.bits=32; test.ch=1; test.nch=1; +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fs=%.1f, bits_in=%d', test.fs/1e3, test.bits_in); +fprintf(', ch=%d', test.ch ); +fprintf(', Nch=%d\n', test.nch ); + +test.fn_in = sprintf('g_test_in.%s', test.fmt); +test.fn_out = sprintf('g_test_out.%s', test.fmt); +test.f = 997; + + +%% Tone sweep parameters +test.is = 20e-3; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.3; % Error if marker positions delta is greater than 0.3s +test.tc = 25; % Min. 20 cycles of sine wave for a frequency +test.a_db = -20; % -20 dBFS level +test.a = 10^(test.a_db/20); +% 0.5 seconds tone, this will be adjusted to be integer number of samples +test.tl = 0.5; + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/g_test_measure.m b/tools/test/audio/std_utils/g_test_measure.m new file mode 100644 index 000000000000..40c98716c55f --- /dev/null +++ b/tools/test/audio/std_utils/g_test_measure.m @@ -0,0 +1,70 @@ +function test = g_test_measure(test) + +%% +% 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 +% + +%% Reference: AES17 6.2.2 Gain +% http://www.aes.org/publications/standards/ + +%% Load output file +[x, nx] = load_test_output(test); + +if nx == 0 + test.g_db = NaN; + test.fail = 1; + return +end + +%% Standard low-pass +y0 = stdlpf(x, test.fu, test.fs); + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(y0, test); + +%% Trim sample by removing first 1s to let the notch to apply +i1 = d+nt_skip; +i2 = i1+nt_use-1; +y = y0(i1:i2); + +%% Gain, SNR +level_in = test.a_db; +level_out = level_dbfs(y); +test.g_db = level_out-level_in; +fprintf('Gain = %6.3f dB (expecting %6.3f dB)\n', test.g_db, test.g_db_expect); + +%% Check pass/fail +test.fail = 0; +if abs(test.g_db_expect-test.g_db) > test.g_db_tol + fprintf('Failed gain %f dB (max %f dB)\n', test.g_db, test.g_db_tol); + test.fail = 1; +end + +end + diff --git a/tools/test/audio/std_utils/level_dbfs.m b/tools/test/audio/std_utils/level_dbfs.m new file mode 100644 index 000000000000..73cddedb4ce8 --- /dev/null +++ b/tools/test/audio/std_utils/level_dbfs.m @@ -0,0 +1,46 @@ +function dbfs = level_dbfs(x) + +%% dbfs = level_dbfs(x) +% +% Input +% x - signal +% +% Output +% dbfs - sigmal level in dBFS +% + +%% +% 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 +% + +%% Reference AES 17 3.12.3 +level_ms = mean(x.^2); +dbfs = 10*log10(level_ms) + 20*log10(sqrt(2)); + +end diff --git a/tools/test/audio/std_utils/stdhpf.m b/tools/test/audio/std_utils/stdhpf.m new file mode 100644 index 000000000000..bf855a063686 --- /dev/null +++ b/tools/test/audio/std_utils/stdhpf.m @@ -0,0 +1,54 @@ +function y = stdhpf(x, fu, fs) + +%% y = stdhpf(x, fu, fs) +% +% Standard high-pass filter +% +% Input +% x - input signal +% fu - upper band-edge frequency +% fs - sample rate +% +% Output +% y - filtered signal +% +% Reference AES17 5.2.6 + +%% +% 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 +% + +%% Design filter +b = stdhpf_get(fu, fs); + +%% Filter +y = filter(b, 1, x); + + +end diff --git a/tools/test/audio/std_utils/stdhpf_get.m b/tools/test/audio/std_utils/stdhpf_get.m new file mode 100644 index 000000000000..367a39bbffb9 --- /dev/null +++ b/tools/test/audio/std_utils/stdhpf_get.m @@ -0,0 +1,68 @@ +function b = stdhpf_get(fu, fs) + +%% y = stdhpf(x, fu, fs) +% +% Standard high-pass filter +% +% Input +% x - input signal +% fu - upper band-edge frequency +% fs - sample rate +% +% Output +% y - filtered signal +% +% Reference AES17 5.2.6 + +%% +% 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 +% + +%% Design filter +rp = 0.5; +rs = -50; % Some margin vs. requirement +a = [0 1]; +fc = min(1.3*fu, 0.99*fs/2); +f = [fu fc]; +dev = [ 10^(rs/20) (10^(rp/20)-1)/(10^(rp/20)+1) ]; +[n, wn, beta, ftype] = kaiserord(f, a, dev, fs); +b = fir1(n, wn, ftype, kaiser(n+1,beta)); + +if 0 + f = linspace(0, fs/2, 1000); + h = freqz(b,1, f, fs); + figure + plot(f, 20*log10(abs(h))) + hold on; + plot( [0 fu], [-40 -40], 'r', [fc fs/2], [-0.5 -0.5], 'r', [fc fs/2], [0.5 0.5], 'r'); + hold off; + grid on; +end + +end diff --git a/tools/test/audio/std_utils/stdlpf.m b/tools/test/audio/std_utils/stdlpf.m new file mode 100644 index 000000000000..56fdc5a44458 --- /dev/null +++ b/tools/test/audio/std_utils/stdlpf.m @@ -0,0 +1,54 @@ +function y = stdlpf(x, fu, fs) + +%% y = stdhpf(x, fu, fs) +% +% Standard high-pass filter +% +% Input +% x - input signal +% fu - upper band-edge frequency +% fs - sample rate +% +% Output +% y - filtered signal +% +% Reference AES17 5.2.5 + +%% +% 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 +% + +%% Design filter +b = stdlpf_get(fu, fs); + +%% Filter +y = filter(b, 1, x); + + +end diff --git a/tools/test/audio/std_utils/stdlpf_get.m b/tools/test/audio/std_utils/stdlpf_get.m new file mode 100644 index 000000000000..ac344d155d55 --- /dev/null +++ b/tools/test/audio/std_utils/stdlpf_get.m @@ -0,0 +1,70 @@ +function b = stdlpf_get(fu, fs) + +%% b = stdlpf_get(fu, fs) +% +% Standard loww-pass filter +% +% Input +% fu - upper band-edge frequency +% fs - sample rate +% +% Output +% b - coefficients for FIR filter +% +% Reference AES17 5.2.5 + +%% +% 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 +% + +%% Design filter +rp = 0.001; % Since this may need to be in frequency response measurement the ripple must be very small +rs = -65; % Some margin vs. requirement +a = [1 0]; +% Note: The fc-fu for digital low-pass is not feasible. Use of fu*1.2 instead +% results to example 24 kHz for 20 kHz upper band-edge. This could be a mistake +% in specification. +fc = min(fu*1.2, 0.99*fs/2); +f = [fu fc]; +dev = [ (10^(rp/20)-1)/(10^(rp/20)+1) 10^(rs/20) ]; +[n, wn, beta, ftype] = kaiserord(f, a, dev, fs); +b = fir1(n, wn, ftype, kaiser(n+1,beta)); + +if 0 + f = linspace(0, fs/2, 1000); + h = freqz(b,1, f, fs); + figure + plot(f, 20*log10(abs(h))) + hold on; + plot( [fc fs/2], [-60 -60], 'r', [0 fu], [-0.1 -0.1], 'r', [0 fu], [0.1 0.1], 'r'); + hold off; + grid on; +end + +end diff --git a/tools/test/audio/std_utils/stdnotch.m b/tools/test/audio/std_utils/stdnotch.m new file mode 100644 index 000000000000..51d00d2e21d3 --- /dev/null +++ b/tools/test/audio/std_utils/stdnotch.m @@ -0,0 +1,47 @@ +function y = stdnotch(x, fn, fs) + +%% y = stdnotch(x, fn, fs) +% +% Input +% x - input signal +% fn - notch frequency +% fs - sample rate +% +% Output +% y - filtered signal +% + +%% +% 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 +% + +[b, a] = stdnotch_get(fn, fs); +y = filter(b, a, x); + +end diff --git a/tools/test/audio/std_utils/stdnotch_get.m b/tools/test/audio/std_utils/stdnotch_get.m new file mode 100644 index 000000000000..5213fa8eae35 --- /dev/null +++ b/tools/test/audio/std_utils/stdnotch_get.m @@ -0,0 +1,70 @@ +function [b, a] = stdnotch_get(fn, fs) + +%% [b, a] = stdnotch_get(fn, fs) +% +% Input +% fn - notch frequency +% fs - sample rate +% +% Output +% b - coefficients for filter zeros +% a - coefficients for filter poles +% + +%% +% 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 +% + +target_q = 2.1; +bw = (2*fn/fs)/target_q; +if exist('iirnotch.m') == 2 + [b, a] = iirnotch(2*fn/fs, bw); +else + [b, a] = pei_tseng_notch(2*fn/fs, bw); +end +if 0 + %% In AES17 5.2.8 standard notch must have Q 1.2-3.0 + % Quality factor is ratio of of center frequency to + % differenence between -3 dB frequencies. + figure; + f = linspace(0.2*fn, min(2*fn,fs/2), 5000); + h = freqz(b, a, f, fs); + m = 20*log10(abs(h)); + plot(f, m); grid on; + idx = find(m < -3); + f1 = f(idx(1)); + f2 = f(idx(end)); + q = fn/(f2-f1); + if (q < 1.2) || (q > 3.0) + fprintf('Required Q value failed, Q = %5.2f\n', q); + else + fprintf('Q = %5.2f\n', q); + end +end +end diff --git a/tools/test/audio/std_utils/stdweight.m b/tools/test/audio/std_utils/stdweight.m new file mode 100644 index 000000000000..92e3a3cb1354 --- /dev/null +++ b/tools/test/audio/std_utils/stdweight.m @@ -0,0 +1,86 @@ +function y = stdweight(x, fs) + +%% y = stdweight(x, fs) +% +% Input +% x - input signal +% fs - sample rate +% +% Output +% y - filtered signal +% + +%% +% 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 +% + +%% Frequency grid for FIR design +f = linspace(0, fs/2, 6000); + +%% From https://en.wikipedia.org/wiki/ITU-R_468_noise_weighting +h1 = -4.737338981378384e-24*f.^6 +2.043828333606125e-15*f.^4 -1.363894795463638e-7*f.^2 +1; +h2 = 1.306612257412824e-19*f.^5 -2.118150887518656e-11*f.^3 +5.559488023498642e-4*f; +RITU = 1.246332637532143e-4*f./sqrt(h1.^2+h2.^2); +ITU = 18.2+20*log10(RITU)-5.63; % AES17 CCIR-RMS +fc = [ 31.5 63 100 200 400 800 1000 2000 3150 4000 5000 6300 7100 8000 9000 10000 12500 14000 16000 20000 31500]; +ga = [-35.5 -29.5 -25.4 -19.4 -13.4 -7.5 -5.6 0 3.4 4.9 6.1 6.6 6.4 5.8 4.5 2.5 -5.6 -10.9 -17.3 -27.8 -48.3]; +tu = [ 2.0 1.4 1.0 0.85 0.70 0.55 0.50 0.50 0.50 0.50 0.50 0.01 0.20 0.40 0.60 0.80 1.2 1.4 1.6 2.0 2.8]; +tl = [ -2.0 -1.4 -1.0 -0.85 -0.70 -0.55 -0.50 -0.50 -0.50 -0.50 -0.50 -0.01 -0.20 -0.40 -0.60 -0.80 -1.2 -1.4 -1.6 -2.0 NaN]; + +%% Fine tune the 6300Hz, 6.6 dB point +if fs > 2*6300 + idx = find(f > 6300, 1, 'first'); + ITU = ITU + 6.6-ITU(idx); +else + idx = find(f > 3150, 1, 'first'); + ITU = ITU + 3.4-ITU(idx); +end + +m_fir = 10.^(ITU/20); +f_fir = 2*f/fs; +n_fir = 4000; % Sufficient up to 192 kHz +if (fs < 96001) + n_fir = 2000; +end +if (fs < 48001) + n_fir = 1000; +end +if (fs < 16001) + n_fir = 400; +end +bz = fir2(n_fir, f_fir, m_fir); +y = filter(bz, 1, x); +if 0 + h = freqz(bz, 1, f, fs); + my_w_db = 20*log10(abs(h)); + figure; + semilogx(f,ITU,fc,ga,'x',fc,ga+tu,fc,ga+tl, f, my_w_db ); + grid on; xlabel('Hz'); ylabel('dB'); +end +end diff --git a/tools/test/audio/std_utils/thdnf_test_input.m b/tools/test/audio/std_utils/thdnf_test_input.m new file mode 100644 index 000000000000..b07f21f42e27 --- /dev/null +++ b/tools/test/audio/std_utils/thdnf_test_input.m @@ -0,0 +1,95 @@ +function test = thdnf_test_input(test) + +%% t = dr_test_input(t) +% +% Create tone data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.fs - sample rate +% t.bits_in - signal word length +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - test signal frequency +% t.tl - tone length in seconds +% t.ts - tone start time +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% Copyright (c) 2016, 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 +% + +%% Reference: AES17 6.3.2 THD+N ratio vs frequency +% http://www.aes.org/publications/standards/ + +if nargin < 1 + fprintf('Warning, using default parameters!\n'); + test.fs = 48e3; test.f_start=20; test.f_end=20e3; test.bits_in=32; test.ch=1; test.nch=1; +end + +if test.ch == 0 + test.ch = 1+round(rand(1,1)*(test.nch-1)); % Test random channel 1..Nch +end + +fprintf('Using parameters Fstart=%.0f Hz, Fend=%.0f Hz, Fs=%.1f Hz, bits_in=%d, ch=%d, Nch=%d\n', ... + test.f_start, test.f_end, test.fs/1e3, test.bits_in, test.ch, test.nch ); + +test.fn_in = sprintf('thdnf_test_in.%s', test.fmt); +test.fn_out = sprintf('thdnf_test_out.%s', test.fmt); +noct = ceil(log(test.f_end/test.f_start)/log(2)); % Max 1 octave steps +test.f = logspace(log10(test.f_start),log10(test.f_end), noct); + + +%% Tone sweep parameters +test.is = 20e-3; % Ignore signal from tone start +test.ie = 20e-3; % Ignore signal from tone end +test.tr = 10e-3; % Gain ramp time for tones +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.1; % Error if marker positions delta is greater than 0.1s +test.a_db = [-1 -20]; % -1 and -20 dBFS levels +test.a = 10.^(test.a_db/20); +test.tl = 4; % 3 seconds tone +test.nst = 2; % Wait 1 seconds for frequency specific notch output to settle + +%% Mix the input file for test and write output +test = mix_sweep(test); + +end diff --git a/tools/test/audio/std_utils/thdnf_test_measure.m b/tools/test/audio/std_utils/thdnf_test_measure.m new file mode 100644 index 000000000000..6e10f17b5f73 --- /dev/null +++ b/tools/test/audio/std_utils/thdnf_test_measure.m @@ -0,0 +1,83 @@ +function test = thdnf_test_measure(test) + +%% +% 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 +% + +%% Reference: AES17 6.3.2 THD+N ratio vs frequency +% http://www.aes.org/publications/standards/ + +%% Load output file +[x, nx] = load_test_output(test); +if nx == 0 + test.g_db = NaN; + test.fail = 1; + return +end + +%% Standard low-pass +y0 = stdlpf(x, test.fu, test.fs); + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(y0, test); + +%% Measure all test frequencies +ml = zeros(test.nf,test.na); +mn = zeros(test.nf,test.na); +n_notch_settle = round(test.fs*test.nst); +nn = 1; +for m=1:test.na + for n=1:test.nf + fprintf('Measuring %.0f Hz ...\n', test.f(n)); + i1 = d+(nn-1)*nt+nt_skip; + i2 = i1+nt_use-1; + nn = nn+1; + y0n = stdnotch(y0(i1:i2), test.f(n), test.fs); + ml(n,m) = level_dbfs(y0(i1:i2)); + mn(n,m) = level_dbfs(y0n(n_notch_settle:end)); + end +end + +test.thdnf = mn - ml; +test.thdnf_high = test.thdnf(:,1); +test.thdnf_low = test.thdnf(:,2); +if max(max(test.thdnf)) > test.thdnf_max + test.fail = 1; +else + test.fail = 0; +end + +test.fh = figure('visible', test.visible); +semilogx(test.f, test.thdnf(:,1), 'b', test.f, test.thdnf(:,2), 'g--'); +grid on; +xlabel('Frequency (Hz)'); +ylabel('THD+N (dB)'); +legend('-1 dBFS','-20 dBFS'); + +end diff --git a/tools/test/audio/test_utils/chirp_test_analyze.m b/tools/test/audio/test_utils/chirp_test_analyze.m new file mode 100644 index 000000000000..e7026f61f5e6 --- /dev/null +++ b/tools/test/audio/test_utils/chirp_test_analyze.m @@ -0,0 +1,91 @@ +function test = chirp_test_analyze(test) + +%% +% 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 +% + +%% Load output file +[x, nx] = load_test_output(test); +if nx < 1 + test.fail = -1; % No data + return; +end + +%% Find sync +[d, nt, nt_use, nt_skip] = find_test_signal(x(:,test.ch(1)), test); + +%% Trim sample +i1 = d+nt_skip; +i2 = i1+nt_use-1; +z = x(i1:i2, :); +y = z(:,test.ch); +s = sum(z,2); + +%% Quick check length, RMS, offset, and channels sum +sz = size(z); +tz = sz(1)/test.fs; +et = abs(test.cl-tz)/test.cl; +rms_db = 10*log10(mean(z.^2)) + 20*log10(sqrt(2)); +offs_db = 20*log10(abs(mean(z))); +sum_max_db = 20*log10(max(abs(s))); +% Check for proper ratio of out/in samples, minimum level, maximum offset +% and maximum of sum of channels. The input is such that the channels should +% sum to zero. A phase difference in channels would cause non-zero output +% for channels sum. Dithered input causes a small non-zero sum value. + +if et > 0.05 + fail = 1; + fprintf('Failed output chirp length, err=%f, t=%f.\n', et, tz); +else if (min(rms_db) < -3) && (test.fs2 + 1 > test.fs1) + fail = 1; + fprintf('Failed output chirp level.\n'); + else if max(offs_db) > -40 + fail = 1; + fprintf('Failed output chirp DC offset.\n'); + else if (sum_max_db > -100) && (mod(test.nch, 2) == 0) + fail = 1; + fprintf('Failed output chirp channels phase.\n'); + else + fail = 0; + end + end + end +end + +test.fh = figure('visible', test.visible); +ns = 1024; +no = round(0.9*ns); +specgram(y(:,1), ns, test.fs, kaiser(ns,27), no); +colormap('jet'); +caxis([-150 0]); +colorbar('EastOutside'); + +test.fail = fail; + +end diff --git a/tools/test/audio/test_utils/chirp_test_input.m b/tools/test/audio/test_utils/chirp_test_input.m new file mode 100644 index 000000000000..89b2861e538b --- /dev/null +++ b/tools/test/audio/test_utils/chirp_test_input.m @@ -0,0 +1,96 @@ +function test = chirp_test_input(test) + +%% t = dr_test_input(t) +% +% Create tone data file for playback & record on real device or +% for algorithm simulation. +% +% Input parameters +% t.fs - sample rate +% t.bits_in - signal word length +% t.ch - mix test signal to channel ch +% t.nch - total number of channels in data +% +% Output parameters +% t.fn_in - created input file name +% t.fn_out - proposed output file name for captured output +% t.f - test signal frequency +% t.tl - tone length in seconds +% t.ts - tone start time +% t.tr - tone gain ramp length in seconds +% t.ti - ignore time from tone start and end, must be ti > tr +% t.a - tone amplitude (lin) +% t.a_db - tone amplitude (dB) +% t.mark_t - length of marker tone in seconds +% t.mark_a - amplitude max of marker tone (lin) +% t.mark_a_db - amplitude max of marker tone (dB) +% + +%% +% Copyright (c) 2016, 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 +% + +if nargin < 1 + fprintf('Warning, using default parameters!\n'); + test.fs = 48e3; test.bits=32; test.ch=1; test.nch=1; +end + +if test.ch == 0 + test.ch = 1:test.nch; % Test all channels 1..Nch +end + +fprintf('Using parameters Fs=%.1f, bits_in=%d', test.fs/1e3, test.bits_in); +fprintf(', ch=%d', test.ch ); +fprintf(', Nch=%d\n', test.nch ); + +test.fn_in = sprintf('chirp_test_in.%s', test.fmt); +test.fn_out = sprintf('chirp_test_out.%s', test.fmt); + + +%% Chirp parameters +test.a_db = -0.1; % Near full scale +test.a = 10^(test.a_db/20); +test.f_min = 20; +test.f_max = 0.99*test.fs/2; +test.cl = 2.0; + + +%% Parameters to find signal between markers +test.nf = 1; +test.na = 1; +test.sm = 3; % Seek start marker from 3s from start +test.em = 3; % Seek end marker from 3s from end +test.mt = 0.3; % Error if marker positions delta is greater than 0.3s +test.is = 0; % Ignore signal from tone start +test.ie = 0; % Ignore signal from tone end + +%% Mix the input file for test and write output +test = mix_chirp(test); + +end diff --git a/tools/test/audio/test_utils/delete_check.m b/tools/test/audio/test_utils/delete_check.m new file mode 100644 index 000000000000..b3e1c8219fac --- /dev/null +++ b/tools/test/audio/test_utils/delete_check.m @@ -0,0 +1,35 @@ +%% +% 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 +% + +function delete_check(really, f) +if really && exist(f) == 2 + delete(f); +end +end diff --git a/tools/test/audio/test_utils/dither_and_quantize.m b/tools/test/audio/test_utils/dither_and_quantize.m new file mode 100644 index 000000000000..56a2a58b71f2 --- /dev/null +++ b/tools/test/audio/test_utils/dither_and_quantize.m @@ -0,0 +1,61 @@ +%% xq = dither_and_quantize(x, bits) +% +% Input +% x - input signal +% bits - number of bits +% +% Output +% (int32) xq - scaled, dithered and quantized signal +% + +%% +% Copyright (c) 2016, 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 +% + +function xq = dither_and_quantize(x, bits) + +if (bits > 32) || (bits < 1) + error('This function supports max 32 bits quantization!'); +end + +scale = 2^(bits-1); +smax = scale-1; +smin = -scale; +sx = size(x); +nx = sx(1); +nch = sx(2); + +xq = int32(floor( scale*x + randn(nx,nch) - randn(nx,nch) -0.5)); % TPDF dither +%xq = int32(round( scale*x )); % Omit dither +idx = find(xq > smax); +xq(idx) = smax; +idx = find(xq < smin); +xq(idx) = smin; + +end diff --git a/tools/test/audio/test_utils/find_test_signal.m b/tools/test/audio/test_utils/find_test_signal.m new file mode 100644 index 000000000000..fee52d56bac0 --- /dev/null +++ b/tools/test/audio/test_utils/find_test_signal.m @@ -0,0 +1,76 @@ +function [d, nt, nt_use, nt_skip] = find_test_signal(x, test) + +%% +% 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 +% + +%% Find start marker +fprintf('Finding test start marker...\n'); +s = sync_chirp(test.fs, 'up'); +nx = length(x); +n_seek = round(test.fs*(test.idle_t + test.mark_t)); +n = min(round(test.fs*test.sm), n_seek); +y = x(1:n); +[r, lags] = xcorr(y, s); +[r_max, idx] = max(r); +d_start = lags(idx); + +%% Find end marker +fprintf('Finding test end marker...\n'); +s = sync_chirp(test.fs, 'down'); +n_seek = round(test.fs*(2*test.idle_t + test.mark_t)); +n = min(round(test.fs*test.em),n_seek); +y = x(end-n+1:end); +[r, lags] = xcorr(y, s); +[r_max, idx] = max(r); +d_end = nx-n+lags(idx); + +%% Check correct length of signal +len = d_end-d_start; +len_s = len/test.fs; +ref_s = test.mark_t+test.nf*test.na*test.tl; +if abs(len_s-ref_s) > test.mt + len_s + ref_s + error('Start and end markers were not found. Test play or capture quality may be poor'); +end + +%% Delay to first tone, length of tone in samples +d = d_start + round(test.mark_t*test.fs); +if (d < 0) + error('Invalid negative delay seen. Test play or capture quality may be poor'); +end +nt = round(test.tl*test.fs); +nt_use = nt -round(test.is*test.fs) -round(test.ie*test.fs); +if nt_use < 0 + error('Test signal length parameters must be wrong!'); +end +nt_skip = round(test.is*test.fs); + +end diff --git a/tools/test/audio/test_utils/load_test_output.m b/tools/test/audio/test_utils/load_test_output.m new file mode 100644 index 000000000000..320a4d633b4c --- /dev/null +++ b/tools/test/audio/test_utils/load_test_output.m @@ -0,0 +1,87 @@ +function [x, nx] = load_test_output(test) + +%% [x, n] = load_test_output(t) +% +% Input +% t.fn_out - file name to load +% t.bits_out - word length of data +% t.fmt - file format 'raw' or 'txt +% t.ch - channel to extract +% t.nch - number of channels in (interleaved) data +% +% Output +% x - samples +% n - number of samples +% + +%% +% 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 +% + +%% Integer type for binary files +switch test.bits_out + case 16 + bfmt = 'int16'; + case 24 + bfmt = 'int32'; + case 32 + bfmt = 'int32'; + otherwise + error('Bits_out must be 16, 24, or 32.'); +end + +%% Check that output file exists +if exist(test.fn_out) + fprintf('Reading output data file %s...\n', test.fn_out); + switch lower(test.fmt) + case 'txt' + out = load(test.fn_out); + case 'raw' + fh = fopen(test.fn_out, 'r'); + out = fread(fh, inf, bfmt); + fclose(fh); + otherwise + error('Fmt must be raw or txt.'); + end +else + out = []; +end + +%% Exctract channels to measure +scale = 1/2^(test.bits_out-1); +lout = length(out); +nx = floor(lout/test.nch); +x = zeros(nx,length(test.ch)); +j = 1; +for ch = test.ch + x(:,j) = out(ch:test.nch:end)*scale; + j = j + 1; +end + +end diff --git a/tools/test/audio/test_utils/mix_chirp.m b/tools/test/audio/test_utils/mix_chirp.m new file mode 100644 index 000000000000..9b57f2c74e79 --- /dev/null +++ b/tools/test/audio/test_utils/mix_chirp.m @@ -0,0 +1,82 @@ +function test = mix_chirp(test) + +%% +% 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 +% + +%% Adjust tone length to integer number of samples +test.nt = round(test.cl*test.fs); % Make number of samples per tone +test.tl = test.nt/test.fs; % an integer by adjusting tl. + +%% Test start and end marker tones +[h1, mark_start] = sync_chirp(test.fs, 'up'); +[h2, mark_end] = sync_chirp(test.fs, 'down'); +test.mark_t = mark_start.t; +test.mark_a = mark_start.a; +test.mark_a_db = mark_start.a_db; +test.ts = mark_start.t; + +%% Idle time to start and end +test.idle_t = 0.5; +n_idle = round(test.fs*test.idle_t); +t_idle = n_idle/test.fs; +x = zeros(test.nt + mark_start.n + mark_end.n +2*n_idle, test.nch, 'int32'); + +%% Add markers +idx1 = n_idle+1; +idx2 = length(x)-n_idle-mark_end.n; +for ch=test.ch + x(idx1:idx1+mark_start.n-1, ch) = dither_and_quantize(h1, test.bits_in); + x(idx2:idx2+mark_end.n-1, ch) = dither_and_quantize(h2, test.bits_in); +end + +%% Dither also idle parts +x(1:n_idle) = dither_and_quantize(zeros(n_idle,1), test.bits_in); +x(end-n_idle+1:end) = dither_and_quantize(zeros(n_idle,1), test.bits_in); + +%% Add Chirp +i1 = n_idle+mark_start.n+1; +i2 = i1+test.nt-1; +fprintf('Mixing %.1f dBFS chirp ...\n', test.a_db); +tc = ((1:round(test.cl*test.fs))-1)/test.fs; +s = test.a * chirp(tc, test.f_min, test.tl, test.f_max, 'linear', 90); +sign = 1; +for ch=test.ch + x(i1:i2, ch) = dither_and_quantize(sign * s, test.bits_in); + sign = -sign; +end + +test.signal = x; + +%% Output +fprintf('Writing output data file %s...\n', test.fn_in); +write_test_data(x, test.fn_in, test.bits_in, test.fmt); +fprintf('Done.\n') + +end diff --git a/tools/test/audio/test_utils/mix_sweep.m b/tools/test/audio/test_utils/mix_sweep.m new file mode 100644 index 000000000000..1b76437b8588 --- /dev/null +++ b/tools/test/audio/test_utils/mix_sweep.m @@ -0,0 +1,103 @@ +function test = mix_sweep(test) + +%% +% 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 +% + +%% Adjust tone lengt to integer number of samples +test.nt = round(test.tl*test.fs); % Make number of samples per tone +test.tl = test.nt/test.fs; % an integer by adjusting tl. +test.nf = length(test.f); % Number of frequencies +test.na = length(test.a); % Number of amplitudes + +%% Test start and end marker tones +[h1, mark_start] = sync_chirp(test.fs, 'up'); +[h2, mark_end] = sync_chirp(test.fs, 'down'); +test.mark_t = mark_start.t; +test.mark_a = mark_start.a; +test.mark_a_db = mark_start.a_db; +test.ts = mark_start.t; + +%% Idle time to start and end +test.idle_t = 0.5; +n_idle = round(test.fs*test.idle_t); +t_idle = n_idle/test.fs; +x = zeros(test.nf*test.na*test.nt +mark_start.n +mark_end.n +2*n_idle, ... + test.nch, 'int32'); + +%% Add markers +idx1 = n_idle+1; +idx2 = length(x)-n_idle-mark_end.n; +for ch=test.ch + x(idx1:idx1+mark_start.n-1, ch) = dither_and_quantize(h1, test.bits_in); + x(idx2:idx2+mark_end.n-1, ch) = dither_and_quantize(h2, test.bits_in); +end + +%% Dither also idle parts +x(1:n_idle) = dither_and_quantize(zeros(n_idle,1), test.bits_in); +x(end-n_idle+1:end) = dither_and_quantize(zeros(n_idle,1), test.bits_in); + +%% Add discrete frequencies sweep +n_r = round(test.fs*test.tr); +win = ones(test.nt,1); +win(1:n_r) = linspace(0,1,n_r); +win(end-n_r+1:end) = linspace(1,0,n_r); +i0 = n_idle+mark_start.n+1; +nn = 1; +for m=1:test.na + for n=1:test.nf + i1 = i0 + (nn-1)*test.nt+1; + i2 = i1+test.nt-1; + nn = nn+1; + if length(test.f) > 1 + f = test.f(n); + else + f = test.f; + end + if length(test.a) > 1 + a = test.a(m); + else + a = test.a; + end + fprintf('Mixing %.0f Hz %.1f dBFS sine ...\n', f, 20*log10(a)); + s = multitone(test.fs, f, a, test.tl); + for ch=test.ch + x(i1:i2, ch) = dither_and_quantize(s.*win, test.bits_in); + end + end +end + +test.signal = x; + +%% Output +fprintf('Writing output data file %s...\n', test.fn_in); +write_test_data(x, test.fn_in, test.bits_in, test.fmt); +fprintf('Done.\n') + +end diff --git a/tools/test/audio/test_utils/mkdir_check.m b/tools/test/audio/test_utils/mkdir_check.m new file mode 100644 index 000000000000..b453d0b8d898 --- /dev/null +++ b/tools/test/audio/test_utils/mkdir_check.m @@ -0,0 +1,35 @@ +%% +% 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 +% + +function d = mkdir_check(d) +if exist(d) ~= 7 + mkdir(d); +end +end diff --git a/tools/test/audio/test_utils/mls_calc_resp.m b/tools/test/audio/test_utils/mls_calc_resp.m new file mode 100644 index 000000000000..41e2185d5261 --- /dev/null +++ b/tools/test/audio/test_utils/mls_calc_resp.m @@ -0,0 +1,98 @@ +function [f, m_db, b] = mls_calc_resp(csv_fn, ref_wfn, meas_wfn, t_tot, np, f_lo, f_hi) + +%% Calculate frequency response from MLS recordings +% +% [f, m, b] = calc_freq_resp(csv_fn, ref_fn, meas_fn, t_tot, np, f_lo, f_hi) +% +% Inputs parameters: +% csv_fn - File name for CSV format response output +% ref_fn - Reference MLS wave file +% meas_fn - Captured MSL wave file +% t_tot - Time window of MLS analysis in s, e.g. 5 - 10 ms +% np - Number of frequency points +% f_lo - Lower frequency limit for analysis +% f_hi - Upper frequency limit for analysis + +%% +% 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 +% + + %% Read audio files + [xr, fs] = audioread(ref_wfn); + [xm, fsm] = audioread(meas_wfn); + sm = size(xm); + nch = sm(2); + + if (fs ~= fsm) + error('Reference and measured sample rates do not match.'); + end + + ind_imp = zeros(1, nch); + for ch=1:nch + [acor(:,ch),lag] = xcorr(xm(:,ch), xr, 'coeff'); + [~,I] = max(abs(acor(:,ch))); + timeDiff = lag(I); + % Crosscorrelation maximum points to max of impulse response. + % Use it beginning of impulse response + ind_imp(ch) = find(lag == timeDiff); + end + % Keep the channels time aligned by using average of max as reference + ind_imp_avg = round(sum(ind_imp)/nch); + + b = []; + nwin_half = round(t_tot*fs); + nwin_tot = 2*nwin_half; + win = hanning(nwin_tot); + for ch = 1:nch + % All channels are windowed from the same location + p1 = ind_imp_avg-nwin_half; + p2 = p1 + nwin_tot-1; + acor_windowed = acor(p1:p2,ch) .* win; + b(:,ch) = acor_windowed; + end + + + %% Compute frequency response + f = logspace(log10(f_lo),log10(f_hi),np); + for ch=1:nch + h(:,ch) = freqz(b(:,ch), 1, f, fs); + end + m_db = 20*log10(abs(h)); + + fh = fopen(csv_fn, 'w'); + for i = 1:np + fprintf(fh, '%10.3f', f(i)); + for j = 1:nch + fprintf(fh, ', %8.3f', m_db(i, j)); + end + fprintf(fh, '\n'); + end + fclose(fh); + +end diff --git a/tools/test/audio/test_utils/multitone.m b/tools/test/audio/test_utils/multitone.m new file mode 100644 index 000000000000..7f3faa37f9bd --- /dev/null +++ b/tools/test/audio/test_utils/multitone.m @@ -0,0 +1,61 @@ +function x = multitone( fs, f, amp, tlength ) + +%% +% Create single or multiple sine wave(s) +% +% x = multitone(fs, f, a, t); +% +% fs - Sample rate +% f - Frequency (Hz) +% a - Amplitude (lin) +% t - Lenght in seconds +% +% Example: +% x = multitone(48000, [997 1997], 10.^([-26 -46]/20), 1.0); +% + +%% +% 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 +% + +n = round(fs*tlength); +t = (0:n-1)/fs; +nf = length(f); +if nf > 1 + ph = rand(nf, 1)*2*pi; +else + ph = 0; +end + +x = amp(1)*sin(2*pi*f(1)*t'); +for i=2:length(f) + x = x + amp(i)*sin(2*pi*f(i)*t+ph(i)); +end + +end diff --git a/tools/test/audio/test_utils/sync_chirp.m b/tools/test/audio/test_utils/sync_chirp.m new file mode 100644 index 000000000000..513a426904a0 --- /dev/null +++ b/tools/test/audio/test_utils/sync_chirp.m @@ -0,0 +1,68 @@ +function [y, mark]= sync_chirp(fs, direction) + +%% [y, mark]= sync_chirp(fs, direction) +% +% Returns a chirp signal that can be used to mark end and beginning of audio +% tests to syncronize input and captured output accurately. +% +% Input +% fs - sample rate +% direction - direction of frequency sweep 'up' or 'down' +% +% Output +% y - windowed chirp signal +% mark - struct with parameters for chirp +% + +%% +% 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 +% + +mark.a_db = -10; +mark.a = 10^(mark.a_db/20); +mark.fs = fs; +mark.t = 0.2; % Short, to not consume much test time +switch lower(direction) + case 'up' + mark.f0 = 200; % Should work with any speaker + mark.f1 = 3500; % Should work with any speaker + case 'down' + mark.f1 = 200; % Should work with any speaker + mark.f0 = 3500; % Should work with any speaker + otherwise + error('Parameter direction must be ''up'' or ''down'''); +end + +mark.n = round(mark.t*fs); +t_vec = (0:mark.n-1)/fs; +w = hanning(mark.n); +x = chirp(t_vec, mark.f0, mark.t, mark.f1, 'linear')'; +y = x .* w * mark.a; + +end diff --git a/tools/test/audio/test_utils/test_run.m b/tools/test/audio/test_utils/test_run.m new file mode 100644 index 000000000000..1eb34057f48f --- /dev/null +++ b/tools/test/audio/test_utils/test_run.m @@ -0,0 +1,53 @@ +%% +% Copyright (c) 2016, 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 +% + +function test = test_run(test) + +if exist(test.ex) == 2 + %fcmd = sprintf('file %s', test.ex); + %[status, output]=system(fcmd); + %if findstr(output, "Tensilica Xtensa") + % ex = sprintf('xt-run --turbo --summary %s', test.ex); + %else + ex = test.ex; + %end +else + error('Can''t find executable %s', test.ex); +end +test.narg = length(test.arg); +arg = ''; +for n=1:test.narg + arg = sprintf('%s %s', arg, char(test.arg(n))); +end +rcmd = sprintf('%s %s', ex, arg); +fprintf('Running ''%s''...\n', rcmd); +system(rcmd); + +end diff --git a/tools/test/audio/test_utils/write_test_data.m b/tools/test/audio/test_utils/write_test_data.m new file mode 100644 index 000000000000..e998fff3446d --- /dev/null +++ b/tools/test/audio/test_utils/write_test_data.m @@ -0,0 +1,71 @@ +function write_test_data(x, fn, bits, fmt) + +%% +% 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 +% + +switch lower(fmt) + case 'raw' + fh = fopen(fn, 'wb'); + case 'txt' + fh = fopen(fn, 'w'); + otherwise + error('The file format must be raw or txt'); +end +switch bits + case 16 + bfmt = 'int16'; + case 24 + bfmt = 'int32'; + case 32 + bfmt = 'int32'; + otherwise + error('The bits must be set to 16, 24, or 32'); +end + +%% Interleave the channels if two or more +sx = size(x); +xi = zeros(sx(1)*sx(2), 1, bfmt); +if sx(2) > 1 + for n=1:sx(2) + xi(n:sx(2):end) = x(:,n); + end +else + xi(1:end) = x; +end + +%% Write file and close +if strcmp(lower(fmt), 'raw') + fwrite(fh, xi, bfmt); +else + fprintf(fh,'%d\n', xi); +end +fclose(fh); + +end diff --git a/tools/test/qa/run_test.sh b/tools/test/qa/run_test.sh new file mode 100755 index 000000000000..8394db45b5a0 --- /dev/null +++ b/tools/test/qa/run_test.sh @@ -0,0 +1,208 @@ +#!/bin/bash + +CURRENT_PATH=`pwd` +FEATURE_PASS=0 +FEATURE_CNT=0 +TEST_TYPE="functionality_test" +FIRMWARE_PATH="/lib/firmware/intel" +AMIXER_PATH="tests/platform/asound_state" +PLATFORM_PATH="tests/platform" +DATE=`date +%Y_%m_%d_%H_%M` +para=$1 + +switch_tplg() { + + # get next tplg name + tplg_num=`cat $CURRENT_PATH/test_status/tplg |awk -F ' ' '{print $1}'` + tplg_next=$(($tplg_num + 1)) + if [ $tplg_next -gt $tplg_max ]; then + echo "Done the test for all supported topologies" + echo "done" > test_status/status + exit 0 + fi + + tplg_name=`sed -n ${tplg_next}p $CURRENT_PATH/$PLATFORM_PATH/$PLATFORM/$MACHINE/tplg` + echo "continue" > $CURRENT_PATH/test_status/status + echo $tplg_next > $CURRENT_PATH/test_status/tplg + + # relink the tplg + if [ $PLATFORM == "byt" -a $MACHINE == "minnow" ]; then + sudo ln -fs $FIRMWARE_PATH/topology/$tplg_name $FIRMWARE_PATH/sof-$PLATFORM-rt5651.tplg + elif [ $PLATFORM == "apl" -a $MACHINE == "up" ]; then + sudo ln -fs $FIRMWARE_PATH/topology/$tplg_name $FIRMWARE_PATH/sof-$PLATFORM-nocodec.tplg + else + sudo ln -fs $FIRMWARE_PATH/topology/$tplg_name $FIRMWARE_PATH/sof-$PLATFORM.tplg + fi + # system will auto reboot for another tplg test + sleep 2 + sudo reboot +} + +feature_test_list() { + tplg_file=`find $FIRMWARE_PATH -name "sof-*.tplg"` + link_path=`readlink $tplg_file` + link_file=${link_path##*/} + + echo "now is testing $link_file" >> $CURRENT_PATH/$test_report + while read line + do + feature_test $line + done < $CURRENT_PATH/$PLATFORM_PATH/$PLATFORM/$MACHINE/feature-test + switch_tplg +} + +run_test() { + #get tplg name + cd $FIRMWARE_PATH + [[ $def_tplg =~ ^/ ]] && cur_tplg=$def_tplg || cur_tplg=`pwd`/$def_tplg + while [ -h $cur_tplg ] + do + b=`ls -ld $cur_tplg|awk '{print $NF}'` + c=`ls -ld $cur_tplg|awk '{print $(NF-2)}'` + [[ $b =~ ^/ ]] && cur_tplg=$b || cur_tplg=`dirname $c`/$b + done + tplg_name=`echo ${cur_tplg:29}` + cd - + + # parse the tplg + SSP=`echo $tplg_name |awk -F "-" '{print $2}'` + MODE=`echo $tplg_name |awk -F "-" '{print $5}'` + PIPELINE=`echo $tplg_name |awk -F "-" '{print $6}'` + FORMAT_INPUT=`echo $tplg_name |awk -F "-" '{print $7}'` + FORMAT_OUTPUT=`echo $tplg_name |awk -F "-" '{print $8}'` + RATE=`echo $tplg_name |awk -F "-" '{print $9}'` + MCLK=`echo $tplg_name |awk -F "-" '{print $10}'` + CODEC=`echo $tplg_name |awk -F "-" '{print $11}'` + + # run test cases for specfied tplg + alsactl restore -f $CURRENT_PATH/$AMIXER_PATH/$PLATFORM/asound.state.$PIPELINE # alsa setting + feature_test_list # run tplg test +} + +feature_test() { + FEATURE_CUT=$((FEATURE_CNT+1)) + TEST_SUIT=$1 + TEST_CASE=$2 + TEST_PARA=$3 + if [ $TEST_SUIT == "PCM_playback" ] || [ $TEST_SUIT == "pulseaudio" ]; then + bash $CURRENT_PATH/tests/$TEST_TYPE/$TEST_CASE.sh $RATE $FORMAT_INPUT $PIPELINE $PLATFORM # run test + cat playback.result | while read line + do + TEST_CASE=`echo $line|awk -F " " '{ print $1}'` + if [[ $line =~ FAIL ]]; then + echo "$TEST_CASE FAIL" + echo "testsuite_"$TEST_SUIT"_testcase_"$TEST_CASE" testtype_"$TEST_TYPE" FAIL" >> $CURRENT_PATH/$test_report + else + echo "$TEST_CASE PASS" + echo "testsuite_"$TEST_SUIT"_testcase_"$TEST_CASE" testtype_"$TEST_TYPE" PASS" >> $CURRENT_PATH/$test_report + fi + done + else + bash $CURRENT_PATH/tests/$TEST_TYPE/$TEST_CASE.sh $TEST_PARA # run test + if [ $? -eq 0 ]; then + FEATURE_PASS=$((FEATURE_PASS+1)) + echo "$TEST_CASE PASS" + echo "testsuite_"$TEST_SUIT"_testcase_"$TEST_CASE" testtype_"$TEST_TYPE" PASS" >> $CURRENT_PATH/$test_report + else + echo "$TEST_CASE FAIL" + echo "testsuite_"$TEST_SUIT"_testcase_"$TEST_CASE" testtype_"$TEST_TYPE" FAIL" >> $CURRENT_PATH/$test_report + fi + fi + sleep 2 +} + +feature_test_common_list(){ + + echo "now is doing the common test on $PLATFORM" >> $CURRENT_PATH/$test_report + while read line + do + feature_test $line + done < tests/common-test + + # run feature test + run_test +} + +check_status() { + tplg_max=`awk 'END{print NR}' $CURRENT_PATH/$PLATFORM_PATH/$PLATFORM/$MACHINE/tplg` + if [ -f test_status/status ]; then + status=`cat test_status/status |awk -F ' ' '{print $1}'` + if [ $status == "new" ]; then + if [ ! -d "report" ]; then + mkdir report + fi + test_report=report/$DATE-$PLATFORM + echo $test_report > test_status/report + tplg_num=1 + echo $tplg_num > test_status/tplg + feature_test_common_list + elif [ $status == "continue" ]; then + test_report=`cat test_status/report |awk -F ' ' '{print $1}'` + run_test + elif [ $status == "done" ]; then + echo "new" > test_status/status + check_status + fi + else + read -p "Unable to get the test status, do you want to reset the test: Y/N?" answer + case $answer in + Y | y) + reset_status;; + N | n) + echo "Test Exit" + exit 0;; + *) + echo "error choice" + check_status;; + esac + fi +} + +# get platform info +get_platform() { + + MOD_VER=`lscpu |grep "Model name" |awk -F " " '{print $6}'` + if [ $MOD_VER == "E3826" ] || [ $MOD_VER == "E3845" ]; then + PLATFORM="byt" + MACHINE="minnow" + def_tplg="sof-byt.tplg" + check_status + elif [ $MOD_VER == "N4200" ]; then + PLATFORM="apl" + MACHINE="up" + MCLK=24576k + def_tplg="sof-apl-nocodec.tplg" + check_status + elif [ $MOD_VER == "0000" ]; then + PLATFORM="cnl" + MACHINE="cnl" + MCLK=24000k + def_tplg="sof-cnl-nocodec.tplg" + check_status + else + echo "no matched platform, please confirm it" + exit 1 + fi +} + +# reset the test status +reset_status() { + if [ ! -d "test_status" ]; then + mkdir test_status + fi + echo "new" > test_status/status + echo "1" > test_status/tplg + get_platform +} + +function main(){ + sleep 5 + + if [ "$para" == "-r" ]; then + reset_status + fi + get_platform +} + +#Audio CI call main function for testing +main diff --git a/tools/test/qa/tests/common-test b/tools/test/qa/tests/common-test new file mode 100644 index 000000000000..ddbc43fd75a4 --- /dev/null +++ b/tools/test/qa/tests/common-test @@ -0,0 +1,9 @@ +information_detection verify_sof_firmware_presence +information_detection verify_sof_firmware_load +information_detection verify_sof_firmware_version_info +information_detection playback_pcm_list +information_detection verify_sound_modules +information_detection capture_pcm_list +information_detection verify_playback_pcm_list +aplay_check check_aplay +dma_trace check_dma_trace diff --git a/tools/test/qa/tests/functionality_test/capture_pcm_list.sh b/tools/test/qa/tests/functionality_test/capture_pcm_list.sh new file mode 100755 index 000000000000..d32cdcfda8a5 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/capture_pcm_list.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Check capture devices with Audio Legacy +arecord -l |grep "device"> /dev/null +if [ $? != 0 ]; then + echo "Fail: Can not get capture pcm list." + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/channel_test.sh b/tools/test/qa/tests/functionality_test/channel_test.sh new file mode 100755 index 000000000000..9bd95de386a1 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/channel_test.sh @@ -0,0 +1,29 @@ +#!bin/bash + +# channel test for low latency +rm -rf playback.result + +input_freq=12000 +bit=S32_LE +# Check Media Playback Pipeline +alsabat -D hw:0,0 -c 2 -F $input_freq:$input_freq -f $bit +if [ $? != 0 ]; then + echo "Fail: channel test failed with low latency pipeline ." + echo "channel_test_with_low_latency pipeline_"$input_freq:$input_freq"_Bit_"$bit" FAIL" >> playback.result +else + echo "channel_test_with_low_latency_pipeline_"$input_freq:$input_freq"_Bit_"$bit" PASS" >> playback.result +fi + +# media pipeline check +frequency_L=900 +frequency_R=12000 +bit=S32_LE +# Check Media Playback Pipeline +alsabat -P hw:0,1 -C hw:0,0 -c 2 -F $frequency_L:$frequency_R -f $bit +if [ $? != 0 ]; then + echo "Fail: channel test failed with media pipeline ." + echo "channel_test_with_media_pipeline_"$frequency_L:$frequency_R"_Bit_"$bit" FAIL" >> playback.result +else + echo "channel_test_with_media_pipeline_"$frequency_L:$frequency_R"_Bit_"$bit" PASS" >> playback.result +fi + diff --git a/tools/test/qa/tests/functionality_test/check_aplay.sh b/tools/test/qa/tests/functionality_test/check_aplay.sh new file mode 100755 index 000000000000..bdc5d28f72e0 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_aplay.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Check aplay function +aplay -D hw:0,0 -f dat -d 5 -c 2 -r 48000 /dev/zero +if [ $? != 0 ]; then + echo "Aplay FAIL" + exit 1 +else + echo "APlay PASS" + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/check_dma_trace.sh b/tools/test/qa/tests/functionality_test/check_dma_trace.sh new file mode 100755 index 000000000000..a67425922eea --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_dma_trace.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# check dma trace output +sudo rmbox -t > rmbox.log & sleep 2 ; pkill -9 rmbox +# get size of trace log +size=`du -k rmbox.log |awk '{print $1}'` + +if [ $size -gt 1 ]; then + exit 0 +else + exit 1 +fi +rm -f rmbox.log diff --git a/tools/test/qa/tests/functionality_test/check_dual_channels_playback.sh b/tools/test/qa/tests/functionality_test/check_dual_channels_playback.sh new file mode 100755 index 000000000000..a54be5106608 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_dual_channels_playback.sh @@ -0,0 +1,30 @@ +#/bin/bash + +# Check two channel playabck function +rm -rf playback.result +RATE=$1 +if [ $RATE == "48k" ]; then + RATE=48000 +fi +FORMAT=$2 +if [ $FORMAT == "s16le" ]; then + FORMAT=dat +elif [ $FORMAT == "s24le" ]; then + FORMAT=S24_3LE +elif [ $FORMAT == "s32le" ]; then + FORMAT=S32_LE +fi + +PIPELINE_TYPE=$3 +PLATFORM=$4 + +# amixer setting for line in/out mode +alsabat -D hw:0,0 -r $RATE -c 2 -f $FORMAT -F 1500 + if [ $? != 0 ]; then + echo "Fail: dual channels playback test failed." + echo "Check_"$PIPELINE_TYPE"_dual_channels_"$RATE"_"$FORMAT"_playback FAIL" >> playback.result + exit 1 + else + echo "Check_"$PIPELINE_TYPE"_dual_channels_"$RATE"_"$FORMAT"_playback PASS" >> playback.result + exit 0 + fi diff --git a/tools/test/qa/tests/functionality_test/check_line_in_out_playback.sh b/tools/test/qa/tests/functionality_test/check_line_in_out_playback.sh new file mode 100755 index 000000000000..04df1061d44e --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_line_in_out_playback.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Check line in/out function +rm -rf playback.result +RATE=$1 +if [ $RATE == "48K" ]; then + RATE=48000 +fi + +FORMAT=$2 +if [ $FORMAT == "s16le" ]; then + FORMAT=dat +elif [ $FORMAT == "s24le" ]; then + FORMAT=S24_LE +elif [ $FORMAT == "s32le" ]; then + FORMAT=S32_LE +fi + +PIPELINE_TYPE=$3 +PLATFORM=$4 + +# amixer setting for line in/out mode +alsactl restore -f asound_state/$PLATFORM/asound.state.line +sleep 2 +alsabat -D hw:0,0 -r $RATE -c 2 -f $FORMAT -F 1500 + if [ $? != 0 ]; then + echo "Fail: line in/out mode playback test failed." + echo "Check_"$PIPELINE_TYPE"_line_in_out_"$RATE"_"$FORMAT"_playback FAIL" >> playback.result + exit 1 + else + echo "Check_"$PIPELINE_TYPE"_line_in_out_"$RATE"_"$FORMAT"_playback PASS" >> playback.result + exit 0 + fi diff --git a/tools/test/qa/tests/functionality_test/check_modules_loading_time.sh b/tools/test/qa/tests/functionality_test/check_modules_loading_time.sh new file mode 100755 index 000000000000..181f19cce4b1 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_modules_loading_time.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# reloading the audio modules +criterion_time=50 + +(time modprobe sof_acpi_dev) >& rl_time.log +reload_time=`cat rl_time.log |grep "real" | awk -F '.' '{print $2}' |cut -c1-3` +echo $reload_time +if [ "$reload_time" -gt "$criterion_time" ]; then + exit 1 +else + exit 0 +fi + +sleep 2 + + diff --git a/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_capture_function.sh b/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_capture_function.sh new file mode 100755 index 000000000000..9c787ad9dacb --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_capture_function.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check capture function +ps -aux |grep pulseaudio +if [ $? != 0 ]; then + usr/bin/pulseaudio --system & + sleep 10 +else + echo "Pass: start pulseaudio server passed" +fi +alsactl restore -f asound_state/asound.state.pulse-c +sleep 2 +rm -rf playback.result +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +alsabat -Phw:0,0 -r 48000 -c 2 -F 1500 -Cpulse +if [ $? != 0 ]; then + echo "Fail: pulseaudio capture failed with passthrough pipeline." + echo "Check_pulseaudio_capture FAIL" >> playback.result +else + echo "Check_pulseaudio_capture PASS" >> playback.result +fi + diff --git a/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_playback_function.sh b/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_playback_function.sh new file mode 100755 index 000000000000..bc4804b1e22f --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_passthrough_pulseaudio_playback_function.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Check playback function +/usr/bin/pulseaudio --system & +sleep 10 + +alsactl restore -f asound_state/asound.state.pulse-p +sleep 2 +rm -rf playback.result +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +alsabat -Ppulse -r 48000 -c 2 -F 1500 -Chw:0,0 +if [ $? != 0 ]; then + echo "Fail: pulseaudio playback failed with passthrough pipeline." + echo "Check_pulseaudio_Playback FAIL" >> playback.result +else + echo "Check_pulseaudio_Playback PASS" >> playback.result +fi + diff --git a/tools/test/qa/tests/functionality_test/check_pcm_playback.sh b/tools/test/qa/tests/functionality_test/check_pcm_playback.sh new file mode 100755 index 000000000000..313b994c6e6a --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_pcm_playback.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Check playback function +FREQ=("17" "31" "67" "131" "257" "521" "997" "1033" "2069" "4139" "8273" "16547") + +rm -rf playback.result +RATE=$1 +if [ $RATE == "48k" ]; then + RATE=48000 +fi + +FORMAT=$2 +if [ $FORMAT == "s16le" ]; then + FORMAT=dat +elif [ $FORMAT == "s24le" ]; then + FORMAT=S24_LE +elif [ $FORMAT == "s32le" ]; then + FORMAT=S32_LE +fi + +PIPELINE_TYPE=$3 +PLATFORM=$4 + +# Check passthrough Playback Pipeline +for freq in "${FREQ[@]}" +do + alsabat -D hw:0,0 -r $RATE -c 2 -f $FORMAT -F $freq + if [ $? != 0 ]; then + echo "Fail: playback failed with "$PIPELINE_TYPE" pipeline." + echo "Check_"$PIPELINE_TYPE"_Playback_"$RATE"_format_"$FORMAT"_freq_"$freq" FAIL" >> playback.result + else + echo "Check_"$PIPELINE_TYPE"_Playback_"$RATE"_format_"$FORMAT"_freq_"$freq" PASS" >> playback.result + echo "Check_"$PIPELINE_TYPE"_Capture_"$RATE"_format_"$FORMAT"_freq_"$freq" PASS" >> playback.result + fi +done + diff --git a/tools/test/qa/tests/functionality_test/check_playback_after_modules_reloaded.sh b/tools/test/qa/tests/functionality_test/check_playback_after_modules_reloaded.sh new file mode 100755 index 000000000000..de11ea67d941 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_playback_after_modules_reloaded.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +#check playback after modules reloaded +pkill -9 alsabat +sleep 2 + +alsactl restore -f asound_state/asound.state-1.0-passthrough-16bit +sleep 2 +alsabat -D hw:0,0 -r 48000 -c 2 -f dat -F 1500 +if [ $? -eq 0 ]; then + exit 0 +else + exit 1 +fi + diff --git a/tools/test/qa/tests/functionality_test/check_playback_function.sh b/tools/test/qa/tests/functionality_test/check_playback_function.sh new file mode 100755 index 000000000000..4edc32613364 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_playback_function.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check playback function +rm -f playback.tmp +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +inputsample=(8000, 16000, 24000, 32000, 44100, 48000) +bitlist=(U8 S16_LE S24_3LE S32_LE) +# Check Media Playback Pipeline +for samplerate in ${inputsample[*]};do + for bit in ${bitlist[*]}; do + alsabat -P hw:0,1 -C hw:0,0 -r $samplerate -c 2 -f $bit + if [ $? != 0 ]; then + echo "Fail: playback failed with Media pipeline." + echo "Check_Media_Playback_Pipeline_Playback_"$samplerate"_Bit_"$bit" FAIL" >> playback.tmp + else + echo "Check_Media_Playback_Pipeline_Playback_"$samplerate"_Bit_"$bit" PASS" >> playback.tmp + fi + done +done +# Check Low Latency Playback Pipeline +for bit in S16_LE S24_3LE S32_LE ; do + alsabat -D hw:0,0 -r 48000 -c 2 -f $bit + if [ $? != 0 ]; then + echo "Fail: playback failed with low latency pipeline." + echo "Check_Low_Latency_Pipeline_Playback_48000_Bit_"$bit" FAIL" >> playback.tmp + else + echo "Check_Low_latency_Pipeline_Playback_48000_Bit_"$bit" PASS" >> playback.tmp + fi +done diff --git a/tools/test/qa/tests/functionality_test/check_pulseaudio_capture_function.sh b/tools/test/qa/tests/functionality_test/check_pulseaudio_capture_function.sh new file mode 100755 index 000000000000..9c787ad9dacb --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_pulseaudio_capture_function.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Check capture function +ps -aux |grep pulseaudio +if [ $? != 0 ]; then + usr/bin/pulseaudio --system & + sleep 10 +else + echo "Pass: start pulseaudio server passed" +fi +alsactl restore -f asound_state/asound.state.pulse-c +sleep 2 +rm -rf playback.result +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +alsabat -Phw:0,0 -r 48000 -c 2 -F 1500 -Cpulse +if [ $? != 0 ]; then + echo "Fail: pulseaudio capture failed with passthrough pipeline." + echo "Check_pulseaudio_capture FAIL" >> playback.result +else + echo "Check_pulseaudio_capture PASS" >> playback.result +fi + diff --git a/tools/test/qa/tests/functionality_test/check_pulseaudio_function.sh b/tools/test/qa/tests/functionality_test/check_pulseaudio_function.sh new file mode 100755 index 000000000000..d3f42b983a9b --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_pulseaudio_function.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Check playback function +rm -rf playback.result +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +inputsample=(8000, 16000, 24000, 32000, 44100, 48000) +bitlist=(U8 S16_LE S24_3LE S32_LE) +# Check Media Playback Pipeline +for samplerate in ${inputsample[*]};do + for bit in ${bitlist[*]}; do + alsabat -P hw:0,1 -C hw:0,0 -r $samplerate -c 2 -f $bit + if [ $? != 0 ]; then + echo "Fail: playback failed with Media pipeline." + echo "Check_Media_Playback_Pipeline_Playback_"$samplerate"_Bit_"$bit" FAIL" >> playback.result + else + echo "Check_Media_Playback_Pipeline_Playback_"$samplerate"_Bit_"$bit" PASS" >> playback.result + fi + done +done +# Check Low Latency Playback Pipeline +for bit in S16_LE S24_3LE S32_LE ; do + alsabat -D hw:0,0 -r 48000 -c 2 -f $bit + if [ $? != 0 ]; then + echo "Fail: playback failed with low latency pipeline." + echo "Check_Low_Latency_Pipeline_Playback_48000_Bit_"$bit" FAIL" >> playback.result + else + echo "Check_Low_latency_Pipeline_Playback_48000_Bit_"$bit" PASS" >> playback.result + fi +done diff --git a/tools/test/qa/tests/functionality_test/check_pulseaudio_playback_function.sh b/tools/test/qa/tests/functionality_test/check_pulseaudio_playback_function.sh new file mode 100755 index 000000000000..bc4804b1e22f --- /dev/null +++ b/tools/test/qa/tests/functionality_test/check_pulseaudio_playback_function.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Check playback function +/usr/bin/pulseaudio --system & +sleep 10 + +alsactl restore -f asound_state/asound.state.pulse-p +sleep 2 +rm -rf playback.result +#inputsample=(8000 11025 12000 16000 18900 22050 24000 32000 44100 48000 64000 88200 96000 176400 192000) +alsabat -Ppulse -r 48000 -c 2 -F 1500 -Chw:0,0 +if [ $? != 0 ]; then + echo "Fail: pulseaudio playback failed with passthrough pipeline." + echo "Check_pulseaudio_Playback FAIL" >> playback.result +else + echo "Check_pulseaudio_Playback PASS" >> playback.result +fi + diff --git a/tools/test/qa/tests/functionality_test/estimate_firmware_loaded_time.sh b/tools/test/qa/tests/functionality_test/estimate_firmware_loaded_time.sh new file mode 100755 index 000000000000..6e94e932acc3 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/estimate_firmware_loaded_time.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Estimate firmware loaded time +t2=`dmesg | grep "firmware boot complete" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'` +t1=`dmesg | grep "loading firmware" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'` +t=`echo "$t2 $t1" | awk '{print $1-$2}'` +# Firmware load time need less than 50ms +if [ $(echo "$t > 0.05" | bc) -eq 1 ]; then + echo "Fail: Firmware load timeout." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/get_mixer_properties.sh b/tools/test/qa/tests/functionality_test/get_mixer_properties.sh new file mode 100755 index 000000000000..ddc9bf7a10ae --- /dev/null +++ b/tools/test/qa/tests/functionality_test/get_mixer_properties.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +#Get mixer properties +amixer -D hw:sofbytcrrt5651 > /dev/null +if [ $? -ne 0 ]; then + echo "get mixer properties failed" + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/modules_reload.sh b/tools/test/qa/tests/functionality_test/modules_reload.sh new file mode 100755 index 000000000000..a9e9d7bda9d9 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/modules_reload.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +PLATFORM=$1 + +lsmod |egrep "snd|sof" > lsmod.list + +SOF_MODULE=(sof_pci_dev sof_acpi_dev snd_soc_acpi_intel_match snd_sof_intel_byt snd_sof_intel_hsw snd_sof_intel_bdw snd_sof_intel_hda_common snd_sof_xtensa_dsp snd_soc_sst_bytcr_rt5640 snd_soc_sst_bytcr_rt5651 snd_soc_sst_cht_bsw_rt5645 snd_soc_sst_cht_bsw_rt5670 snd_soc_sst_byt_cht_da7213 snd_soc_sst_bxt_pcm512x snd_soc_sst_bxt_tdf8532 snd_soc_cnl_rt274 snd_sof_nocodec snd_sof snd_soc_rt5670 snd_soc_rt5645 snd_soc_rt5651 snd_soc_rt5640 snd_soc_rl6231 snd_soc_da7213 snd_soc_pcm512x_i2c snd_soc_pcm512x snd_soc_tdf8532 snd_soc_rt274 snd_soc_acpi) +RELOAD_MODULE=(modprobe snd_soc_rt5670 modprobe snd_soc_rt5645 modprobe snd_soc_rt5651 modprobe snd_soc_rt5640 modprobe snd_soc_da7213 modprobe snd_soc_pcm512x_i2c modprobe snd_soc_tdf8532 modprobe snd_soc_rt274 modprobe sof_acpi_dev modprobe sof_pci_dev) + +LOAD_MODULES=($(awk '{print $1}' lsmod.list)) + +ERR_COUNT_BEFORE=`dmesg | grep sof-audio | grep "error" | wc -l` + +# unload audio modules +remove() +{ + for module in ${SOF_MODULE[@]} + do + if lsmod | grep "$module" &> /dev/null ; then + echo "Removing $module" + rmmod $module + else + echo "skipping $module, not loaded" + fi + done +} + +err_check() +{ + ERR_COUNT_AFTER=`dmesg | grep sof-audio | grep "error" | wc -l` + if [ $ERR_COUNT_AFTER -gt $ERR_COUNT_BEFORE ] + then + exit 1 + else + exit 0 + fi +} + +# reload audio modules +insert(){ +RELOAD_MODULE=(snd_soc_rt5670 snd_soc_rt5645 snd_soc_rt5651 snd_soc_rt5640 snd_soc_da7213 snd_soc_pcm512x_i2c snd_soc_tdf8532 sof_acpi_dev sof_pci_dev) + for module in ${RELOAD_MODULE[@]} + do + modprobe $module + done +} + +remove +sleep 2 +insert +err_check diff --git a/tools/test/qa/tests/functionality_test/playback_pcm_list.sh b/tools/test/qa/tests/functionality_test/playback_pcm_list.sh new file mode 100755 index 000000000000..5e65d3406b2f --- /dev/null +++ b/tools/test/qa/tests/functionality_test/playback_pcm_list.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Check playback PCM list +aplay -l > /dev/null +if [ $? != 0 ]; then + echo "Fail: Can not get playback pcm list." + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/set_ADC_volume_to_maximum.sh b/tools/test/qa/tests/functionality_test/set_ADC_volume_to_maximum.sh new file mode 100755 index 000000000000..71f02115cabb --- /dev/null +++ b/tools/test/qa/tests/functionality_test/set_ADC_volume_to_maximum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +#Get mixer properties +amixer -D hw:sofbytcrrt5651 sset 'ADC' 127 > /dev/null +if [ $? -ne 0 ]; then + echo "set ADC volume to maximum FAIL" + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/set_ADC_volume_to_minimum.sh b/tools/test/qa/tests/functionality_test/set_ADC_volume_to_minimum.sh new file mode 100755 index 000000000000..48ad7e197bd6 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/set_ADC_volume_to_minimum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +#Get mixer properties +amixer -D hw:sofbytcrrt5651 sset 'ADC' 0 > /dev/null +if [ $? -ne 0 ]; then + echo "set ADC volume to minimum FAIL" + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/set_HP_volume_to_maximum.sh b/tools/test/qa/tests/functionality_test/set_HP_volume_to_maximum.sh new file mode 100755 index 000000000000..bc001714bdcf --- /dev/null +++ b/tools/test/qa/tests/functionality_test/set_HP_volume_to_maximum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +#Get mixer properties +amixer -D hw:sofbytcrrt5651 sset 'HP' 39 > /dev/null +if [ $? -ne 0 ]; then + echo "set HP volume to maximum FAIL" + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/set_HP_volume_to_minimum.sh b/tools/test/qa/tests/functionality_test/set_HP_volume_to_minimum.sh new file mode 100755 index 000000000000..9f843dd98b45 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/set_HP_volume_to_minimum.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +#Get mixer properties +amixer -D hw:sofbytcrrt5651 sset 'HP' 0 > /dev/null +if [ $? -ne 0 ]; then + echo "set HP volume to minimum FAIL" + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/verify_capture_info.sh b/tools/test/qa/tests/functionality_test/verify_capture_info.sh new file mode 100755 index 000000000000..632871ba2540 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_capture_info.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +#diff test_scripts/pcm0cinfo /proc/asound/card0/pcm0c/info > /tmp/capinfdiff.log +cat /proc/asound/sofbytcrrt5651/pcm0c/info |grep "stream: CAPTURE" > /dev/null +if [ $? -ne 0 ]; then + echo "Fail: DSP capture info doesnot match" +# echo "The diff is:" +# cat /tmp/capinfdiff.log | while read line +# do +# echo $line +# done + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/verify_playback_pcm_list.sh b/tools/test/qa/tests/functionality_test/verify_playback_pcm_list.sh new file mode 100755 index 000000000000..528061d4e2af --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_playback_pcm_list.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Check playback pcm list. +aplay -l |grep "device"> /dev/null +if [ $? != 0 ]; then + echo "Fail: Can not get playback pcm list." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/verify_sof_firmware_load.sh b/tools/test/qa/tests/functionality_test/verify_sof_firmware_load.sh new file mode 100755 index 000000000000..ad6b8a909fb7 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_sof_firmware_load.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Verify DSP firmware is loaded +#dmesg | grep "FW loaded" > /dev/null +dmesg | grep "firmware boot complete" > /dev/null +if [ $? != 0 ]; then + echo "Fail: DSP firmware were not loaded." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/verify_sof_firmware_presence.sh b/tools/test/qa/tests/functionality_test/verify_sof_firmware_presence.sh new file mode 100755 index 000000000000..0740ec43a261 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_sof_firmware_presence.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +MOD_VER=`lscpu |grep "Model name" |awk -F " " '{print $6}'` +if [ $MOD_VER == "E3826" ] || [ $MOD_VER == "E3845" ]; then + PLATFORM="byt" +elif [ $MOD_VER == "A3960" ] || [ $MOD_VER == "N4200" ]; then + PLATFORM="apl" +elif [ $MOD_VER == "0000" ]; then + PLATFORM="cnl" +fi + +# Verify DSP firmware is presence +ls /lib/firmware/intel/sof-$PLATFORM.ri > /dev/null +if [ $? != 0 ]; then + echo "Fail: DSP firmware doesnot presence." + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/verify_sof_firmware_version.sh b/tools/test/qa/tests/functionality_test/verify_sof_firmware_version.sh new file mode 100755 index 000000000000..a8e926283149 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_sof_firmware_version.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Verify DSP firmware is loaded +firmware_version=0.9 +get_version=`dmesg | grep "FW loaded" |head -1 |grep "version:" |cut -d : -f 4 |cut -c 2-4` +#get_version=`cat /var/log/kern.log | grep "FW loaded" |head -1 |grep "version:" |cut -d : -f 7 |cut -b 2-4` +if [ "$get_version" != "$firmware_version" ]; then + echo "Fail: DSP firmware were not loaded." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/verify_sof_firmware_version_info.sh b/tools/test/qa/tests/functionality_test/verify_sof_firmware_version_info.sh new file mode 100755 index 000000000000..7f14a14a4951 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_sof_firmware_version_info.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Verify DSP topology loading +dmesg | grep "Firmware info" > /dev/null +if [ $? != 0 ]; then + echo "Fail: No firmware info exist." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/functionality_test/verify_sound_modules.sh b/tools/test/qa/tests/functionality_test/verify_sound_modules.sh new file mode 100755 index 000000000000..f032dfa0bac2 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_sound_modules.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Verify DSP sound modules are loaded +lsmod | grep -i snd_soc > /dev/null +if [ $? != 0 ]; then + echo "Fail: Intel HDA modules were not loaded." + exit 1 +else + exit 0 +fi diff --git a/tools/test/qa/tests/functionality_test/verify_topology_load.sh b/tools/test/qa/tests/functionality_test/verify_topology_load.sh new file mode 100755 index 000000000000..f85c59455e10 --- /dev/null +++ b/tools/test/qa/tests/functionality_test/verify_topology_load.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Verify DSP topology loading +dmesg | grep "loading topology" > /dev/null +if [ $? != 0 ]; then + echo "Fail: DSP topology was not loaded." + exit 1 +else + exit 0 +fi + diff --git a/tools/test/qa/tests/platform/apl/up/feature-test b/tools/test/qa/tests/platform/apl/up/feature-test new file mode 100644 index 000000000000..4e4066de42b9 --- /dev/null +++ b/tools/test/qa/tests/platform/apl/up/feature-test @@ -0,0 +1,2 @@ +PCM_playback check_pcm_playback +PCM_playback check_dual_channels_playback diff --git a/tools/test/qa/tests/platform/apl/up/tplg b/tools/test/qa/tests/platform/apl/up/tplg new file mode 100644 index 000000000000..c606558a4eeb --- /dev/null +++ b/tools/test/qa/tests/platform/apl/up/tplg @@ -0,0 +1,2 @@ +test-ssp5-mclk-0-I2S-volume-s16le-s16le-48k-24576k-nocodec.tplg +test-ssp5-mclk-0-DSP_A-volume-s16le-s16le-48k-24576k-nocodec.tplg diff --git a/tools/test/qa/tests/platform/asound_state/apl/asound.state.passthrough b/tools/test/qa/tests/platform/asound_state/apl/asound.state.passthrough new file mode 100644 index 000000000000..fa1a93effe28 --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/apl/asound.state.passthrough @@ -0,0 +1,34 @@ +state.sofsofnocodec { + control.1 { + iface MIXER + name 'PGA1.0 Master Playback Volume 1' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1200 + dbvalue.1 -1200 + } + } + control.2 { + iface MIXER + name 'PGA2.0 Master Capture Volume 2' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1200 + dbvalue.1 -1200 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/apl/asound.state.volume b/tools/test/qa/tests/platform/asound_state/apl/asound.state.volume new file mode 100644 index 000000000000..fa1a93effe28 --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/apl/asound.state.volume @@ -0,0 +1,34 @@ +state.sofsofnocodec { + control.1 { + iface MIXER + name 'PGA1.0 Master Playback Volume 1' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1200 + dbvalue.1 -1200 + } + } + control.2 { + iface MIXER + name 'PGA2.0 Master Capture Volume 2' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1200 + dbvalue.1 -1200 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/byt/asound.state.line b/tools/test/qa/tests/platform/asound_state/byt/asound.state.line new file mode 100644 index 000000000000..c2a513ee94ca --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/byt/asound.state.line @@ -0,0 +1,1036 @@ +state.sofbytcrrt5651 { + control.1 { + iface MIXER + name 'HP Playback Volume' + value.0 21 + value.1 21 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -1500 + dbvalue.1 -1500 + } + } + control.2 { + iface MIXER + name 'OUT Playback Volume' + value.0 24 + value.1 24 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -1050 + dbvalue.1 -1050 + } + } + control.3 { + iface MIXER + name 'DAC2 Playback Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.4 { + iface MIXER + name 'DAC1 Playback Volume' + value.0 169 + value.1 169 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -2250 + dbvalue.1 -2250 + } + } + control.5 { + iface MIXER + name 'Mono DAC Playback Volume' + value.0 163 + value.1 163 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -4500 + dbvalue.1 -4500 + } + } + control.6 { + iface MIXER + name 'IN1 Boost' + value 1 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2000 + } + } + control.7 { + iface MIXER + name 'IN2 Boost' + value 1 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2000 + } + } + control.8 { + iface MIXER + name 'IN Capture Volume' + value.0 16 + value.1 16 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 31' + dbmin -3450 + dbmax 1200 + dbvalue.0 -1050 + dbvalue.1 -1050 + } + } + control.9 { + iface MIXER + name 'ADC Capture Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.10 { + iface MIXER + name 'ADC Capture Volume' + value.0 106 + value.1 106 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 22125 + dbvalue.1 22125 + } + } + control.11 { + iface MIXER + name 'Mono ADC Capture Volume' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 -17625 + dbvalue.1 -17625 + } + } + control.12 { + iface MIXER + name 'ADC Boost Gain' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 3' + dbmin 0 + dbmax 3600 + dbvalue.0 0 + dbvalue.1 0 + } + } + control.13 { + iface MIXER + name 'IF1 ASRC Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.14 { + iface MIXER + name 'IF2 ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.15 { + iface MIXER + name 'DMIC ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.16 { + iface MIXER + name 'ADC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.17 { + iface MIXER + name 'DAC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.18 { + iface MIXER + name 'Headphone Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.19 { + iface MIXER + name 'Headset Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.20 { + iface MIXER + name 'Internal Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.21 { + iface MIXER + name 'Speaker Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.22 { + iface MIXER + name 'Line In Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.23 { + iface MIXER + name 'RECMIXL INL1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.24 { + iface MIXER + name 'RECMIXL BST3 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.25 { + iface MIXER + name 'RECMIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.26 { + iface MIXER + name 'RECMIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.27 { + iface MIXER + name 'RECMIXR INR1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.28 { + iface MIXER + name 'RECMIXR BST3 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.29 { + iface MIXER + name 'RECMIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.30 { + iface MIXER + name 'RECMIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.31 { + iface MIXER + name 'Stereo1 ADC L2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.32 { + iface MIXER + name 'Stereo1 ADC R2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.33 { + iface MIXER + name 'Stereo1 ADC L1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.34 { + iface MIXER + name 'Stereo1 ADC R1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.35 { + iface MIXER + name 'Stereo2 ADC L2 Mux' + value 'DD MIXL' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC L' + item.1 'DD MIXL' + } + } + control.36 { + iface MIXER + name 'Stereo2 ADC L1 Mux' + value ADCL + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXL' + item.1 ADCL + } + } + control.37 { + iface MIXER + name 'Stereo2 ADC R1 Mux' + value 'DD MIXR' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXR' + item.1 ADCR + } + } + control.38 { + iface MIXER + name 'Stereo2 ADC R2 Mux' + value 'DMIC R' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC R' + item.1 'DD MIXR' + } + } + control.39 { + iface MIXER + name 'Stereo1 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.40 { + iface MIXER + name 'Stereo1 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.41 { + iface MIXER + name 'Stereo1 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.42 { + iface MIXER + name 'Stereo1 ADC MIXR ADC2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.43 { + iface MIXER + name 'Stereo2 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.44 { + iface MIXER + name 'Stereo2 ADC MIXL ADC2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.45 { + iface MIXER + name 'Stereo2 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.46 { + iface MIXER + name 'Stereo2 ADC MIXR ADC2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.47 { + iface MIXER + name 'IF2 ADC' + value 'IF1 ADC1' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'IF1 ADC1' + item.1 'IF1 ADC2' + } + } + control.48 { + iface MIXER + name 'PDM L Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.49 { + iface MIXER + name 'PDM R Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.50 { + iface MIXER + name 'DAC MIXL Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.51 { + iface MIXER + name 'DAC MIXL INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.52 { + iface MIXER + name 'DAC MIXR Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.53 { + iface MIXER + name 'DAC MIXR INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.54 { + iface MIXER + name 'DAC L2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.55 { + iface MIXER + name 'DAC R2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.56 { + iface MIXER + name 'Stereo DAC MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.57 { + iface MIXER + name 'Stereo DAC MIXL DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.58 { + iface MIXER + name 'Stereo DAC MIXL DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.59 { + iface MIXER + name 'Stereo DAC MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.60 { + iface MIXER + name 'Stereo DAC MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.61 { + iface MIXER + name 'Stereo DAC MIXR DAC L1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.62 { + iface MIXER + name 'DD MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.63 { + iface MIXER + name 'DD MIXL DAC L2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.64 { + iface MIXER + name 'DD MIXL DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.65 { + iface MIXER + name 'DD MIXR DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.66 { + iface MIXER + name 'DD MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.67 { + iface MIXER + name 'DD MIXR DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.68 { + iface MIXER + name 'OUT MIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.69 { + iface MIXER + name 'OUT MIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.70 { + iface MIXER + name 'OUT MIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.71 { + iface MIXER + name 'OUT MIXL REC MIXL Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.72 { + iface MIXER + name 'OUT MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.73 { + iface MIXER + name 'OUT MIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.74 { + iface MIXER + name 'OUT MIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.75 { + iface MIXER + name 'OUT MIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.76 { + iface MIXER + name 'OUT MIXR REC MIXR Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.77 { + iface MIXER + name 'OUT MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.78 { + iface MIXER + name 'OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.79 { + iface MIXER + name 'OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.80 { + iface MIXER + name 'HPOVOL L Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.81 { + iface MIXER + name 'HPOVOL R Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.82 { + iface MIXER + name 'HPO MIX DAC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.83 { + iface MIXER + name 'HPO MIX HPVOL Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.84 { + iface MIXER + name 'LOUT MIX DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.85 { + iface MIXER + name 'LOUT MIX DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.86 { + iface MIXER + name 'LOUT MIX OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.87 { + iface MIXER + name 'LOUT MIX OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.88 { + iface MIXER + name 'HPO L Playback Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.89 { + iface MIXER + name 'HPO R Playback Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.90 { + iface MIXER + name 'LOUT L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.91 { + iface MIXER + name 'LOUT R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.92 { + iface MIXER + name 'PGA1.0 Master Playback Volume 1' + value.0 24 + value.1 24 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1600 + dbvalue.1 -1600 + } + } + control.93 { + iface MIXER + name 'PGA2.0 Master Capture Volume 2' + value.0 24 + value.1 24 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 32' + dbmin -9999999 + dbmax 0 + dbvalue.0 -1600 + dbvalue.1 -1600 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/byt/asound.state.passthrough b/tools/test/qa/tests/platform/asound_state/byt/asound.state.passthrough new file mode 100644 index 000000000000..6302218c0454 --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/byt/asound.state.passthrough @@ -0,0 +1,1014 @@ +state.sofbytcrrt5651 { + control.1 { + iface MIXER + name 'HP Playback Volume' + value.0 10 + value.1 10 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -3150 + dbvalue.1 -3150 + } + } + control.2 { + iface MIXER + name 'OUT Playback Volume' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -750 + dbvalue.1 -750 + } + } + control.3 { + iface MIXER + name 'DAC2 Playback Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.4 { + iface MIXER + name 'DAC1 Playback Volume' + value.0 159 + value.1 159 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -6000 + dbvalue.1 -6000 + } + } + control.5 { + iface MIXER + name 'Mono DAC Playback Volume' + value.0 163 + value.1 163 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -4500 + dbvalue.1 -4500 + } + } + control.6 { + iface MIXER + name 'IN1 Boost' + value 2 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2400 + } + } + control.7 { + iface MIXER + name 'IN2 Boost' + value 1 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2000 + } + } + control.8 { + iface MIXER + name 'IN Capture Volume' + value.0 8 + value.1 8 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 31' + dbmin -3450 + dbmax 1200 + dbvalue.0 -2250 + dbvalue.1 -2250 + } + } + control.9 { + iface MIXER + name 'ADC Capture Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.10 { + iface MIXER + name 'ADC Capture Volume' + value.0 112 + value.1 112 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 24375 + dbvalue.1 24375 + } + } + control.11 { + iface MIXER + name 'Mono ADC Capture Volume' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 -17625 + dbvalue.1 -17625 + } + } + control.12 { + iface MIXER + name 'ADC Boost Gain' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 3' + dbmin 0 + dbmax 3600 + dbvalue.0 0 + dbvalue.1 0 + } + } + control.13 { + iface MIXER + name 'IF1 ASRC Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.14 { + iface MIXER + name 'IF2 ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.15 { + iface MIXER + name 'DMIC ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.16 { + iface MIXER + name 'ADC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.17 { + iface MIXER + name 'DAC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.18 { + iface MIXER + name 'Headphone Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.19 { + iface MIXER + name 'Headset Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.20 { + iface MIXER + name 'Internal Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.21 { + iface MIXER + name 'Speaker Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.22 { + iface CARD + name 'Headphone Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.23 { + iface CARD + name 'Headset Mic Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.24 { + iface MIXER + name 'RECMIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.25 { + iface MIXER + name 'RECMIXL BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.26 { + iface MIXER + name 'RECMIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.27 { + iface MIXER + name 'RECMIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.28 { + iface MIXER + name 'RECMIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.29 { + iface MIXER + name 'RECMIXR BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.30 { + iface MIXER + name 'RECMIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.31 { + iface MIXER + name 'RECMIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.32 { + iface MIXER + name 'Stereo1 ADC L2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.33 { + iface MIXER + name 'Stereo1 ADC R2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.34 { + iface MIXER + name 'Stereo1 ADC L1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.35 { + iface MIXER + name 'Stereo1 ADC R1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.36 { + iface MIXER + name 'Stereo2 ADC L2 Mux' + value 'DD MIXL' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC L' + item.1 'DD MIXL' + } + } + control.37 { + iface MIXER + name 'Stereo2 ADC L1 Mux' + value ADCL + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXL' + item.1 ADCL + } + } + control.38 { + iface MIXER + name 'Stereo2 ADC R1 Mux' + value 'DD MIXR' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXR' + item.1 ADCR + } + } + control.39 { + iface MIXER + name 'Stereo2 ADC R2 Mux' + value 'DMIC R' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC R' + item.1 'DD MIXR' + } + } + control.40 { + iface MIXER + name 'Stereo1 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.41 { + iface MIXER + name 'Stereo1 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.42 { + iface MIXER + name 'Stereo1 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.43 { + iface MIXER + name 'Stereo1 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.44 { + iface MIXER + name 'Stereo2 ADC MIXL ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.45 { + iface MIXER + name 'Stereo2 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.46 { + iface MIXER + name 'Stereo2 ADC MIXR ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.47 { + iface MIXER + name 'Stereo2 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.48 { + iface MIXER + name 'IF2 ADC' + value 'IF1 ADC1' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'IF1 ADC1' + item.1 'IF1 ADC2' + } + } + control.49 { + iface MIXER + name 'PDM L Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.50 { + iface MIXER + name 'PDM R Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.51 { + iface MIXER + name 'DAC MIXL Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.52 { + iface MIXER + name 'DAC MIXL INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.53 { + iface MIXER + name 'DAC MIXR Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.54 { + iface MIXER + name 'DAC MIXR INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.55 { + iface MIXER + name 'DAC L2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.56 { + iface MIXER + name 'DAC R2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.57 { + iface MIXER + name 'Stereo DAC MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.58 { + iface MIXER + name 'Stereo DAC MIXL DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.59 { + iface MIXER + name 'Stereo DAC MIXL DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.60 { + iface MIXER + name 'Stereo DAC MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.61 { + iface MIXER + name 'Stereo DAC MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.62 { + iface MIXER + name 'Stereo DAC MIXR DAC L1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.63 { + iface MIXER + name 'DD MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.64 { + iface MIXER + name 'DD MIXL DAC L2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.65 { + iface MIXER + name 'DD MIXL DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.66 { + iface MIXER + name 'DD MIXR DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.67 { + iface MIXER + name 'DD MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.68 { + iface MIXER + name 'DD MIXR DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.69 { + iface MIXER + name 'OUT MIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.70 { + iface MIXER + name 'OUT MIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.71 { + iface MIXER + name 'OUT MIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.72 { + iface MIXER + name 'OUT MIXL REC MIXL Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.73 { + iface MIXER + name 'OUT MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.74 { + iface MIXER + name 'OUT MIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.75 { + iface MIXER + name 'OUT MIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.76 { + iface MIXER + name 'OUT MIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.77 { + iface MIXER + name 'OUT MIXR REC MIXR Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.78 { + iface MIXER + name 'OUT MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.79 { + iface MIXER + name 'OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.80 { + iface MIXER + name 'OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.81 { + iface MIXER + name 'HPOVOL L Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.82 { + iface MIXER + name 'HPOVOL R Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.83 { + iface MIXER + name 'HPO MIX DAC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.84 { + iface MIXER + name 'HPO MIX HPVOL Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.85 { + iface MIXER + name 'LOUT MIX DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.86 { + iface MIXER + name 'LOUT MIX DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.87 { + iface MIXER + name 'LOUT MIX OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.88 { + iface MIXER + name 'LOUT MIX OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.89 { + iface MIXER + name 'HPO L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.90 { + iface MIXER + name 'HPO R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.91 { + iface MIXER + name 'LOUT L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.92 { + iface MIXER + name 'LOUT R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-c b/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-c new file mode 100644 index 000000000000..75565b135fb4 --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-c @@ -0,0 +1,1024 @@ +state.sofbytcrrt5651 { + control.1 { + iface MIXER + name 'HP Playback Volume' + value.0 11 + value.1 11 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -3000 + dbvalue.1 -3000 + } + } + control.2 { + iface MIXER + name 'OUT Playback Volume' + value.0 30 + value.1 30 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -150 + dbvalue.1 -150 + } + } + control.3 { + iface MIXER + name 'DAC2 Playback Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.4 { + iface MIXER + name 'DAC1 Playback Volume' + value.0 159 + value.1 159 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -6000 + dbvalue.1 -6000 + } + } + control.5 { + iface MIXER + name 'Mono DAC Playback Volume' + value.0 163 + value.1 163 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -4500 + dbvalue.1 -4500 + } + } + control.6 { + iface MIXER + name 'IN1 Boost' + value 6 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 4400 + } + } + control.7 { + iface MIXER + name 'IN2 Boost' + value 3 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 3000 + } + } + control.8 { + iface MIXER + name 'IN Capture Volume' + value.0 8 + value.1 8 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 31' + dbmin -3450 + dbmax 1200 + dbvalue.0 -2250 + dbvalue.1 -2250 + } + } + control.9 { + iface MIXER + name 'ADC Capture Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.10 { + iface MIXER + name 'ADC Capture Volume' + value.0 111 + value.1 111 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 24000 + dbvalue.1 24000 + } + } + control.11 { + iface MIXER + name 'Mono ADC Capture Volume' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 -17625 + dbvalue.1 -17625 + } + } + control.12 { + iface MIXER + name 'ADC Boost Gain' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 3' + dbmin 0 + dbmax 3600 + dbvalue.0 0 + dbvalue.1 0 + } + } + control.13 { + iface MIXER + name 'IF1 ASRC Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.14 { + iface MIXER + name 'IF2 ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.15 { + iface MIXER + name 'DMIC ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.16 { + iface MIXER + name 'ADC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.17 { + iface MIXER + name 'DAC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.18 { + iface MIXER + name 'Headphone Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.19 { + iface MIXER + name 'Headset Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.20 { + iface MIXER + name 'Internal Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.21 { + iface MIXER + name 'Speaker Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.22 { + iface MIXER + name 'Line In Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.23 { + iface CARD + name 'Headphone Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.24 { + iface CARD + name 'Headset Mic Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.25 { + iface MIXER + name 'RECMIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.26 { + iface MIXER + name 'RECMIXL BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.27 { + iface MIXER + name 'RECMIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.28 { + iface MIXER + name 'RECMIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.29 { + iface MIXER + name 'RECMIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.30 { + iface MIXER + name 'RECMIXR BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.31 { + iface MIXER + name 'RECMIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.32 { + iface MIXER + name 'RECMIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.33 { + iface MIXER + name 'Stereo1 ADC L2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.34 { + iface MIXER + name 'Stereo1 ADC R2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.35 { + iface MIXER + name 'Stereo1 ADC L1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.36 { + iface MIXER + name 'Stereo1 ADC R1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.37 { + iface MIXER + name 'Stereo2 ADC L2 Mux' + value 'DD MIXL' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC L' + item.1 'DD MIXL' + } + } + control.38 { + iface MIXER + name 'Stereo2 ADC L1 Mux' + value ADCL + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXL' + item.1 ADCL + } + } + control.39 { + iface MIXER + name 'Stereo2 ADC R1 Mux' + value 'DD MIXR' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXR' + item.1 ADCR + } + } + control.40 { + iface MIXER + name 'Stereo2 ADC R2 Mux' + value 'DMIC R' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC R' + item.1 'DD MIXR' + } + } + control.41 { + iface MIXER + name 'Stereo1 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.42 { + iface MIXER + name 'Stereo1 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.43 { + iface MIXER + name 'Stereo1 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.44 { + iface MIXER + name 'Stereo1 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.45 { + iface MIXER + name 'Stereo2 ADC MIXL ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.46 { + iface MIXER + name 'Stereo2 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.47 { + iface MIXER + name 'Stereo2 ADC MIXR ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.48 { + iface MIXER + name 'Stereo2 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.49 { + iface MIXER + name 'IF2 ADC' + value 'IF1 ADC1' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'IF1 ADC1' + item.1 'IF1 ADC2' + } + } + control.50 { + iface MIXER + name 'PDM L Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.51 { + iface MIXER + name 'PDM R Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.52 { + iface MIXER + name 'DAC MIXL Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.53 { + iface MIXER + name 'DAC MIXL INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.54 { + iface MIXER + name 'DAC MIXR Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.55 { + iface MIXER + name 'DAC MIXR INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.56 { + iface MIXER + name 'DAC L2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.57 { + iface MIXER + name 'DAC R2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.58 { + iface MIXER + name 'Stereo DAC MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.59 { + iface MIXER + name 'Stereo DAC MIXL DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.60 { + iface MIXER + name 'Stereo DAC MIXL DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.61 { + iface MIXER + name 'Stereo DAC MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.62 { + iface MIXER + name 'Stereo DAC MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.63 { + iface MIXER + name 'Stereo DAC MIXR DAC L1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.64 { + iface MIXER + name 'DD MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.65 { + iface MIXER + name 'DD MIXL DAC L2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.66 { + iface MIXER + name 'DD MIXL DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.67 { + iface MIXER + name 'DD MIXR DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.68 { + iface MIXER + name 'DD MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.69 { + iface MIXER + name 'DD MIXR DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.70 { + iface MIXER + name 'OUT MIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.71 { + iface MIXER + name 'OUT MIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.72 { + iface MIXER + name 'OUT MIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.73 { + iface MIXER + name 'OUT MIXL REC MIXL Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.74 { + iface MIXER + name 'OUT MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.75 { + iface MIXER + name 'OUT MIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.76 { + iface MIXER + name 'OUT MIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.77 { + iface MIXER + name 'OUT MIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.78 { + iface MIXER + name 'OUT MIXR REC MIXR Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.79 { + iface MIXER + name 'OUT MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.80 { + iface MIXER + name 'OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.81 { + iface MIXER + name 'OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.82 { + iface MIXER + name 'HPOVOL L Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.83 { + iface MIXER + name 'HPOVOL R Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.84 { + iface MIXER + name 'HPO MIX DAC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.85 { + iface MIXER + name 'HPO MIX HPVOL Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.86 { + iface MIXER + name 'LOUT MIX DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.87 { + iface MIXER + name 'LOUT MIX DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.88 { + iface MIXER + name 'LOUT MIX OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.89 { + iface MIXER + name 'LOUT MIX OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.90 { + iface MIXER + name 'HPO L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.91 { + iface MIXER + name 'HPO R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.92 { + iface MIXER + name 'LOUT L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.93 { + iface MIXER + name 'LOUT R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-p b/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-p new file mode 100644 index 000000000000..05f8e02eb56e --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/byt/asound.state.pulse-p @@ -0,0 +1,1024 @@ +state.sofbytcrrt5651 { + control.1 { + iface MIXER + name 'HP Playback Volume' + value.0 14 + value.1 14 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -2550 + dbvalue.1 -2550 + } + } + control.2 { + iface MIXER + name 'OUT Playback Volume' + value.0 24 + value.1 24 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -1050 + dbvalue.1 -1050 + } + } + control.3 { + iface MIXER + name 'DAC2 Playback Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.4 { + iface MIXER + name 'DAC1 Playback Volume' + value.0 159 + value.1 159 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -6000 + dbvalue.1 -6000 + } + } + control.5 { + iface MIXER + name 'Mono DAC Playback Volume' + value.0 163 + value.1 163 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -4500 + dbvalue.1 -4500 + } + } + control.6 { + iface MIXER + name 'IN1 Boost' + value 2 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2400 + } + } + control.7 { + iface MIXER + name 'IN2 Boost' + value 1 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2000 + } + } + control.8 { + iface MIXER + name 'IN Capture Volume' + value.0 7 + value.1 7 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 31' + dbmin -3450 + dbmax 1200 + dbvalue.0 -2400 + dbvalue.1 -2400 + } + } + control.9 { + iface MIXER + name 'ADC Capture Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.10 { + iface MIXER + name 'ADC Capture Volume' + value.0 111 + value.1 111 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 24000 + dbvalue.1 24000 + } + } + control.11 { + iface MIXER + name 'Mono ADC Capture Volume' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 -17625 + dbvalue.1 -17625 + } + } + control.12 { + iface MIXER + name 'ADC Boost Gain' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 3' + dbmin 0 + dbmax 3600 + dbvalue.0 0 + dbvalue.1 0 + } + } + control.13 { + iface MIXER + name 'IF1 ASRC Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.14 { + iface MIXER + name 'IF2 ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.15 { + iface MIXER + name 'DMIC ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.16 { + iface MIXER + name 'ADC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.17 { + iface MIXER + name 'DAC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.18 { + iface MIXER + name 'Headphone Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.19 { + iface MIXER + name 'Headset Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.20 { + iface MIXER + name 'Internal Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.21 { + iface MIXER + name 'Speaker Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.22 { + iface MIXER + name 'Line In Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.23 { + iface CARD + name 'Headphone Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.24 { + iface CARD + name 'Headset Mic Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.25 { + iface MIXER + name 'RECMIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.26 { + iface MIXER + name 'RECMIXL BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.27 { + iface MIXER + name 'RECMIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.28 { + iface MIXER + name 'RECMIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.29 { + iface MIXER + name 'RECMIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.30 { + iface MIXER + name 'RECMIXR BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.31 { + iface MIXER + name 'RECMIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.32 { + iface MIXER + name 'RECMIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.33 { + iface MIXER + name 'Stereo1 ADC L2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.34 { + iface MIXER + name 'Stereo1 ADC R2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.35 { + iface MIXER + name 'Stereo1 ADC L1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.36 { + iface MIXER + name 'Stereo1 ADC R1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.37 { + iface MIXER + name 'Stereo2 ADC L2 Mux' + value 'DD MIXL' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC L' + item.1 'DD MIXL' + } + } + control.38 { + iface MIXER + name 'Stereo2 ADC L1 Mux' + value ADCL + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXL' + item.1 ADCL + } + } + control.39 { + iface MIXER + name 'Stereo2 ADC R1 Mux' + value 'DD MIXR' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXR' + item.1 ADCR + } + } + control.40 { + iface MIXER + name 'Stereo2 ADC R2 Mux' + value 'DMIC R' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC R' + item.1 'DD MIXR' + } + } + control.41 { + iface MIXER + name 'Stereo1 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.42 { + iface MIXER + name 'Stereo1 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.43 { + iface MIXER + name 'Stereo1 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.44 { + iface MIXER + name 'Stereo1 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.45 { + iface MIXER + name 'Stereo2 ADC MIXL ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.46 { + iface MIXER + name 'Stereo2 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.47 { + iface MIXER + name 'Stereo2 ADC MIXR ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.48 { + iface MIXER + name 'Stereo2 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.49 { + iface MIXER + name 'IF2 ADC' + value 'IF1 ADC1' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'IF1 ADC1' + item.1 'IF1 ADC2' + } + } + control.50 { + iface MIXER + name 'PDM L Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.51 { + iface MIXER + name 'PDM R Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.52 { + iface MIXER + name 'DAC MIXL Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.53 { + iface MIXER + name 'DAC MIXL INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.54 { + iface MIXER + name 'DAC MIXR Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.55 { + iface MIXER + name 'DAC MIXR INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.56 { + iface MIXER + name 'DAC L2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.57 { + iface MIXER + name 'DAC R2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.58 { + iface MIXER + name 'Stereo DAC MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.59 { + iface MIXER + name 'Stereo DAC MIXL DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.60 { + iface MIXER + name 'Stereo DAC MIXL DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.61 { + iface MIXER + name 'Stereo DAC MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.62 { + iface MIXER + name 'Stereo DAC MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.63 { + iface MIXER + name 'Stereo DAC MIXR DAC L1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.64 { + iface MIXER + name 'DD MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.65 { + iface MIXER + name 'DD MIXL DAC L2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.66 { + iface MIXER + name 'DD MIXL DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.67 { + iface MIXER + name 'DD MIXR DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.68 { + iface MIXER + name 'DD MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.69 { + iface MIXER + name 'DD MIXR DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.70 { + iface MIXER + name 'OUT MIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.71 { + iface MIXER + name 'OUT MIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.72 { + iface MIXER + name 'OUT MIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.73 { + iface MIXER + name 'OUT MIXL REC MIXL Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.74 { + iface MIXER + name 'OUT MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.75 { + iface MIXER + name 'OUT MIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.76 { + iface MIXER + name 'OUT MIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.77 { + iface MIXER + name 'OUT MIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.78 { + iface MIXER + name 'OUT MIXR REC MIXR Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.79 { + iface MIXER + name 'OUT MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.80 { + iface MIXER + name 'OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.81 { + iface MIXER + name 'OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.82 { + iface MIXER + name 'HPOVOL L Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.83 { + iface MIXER + name 'HPOVOL R Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.84 { + iface MIXER + name 'HPO MIX DAC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.85 { + iface MIXER + name 'HPO MIX HPVOL Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.86 { + iface MIXER + name 'LOUT MIX DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.87 { + iface MIXER + name 'LOUT MIX DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.88 { + iface MIXER + name 'LOUT MIX OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.89 { + iface MIXER + name 'LOUT MIX OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.90 { + iface MIXER + name 'HPO L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.91 { + iface MIXER + name 'HPO R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.92 { + iface MIXER + name 'LOUT L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.93 { + iface MIXER + name 'LOUT R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } +} diff --git a/tools/test/qa/tests/platform/asound_state/byt/asound.state.volume b/tools/test/qa/tests/platform/asound_state/byt/asound.state.volume new file mode 100644 index 000000000000..6302218c0454 --- /dev/null +++ b/tools/test/qa/tests/platform/asound_state/byt/asound.state.volume @@ -0,0 +1,1014 @@ +state.sofbytcrrt5651 { + control.1 { + iface MIXER + name 'HP Playback Volume' + value.0 10 + value.1 10 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -3150 + dbvalue.1 -3150 + } + } + control.2 { + iface MIXER + name 'OUT Playback Volume' + value.0 26 + value.1 26 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 39' + dbmin -4650 + dbmax 1200 + dbvalue.0 -750 + dbvalue.1 -750 + } + } + control.3 { + iface MIXER + name 'DAC2 Playback Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.4 { + iface MIXER + name 'DAC1 Playback Volume' + value.0 159 + value.1 159 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -6000 + dbvalue.1 -6000 + } + } + control.5 { + iface MIXER + name 'Mono DAC Playback Volume' + value.0 163 + value.1 163 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 175' + dbmin -65625 + dbmax 0 + dbvalue.0 -4500 + dbvalue.1 -4500 + } + } + control.6 { + iface MIXER + name 'IN1 Boost' + value 2 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2400 + } + } + control.7 { + iface MIXER + name 'IN2 Boost' + value 1 + comment { + access 'read write' + type INTEGER + count 1 + range '0 - 8' + dbmin 0 + dbmax 5200 + dbvalue.0 2000 + } + } + control.8 { + iface MIXER + name 'IN Capture Volume' + value.0 8 + value.1 8 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 31' + dbmin -3450 + dbmax 1200 + dbvalue.0 -2250 + dbvalue.1 -2250 + } + } + control.9 { + iface MIXER + name 'ADC Capture Switch' + value.0 true + value.1 true + comment { + access 'read write' + type BOOLEAN + count 2 + } + } + control.10 { + iface MIXER + name 'ADC Capture Volume' + value.0 112 + value.1 112 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 24375 + dbvalue.1 24375 + } + } + control.11 { + iface MIXER + name 'Mono ADC Capture Volume' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 127' + dbmin -17625 + dbmax 30000 + dbvalue.0 -17625 + dbvalue.1 -17625 + } + } + control.12 { + iface MIXER + name 'ADC Boost Gain' + value.0 0 + value.1 0 + comment { + access 'read write' + type INTEGER + count 2 + range '0 - 3' + dbmin 0 + dbmax 3600 + dbvalue.0 0 + dbvalue.1 0 + } + } + control.13 { + iface MIXER + name 'IF1 ASRC Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.14 { + iface MIXER + name 'IF2 ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.15 { + iface MIXER + name 'DMIC ASRC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.16 { + iface MIXER + name 'ADC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.17 { + iface MIXER + name 'DAC IF2 Data Switch' + value Normal + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 Normal + item.1 Swap + item.2 'left copy to right' + item.3 'right copy to left' + } + } + control.18 { + iface MIXER + name 'Headphone Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.19 { + iface MIXER + name 'Headset Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.20 { + iface MIXER + name 'Internal Mic Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.21 { + iface MIXER + name 'Speaker Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.22 { + iface CARD + name 'Headphone Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.23 { + iface CARD + name 'Headset Mic Jack' + value true + comment { + access read + type BOOLEAN + count 1 + } + } + control.24 { + iface MIXER + name 'RECMIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.25 { + iface MIXER + name 'RECMIXL BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.26 { + iface MIXER + name 'RECMIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.27 { + iface MIXER + name 'RECMIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.28 { + iface MIXER + name 'RECMIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.29 { + iface MIXER + name 'RECMIXR BST3 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.30 { + iface MIXER + name 'RECMIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.31 { + iface MIXER + name 'RECMIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.32 { + iface MIXER + name 'Stereo1 ADC L2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.33 { + iface MIXER + name 'Stereo1 ADC R2 Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 DMIC + item.1 'DD MIX' + } + } + control.34 { + iface MIXER + name 'Stereo1 ADC L1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.35 { + iface MIXER + name 'Stereo1 ADC R1 Mux' + value ADC + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 ADC + } + } + control.36 { + iface MIXER + name 'Stereo2 ADC L2 Mux' + value 'DD MIXL' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC L' + item.1 'DD MIXL' + } + } + control.37 { + iface MIXER + name 'Stereo2 ADC L1 Mux' + value ADCL + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXL' + item.1 ADCL + } + } + control.38 { + iface MIXER + name 'Stereo2 ADC R1 Mux' + value 'DD MIXR' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIXR' + item.1 ADCR + } + } + control.39 { + iface MIXER + name 'Stereo2 ADC R2 Mux' + value 'DMIC R' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DMIC R' + item.1 'DD MIXR' + } + } + control.40 { + iface MIXER + name 'Stereo1 ADC MIXL ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.41 { + iface MIXER + name 'Stereo1 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.42 { + iface MIXER + name 'Stereo1 ADC MIXR ADC1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.43 { + iface MIXER + name 'Stereo1 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.44 { + iface MIXER + name 'Stereo2 ADC MIXL ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.45 { + iface MIXER + name 'Stereo2 ADC MIXL ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.46 { + iface MIXER + name 'Stereo2 ADC MIXR ADC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.47 { + iface MIXER + name 'Stereo2 ADC MIXR ADC2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.48 { + iface MIXER + name 'IF2 ADC' + value 'IF1 ADC1' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'IF1 ADC1' + item.1 'IF1 ADC2' + } + } + control.49 { + iface MIXER + name 'PDM L Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.50 { + iface MIXER + name 'PDM R Mux' + value 'DD MIX' + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 'DD MIX' + item.1 'Stereo DAC MIX' + } + } + control.51 { + iface MIXER + name 'DAC MIXL Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.52 { + iface MIXER + name 'DAC MIXL INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.53 { + iface MIXER + name 'DAC MIXR Stereo ADC Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.54 { + iface MIXER + name 'DAC MIXR INF1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.55 { + iface MIXER + name 'DAC L2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.56 { + iface MIXER + name 'DAC R2 Mux' + value IF2 + comment { + access 'read write' + type ENUMERATED + count 1 + item.0 IF1 + item.1 IF2 + } + } + control.57 { + iface MIXER + name 'Stereo DAC MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.58 { + iface MIXER + name 'Stereo DAC MIXL DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.59 { + iface MIXER + name 'Stereo DAC MIXL DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.60 { + iface MIXER + name 'Stereo DAC MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.61 { + iface MIXER + name 'Stereo DAC MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.62 { + iface MIXER + name 'Stereo DAC MIXR DAC L1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.63 { + iface MIXER + name 'DD MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.64 { + iface MIXER + name 'DD MIXL DAC L2 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.65 { + iface MIXER + name 'DD MIXL DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.66 { + iface MIXER + name 'DD MIXR DAC R1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.67 { + iface MIXER + name 'DD MIXR DAC R2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.68 { + iface MIXER + name 'DD MIXR DAC L2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.69 { + iface MIXER + name 'OUT MIXL BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.70 { + iface MIXER + name 'OUT MIXL BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.71 { + iface MIXER + name 'OUT MIXL INL1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.72 { + iface MIXER + name 'OUT MIXL REC MIXL Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.73 { + iface MIXER + name 'OUT MIXL DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.74 { + iface MIXER + name 'OUT MIXR BST2 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.75 { + iface MIXER + name 'OUT MIXR BST1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.76 { + iface MIXER + name 'OUT MIXR INR1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.77 { + iface MIXER + name 'OUT MIXR REC MIXR Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.78 { + iface MIXER + name 'OUT MIXR DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.79 { + iface MIXER + name 'OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.80 { + iface MIXER + name 'OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.81 { + iface MIXER + name 'HPOVOL L Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.82 { + iface MIXER + name 'HPOVOL R Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.83 { + iface MIXER + name 'HPO MIX DAC1 Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.84 { + iface MIXER + name 'HPO MIX HPVOL Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.85 { + iface MIXER + name 'LOUT MIX DAC L1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.86 { + iface MIXER + name 'LOUT MIX DAC R1 Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.87 { + iface MIXER + name 'LOUT MIX OUTVOL L Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.88 { + iface MIXER + name 'LOUT MIX OUTVOL R Switch' + value false + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.89 { + iface MIXER + name 'HPO L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.90 { + iface MIXER + name 'HPO R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.91 { + iface MIXER + name 'LOUT L Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } + control.92 { + iface MIXER + name 'LOUT R Playback Switch' + value true + comment { + access 'read write' + type BOOLEAN + count 1 + } + } +} diff --git a/tools/test/qa/tests/platform/byt/feature-test b/tools/test/qa/tests/platform/byt/feature-test new file mode 100644 index 000000000000..1f806f4a5ffa --- /dev/null +++ b/tools/test/qa/tests/platform/byt/feature-test @@ -0,0 +1,8 @@ +PCM_playback check_pcm_playback +PCM_playback check_line_in_out_playback +PCM_playback check_dual_channels_playback +volume_control get_mixer_properties +volume_control set_HP_volume_to_minimum +volume_control set_HP_volume_to_maximum +volume_control set_ADC_volume_to_minimum +volume_control set_ADC_volume_to_maximum diff --git a/tools/test/qa/tests/platform/byt/minnow/feature-test b/tools/test/qa/tests/platform/byt/minnow/feature-test new file mode 100644 index 000000000000..241b1397f711 --- /dev/null +++ b/tools/test/qa/tests/platform/byt/minnow/feature-test @@ -0,0 +1,7 @@ +PCM_playback check_line_in_out_playback +PCM_playback check_dual_channels_playback +volume_control get_mixer_properties +volume_control set_HP_volume_to_minimum +volume_control set_HP_volume_to_maximum +volume_control set_ADC_volume_to_minimum +volume_control set_ADC_volume_to_maximum diff --git a/tools/test/qa/tests/platform/byt/minnow/tplg b/tools/test/qa/tests/platform/byt/minnow/tplg new file mode 100644 index 000000000000..076b01ca5fce --- /dev/null +++ b/tools/test/qa/tests/platform/byt/minnow/tplg @@ -0,0 +1,3 @@ +test-ssp2-mclk-0-I2S-volume-s16le-s24le-48k-19200k-codec.tplg +test-ssp2-mclk-0-I2S-volume-s24le-s24le-48k-19200k-codec.tplg +test-ssp2-mclk-0-I2S-volume-s24le-s16le-48k-19200k-codec.tplg diff --git a/tools/test/qa/tests/platform/byt/tplg b/tools/test/qa/tests/platform/byt/tplg new file mode 100644 index 000000000000..f57370f0b9ff --- /dev/null +++ b/tools/test/qa/tests/platform/byt/tplg @@ -0,0 +1,7 @@ +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-0 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-1 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-2 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-3 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-4 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-5 +test-ssp2-I2S-volume-s16le-s16le-48k-19200k-codec.tplg-6 diff --git a/tools/test/qa/tests/smoke_test/byt_smoke_test_48k16bit_passthrough.sh b/tools/test/qa/tests/smoke_test/byt_smoke_test_48k16bit_passthrough.sh new file mode 100755 index 000000000000..0ac1714665c0 --- /dev/null +++ b/tools/test/qa/tests/smoke_test/byt_smoke_test_48k16bit_passthrough.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +# default devices +psth_p="0,0" # device ID of pass-through playback +psth_c="0,0" # device ID of pass-through capture + +# flag for modules status +flag=0 + +# audio modules list +modules_list="sof_acpi_dev snd_sof_intel_hsw snd_sof_intel_bdw snd_sof_intel_byt snd_soc_sst_bytcr_rt5651 + snd_soc_rt5651 snd_sof snd_soc-core snd_soc_acpi snd_soc_acpi_intel_match snd_soc_rl6231" + +# features passes vs. features all +feature_pass=0 +feature_cnt=1 + +init_counter () { + feature_pass=0 + feature_all=0 +} + +evaluate_result () { + feature_cnt=$((feature_cnt+1)) + if [ $1 -eq 0 ]; then + feature_pass=$((feature_pass+1)) + echo "pass" + sleep 1 + else + echo "fail" + sleep 1 + fi +} + +print_result () { + let feature_cnt=$feature_cnt-1 + echo "[$feature_pass/$feature_cnt] features passes." +} + +# test items +run_feature_test() { + init_counter + + # check FW loading + echo "$feature_cnt: check FW loading" + dmesg |grep "firmware boot complete" > /dev/null + evaluate_result $? + # check sound modules + echo "$feature_cnt: check sound modules" + lsmod |grep "snd" > /dev/null + evaluate_result $? + # check sof modules + echo "$feature_cnt: check sof modules" + lsmod |grep "sof" > /dev/null + evaluate_result $? + # check PCMs + echo "$feature_cnt: check playback PCMs list" + aplay -l |grep "device" + evaluate_result $? + echo "$feature_cnt: check capture PCM list" + arecord -l |grep "device" > /dev/null + evaluate_result $? + # check audio playback + echo "$feature_cnt: check Mono wav playback with pass-through pipeline" + aplay -Dhw:$psth_p -c1 -r48000 -f dat -d5 /dev/zero > /dev/null + evaluate_result $? + echo "$feature_cnt: check stereo wav playback with pass-through pipeline" + aplay -Dhw:$psth_p -c2 -r48000 -f dat -d5 /dev/zero > /dev/null + evaluate_result $? + # check audio capture + echo "$feature_cnt: check mono wav capture" + arecord -Dhw:$path_c -c1 -r48000 -f dat -d2 /dev/zero + evaluate_result $? + echo "$feature_cnt: check stereo wav capture" + arecord -Dhw:$psth_c -c2 -r48000 -f dat -d5 /dev/null + evaluate_result $? + # check modules unloadable + echo "$feature_cnt: check the modules unloadable" + for modules in $modules_list + do + rmmod $modules + done + lsmod |grep snd_soc + if [ $? -eq 0 ]; then + evaluate_result 1 + flag=0 + else + evaluate_result 0 + flag=1 + fi + # check the modules reloadable + echo "$feature_cnt: check the modules reloadable" + if [ $flag -eq 1 ]; then + modprobe sof-acpi-dev + if [ $? -eq 0 ]; then + evaluate_result 0 + flag=0 + else + evaluate_result 1 + flag=1 + fi + else + echo "modules unload failed, skip modules reloadable test" + let feature_cnt=$feature_cnt-1 + fi + # check playback/capture after modules reloaded + sleep 8 # waiting for PCM device ready + if [ $flag -eq 0 ]; then + echo "$feature_cnt: check audio playback after modules reloaded" + aplay -Dhw:$psth_p -c2 -r48000 -f dat -d5 /dev/zero + evaluate_result $? + echo "$feature_cnt: check audio capture after modules reloaded" + arecord -Dhw:$psth_c -c2 -r48000 -f dat -d5 /dev/null + evaluate_result $? + else + echo "modules reloading failed, skip the playback/capture check" + fi + + print_result +} + +echo "*******************************************" +echo " SOF Smoke Test " +echo "-------------------------------------------" + +# get device +echo "usage:" +echo " $0 " + +if [ $# -eq 2 ]; then + psth_p=$1 + psth_c=$2 +elif [ $# -eq 1 ]; then + psth_p=$1 + psth_c=$1 +fi + +echo "current setting:" +echo " playback device: pass-through playback device: $psth_p \ + capture device: pass-through capture device: $psth_c" + +# run test +run_feature_test +echo "*******************************************" diff --git a/tools/test/qa/tests/stability_test/test_modules_reloadable.sh b/tools/test/qa/tests/stability_test/test_modules_reloadable.sh new file mode 100755 index 000000000000..335a98118ed1 --- /dev/null +++ b/tools/test/qa/tests/stability_test/test_modules_reloadable.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +COUNTER=0 +MAXLOOPS=100 +touch test.log + +# remove audio modules +remove() +{ + rmmod sof_acpi_dev + rmmod snd_soc_acpi_intel_match +# rmmod snd_sof_nocodec +# rmmod snd_sof_intel_hsw +# rmmod snd_sof_intel_bdw + rmmod snd_sof_intel_byt + rmmod snd_sof + rmmod snd_soc_sst_bytcr_rt5651 + rmmod snd_soc_acpi +} + +# reload audio modules +reload() +{ + modprobe sof_acpi_dev +} + +err_check() +{ + unset FW_BOOT + unset ERROR + FW_BOOT=$(dmesg | grep sof-audio | grep "boot complete") + ERROR=$(dmesg | grep sof-audio | grep "error") + if [ ! -z "$ERROR" ] || [ -z "$FW_BOOT" ] + then + echo "modules reload failed with error" + dmesg > dmesg.log + exit 1 + else + echo "audio modules are reloaded successfully" + fi +} + +playback() +{ + aplay -D hw:0,0 -r 48000 -c2 -f dat -d5 /dev/zero +} + +main() +{ +echo "modules reloadable test start: " > result.log +while [ $COUNTER -lt $MAXLOOPS ]; do + echo "test $COUNTER" + echo "audio modules are removing..." + remove + if [ $? -eq 0 ]; then + echo "$COUNTER: modules remove - PASS" >> result.log + else + echo "$COUNTER: modules remove - FAIL" >> result.log + dmesg > dmesg.log + exit 1 + fi + sleep 1 + + # check modules is removed + aplay -l |grep "device" > /dev/null + if [ $? -ne 0 ]; then + echo "$COUNTER: check audio device after modules removed - PASS" >> result.log + else + echo "$COUNTER: check audio device after modules removed - FAIL" >> result.log + dmesg > dmesg.log + exit 1 + fi + sleep 1 + + # reload the audio moduels + echo "audio modules are reloading..." + reload + if [ $? -eq 0 ]; then + echo "$COUNTER: modules reload - PASS" >> result.log + else + echo "$COUNTER: modules reload - FAIL" >> result.log + dmesg > dmesg.log + exit 1 + fi + + # check the error log + err_check + + sleep 8 # wait for modules initComplete + + # check playback after modules reloaded + playback + if [ $? -eq 0 ]; then + echo "$COUNTER: playback after modules reloaded - PASS" >> result.log + else + echo "$COUNTER: playback after modules reloaded - FAIL" >> result.log + dmesg > dmesg.log + exit 1 + fi + + sleep 1 + let COUNTER+=1 +done +} + +main diff --git a/tools/test/topology/Makefile.am b/tools/test/topology/Makefile.am new file mode 100644 index 000000000000..be2830bd2b92 --- /dev/null +++ b/tools/test/topology/Makefile.am @@ -0,0 +1,32 @@ + +# +# Dependencies +# + +if XARGS +export USE_XARGS=yes +endif + +DEPS = \ + ../../topology/platform/intel/*.m4 \ + ../../topology/common/*.m4 \ + ../../topology/m4/*.m4 \ + ../../topology/sof/*.m4 + +# Uncomment the following line if you want to debug conf files +.PRECIOUS: %.conf + +all : *.m4 ${DEPS} + ./tplg-build.sh + +clean-local: + rm -f *.conf + rm -f *.tplg + + +EXTRA_DIST = \ + test-capture.m4 \ + test-playback.m4 \ + test-tone-playback.m4 \ + test-all.m4 \ + tplg-build.sh diff --git a/tools/test/topology/test-all.m4 b/tools/test/topology/test-all.m4 new file mode 100644 index 000000000000..518c909cf129 --- /dev/null +++ b/tools/test/topology/test-all.m4 @@ -0,0 +1,97 @@ +# +# Topology for pass through pipeline +# + +# Include topology builder +include(`dai.m4') +include(`ssp.m4') +include(`utils.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`byt.m4') + +# +# Machine Specific Config - !! MUST BE SET TO MATCH TEST MACHINE DRIVER !! +# +# TEST_PIPE_NAME - Pipe name +# TEST_DAI_LINK_NAME - BE DAI link name e.g. "NoCodec" +# TEST_DAI_PORT - SSP port number e.g. 2 +# TEST_DAI_FORMAT - SSP data format e.g s16le +# TEST_PIPE_FORMAT - Pipeline format e.g. s16le +# TEST_SSP_MCLK - SSP BCLK in Hz +# TEST_SSP_BCLK - SSP BCLK in Hz +# TEST_SSP_PHY_BITS - SSP physical slot size +# TEST_SSP_DATA_BITS - SSP data slot size +# TEST_SSP_MODE - SSP mode e.g. I2S, LEFT_J, DSP_A and DSP_B +# + +# +# Define the pipeline +# +# PCM0 <-- TEST_PIPE_NAME pipe --> SSP TEST_DAI_PORT +# + +# Passthrough playback pipeline 1 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 + +PIPELINE_PCM_DAI_ADD(sof/pipe-TEST_PIPE_NAME-playback.m4, + 1, 0, 2, TEST_PIPE_FORMAT, + 48, 1000, 0, 0, + TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_FORMAT, 2) + + +# Passthrough playback pipeline 2 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 + +PIPELINE_PCM_DAI_ADD(sof/pipe-TEST_PIPE_NAME-capture.m4, + 2, 0, 2, TEST_PIPE_FORMAT, + 48, 1000, 0, 0, + TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_FORMAT, 2) + +# +# DAI configuration +# +# SSP port TEST_DAI_PORT is our only pipeline DAI +# + +# playback DAI is SSP TEST_DAI_PORT using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SOURCE_1, 2, TEST_DAI_FORMAT, + 48, 1000, 0, 0) + +# capture DAI is SSP TEST_DAI_PORT using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SINK_2, 2, TEST_DAI_FORMAT, + 48, 1000, 0, 0) + +# PCM Passthrough +PCM_DUPLEX_ADD(Passthrough, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +# Clocks masters wrt codec +# +# TEST_SSP_DATA_BITS bit I2S using TEST_SSP_PHY_BITS bit sample conatiner on SSP TEST_DAI_PORT +# +DAI_CONFIG(TEST_DAI_TYPE, TEST_DAI_PORT, + ifelse(index(TEST_DAI_LINK_NAME, NoCodec), -1, 0 ,TEST_DAI_PORT), + TEST_DAI_LINK_NAME, + SSP_CONFIG(TEST_SSP_MODE, + SSP_CLOCK(mclk, TEST_SSP_MCLK, codec_mclk_in), + SSP_CLOCK(bclk, TEST_SSP_BCLK, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, TEST_SSP_PHY_BITS, 3, 3), + SSP_CONFIG_DATA(TEST_DAI_TYPE, TEST_DAI_PORT, + TEST_SSP_DATA_BITS, TEST_SSP_MCLK_ID))) diff --git a/tools/test/topology/test-capture.m4 b/tools/test/topology/test-capture.m4 new file mode 100644 index 000000000000..4e10d3d31b53 --- /dev/null +++ b/tools/test/topology/test-capture.m4 @@ -0,0 +1,89 @@ +# +# Topology for pass through pipeline +# + +# Include topology builder +include(`dai.m4') +include(`ssp.m4') +include(`dmic.m4') +include(`utils.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`byt.m4') + +# +# Machine Specific Config - !! MUST BE SET TO MATCH TEST MACHINE DRIVER !! +# +# TEST_PIPE_NAME - Pipe name +# TEST_DAI_LINK_NAME - BE DAI link name e.g. "NoCodec" +# TEST_DAI_PORT - SSP port number e.g. 2 +# TEST_DAI_FORMAT - SSP data format e.g s16le +# TEST_PIPE_FORMAT - Pipeline format e.g. s16le +# TEST_SSP_MCLK - SSP MCLK in Hz +# TEST_SSP_BCLK - SSP BCLK in Hz +# TEST_SSP_PHY_BITS - SSP physical slot size +# TEST_SSP_DATA_BITS - SSP data slot size +# TEST_SSP_MODE - SSP mode e.g. I2S, LEFT_J, DSP_A and DSP_B +# + +# +# Define the pipeline +# +# PCM0 <---> SSP TEST_DAI_PORT +# + +# Passthrough capture pipeline 2 on PCM 0 using max 4 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 + +PIPELINE_PCM_DAI_ADD(sof/pipe-TEST_PIPE_NAME-capture.m4, + 2, 0, 4, TEST_PIPE_FORMAT, + 48, 1000, 0, 0, + TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_FORMAT, 2) + +# +# DAI configuration +# +# SSP port TEST_DAI_PORT is our only pipeline DAI +# +# capture DAI is SSP TEST_DAI_PORT using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SINK_2, 2, TEST_DAI_FORMAT, + 48, 1000, 0, 0) + +# PCM Passthrough +PCM_CAPTURE_ADD(Passthrough, 0, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +# Clocks masters wrt codec +# +# TEST_SSP_DATA_BITS bit I2S using TEST_SSP_PHY_BITS bit sample conatiner on SSP TEST_DAI_PORT +# +DAI_CONFIG(TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + ifelse(TEST_DAI_TYPE, `SSP', + SSP_CONFIG(TEST_SSP_MODE, + SSP_CLOCK(mclk, TEST_SSP_MCLK, codec_mclk_in), + SSP_CLOCK(bclk, TEST_SSP_BCLK, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, TEST_SSP_PHY_BITS, 3, 3), + SSP_CONFIG_DATA(TEST_DAI_TYPE, TEST_DAI_PORT, + TEST_SSP_DATA_BITS, TEST_SSP_MCLK_ID)), + TEST_DAI_TYPE, `DMIC', + DMIC_CONFIG(TEST_DMIC_DRIVER_VERSION, TEST_DMIC_CLK_MIN, + TEST_DMIC_CLK_MAX, TEST_DMIC_DUTY_MIN, + TEST_DMIC_DUTY_MAX, TEST_DMIC_SAMPLE_RATE, + DMIC_WORD_LENGTH(TEST_DAI_FORMAT), + TEST_DAI_TYPE, TEST_DAI_PORT, + PDM_CONFIG(TEST_DAI_TYPE, TEST_DAI_PORT, + TEST_DMIC_PDM_CONFIG)), + `')) diff --git a/tools/test/topology/test-equalizer-playback-ssp.m4 b/tools/test/topology/test-equalizer-playback-ssp.m4 new file mode 100644 index 000000000000..ab775a451ed2 --- /dev/null +++ b/tools/test/topology/test-equalizer-playback-ssp.m4 @@ -0,0 +1,74 @@ +# +# Topology for pass through pipeline +# + +# Include topology builder +include(`pipeline.m4') +include(`dai.m4') +include(`utils.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`dsps/byt.m4') + +# +# Machine Specific Config - !! MUST BE SET TO MATCH TEST MACHINE DRIVER !! +# +# TEST_PIPE_NAME - Pipe name +# TEST_DAI_LINK_NAME - BE DAI link name e.g. "NoCodec" +# TEST_SSP_PORT - SSP port number e.g. 2 +# TEST_SSP_FORMAT - SSP data format e.g s16le +# TEST_PIPE_FORMAT - Pipeline format e.g. s16le +# TEST_SSP_MCLK - SSP MCLK in Hz +# TEST_SSP_BCLK - SSP BCLK in Hz +# TEST_SSP_PHY_BITS - SSP physical slot size +# TEST_SSP_DATA_BITS - SSP data slot size +# + +# +# Define the pipeline +# +# PCM0 <---> SSP TEST_SSP_PORT +# + +# Passthrough playback pipeline 1 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +# Use DMAC 0 channel 1 for PCM audio playback data + +PIPELINE_PCM_DAI_ADD(sof/pipe-TEST_PIPE_NAME-playback.m4, + 1, 0, 2, TEST_PIPE_FORMAT, + 48, 1000, 0, 0, 0, 1, + SSP, TEST_SSP_PORT, TEST_SSP_FORMAT, 2) +# +# DAI configuration +# +# SSP port TEST_SSP_PORT is our only pipeline DAI +# + +# playback DAI is SSP TEST_SSP_PORT using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, TEST_SSP_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SOURCE_1, 2, TEST_SSP_FORMAT, + 48, 1000, 0, 0) + +# PCM Passthrough +PCM_PLAYBACK_ADD(Passthrough, 3, 0, 0, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# +# Clocks masters wrt codec +# +# TEST_SSP_DATA_BITS bit I2S using TEST_SSP_PHY_BITS bit sample conatiner on SSP TEST_SSP_PORT +# +DAI_CONFIG(SSP, TEST_SSP_PORT, TEST_DAI_LINK_NAME, I2S, TEST_SSP_DATA_BITS, + DAI_CLOCK(mclk, TEST_SSP_MCLK, slave), + DAI_CLOCK(bclk, TEST_SSP_BCLK, slave), + DAI_CLOCK(fsync, 48000, slave), + DAI_TDM(2, TEST_SSP_PHY_BITS, 3, 3)) diff --git a/tools/test/topology/test-playback.m4 b/tools/test/topology/test-playback.m4 new file mode 100644 index 000000000000..9833ea97ddcc --- /dev/null +++ b/tools/test/topology/test-playback.m4 @@ -0,0 +1,78 @@ +# +# Topology for pass through pipeline +# + +# Include topology builder +include(`pipeline.m4') +include(`dai.m4') +include(`ssp.m4') +include(`utils.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`byt.m4') + +# +# Machine Specific Config - !! MUST BE SET TO MATCH TEST MACHINE DRIVER !! +# +# TEST_PIPE_NAME - Pipe name +# TEST_DAI_LINK_NAME - BE DAI link name e.g. "NoCodec" +# TEST_DAI_PORT - SSP port number e.g. 2 +# TEST_DAI_FORMAT - SSP data format e.g s16le +# TEST_PIPE_FORMAT - Pipeline format e.g. s16le +# TEST_SSP_MCLK - SSP MCLK in Hz +# TEST_SSP_BCLK - SSP BCLK in Hz +# TEST_SSP_PHY_BITS - SSP physical slot size +# TEST_SSP_DATA_BITS - SSP data slot size +# TEST_SSP_MODE - SSP mode e.g. I2S, LEFT_J, DSP_A and DSP_B +# + +# +# Define the pipeline +# +# PCM0 <---> SSP TEST_DAI_PORT +# + +# Passthrough playback pipeline 1 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 + +PIPELINE_PCM_DAI_ADD(sof/pipe-TEST_PIPE_NAME-playback.m4, + 1, 0, 2, TEST_PIPE_FORMAT, + 48, 1000, 0, 0, + TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_FORMAT, 2) +# +# DAI configuration +# +# SSP port TEST_DAI_PORT is our only pipeline DAI +# + +# playback DAI is SSP TEST_DAI_PORT using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SOURCE_1, 2, TEST_DAI_FORMAT, + 48, 1000, 0, 0) + +# PCM Passthrough +PCM_PLAYBACK_ADD(Passthrough, 0, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# +# Clocks masters wrt codec +# +# TEST_SSP_DATA_BITS bit I2S using TEST_SSP_PHY_BITS bit sample conatiner on SSP TEST_DAI_PORT +# +DAI_CONFIG(TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + SSP_CONFIG(TEST_SSP_MODE, + SSP_CLOCK(mclk, TEST_SSP_MCLK, codec_slave), + SSP_CLOCK(bclk, TEST_SSP_BCLK, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, TEST_SSP_PHY_BITS, 3, 3), + SSP_CONFIG_DATA(TEST_DAI_TYPE, TEST_DAI_PORT, + TEST_SSP_DATA_BITS, TEST_SSP_MCLK_ID))) diff --git a/tools/test/topology/test-tone-playback.m4 b/tools/test/topology/test-tone-playback.m4 new file mode 100644 index 000000000000..77db4d1d84bf --- /dev/null +++ b/tools/test/topology/test-tone-playback.m4 @@ -0,0 +1,70 @@ +# +# Topology for Tone Generator Playback +# + +# Include topology builder +include(`pipeline.m4') +include(`dai.m4') +include(`ssp.m4') +include(`utils.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`byt.m4') + +# +# Machine Specific Config - !! MUST BE SET TO MATCH TEST MACHINE DRIVER !! +# +# TEST_PIPE_NAME - Pipe name +# TEST_DAI_LINK_NAME - BE DAI link name e.g. "NoCodec" +# TEST_DAI_PORT - SSP port number e.g. 2 +# TEST_DAI_FORMAT - SSP data format e.g s16le +# TEST_PIPE_FORMAT - Pipeline format e.g. s16le +# TEST_SSP_MCLK - SSP MCLK in Hz +# TEST_SSP_BCLK - SSP BCLK in Hz +# TEST_SSP_PHY_BITS - SSP physical slot size +# TEST_SSP_DATA_BITS - SSP data slot size +# + +# +# Define the pipeline +# +# Tone --B0--> volume --B1--> SSP2 +# + +# Set sample rate for tone +define(`TONE_SAMPLE_RATE', 48000) + +# Tone Playback pipeline 5 using max 2 channels of TEST_PIPE_FORMAT. +# Schedule with 48 frame per 1000us deadline on core 0 with priority 0 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, TEST_PIPE_FORMAT, + 48, 1000, 0, 0) + +# playback DAI is SSP2 using 2 periods +# Buffers use TEST_DAI_FORMAT format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 5, TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + PIPELINE_SOURCE_5, 2, TEST_DAI_FORMAT, + 48, 1000, 2, 0) + +# +# BE configurations - overrides config in ACPI if present +# +# Clocks masters wrt codec +# +# TEST_SSP_DATA_BITS bit I2S using TEST_SSP_PHY_BITS bit sample conatiner on SSP TEST_DAI_PORT +# +DAI_CONFIG(TEST_DAI_TYPE, TEST_DAI_PORT, TEST_DAI_PORT, TEST_DAI_LINK_NAME, + SSP_CONFIG(TEST_SSP_MODE, + SSP_CLOCK(mclk, TEST_SSP_MCLK, codec_mclk_in), + SSP_CLOCK(bclk, TEST_SSP_BCLK, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, TEST_SSP_PHY_BITS, 3, 3), + SSP_CONFIG_DATA(TEST_DAI_TYPE, TEST_DAI_PORT, + TEST_SSP_DATA_BITS, TEST_SSP_MCLK_ID))) diff --git a/tools/test/topology/tplg-build.sh b/tools/test/topology/tplg-build.sh new file mode 100755 index 000000000000..9df05ac71154 --- /dev/null +++ b/tools/test/topology/tplg-build.sh @@ -0,0 +1,259 @@ +#!/bin/bash + +# Utility script to pre-process and compile topology sources into topology test +# binaries. Currently supports simple PCM <-> component <-> SSP style tests +# using simple_test() + +# fail immediately on any errors +set -e + +# M4 preprocessor flags +export M4PATH="../../topology/:../../topology/m4:../../topology/common:../../topology/platform/intel:../../topology/platform/common" + +# Simple component test cases +# can be used on components with 1 sink and 1 source. +SIMPLE_TESTS=(test-all test-capture test-playback) +TONE_TEST=test-tone-playback +DMIC_TEST=test-capture +TEST_STRINGS="" +M4_STRINGS="" +# process m4 simple tests - +# simple_test(name, pipe_name, be_name, format, dai_id, dai_format, dai_phy_bits, dai_data_bits dai_bclk) +# 1) name - test filename suffix +# 2) pipe_name - test component pipeline filename in sof/ +# 3) be_name - BE DAI link name in machine driver, used for matching +# 4) format - PCM sample format +# 5) dai_type - dai type e.g. SSP/DMIC +# 5) dai_id - SSP port number +# 6) dai_format - SSP sample format +# 7) dai_phy_bits - SSP physical number of BLKCs per slot/channel +# 8) dai_data_bits - SSP number of valid data bits per slot/channel +# 9) dai_bclk - SSP BCLK in HZ +# 10) dai_mclk - SSP MCLK in HZ +# 11) SSP mode - SSP mode e.g. I2S, LEFT_J, DSP_A and DSP_B +# 12) SSP mclk_id +# 13) Test pipelines +# + +function simple_test { + if [ $5 == "SSP" ] + then + TESTS=("${!14}") + elif [ $5 == "DMIC" ] + then + TESTS=("${!15}") + fi + for i in ${TESTS[@]} + do + if [ $5 == "DMIC" ] + then + TFILE="$i-dmic$6-${14}-$2-$4-$7-$((${13} / 1000))k-$1" + echo "M4 pre-processing test $i -> ${TFILE}" + m4 ${M4_FLAGS} \ + -DTEST_PIPE_NAME="$2" \ + -DTEST_DAI_LINK_NAME="$3" \ + -DTEST_DAI_PORT=$6 \ + -DTEST_DAI_FORMAT=$7 \ + -DTEST_PIPE_FORMAT=$4 \ + -DTEST_DAI_TYPE=$5 \ + -DTEST_DMIC_DRIVER_VERSION=$8 \ + -DTEST_DMIC_CLK_MIN=$9 \ + -DTEST_DMIC_CLK_MAX=${10} \ + -DTEST_DMIC_DUTY_MIN=${11} \ + -DTEST_DMIC_DUTY_MAX=${12} \ + -DTEST_DMIC_SAMPLE_RATE=${13} \ + -DTEST_DMIC_PDM_CONFIG=${14} \ + $i.m4 > ${TFILE}.conf + echo "Compiling test $i -> ${TFILE}.tplg" + alsatplg -v 1 -c ${TFILE}.conf -o ${TFILE}.tplg + else + if [ "$USE_XARGS" == "yes" ] + then + #if DAI type is SSP, define the SSP specific params + if [ $5 == "SSP" ] + then + if [ $i == "test-all" ] + then + TFILE="test-ssp$6-mclk-${13}-${12}-$2-$4-$7-48k-$((${11} / 1000))k-$1" + else + TFILE="$i-ssp$6-mclk-${13}-${12}-$2-$4-$7-48k-$((${11} / 1000))k-$1" + fi + #create input string for batch m4 processing + M4_STRINGS+="-DTEST_PIPE_NAME=$2,-DTEST_DAI_LINK_NAME=$3\ + -DTEST_DAI_PORT=$6,-DTEST_DAI_FORMAT=$7\ + -DTEST_PIPE_FORMAT=$4,-DTEST_SSP_BCLK=${10}\ + -DTEST_SSP_MCLK=${11},-DTEST_SSP_PHY_BITS=$8\ + -DTEST_SSP_DATA_BITS=$9,-DTEST_SSP_MODE=${12}\ + -DTEST_SSP_MCLK_ID=${13},-DTEST_DAI_TYPE=$5\ + $i.m4,${TFILE}," + #create input string for batch processing of conf files + TEST_STRINGS+=${TFILE}"," + fi + else + #if DAI type is SSP, define the SSP specific params + if [ $5 == "SSP" ] + then + if [ $i == "test-all" ] + then + TFILE="test-ssp$6-mclk-${13}-${12}-$2-$4-$7-48k-$((${11} / 1000))k-$1" + else + TFILE="$i-ssp$6-mclk-${13}-${12}-$2-$4-$7-48k-$((${11} / 1000))k-$1" + fi + echo "M4 pre-processing test $i -> ${TFILE}" + m4 ${M4_FLAGS} \ + -DTEST_PIPE_NAME="$2" \ + -DTEST_DAI_LINK_NAME="$3" \ + -DTEST_DAI_PORT=$6 \ + -DTEST_DAI_FORMAT=$7 \ + -DTEST_PIPE_FORMAT=$4 \ + -DTEST_SSP_BCLK=${10} \ + -DTEST_SSP_MCLK=${11} \ + -DTEST_SSP_PHY_BITS=$8 \ + -DTEST_SSP_DATA_BITS=$9 \ + -DTEST_SSP_MODE=${12} \ + -DTEST_SSP_MCLK_ID=${13} \ + -DTEST_DAI_TYPE=$5 \ + $i.m4 > ${TFILE}.conf + echo "Compiling test $i -> ${TFILE}.tplg" + alsatplg -v 1 -c ${TFILE}.conf -o ${TFILE}.tplg + fi + fi + fi + done +} + +echo "Preparing topology build input..." + +# Pre-process the simple tests +simple_test nocodec passthrough "NoCodec-2" s16le SSP 2 s16le 20 16 1920000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec passthrough "NoCodec-2" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s16le SSP 2 s16le 20 16 1920000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s16le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec src "NoCodec-2" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] + +simple_test codec passthrough "SSP2-Codec" s16le SSP 2 s16le 20 16 1920000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec passthrough "SSP2-Codec" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec volume "SSP2-Codec" s16le SSP 2 s16le 20 16 1920000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec volume "SSP2-Codec" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec volume "SSP2-Codec" s24le SSP 2 s16le 20 16 1920000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec volume "SSP2-Codec" s16le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] +simple_test codec src "SSP2-Codec" s24le SSP 2 s24le 25 24 2400000 19200000 I2S 0 SIMPLE_TESTS[@] + +# for APL +APL_PROTOCOL_TESTS=(I2S LEFT_J DSP_A DSP_B) +APL_SSP_TESTS=(0 1 2 3 4 5) +APL_MODE_TESTS=(volume src) +APL_FORMAT_TESTS=(s16le s24le s32le) +MCLK_IDS=(0 1) + +for protocol in ${APL_PROTOCOL_TESTS[@]} +do + for ssp in ${APL_SSP_TESTS[@]} + do + for mode in ${APL_MODE_TESTS[@]} + do + for format in ${APL_FORMAT_TESTS[@]} + do + for mclk_id in ${MCLK_IDS[@]} + do + simple_test nocodec $mode "NoCodec-${ssp}" $format SSP $ssp s16le 16 16 1536000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test nocodec $mode "NoCodec-${ssp}" $format SSP $ssp s24le 32 24 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test nocodec $mode "NoCodec-${ssp}" $format SSP $ssp s32le 32 32 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + + simple_test codec $mode "SSP${ssp}-Codec" $format SSP $ssp s16le 16 16 1536000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test codec $mode "SSP${ssp}-Codec" $format SSP $ssp s24le 32 24 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test codec $mode "SSP${ssp}-Codec" $format SSP $ssp s32le 32 32 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + done + done + done + for mclk_id in ${MCLK_IDS[@]} + do + simple_test nocodec passthrough "NoCodec-${ssp}" s16le SSP $ssp s16le 16 16 1536000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test nocodec passthrough "NoCodec-${ssp}" s24le SSP $ssp s24le 32 24 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test nocodec passthrough "NoCodec-${ssp}" s32le SSP $ssp s32le 32 32 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + + simple_test codec passthrough "SSP${ssp}-Codec" s16le SSP $ssp s16le 16 16 1536000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test codec passthrough "SSP${ssp}-Codec" s24le SSP $ssp s24le 32 24 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + simple_test codec passthrough "SSP${ssp}-Codec" s32le SSP $ssp s32le 32 32 3072000 24576000 $protocol $mclk_id SIMPLE_TESTS[@] + done + done +done + +for protocol in ${APL_PROTOCOL_TESTS[@]} +do + for ssp in ${APL_SSP_TESTS[@]} + do + for mode in ${APL_MODE_TESTS[@]} + do + for format in ${APL_FORMAT_TESTS[@]} + do + simple_test nocodec $mode "NoCodec-${ssp}" $format SSP $ssp s16le 20 16 1920000 19200000 $protocol 0 SIMPLE_TESTS[@] + simple_test nocodec $mode "NoCodec-${ssp}" $format SSP $ssp s24le 25 24 2400000 19200000 $protocol 0 SIMPLE_TESTS[@] + + simple_test codec $mode "SSP${ssp}-Codec" $format SSP $ssp s16le 20 16 1920000 19200000 $protocol 0 SIMPLE_TESTS[@] + simple_test codec $mode "SSP${ssp}-Codec" $format SSP $ssp s24le 25 24 2400000 19200000 $protocol 0 SIMPLE_TESTS[@] + done + done + simple_test nocodec passthrough "NoCodec-${ssp}" s16le SSP $ssp s16le 20 16 1920000 19200000 $protocol 0 SIMPLE_TESTS[@] + simple_test nocodec passthrough "NoCodec-${ssp}" s24le SSP $ssp s24le 25 24 2400000 19200000 $protocol 0 SIMPLE_TESTS[@] + + simple_test codec passthrough "SSP${ssp}-Codec" s16le SSP $ssp s16le 20 16 1920000 19200000 $protocol 0 SIMPLE_TESTS[@] + simple_test codec passthrough "SSP${ssp}-Codec" s24le SSP $ssp s24le 25 24 2400000 19200000 $protocol 0 SIMPLE_TESTS[@] + done +done + +# for CNL +simple_test nocodec passthrough "NoCodec-0" s16le SSP 0 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec passthrough "NoCodec-2" s24le SSP 0 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-0" s16le SSP 0 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-0" s16le SSP 0 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-0" s24le SSP 0 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-0" s24le SSP 0 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] + +simple_test nocodec passthrough "NoCodec-2" s16le SSP 2 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec passthrough "NoCodec-2" s24le SSP 2 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s16le SSP 2 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s16le SSP 2 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s24le SSP 2 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec volume "NoCodec-2" s24le SSP 2 s16le 25 16 2400000 24000000 I2S 0 SIMPLE_TESTS[@] +simple_test nocodec src "NoCodec-4" s24le SSP 4 s24le 25 24 2400000 24000000 I2S 0 SIMPLE_TESTS[@] + +# Tone test: Tone component only supports s32le currently +simple_test codec tone "SSP2-Codec" s32le SSP 2 s16le 20 16 1920000 19200000 I2S 0 TONE_TEST[@] +#Tone Test for APL +simple_test codec tone "SSP5-Codec" s32le SSP 5 s24le 32 24 3072000 24576000 I2S 0 TONE_TEST[@] +simple_test codec tone "SSP5-Codec" s32le SSP 5 s32le 32 32 3072000 24576000 I2S 0 TONE_TEST[@] + +# DMIC Test Topologies for APL/GLK +DMIC_PDM_CONFIGS=(MONO_PDM0_MICA MONO_PDM0_MICB STEREO_PDM0 STEREO_PDM1 FOUR_CH_PDM0_PDM1) +DMIC_SAMPLE_RATE=(8000 16000 24000 32000 48000 64000 96000) +DMIC_SAMPLE_FORMATS=(s16le s32le) + +for pdm in ${DMIC_PDM_CONFIGS[@]} +do + for rate in ${DMIC_SAMPLE_RATE[@]} + do + for format in ${DMIC_SAMPLE_FORMATS[@]} + do + simple_test nocodec passthrough "DMIC0" $format DMIC 0\ + $format 1 500000 4800000 40 60 $rate $pdm\ + DMIC_TEST[@] + done + done +done + +if [ "$USE_XARGS" == "yes" ] +then + echo "Batch processing m4 files..." + M4_STRINGS=${M4_STRINGS%?} + #m4 processing + echo $M4_STRINGS | tr " " "," | tr '\n' '\0' | xargs -P0 -d ',' -n14 bash -c 'm4 "${@:1:${#}-1}" > ${14}.conf' m4 + + #execute alsatplg to create topology binary + TEST_STRINGS=${TEST_STRINGS%?} + echo $TEST_STRINGS | tr '\n' ',' |\ + xargs -d ',' -P0 -n1 -I string alsatplg -v 1 -c\ + string".conf" -o string".tplg" +fi + diff --git a/tools/topology/Makefile.am b/tools/topology/Makefile.am new file mode 100644 index 000000000000..564fed412ac6 --- /dev/null +++ b/tools/topology/Makefile.am @@ -0,0 +1,89 @@ + +# +# Dependencies +# + +SUBDIRS = m4 sof common platform + +DEPS = \ + platform/intel/*.m4 \ + platform/common/*.m4 \ + common/*.m4 \ + m4/*.m4 \ + sof/*.m4 + +# +# Machines +# + +MACHINES = \ + sof-cht-nocodec.tplg \ + sof-cht-max98090.tplg \ + sof-whl-hda.tplg \ + sof-hda-generic.tplg \ + sof-apl-nocodec.tplg \ + sof-byt-nocodec.tplg \ + sof-bdw-rt286.tplg \ + sof-bdw-rt5640.tplg \ + sof-byt-rt5640.tplg \ + sof-byt-rt5645.tplg \ + sof-byt-rt5651.tplg \ + sof-byt-da7213.tplg \ + sof-cnl-rt274.tplg \ + sof-hsw-rt5640.tplg \ + sof-apl-tdf8532.tplg \ + sof-apl-pcm512x.tplg \ + sof-apl-rt298.tplg \ + sof-apl-wm8804.tplg \ + sof-apl-da7219.tplg \ + sof-glk-da7219.tplg \ + sof-icl-nocodec.tplg \ + sof-apl-eq-pcm512x.tplg \ + sof-apl-eq-dmic.tplg \ + sof-apl-dmic-2ch.tplg \ + sof-apl-dmic-4ch.tplg \ + sof-icl-dmic-4ch.tplg + + +# Uncomment the following line if you want to debug conf files +.PRECIOUS: %.conf + +%.conf : %.m4 ${DEPS} + m4 -I m4 -I common -I platform/common $< > $@ + +%.tplg : %.conf + alsatplg -v 1 -c $< -o $@ + +all: ${MACHINES} + +clean-local: + rm -f *.conf + rm -f *.tplg + +EXTRA_DIST = \ + sof-cht-nocodec.m4 \ + sof-cht-max98090.m4 \ + sof-apl-hdmi.m4 \ + sof-whl-hda.m4 \ + sof-hda-generic.m4 \ + sof-apl-nocodec.m4 \ + sof-byt-nocodec.m4 \ + sof-bdw-rt286.m4 \ + sof-bdw-rt5640.m4 \ + sof-byt-rt5640.m4 \ + sof-byt-rt5645.m4 \ + sof-byt-rt5651.m4 \ + sof-byt-da7213.m4 \ + sof-cnl-rt274.m4 \ + sof-hsw-rt5640.m4 \ + sof-apl-tdf8532.m4 \ + sof-apl-pcm512x.m4 \ + sof-apl-rt298.m4 \ + sof-apl-wm8804.m4 \ + sof-apl-da7219.m4 \ + sof-glk-da7219.m4 \ + sof-icl-nocodec.m4 \ + sof-apl-eq-pcm512x.m4 \ + sof-apl-eq-dmic.m4 \ + sof-apl-dmic-4ch.m4 \ + sof-apl-dmic-2ch.m4 diff --git a/tools/topology/common/Makefile.am b/tools/topology/common/Makefile.am new file mode 100644 index 000000000000..7e207a79703f --- /dev/null +++ b/tools/topology/common/Makefile.am @@ -0,0 +1,4 @@ +EXTRA_DIST = \ + tlv.m4 \ + memory.m4 + diff --git a/tools/topology/common/memory.m4 b/tools/topology/common/memory.m4 new file mode 100644 index 000000000000..0852dffefd64 --- /dev/null +++ b/tools/topology/common/memory.m4 @@ -0,0 +1,15 @@ +dnl +dnl Memory capabilities. +dnl +dnl These are ORed together to create a capability mask that's sent to the +dnl SOF firmware when creating buffer or allocating other memory resources. +dnl +dnl ** Must match SOF_MEM_CAPS_ values in ipc.h ** + +define(`MEM_CAP_RAM', eval(1 << 0)) +define(`MEM_CAP_ROM', eval(1 << 1)) +define(`MEM_CAP_EXT', eval(1 << 2)) +define(`MEM_CAP_LP', eval(1 << 3)) +define(`MEM_CAP_HP', eval(1 << 4)) +define(`MEM_CAP_DMA', eval(1 << 5)) +define(`MEM_CAP_CACHE', eval(1 << 6)) diff --git a/tools/topology/common/tlv.m4 b/tools/topology/common/tlv.m4 new file mode 100644 index 000000000000..f1a9effc3dfa --- /dev/null +++ b/tools/topology/common/tlv.m4 @@ -0,0 +1,14 @@ +# TLV +# +# Common TLV control ranges +# + +SectionTLV."vtlv_m90s3" { + Comment "-64dB step 2dB" + + scale { + min "-6400" + step "200" + mute "1" + } +} diff --git a/tools/topology/m4/Makefile.am b/tools/topology/m4/Makefile.am new file mode 100644 index 000000000000..4d74cefaa8cf --- /dev/null +++ b/tools/topology/m4/Makefile.am @@ -0,0 +1,12 @@ +EXTRA_DIST = \ + buffer.m4 \ + dai.m4 \ + hda.m4 \ + mixer.m4 \ + mixercontrol.m4 \ + pcm.m4 \ + pga.m4 \ + pipeline.m4 \ + src.m4 \ + tone.m4 \ + utils.m4 diff --git a/tools/topology/m4/buffer.m4 b/tools/topology/m4/buffer.m4 new file mode 100644 index 000000000000..55dd06524856 --- /dev/null +++ b/tools/topology/m4/buffer.m4 @@ -0,0 +1,32 @@ +divert(-1) + +dnl Define the macro for buffer widget + +dnl Buffer name) +define(`N_BUFFER', `BUF'PIPELINE_ID`.'$1) + +dnl W_BUFFER(name, size, capabilities) +define(`W_BUFFER', +`SectionVendorTuples."'N_BUFFER($1)`_tuples" {' +` tokens "sof_buffer_tokens"' +` tuples."word" {' +` SOF_TKN_BUF_SIZE' STR($2) +` SOF_TKN_BUF_CAPS' STR($3) +` }' +`}' +`SectionData."'N_BUFFER($1)`_data" {' +` tuples "'N_BUFFER($1)`_tuples"' +`}' +`SectionWidget."'N_BUFFER($1)`" {' +` index "'PIPELINE_ID`"' +` type "buffer"' +` no_pm "true"' +` data [' +` "'N_BUFFER($1)`_data"' +` ]' +`}') + +dnl COMP_BUFFER_SIZE( num_periods, sample_size, channels, fmames) +define(`COMP_BUFFER_SIZE', `eval(`$1 * $2 * $3 * $4')') + +divert(0)dnl diff --git a/tools/topology/m4/bytecontrol.m4 b/tools/topology/m4/bytecontrol.m4 new file mode 100644 index 000000000000..22a7b6f31c5d --- /dev/null +++ b/tools/topology/m4/bytecontrol.m4 @@ -0,0 +1,62 @@ +divert(-1) + +dnl Define macro for byte control + +dnl CONTROLBYTES_MAX(comment, value) +define(`CONTROLBYTES_MAX', +`#$1' +` max STR($2)') + +dnl CONTROLMIXER_TLV(comment, value) +define(`CONTROLBYTES_TLV', +`#$1' +` tlv STR($2)') + +dnl CONTROLMIXER_OPS(info, comment, get, put) +define(`CONTROLBYTES_OPS', +`ops."ctl" {' +` info STR($1)' +` #$2' +` }') + +dnl CONTROLMIXER_OPS(info, comment, get, put) +define(`CONTROLBYTES_EXTOPS', +`extops."extctl" {' +` #$1' +` get STR($2)' +` put STR($3)' +` }') + +define(`CONTROLBYTES_PRIV', +`SectionData.STR($1) {' +` $2' +`}') + +dnl C_CONTROLMIXER(name, index, ops, base, num_regs, mask, max, tlv, priv) +define(`C_CONTROLBYTES', +`SectionControlBytes.STR($1) {' +`' +` # control belongs to this index group' +` index STR($2)' +`' +` # control uses bespoke driver get/put/info ID for io ops' +` $3' +` # control uses bespoke driver get/put/info ID for ext ops' +` $4' +`' +` base STR($5)' +` num_regs STR($6)' +` mask STR($7)' +` $8' +` $9' +` access [' +` tlv_write' +` tlv_read' +` tlv_callback' +` ]' +` data [' +` $10' +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/dai.m4 b/tools/topology/m4/dai.m4 new file mode 100644 index 000000000000..2303671bc618 --- /dev/null +++ b/tools/topology/m4/dai.m4 @@ -0,0 +1,201 @@ +divert(-1) + +include(`debug.m4') + +dnl Define macros for DAI IN/OUT widgets and DAI config + +dnl DAI name) +define(`N_DAI', DAI_NAME) +define(`N_DAI_OUT', DAI_NAME`.OUT') +define(`N_DAI_IN', DAI_NAME`.IN') + +dnl W_DAI_OUT(type, index, dai_link, format, periods_sink, periods_source, preload) +define(`W_DAI_OUT', +`SectionVendorTuples."'N_DAI_OUT($2)`_tuples_w_comp" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($5) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($6) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($7) +` }' +`}' +`SectionData."'N_DAI_OUT($2)`_data_w_comp" {' +` tuples "'N_DAI_OUT($2)`_tuples_w_comp"' +`}' +`SectionVendorTuples."'N_DAI_OUT($2)`_tuples_w" {' +` tokens "sof_dai_tokens"' +` tuples."word" {' +` SOF_TKN_DAI_INDEX' $2 +` SOF_TKN_DAI_DIRECTION' "0" +` }' +`}' +`SectionData."'N_DAI_OUT($2)`_data_w" {' +` tuples "'N_DAI_OUT($2)`_tuples_w"' +`}' +`SectionVendorTuples."'N_DAI_OUT($2)`_tuples_str" {' +` tokens "sof_dai_tokens"' +` tuples."string" {' +` SOF_TKN_DAI_TYPE' $1 +` }' +`}' +`SectionData."'N_DAI_OUT($2)`_data_str" {' +` tuples "'N_DAI_OUT($2)`_tuples_str"' +`}' +`SectionVendorTuples."'N_DAI_OUT($2)`_tuples_comp_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($4) +` }' +`}' +`SectionData."'N_DAI_OUT($2)`_data_comp_str" {' +` tuples "'N_DAI_OUT($2)`_tuples_comp_str"' +`}' +`SectionWidget."'N_DAI_OUT`" {' +` index "'PIPELINE_ID`"' +` type "dai_in"' +` stream_name' STR($3) +` no_pm "true"' +` data [' +` "'N_DAI_OUT($2)`_data_w"' +` "'N_DAI_OUT($2)`_data_w_comp"' +` "'N_DAI_OUT($2)`_data_str"' +` "'N_DAI_OUT($2)`_data_comp_str"' +` ]' +`}') + +dnl W_DAI_IN(type, index, dai_link, format, periods_sink, periods_source, preload) +define(`W_DAI_IN', +`SectionVendorTuples."'N_DAI_IN($2)`_tuples_w_comp" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($5) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($6) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($7) +` }' +`}' +`SectionData."'N_DAI_IN($2)`_data_w_comp" {' +` tuples "'N_DAI_IN($2)`_tuples_w_comp"' +`}' +`SectionVendorTuples."'N_DAI_IN($2)`_tuples_w" {' +` tokens "sof_dai_tokens"' +` tuples."word" {' +` SOF_TKN_DAI_INDEX' $2 +` SOF_TKN_DAI_DIRECTION' "1" +` }' +`}' +`SectionData."'N_DAI_IN($2)`_data_w" {' +` tuples "'N_DAI_IN($2)`_tuples_w"' +`}' +`SectionVendorTuples."'N_DAI_IN($2)`_tuples_str" {' +` tokens "sof_dai_tokens"' +` tuples."string" {' +` SOF_TKN_DAI_TYPE' $1 +` }' +`}' +`SectionData."'N_DAI_IN($2)`_data_str" {' +` tuples "'N_DAI_IN($2)`_tuples_str"' +`}' +`SectionVendorTuples."'N_DAI_IN($2)`_tuples_comp_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($4) +` }' +`}' +`SectionData."'N_DAI_IN($2)`_data_comp_str" {' +` tuples "'N_DAI_IN($2)`_tuples_comp_str"' +`}' +`SectionWidget."'N_DAI_IN`" {' +` index "'PIPELINE_ID`"' +` type "dai_out"' +` stream_name' STR($3) +` no_pm "true"' +` data [' +` "'N_DAI_IN($2)`_data_w"' +` "'N_DAI_IN($2)`_data_w_comp"' +` "'N_DAI_IN($2)`_data_str"' +` "'N_DAI_IN($2)`_data_comp_str"' +` ]' +`}') + +dnl D_DAI(id, playback, capture, data)) +define(`D_DAI', `SectionDAI."'N_DAI`" {' +` index "'PIPELINE_ID`"' +` id "'$1`"' +` playback "'$2`"' +` capture "'$3`"' +`}') + +dnl DAI Config) +define(`N_DAI_CONFIG', `DAICONFIG.'$1) + +dnl DAI_CONFIG(type, idx, link_id, name, ssp_config/dmic_config) +define(`DAI_CONFIG', +`SectionHWConfig."'$1$2`" {' +`' +` id "'$3`"' +`' +` ifelse($1, `SSP', $5, `}')' +`ifelse($1, `DMIC', $5, `')' +`SectionVendorTuples."'N_DAI_CONFIG($1$2)`_tuples_common" {' +` tokens "sof_dai_tokens"' +` tuples."string" {' +` SOF_TKN_DAI_TYPE' STR($1) +` }' +` tuples."word" {' +` SOF_TKN_DAI_INDEX' STR($2) +` }' +`}' +`SectionData."'N_DAI_CONFIG($1$2)`_data_common" {' +` tuples "'N_DAI_CONFIG($1$2)`_tuples_common"' +`}' +`' +`SectionBE."'$4`" {' +` id "'$3`"' +` index "0"' +` default_hw_conf_id "'$3`"' +`' +` hw_configs [' +` "'$1$2`"' +` ]' +` data [' +` "'N_DAI_CONFIG($1$2)`_data"' +` "'N_DAI_CONFIG($1$2)`_data_common"' +`ifelse($1, `DMIC',` "'N_DAI_CONFIG($1$2)`_pdm_data"', `')' +` ]' +`}' +`DEBUG_DAI_CONFIG($1, $3)' +) + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) +define(`DAI_ADD', +`undefine(`PIPELINE_ID')' +`undefine(`DAI_TYPE')' +`undefine(`DAI_INDEX')' +`undefine(`DAI_BE')' +`undefine(`DAI_BUF')' +`undefine(`DAI_PERIODS')' +`undefine(`DAI_FORMAT')' +`undefine(`SCHEDULE_FRAMES')' +`undefine(`SCHEDULE_DEADLINE')' +`undefine(`SCHEDULE_PRIORITY')' +`undefine(`SCHEDULE_CORE')' +`define(`PIPELINE_ID', $2)' +`define(`DAI_TYPE', STR($3))' +`define(`DAI_INDEX', STR($4))' +`define(`DAI_BE', $5)' +`define(`DAI_BUF', $6)' +`define(`DAI_NAME', $3$4)' +`define(`DAI_PERIODS', $7)' +`define(`DAI_FORMAT', $8)' +`define(`SCHEDULE_FRAMES', $9)' +`define(`SCHEDULE_DEADLINE', $10)' +`define(`SCHEDULE_PRIORITY', $11)' +`define(`SCHEDULE_CORE', $12)' +`include($1)' +`DEBUG_DAI($3, $4)' +) + +divert(0)dnl diff --git a/tools/topology/m4/debug.m4 b/tools/topology/m4/debug.m4 new file mode 100644 index 000000000000..6cd16c863cb8 --- /dev/null +++ b/tools/topology/m4/debug.m4 @@ -0,0 +1,29 @@ +divert(-1) + +define(`DEBUG_START', +`ifdef(`GRAPH', `errprint(`digraph topology { +node [color=Red,fontname=Courier] +edge [color=Blue, style=dashed]' +)')') + +define(`DEBUG_END', +`ifdef(`GRAPH', `errprint(`}' +)')') + +define(`DEBUG_GRAPH', +`ifdef(`GRAPH', `errprint("$2"->"$1" +)')') + +define(`DEBUG_DAI', +`ifdef(`INFO', `errprint(/* note: $1 DAI ADD dai_index $2 should match the member (index) in struct dai array (firmware platform specific, usually in dai.c) */ +)')') + +define(`DEBUG_DAI_CONFIG', +`ifdef(`INFO', `errprint(/* note: $1 DAI CONFIG id $2 should match the member (id) in struct snd_soc_dai_link in kernel machine driver (usually under linux/sound/soc/intel/boards/) */ +)')') + +define(`DEBUG_PCM_ADD', +`ifdef(`INFO', `errprint(/* note: PCM ADD for $1 id $2 should be unique within playback or capture pcm ids*/ +)')') + +divert(0)dnl diff --git a/tools/topology/m4/eq_fir.m4 b/tools/topology/m4/eq_fir.m4 new file mode 100644 index 000000000000..75d1d9f7d089 --- /dev/null +++ b/tools/topology/m4/eq_fir.m4 @@ -0,0 +1,53 @@ +divert(-1) + +dnl Define macro for Eq effect widget + +dnl EQ name) +define(`N_EQ_FIR', `EQFIR'PIPELINE_ID`.'$1) + +dnl W_EQ(name, format, periods_sink, periods_source, preload, kcontrols_list) +define(`W_EQ_FIR', +`SectionVendorTuples."'N_EQ_FIR($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_EQ_FIR($1)`_data_w" {' +` tuples "'N_EQ_FIR($1)`_tuples_w"' +`}' +`SectionVendorTuples."'N_EQ_FIR($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_EQ_FIR($1)`_data_str" {' +` tuples "'N_EQ_FIR($1)`_tuples_str"' +`}' +`SectionVendorTuples."'N_EQ_FIR($1)`_tuples_str_type" {' +` tokens "sof_effect_tokens"' +` tuples."string" {' +` SOF_TKN_EFFECT_TYPE' "EQFIR" +` }' +`}' +`SectionData."'N_EQ_FIR($1)`_data_str_type" {' +` tuples "'N_EQ_FIR($1)`_tuples_str_type"' +`}' +`SectionWidget."'N_EQ_FIR($1)`" {' +` index "'PIPELINE_ID`"' +` type "effect"' +` no_pm "true"' +` data [' +` "'N_EQ_FIR($1)`_data_w"' +` "'N_EQ_FIR($1)`_data_str"' +` "'N_EQ_FIR($1)`_data_str_type"' +` ]' +` bytes [' + $6 +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/eq_fir_coef_flat.m4 b/tools/topology/m4/eq_fir_coef_flat.m4 new file mode 100644 index 000000000000..c7ae5d6309af --- /dev/null +++ b/tools/topology/m4/eq_fir_coef_flat.m4 @@ -0,0 +1,6 @@ +# Flat FIR EQ 11-Oct-2018 +CONTROLBYTES_PRIV(EQFIR_priv, +` bytes "0x18,0x00,0x00,0x00,0x02,0x00,0x01,0x00,' +` 0x00,0x00,0x00,0x00,0x04,0x00,0xff,0xff,' +` 0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00"' +) diff --git a/tools/topology/m4/eq_iir.m4 b/tools/topology/m4/eq_iir.m4 new file mode 100644 index 000000000000..1f6466bd9b6f --- /dev/null +++ b/tools/topology/m4/eq_iir.m4 @@ -0,0 +1,53 @@ +divert(-1) + +dnl Define macro for Eq effect widget + +dnl EQ name) +define(`N_EQ_IIR', `EQIIR'PIPELINE_ID`.'$1) + +dnl W_EQ(name, format, periods_sink, periods_source, preload, kcontrols_list) +define(`W_EQ_IIR', +`SectionVendorTuples."'N_EQ_IIR($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_EQ_IIR($1)`_data_w" {' +` tuples "'N_EQ_IIR($1)`_tuples_w"' +`}' +`SectionVendorTuples."'N_EQ_IIR($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_EQ_IIR($1)`_data_str" {' +` tuples "'N_EQ_IIR($1)`_tuples_str"' +`}' +`SectionVendorTuples."'N_EQ_IIR($1)`_tuples_str_type" {' +` tokens "sof_effect_tokens"' +` tuples."string" {' +` SOF_TKN_EFFECT_TYPE' "EQIIR" +` }' +`}' +`SectionData."'N_EQ_IIR($1)`_data_str_type" {' +` tuples "'N_EQ_IIR($1)`_tuples_str_type"' +`}' +`SectionWidget."'N_EQ_IIR($1)`" {' +` index "'PIPELINE_ID`"' +` type "effect"' +` no_pm "true"' +` data [' +` "'N_EQ_IIR($1)`_data_w"' +` "'N_EQ_IIR($1)`_data_str"' +` "'N_EQ_IIR($1)`_data_str_type"' +` ]' +` bytes [' + $6 +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/eq_iir_coef_flat.m4 b/tools/topology/m4/eq_iir_coef_flat.m4 new file mode 100644 index 000000000000..12769abd37f4 --- /dev/null +++ b/tools/topology/m4/eq_iir_coef_flat.m4 @@ -0,0 +1,10 @@ +# Flat IIR EQ 11-Oct-2018 +CONTROLBYTES_PRIV(EQIIR_priv, +` bytes "0x38,0x00,0x00,0x00,0x02,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x9e,0x73,0x13,0x20,' +` 0x00,0x00,0x00,0x00,0xb2,0x7f,0x00,0x00"' +) diff --git a/tools/topology/m4/eq_iir_coef_highpass_50hz_20db_48khz.m4 b/tools/topology/m4/eq_iir_coef_highpass_50hz_20db_48khz.m4 new file mode 100644 index 000000000000..fcd73b5bd343 --- /dev/null +++ b/tools/topology/m4/eq_iir_coef_highpass_50hz_20db_48khz.m4 @@ -0,0 +1,10 @@ +# 50 Hz 2nd order high-pass and +20 dB gain 09-Oct-2018 +CONTROLBYTES_PRIV(EQIIR_priv, +` bytes "0x38,0x00,0x00,0x00,0x02,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x63,0xf3,0x96,0xc0,' +` 0xc6,0x59,0x68,0x7f,0x6d,0x89,0xed,0x1f,' +` 0x27,0xed,0x24,0xc0,0x6d,0x89,0xed,0x1f,' +` 0xfc,0xff,0xff,0xff,0xd0,0x4f,0x00,0x00"' +) diff --git a/tools/topology/m4/hda.m4 b/tools/topology/m4/hda.m4 new file mode 100644 index 000000000000..dcce69fc5370 --- /dev/null +++ b/tools/topology/m4/hda.m4 @@ -0,0 +1,22 @@ +dnl HDA_DAI_CONFIG(idx, link_id, name) +define(`HDA_DAI_CONFIG', +`SectionVendorTuples."'N_DAI_CONFIG(HDA$1)`_tuples_common" {' +` tokens "sof_dai_tokens"' +` tuples."string" {' +` SOF_TKN_DAI_TYPE "HDA"' +` }' +` tuples."word" {' +` SOF_TKN_DAI_INDEX' STR($1) +` }' +`}' +`SectionData."'N_DAI_CONFIG(HDA$1)`_data_common" {' +` tuples "'N_DAI_CONFIG(HDA$1)`_tuples_common"' +`}' +`' +`SectionBE."'$3`" {' +` id "'$2`"' +` index "0"' +` data [' +` "'N_DAI_CONFIG(HDA$1)`_data_common"' +` ]' +`}') diff --git a/tools/topology/m4/mixer.m4 b/tools/topology/m4/mixer.m4 new file mode 100644 index 000000000000..1f2376ea3622 --- /dev/null +++ b/tools/topology/m4/mixer.m4 @@ -0,0 +1,43 @@ +divert(-1) + +dnl Define macro for Mixer widget + +dnl Mixer Name) +define(`N_MIXER', `MIXER'PIPELINE_ID`.'$1) + +dnl Pipe Buffer name in pipeline (pipeline, buffer) +define(`NPIPELINE_MIXER', `MIXER'$1`.'$2) + +dnl W_MIXER(name, format, periods_sink, periods_source, preload) +define(`W_MIXER', +`SectionVendorTuples."'N_MIXER($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_MIXER($1)`_data_w" {' +` tuples "'N_MIXER($1)`_tuples_w"' +`}' +`SectionVendorTuples."'N_MIXER($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_MIXER($1)`_data_str" {' +` tuples "'N_MIXER($1)`_tuples_str"' +`}' +`SectionWidget."'N_MIXER($1)`" {' +` index "'PIPELINE_ID`"' +` type "mixer"' +` no_pm "true"' +` data [' +` "'N_MIXER($1)`_data_w"' +` "'N_MIXER($1)`_data_str"' +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/mixercontrol.m4 b/tools/topology/m4/mixercontrol.m4 new file mode 100644 index 000000000000..a3423c385746 --- /dev/null +++ b/tools/topology/m4/mixercontrol.m4 @@ -0,0 +1,49 @@ +divert(-1) + +dnl Define macro for mixer control + +dnl KCONTROL_CHANNEL(name, reg, shift) +define(`KCONTROL_CHANNEL', +`channel.STR($1) {' +` reg STR($2)' +` shift STR($3)' +` }') + +dnl CONTROLMIXER_MAX(comment, value) +define(`CONTROLMIXER_MAX', +`#$1' +` max STR($2)') + +dnl CONTROLMIXER_TLV(comment, value) +define(`CONTROLMIXER_TLV', +`#$1' +` tlv STR($2)') + +dnl CONTROLMIXER_OPS(info, comment, get, put) +define(`CONTROLMIXER_OPS', +`ops."ctl" {' +` info STR($1)' +` #$2' +` get STR($3)' +` put STR($4)' +` }') + +dnl C_CONTROLMIXER(name, index, ops, max, invert, tlv, KCONTROL_CHANNELS) +define(`C_CONTROLMIXER', +`SectionControlMixer."$1 PIPELINE_ID" {' +`' +` # control belongs to this index group' +` index STR($2)' +`' +` #$7' +` $8' +` # control uses bespoke driver get/put/info ID' +` $3' +`' +` $4' +` invert STR($5)' +` $6' + +`}') + +divert(0)dnl diff --git a/tools/topology/m4/pcm.m4 b/tools/topology/m4/pcm.m4 new file mode 100644 index 000000000000..f8b4ee679ad7 --- /dev/null +++ b/tools/topology/m4/pcm.m4 @@ -0,0 +1,130 @@ +divert(-1) + +dnl Define the macro for PCM playback/capture/capabilities + +dnl PCM name) +define(`N_PCMP', `PCM'$1`P') +define(`N_PCMC', `PCM'$1`C') + +dnl W_PCM_PLAYBACK(pcm, stream, periods_sink, periods_source, preload) +dnl PCM platform configuration +define(`W_PCM_PLAYBACK', +`SectionVendorTuples."'N_PCMP($1)`_tuples_w_comp" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_PCMP($1)`_data_w_comp" {' +` tuples "'N_PCMP($1)`_tuples_w_comp"' +`}' +`SectionWidget."'N_PCMP($1)`" {' +` index "'PIPELINE_ID`"' +` type "aif_in"' +` no_pm "true"' +` stream_name "'$2` '$1`"' +` data [' +` "'N_PCMP($1)`_data_w_comp"' +` ]' +`}') + + +dnl W_PCM_CAPTURE(pcm, stream, periods_sink, periods_source, preload) +define(`W_PCM_CAPTURE', +`SectionVendorTuples."'N_PCMC($1)`_tuples_w_comp" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_PCMC($1)`_data_w_comp" {' +` tuples "'N_PCMC($1)`_tuples_w_comp"' +`}' +`SectionWidget."'N_PCMC($1)`" {' +` index "'PIPELINE_ID`"' +` type "aif_out"' +` no_pm "true"' +` stream_name "'$2` '$1`"' +` data [' +` "'N_PCMC($1)`_data_w_comp"' +` ]' +`}') + +dnl PCM_CAPABILITIES(name, formats, rate_min, rate_max, channels_min, channels_max, periods_min, periods_max, period_size_min, period_size_max, buffer_size_min, buffer_size_max) +define(`PCM_CAPABILITIES', +`SectionPCMCapabilities.STR($1) {' +`' +` formats "$2"' +` rate_min STR($3)' +` rate_max STR($4)' +` channels_min STR($5)' +` channels_max STR($6)' +` periods_min STR($7)' +` periods_max STR($8)' +` period_size_min STR($9)' +` period_size_max STR($10)' +` buffer_size_min STR($11)' +` buffer_size_max STR($12)' +`}') + +dnl PCM_PLAYBACK_ADD(name, pcm_id, playback) +define(`PCM_PLAYBACK_ADD', +`SectionPCM.STR($1) {' +`' +` # used for binding to the PCM' +` id STR($2)' +`' +` dai.STR($1 $2) {' +` id STR($2)' +` }' +`' +` pcm."playback" {' +`' +` capabilities STR($3)' +` }' +`}') + +dnl PCM_CAPTURE_ADD(name, pcm_id, capture) +define(`PCM_CAPTURE_ADD', +`SectionPCM.STR($1) {' +`' +` # used for binding to the PCM' +` id STR($2)' +`' +` dai.STR($1 $2) {' +` id STR($2)' +` }' +`' +` pcm."capture" {' +`' +` capabilities STR($3)' +` }' +`}') + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) +define(`PCM_DUPLEX_ADD', +`SectionPCM.STR($1) {' +`' +` # used for binding to the PCM' +` id STR($2)' +`' +` dai.STR($1 $2) {' +` id STR($2)' +` }' +`' +` pcm."capture" {' +`' +` capabilities STR($4)' +` }' +`' +` pcm."playback" {' +`' +` capabilities STR($3)' +` }' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/pga.m4 b/tools/topology/m4/pga.m4 new file mode 100644 index 000000000000..f38f820295a5 --- /dev/null +++ b/tools/topology/m4/pga.m4 @@ -0,0 +1,44 @@ +divert(-1) + +dnl Define macro for PGA widget + +dnl PGA name) +define(`N_PGA', `PGA'PIPELINE_ID`.'$1) + +dnl W_PGA(name, format, periods_sink, periods_source, preload, kcontrol0. kcontrol1...etc) +define(`W_PGA', +`SectionVendorTuples."'N_PGA($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionData."'N_PGA($1)`_data_w" {' +` tuples "'N_PGA($1)`_tuples_w"' +`}' +`SectionVendorTuples."'N_PGA($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_PGA($1)`_data_str" {' +` tuples "'N_PGA($1)`_tuples_str"' +`}' +`SectionWidget."'N_PGA($1)`" {' +` index "'PIPELINE_ID`"' +` type "pga"' +` no_pm "true"' +` data [' +` "'N_PGA($1)`_data_w"' +` "'N_PGA($1)`_data_str"' +` ]' +` mixer [' + $6 +` ]' + +`}') + +divert(0)dnl diff --git a/tools/topology/m4/pipeline.m4 b/tools/topology/m4/pipeline.m4 new file mode 100644 index 000000000000..8c0ac8779e59 --- /dev/null +++ b/tools/topology/m4/pipeline.m4 @@ -0,0 +1,113 @@ +divert(-1) + +dnl Define macro for pipeline widget + +dnl Pipeline name) +define(`N_PIPELINE', `PIPELINE.'PIPELINE_ID`.'$1) + +dnl W_PIPELINE(stream, deadline, priority, frames, core, timer, platform) +define(`W_PIPELINE', +`SectionVendorTuples."'N_PIPELINE($1)`_tuples" {' +` tokens "sof_sched_tokens"' +` tuples."word" {' +` SOF_TKN_SCHED_DEADLINE' STR($2) +` SOF_TKN_SCHED_PRIORITY' STR($3) +` SOF_TKN_SCHED_CORE' STR($5) +` SOF_TKN_SCHED_FRAMES' STR($4) +` SOF_TKN_SCHED_TIMER' STR($6) +` }' +`}' +`SectionData."'N_PIPELINE($1)`_data" {' +` tuples "'N_PIPELINE($1)`_tuples"' +`}' +`SectionWidget."'N_PIPELINE($1)`" {' +` index "'PIPELINE_ID`"' +` type "scheduler"' +` no_pm "true"' +` stream_name "'$1`"' +` data [' +` "'N_PIPELINE($1)`_data"' +` "'$7`"' +` ]' +`}') + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) +define(`PIPELINE_PCM_ADD', +`undefine(`PCM_ID')' +`undefine(`PIPELINE_ID')' +`undefine(`PIPELINE_CHANNELS')' +`undefine(`PIPELINE_FORMAT')' +`undefine(`SCHEDULE_FRAMES')' +`undefine(`SCHEDULE_DEADLINE')' +`undefine(`SCHEDULE_PRIORITY')' +`undefine(`SCHEDULE_CORE')' +`define(`PIPELINE_ID', $2)' +`define(`PCM_ID', $3)' +`define(`PIPELINE_CHANNELS', $4)' +`define(`PIPELINE_FORMAT', $5)' +`define(`SCHEDULE_FRAMES', $6)' +`define(`SCHEDULE_DEADLINE', $7)' +`define(`SCHEDULE_PRIORITY', $8)' +`define(`SCHEDULE_CORE', $9)' +`define(`DAI_FORMAT', $5)' +`include($1)' +`DEBUG_PCM_ADD($1, $3)' +) + +dnl PIPELINE_PCM_DAI_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core, +dnl dai type, dai_index, dai format, periods) +define(`PIPELINE_PCM_DAI_ADD', +`undefine(`PCM_ID')' +`undefine(`PIPELINE_ID')' +`undefine(`PIPELINE_CHANNELS')' +`undefine(`PIPELINE_FORMAT')' +`undefine(`SCHEDULE_FRAMES')' +`undefine(`SCHEDULE_DEADLINE')' +`undefine(`SCHEDULE_PRIORITY')' +`undefine(`SCHEDULE_CORE')' +`undefine(`DAI_TYPE')' +`undefine(`DAI_INDEX')' +`undefine(`DAI_FORMAT')' +`undefine(`DAI_PERIODS')' +`define(`PIPELINE_ID', $2)' +`define(`PCM_ID', $3)' +`define(`PIPELINE_CHANNELS', $4)' +`define(`PIPELINE_FORMAT', $5)' +`define(`SCHEDULE_FRAMES', $6)' +`define(`SCHEDULE_DEADLINE', $7)' +`define(`SCHEDULE_PRIORITY', $8)' +`define(`SCHEDULE_CORE', $9)' +`define(`DAI_TYPE', STR($10))' +`define(`DAI_INDEX', STR($11))' +`define(`DAI_FORMAT', $12)' +`define(`DAI_PERIODS', $13)' +`define(`DAI_NAME', $10$11)' +`include($1)' +) + +dnl PIPELINE_ADD(pipeline, +dnl pipe id, max channels, format, +dnl frames, deadline, priority, core) +define(`PIPELINE_ADD', +`undefine(`PIPELINE_ID')' +`undefine(`PIPELINE_CHANNELS')' +`undefine(`PIPELINE_FORMAT')' +`undefine(`SCHEDULE_FRAMES')' +`undefine(`SCHEDULE_DEADLINE')' +`undefine(`SCHEDULE_PRIORITY')' +`undefine(`SCHEDULE_CORE')' +`define(`PIPELINE_ID', $2)' +`define(`PIPELINE_CHANNELS', $3)' +`define(`PIPELINE_FORMAT', $4)' +`define(`SCHEDULE_FRAMES', $5)' +`define(`SCHEDULE_DEADLINE', $6)' +`define(`SCHEDULE_PRIORITY', $7)' +`define(`SCHEDULE_CORE', $8)' +`include($1)' +) + +divert(0)dnl diff --git a/tools/topology/m4/src.m4 b/tools/topology/m4/src.m4 new file mode 100644 index 000000000000..aca18e3f9009 --- /dev/null +++ b/tools/topology/m4/src.m4 @@ -0,0 +1,41 @@ +divert(-1) + +dnl Defines the macro for SRC widget + +dnl SRC name) +define(`N_SRC', `SRC'PIPELINE_ID`.'$1) + +dnl W_SRC(name, format, periods_sink, periods_source, data, preload) +define(`W_SRC', +`SectionVendorTuples."'N_SRC($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($6) +` }' +`}' +`SectionData."'N_SRC($1)`_data_w" {' +` tuples "'N_SRC($1)`_tuples_w"' +`}' +`SectionVendorTuples."'N_SRC($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_SRC($1)`_data_str" {' +` tuples "'N_SRC($1)`_tuples_str"' +`}' +`SectionWidget."'N_SRC($1)`" {' +` index "'PIPELINE_ID`"' +` type "src"' +` no_pm "true"' +` data [' +` "'N_SRC($1)`_data_w"' +` "'N_SRC($1)`_data_str"' +` "'$5`"' +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/tone.m4 b/tools/topology/m4/tone.m4 new file mode 100644 index 000000000000..583134c6f920 --- /dev/null +++ b/tools/topology/m4/tone.m4 @@ -0,0 +1,50 @@ +divert(-1) + +dnl Define macro for siggen widget + +dnl Tone name) +define(`N_TONE', `TONE'PIPELINE_ID`.'$1) + +dnl W_TONE(name, format, periods_sink, periods_source, preload, kcontrols_list) +define(`W_TONE', +`SectionVendorTuples."'N_TONE($1)`_tuples_w" {' +` tokens "sof_comp_tokens"' +` tuples."word" {' +` SOF_TKN_COMP_PERIOD_SINK_COUNT' STR($3) +` SOF_TKN_COMP_PERIOD_SOURCE_COUNT' STR($4) +` SOF_TKN_COMP_PRELOAD_COUNT' STR($5) +` }' +`}' +`SectionVendorTuples."'N_TONE($1)`_tone_tuples_w" {' +` tokens "sof_tone_tokens"' +` tuples."word" {' +` SOF_TKN_TONE_SAMPLE_RATE' ifdef(TONE_SAMPLE_RATE, STR(TONE_SAMPLE_RATE), "48000") +` }' +`}' +`SectionData."'N_TONE($1)`_data_w" {' +` tuples "'N_TONE($1)`_tuples_w"' +` tuples "'N_TONE($1)`_tone_tuples_w"' +`}' +`SectionVendorTuples."'N_TONE($1)`_tuples_str" {' +` tokens "sof_comp_tokens"' +` tuples."string" {' +` SOF_TKN_COMP_FORMAT' STR($2) +` }' +`}' +`SectionData."'N_TONE($1)`_data_str" {' +` tuples "'N_TONE($1)`_tuples_str"' +`}' +`SectionWidget."'N_TONE($1)`" {' +` index "'PIPELINE_ID`"' +` type "siggen"' +` no_pm "true"' +` data [' +` "'N_TONE($1)`_data_w"' +` "'N_TONE($1)`_data_str"' +` ]' +` mixer [' + $6 +` ]' +`}') + +divert(0)dnl diff --git a/tools/topology/m4/utils.m4 b/tools/topology/m4/utils.m4 new file mode 100644 index 000000000000..a1fe94bfaa3e --- /dev/null +++ b/tools/topology/m4/utils.m4 @@ -0,0 +1,114 @@ +divert(-1) + +include(`debug.m4') + +define(`concat',`$1$2') + +define(`STR', `"'$1`"') + +dnl Argument iterator. +define(`argn', `ifelse(`$1', 1, ``$2'', + `argn(decr(`$1'), shift(shift($@)))')') + +dnl Defines a list of items from a variable number of params. +dnl Use as last argument in a macro. +dnl The first argument specifies the number of tabs to be added for formatting +define(`LIST_LOOP', `argn(j,$@) +$1ifelse(i,`2', `', `define(`i', decr(i))define(`j', incr(j))$0($@)')') + +define(`LIST', `pushdef(`i', $#)pushdef(`j', `2')LIST_LOOP($@)popdef(i)popdef(j)') + +dnl Sums a list of variable arguments. Use as last argument in macro. +define(`SUM_LOOP', `eval(argn(j,$@) + ifelse(i,`1', `', `define(`i', decr(i)) define(`j', incr(j)) + $0($@)'))') + +dnl Memory capabilities +define(`MEMCAPS', `pushdef(`i', $#) pushdef(`j', `1') SUM_LOOP($@)') + +dnl create direct DAPM/pipeline link between 2 widgets) +define(`dapm', `"$1, , $2"'`DEBUG_GRAPH($1, $2)') + +dnl COMP_SAMPLE_SIZE(FMT) +define(`COMP_SAMPLE_SIZE', +`ifelse( + $1, `s16le', `2', + $1, `s24_4le', `4', + $1, `s32le', `4', + $1, `float', `4', + `4')') + +dnl COMP_FORMAT_NAME(FMT) +define(`COMP_FORMAT_NAME', +`ifelse( + $1, `s16le', `S16_LE', + $1, `s24le', `S24_LE', + $1, `s32le', `S32_LE', + $1, `float', `FLOAT_LE', + )') + +dnl P_GRAPH(name, CONNECTIONS) +define(`P_GRAPH', +`SectionGraph.STR($1) {' +` index STR($2)' +`' +` lines [' +` $3' +` ]' +`}') + +dnl W_VENDORTUPLES(name, tokens, RATE_OUT) +define(`W_VENDORTUPLES', +`SectionVendorTuples.STR($1) {' +` tokens STR($2)' +`' +` tuples."word" {' +` $3' +` }' +`}') + +dnl W_DATA(name, tuples) +define(`W_DATA', +`SectionData.STR($1) {' +` tuples STR($2)' +`}') + +dnl VIRTUAL_DAPM_ROUTE_OUT(name, dai type, dai index, direction, index) +define(`VIRTUAL_DAPM_ROUTE_OUT', +`SectionWidget.STR($1) {' +` index STR($5)' +` type "output"' +` no_pm "true"' +`}' +`SectionGraph.STR($2) {' +` index STR($5)' +`' +` lines [' +` dapm($1,$2$3.$4)' +` ]' +`}') + +dnl VIRTUAL_DAPM_ROUTE_IN(name, dai type, dai index, direction, index) +define(`VIRTUAL_DAPM_ROUTE_IN', +`SectionWidget.STR($1) {' +` index STR($5)' +` type "input"' +` no_pm "true"' +`}' +`SectionGraph.STR($2) {' +` index STR($5)' +`' +` lines [' +` dapm($2$3.$4, $1)' +` ]' +`}') + +dnl VIRTUAL_WIDGET(name, index) +define(`VIRTUAL_WIDGET', +`SectionWidget.STR($1) {' +` index STR($2)' +` type "out_drv"' +` no_pm "true"' +`}') + +divert(0) dnl + diff --git a/tools/topology/platform/Makefile.am b/tools/topology/platform/Makefile.am new file mode 100644 index 000000000000..011ff9e938aa --- /dev/null +++ b/tools/topology/platform/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = intel common diff --git a/tools/topology/platform/common/Makefile.am b/tools/topology/platform/common/Makefile.am new file mode 100644 index 000000000000..a8576d588efc --- /dev/null +++ b/tools/topology/platform/common/Makefile.am @@ -0,0 +1,2 @@ +EXTRA_DIST = \ + ssp.m4 diff --git a/tools/topology/platform/common/ssp.m4 b/tools/topology/platform/common/ssp.m4 new file mode 100644 index 000000000000..f3c78626c1c0 --- /dev/null +++ b/tools/topology/platform/common/ssp.m4 @@ -0,0 +1,46 @@ +divert(-1) + +dnl SSP related macros + +dnl SSP_CLOCK(clock, freq, codec_master) +define(`SSP_CLOCK', + $1 STR($3) + $1_freq STR($2)) + + +dnl SSP_TDM(slots, width, tx_mask, rx_mask) +define(`SSP_TDM', +`tdm_slots 'STR($1) +` tdm_slot_width 'STR($2) +` tx_slots 'STR($3) +` rx_slots 'STR($4) +) +dnl SSP_CONFIG(format, mclk, bclk, fsync, tdm, ssp_config_data) +define(`SSP_CONFIG', +` format "'$1`"' +` '$2 +` '$3 +` '$4 +` '$5 +`}' +$6 +) + +dnl SSP_CONFIG_DATA(type, idx, valid bits, mclk_id) +dnl mclk_id is optional +define(`SSP_CONFIG_DATA', +`SectionVendorTuples."'N_DAI_CONFIG($1$2)`_tuples" {' +` tokens "sof_ssp_tokens"' +` tuples."word" {' +` SOF_TKN_INTEL_SSP_SAMPLE_BITS' STR($3) +` }' +` tuples."short" {' +` SOF_TKN_INTEL_SSP_MCLK_ID' ifelse($4, `', "0", STR($4)) +` }' +`}' +`SectionData."'N_DAI_CONFIG($1$2)`_data" {' +` tuples "'N_DAI_CONFIG($1$2)`_tuples"' +`}' +) + +divert(0)dnl diff --git a/tools/topology/platform/intel/Makefile.am b/tools/topology/platform/intel/Makefile.am new file mode 100644 index 000000000000..bc56971989ed --- /dev/null +++ b/tools/topology/platform/intel/Makefile.am @@ -0,0 +1,9 @@ +EXTRA_DIST = \ + bdw.m4 \ + bxt.m4 \ + byt.m4 \ + cht.m4 \ + hsw.m4 \ + cnl.m4 \ + dmic.m4 + diff --git a/tools/topology/platform/intel/bdw.m4 b/tools/topology/platform/intel/bdw.m4 new file mode 100644 index 000000000000..1af669996969 --- /dev/null +++ b/tools/topology/platform/intel/bdw.m4 @@ -0,0 +1,31 @@ +# +# Broadwell differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Broadwell +define(`PLATFORM_DAI_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_HOST_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_PASS_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/bxt.m4 b/tools/topology/platform/intel/bxt.m4 new file mode 100644 index 000000000000..76265130e8cb --- /dev/null +++ b/tools/topology/platform/intel/bxt.m4 @@ -0,0 +1,34 @@ +# +# Broxton differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Baytrail +define(`PLATFORM_DAI_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_HOST_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_PASS_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/byt.m4 b/tools/topology/platform/intel/byt.m4 new file mode 100644 index 000000000000..a25d9935f0bc --- /dev/null +++ b/tools/topology/platform/intel/byt.m4 @@ -0,0 +1,31 @@ +# +# Baytrail differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Baytrail +define(`PLATFORM_DAI_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_HOST_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_PASS_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/cht.m4 b/tools/topology/platform/intel/cht.m4 new file mode 100644 index 000000000000..b6317cdcfed3 --- /dev/null +++ b/tools/topology/platform/intel/cht.m4 @@ -0,0 +1,31 @@ +# +# Cherrytrail differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Cherrytrail +define(`PLATFORM_DAI_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_HOST_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_PASS_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/cnl.m4 b/tools/topology/platform/intel/cnl.m4 new file mode 100644 index 000000000000..96bf6de2462b --- /dev/null +++ b/tools/topology/platform/intel/cnl.m4 @@ -0,0 +1,35 @@ +# +# Broxton differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Cannonlake +define(`PLATFORM_DAI_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_HOST_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_PASS_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/dmic.m4 b/tools/topology/platform/intel/dmic.m4 new file mode 100644 index 000000000000..7a93069ee81e --- /dev/null +++ b/tools/topology/platform/intel/dmic.m4 @@ -0,0 +1,69 @@ +divert(-1) + +dnl DMIC related macros + +dnl PDM_TUPLES(pdm ctrl id, mic_a_enable, mic_b_enable, polarity_a, polarity_b, +dnl clk_egde, skew) +define(`PDM_TUPLES', +` tuples."short.pdm$1" {' +` SOF_TKN_INTEL_DMIC_PDM_CTRL_ID' STR($1) +` SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable' STR($2) +` SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable' STR($3) +` SOF_TKN_INTEL_DMIC_PDM_POLARITY_A' STR($4) +` SOF_TKN_INTEL_DMIC_PDM_POLARITY_B' STR($5) +` SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE' STR($6) +` SOF_TKN_INTEL_DMIC_PDM_SKEW' STR($7) +` }' +) + +dnl PDM_CONFIG(type, idx, num pdm active, pdm tuples list) +define(`PDM_CONFIG', +` SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE' STR($3) +` }' +`}' +`SectionVendorTuples."'N_DAI_CONFIG($1$2)`_pdm_tuples" {' +` tokens "sof_dmic_pdm_tokens"' +$4 +`}' +) + +dnl DMIC currently only supports 16 bit or 32-bit word length +dnl DMIC_WORD_LENGTH(frame format) +define(`DMIC_WORD_LENGTH', +`ifelse($1, `s16le', 16, $1, `s32le', 32, `')') + +dnl DMIC_CONFIG(driver_version, clk_min, clk_mac, duty_min, duty_max, +dnl sample_rate, +dnl fifo word length, type, idx, pdm controller config) +define(`DMIC_CONFIG', +`SectionVendorTuples."'N_DAI_CONFIG($8$9)`_dmic_tuples" {' +` tokens "sof_dmic_tokens"' +` tuples."word" {' +` SOF_TKN_INTEL_DMIC_DRIVER_VERSION' STR($1) +` SOF_TKN_INTEL_DMIC_CLK_MIN' STR($2) +` SOF_TKN_INTEL_DMIC_CLK_MAX' STR($3) +` SOF_TKN_INTEL_DMIC_DUTY_MIN' STR($4) +` SOF_TKN_INTEL_DMIC_DUTY_MAX' STR($5) +` SOF_TKN_INTEL_DMIC_SAMPLE_RATE' STR($6) +` SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH' STR($7) +dnl PDM config for the number of active PDM controllers +$10 +`SectionData."'N_DAI_CONFIG($8$9)`_pdm_data" {' +` tuples "'N_DAI_CONFIG($8$9)`_pdm_tuples"' +`}' +`SectionData."'N_DAI_CONFIG($8$9)`_data" {' +` tuples "'N_DAI_CONFIG($8$9)`_dmic_tuples"' + +`}' +) + +dnl DMIC PDM configurations +dnl macros to get the number of active pdm's and their config +define(`MONO_PDM0_MICA', `1, LIST(`', PDM_TUPLES(0, 1, 0, 0, 0, 0, 0))') +define(`MONO_PDM0_MICB', `1, LIST(`', PDM_TUPLES(0, 0, 1, 0, 0, 0, 0))') +define(`STEREO_PDM0', `1, LIST(`', PDM_TUPLES(0, 1, 1, 0, 0, 0, 0))') +define(`STEREO_PDM1', `1, LIST(`', PDM_TUPLES(1, 1, 1, 0, 0, 0, 0))') +define(`FOUR_CH_PDM0_PDM1', + `2, LIST(`', PDM_TUPLES(0, 1, 1, 0, 0, 0, 0), PDM_TUPLES(1, 1, 1, 0, 0, 0, 0))') + +divert(0)dnl diff --git a/tools/topology/platform/intel/hsw.m4 b/tools/topology/platform/intel/hsw.m4 new file mode 100644 index 000000000000..c096732a7cc5 --- /dev/null +++ b/tools/topology/platform/intel/hsw.m4 @@ -0,0 +1,31 @@ +# +# Haswell differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for diferent buffer types on Haswell +define(`PLATFORM_DAI_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_HOST_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_PASS_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/platform/intel/icl.m4 b/tools/topology/platform/intel/icl.m4 new file mode 100644 index 000000000000..9671289fdafc --- /dev/null +++ b/tools/topology/platform/intel/icl.m4 @@ -0,0 +1,38 @@ +# +# Icelake differentiation for pipelines and components +# + +include(`memory.m4') + +dnl Memory capabilities for different buffer types on Icelake +define(`PLATFORM_DAI_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_HOST_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_PASS_MEM_CAP', + MEMCAPS(MEM_CAP_RAM, MEM_CAP_DMA, MEM_CAP_CACHE, MEM_CAP_HP)) +define(`PLATFORM_COMP_MEM_CAP', MEMCAPS(MEM_CAP_RAM, MEM_CAP_CACHE)) + +# Low Latency PCM Configuration +W_VENDORTUPLES(pipe_ll_schedule_plat_tokens, sof_sched_tokens, + LIST(` ', `SOF_TKN_SCHED_MIPS "50000"')) + +W_DATA(pipe_ll_schedule_plat, pipe_ll_schedule_plat_tokens) + +# Media PCM Configuration +W_VENDORTUPLES(pipe_media_schedule_plat_tokens, sof_sched_tokens, + LIST(` ', `SOF_TKN_SCHED_MIPS "100000"')) + +W_DATA(pipe_media_schedule_plat, pipe_media_schedule_plat_tokens) + +# Tone Signal Generator Configuration +W_VENDORTUPLES(pipe_tone_schedule_plat_tokens, sof_sched_tokens, + LIST(` ', `SOF_TKN_SCHED_MIPS "200000"')) + +W_DATA(pipe_tone_schedule_plat, pipe_tone_schedule_plat_tokens) + +# DAI schedule Configuration - scheduled by IRQ +W_VENDORTUPLES(pipe_dai_schedule_plat_tokens, sof_sched_tokens, + LIST(` ', `SOF_TKN_SCHED_MIPS "5000"')) + +W_DATA(pipe_dai_schedule_plat, pipe_dai_schedule_plat_tokens) diff --git a/tools/topology/sof-apl-da7219.m4 b/tools/topology/sof-apl-da7219.m4 new file mode 100644 index 000000000000..aaba865e005d --- /dev/null +++ b/tools/topology/sof-apl-da7219.m4 @@ -0,0 +1,143 @@ +# +# Topology for ApolloLake with Dialog7219 codec. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include bxt DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +DEBUG_START + +# +# Define the pipelines +# +# PCM0 ----> volume -----> SSP5 (speaker - maxim98357a) +# PCM1 <---> volume <----> SSP1 (headset - da7219) +# PCM99 <---- volume <----- DMIC0 (dmic capture) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 2 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 2, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 3, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 4 on PCM 0 using max 4 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +#PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 4, 99, 4, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is SSP5 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_1, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 2, SSP, 1, SSP1-Codec, + PIPELINE_SOURCE_2, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 3, SSP, 1, SSP1-Codec, + PIPELINE_SINK_3, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is DMIC0 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 4, DMIC, 0, dmic01, + PIPELINE_SINK_4, 2, s32le, + 48, 1000, 0, 0) + +PCM_PLAYBACK_ADD(Speakers, 0, PIPELINE_PCM_1) +PCM_DUPLEX_ADD(Headset, 1, PIPELINE_PCM_2, PIPELINE_PCM_3) +PCM_CAPTURE_ADD(DMIC01, 99, PIPELINE_PCM_4) + +# +# BE configurations - overrides config in ACPI if present +# + +#SSP 5 (ID: 0) with 19.2 MHz mclk with MCLK_ID 0 (unused), 1.536 MHz blck +DAI_CONFIG(SSP, 5, 0, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 16, 0))) + +#SSP 1 (ID: 1) with 19.2 MHz mclk with MCLK_ID 0, 1.92 MHz bclk +DAI_CONFIG(SSP, 1, 1, SSP1-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 1920000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 20, 3, 3), + SSP_CONFIG_DATA(SSP, 1, 16, 0))) + +# dmic01 (id: 2) +DAI_CONFIG(DMIC, 0, 2, dmic01, + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + DMIC_WORD_LENGTH(s32le), DMIC, 0, + # FIXME: what is the right configuration + # PDM_CONFIG(DMIC, 0, FOUR_CH_PDM0_PDM1))) + PDM_CONFIG(DMIC, 0, STEREO_PDM0))) + +## remove warnings with SST hard-coded routes (FIXME) + +VIRTUAL_WIDGET(ssp5 Tx, 0) +VIRTUAL_WIDGET(ssp1 Rx, 1) +VIRTUAL_WIDGET(ssp1 Tx, 2) +VIRTUAL_WIDGET(DMIC01 Rx, 3) +VIRTUAL_WIDGET(DMic, 4) +VIRTUAL_WIDGET(dmic01_hifi, 5) +VIRTUAL_WIDGET(hif5-0 Output, 6) +VIRTUAL_WIDGET(hif6-0 Output, 7) +VIRTUAL_WIDGET(hif7-0 Output, 8) +VIRTUAL_WIDGET(hifi1, 9) +VIRTUAL_WIDGET(hifi2, 10) +VIRTUAL_WIDGET(hifi3, 11) + +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, SSP, 0, OUT, 12) +VIRTUAL_DAPM_ROUTE_OUT(codec1_out, SSP, 0, OUT, 13) +VIRTUAL_DAPM_ROUTE_OUT(ssp1 Tx, SSP, 0, OUT, 14) +VIRTUAL_DAPM_ROUTE_IN(ssp1 Rx, SSP, 0, IN, 15) +VIRTUAL_DAPM_ROUTE_OUT(Capture, SSP, 0, OUT, 16) +VIRTUAL_DAPM_ROUTE_OUT(SoC DMIC, SSP, 0, OUT, 17) +VIRTUAL_DAPM_ROUTE_IN(codec0_in, SSP, 0, IN, 18) + +DEBUG_END diff --git a/tools/topology/sof-apl-dmic-2ch.m4 b/tools/topology/sof-apl-dmic-2ch.m4 new file mode 100644 index 000000000000..0a8091b2904b --- /dev/null +++ b/tools/topology/sof-apl-dmic-2ch.m4 @@ -0,0 +1,75 @@ +# +# Topology for Apollo Lake with direct attach digital microphones array +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM6 <---- volume <----- DMIC6 (DMIC01) +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + + +# Passthrough capture pipeline 1 on PCM 6 using max 2 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 1, 6, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + + +# capture DAI is DMIC 0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 1, DMIC, 0, NoCodec-6, + PIPELINE_SINK_1, 2, s32le, + 48, 1000, 0, 0) + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) + +dnl PCM_CAPTURE_ADD(name, pipeline, capture) +PCM_CAPTURE_ADD(DMIC01, 6, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +dnl DAI_CONFIG(type, dai_index, link_id, name, ssp_config/dmic_config) + +DAI_CONFIG(DMIC, 0, 6, NoCodec-6, + dnl DMIC_CONFIG(driver_version, clk_min, clk_mac, duty_min, duty_max, + dnl sample_rate, + dnl fifo word length, type, dai_index, pdm controller config) + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + dnl DMIC_WORD_LENGTH(frame_format) + DMIC_WORD_LENGTH(s32le), DMIC, 0, + dnl PDM_CONFIG(type, dai_index, num pdm active, pdm tuples list) + dnl STEREO_PDM0 is a pre-defined pdm config for stereo capture + PDM_CONFIG(DMIC, 0, STEREO_PDM0))) + diff --git a/tools/topology/sof-apl-dmic-4ch.m4 b/tools/topology/sof-apl-dmic-4ch.m4 new file mode 100644 index 000000000000..74cbdb958838 --- /dev/null +++ b/tools/topology/sof-apl-dmic-4ch.m4 @@ -0,0 +1,75 @@ +# +# Topology for Apollo Lake with direct attach digital microphones array +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM6 <---- volume <----- DMIC6 (DMIC01) +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + + +# Passthrough capture pipeline 1 on PCM 6 using max 4 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 1, 6, 4, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + + +# capture DAI is DMIC 0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 1, DMIC, 0, NoCodec-6, + PIPELINE_SINK_1, 2, s32le, + 48, 1000, 0, 0) + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) + +dnl PCM_CAPTURE_ADD(name, pipeline, capture) +PCM_CAPTURE_ADD(DMIC01, 6, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +dnl DAI_CONFIG(type, dai_index, link_id, name, ssp_config/dmic_config) + +DAI_CONFIG(DMIC, 0, 6, NoCodec-6, + dnl DMIC_CONFIG(driver_version, clk_min, clk_mac, duty_min, duty_max, + dnl sample_rate, + dnl fifo word length, type, dai_index, pdm controller config) + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + dnl DMIC_WORD_LENGTH(frame_format) + DMIC_WORD_LENGTH(s32le), DMIC, 0, + dnl PDM_CONFIG(type, dai_index, num pdm active, pdm tuples list) + dnl STEREO_PDM0 is a pre-defined pdm config for stereo capture + PDM_CONFIG(DMIC, 0, FOUR_CH_PDM0_PDM1))) + diff --git a/tools/topology/sof-apl-eq-dmic.m4 b/tools/topology/sof-apl-eq-dmic.m4 new file mode 100644 index 000000000000..f38bb1acfee0 --- /dev/null +++ b/tools/topology/sof-apl-eq-dmic.m4 @@ -0,0 +1,75 @@ +# +# Topology for Apollo Lake with direct attach digital microphones array +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM6 <---- EQ IIR <----- DMIC6 (DMIC01) +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + + +# Passthrough capture pipeline 13 on PCM 6 using max 4 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-eq-capture.m4, + 1, 6, 4, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + + +# capture DAI is DMIC 0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 1, DMIC, 0, NoCodec-6, + PIPELINE_SINK_1, 2, s32le, + 48, 1000, 0, 0) + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) + +dnl PCM_CAPTURE_ADD(name, pipeline, capture) +PCM_CAPTURE_ADD(DMIC01, 6, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +dnl DAI_CONFIG(type, dai_index, link_id, name, ssp_config/dmic_config) + +DAI_CONFIG(DMIC, 0, 6, NoCodec-6, + dnl DMIC_CONFIG(driver_version, clk_min, clk_mac, duty_min, duty_max, + dnl sample_rate, + dnl fifo word length, type, dai_index, pdm controller config) + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + dnl DMIC_WORD_LENGTH(frame_format) + DMIC_WORD_LENGTH(s32le), DMIC, 0, + dnl PDM_CONFIG(type, dai_index, num pdm active, pdm tuples list) + dnl STEREO_PDM0 is a pre-defined pdm config for stereo capture + PDM_CONFIG(DMIC, 0, FOUR_CH_PDM0_PDM1))) + diff --git a/tools/topology/sof-apl-eq-pcm512x.m4 b/tools/topology/sof-apl-eq-pcm512x.m4 new file mode 100644 index 000000000000..25de02418a7b --- /dev/null +++ b/tools/topology/sof-apl-eq-pcm512x.m4 @@ -0,0 +1,55 @@ +# +# Topology for generic Apollolake UP^2 with pcm512x codec with equalizer components. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 ----> EQ IIR ----> EQ FIR ----> volume ----> SSP5 (pcm512x) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-eq-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is SSP5 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency, id 0 +PCM_PLAYBACK_ADD(Port5, 0, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +DAI_CONFIG(SSP, 5, 0, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 3072000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 32, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 24))) diff --git a/tools/topology/sof-apl-nocodec.m4 b/tools/topology/sof-apl-nocodec.m4 new file mode 100644 index 000000000000..b82503d812ef --- /dev/null +++ b/tools/topology/sof-apl-nocodec.m4 @@ -0,0 +1,284 @@ +# +# Topology for generic Apollolake board with no codec and digital mic array. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`ssp.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM0 <---> volume <----> SSP0 +# PCM1 <---> Volume <----> SSP1 +# PCM2 <---> volume <----> SSP2 +# PCM3 <---> volume <----> SSP3 +# PCM4 <---> volume <----> SSP4 +# PCM5 <---> volume <----> SSP5 +# PCM6 <---- volume <----- DMIC6 (DMIC01) +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 2, 0, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 3 on PCM 1 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 3, 1, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 4 on PCM 1 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 4, 1, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 5 on PCM 2 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 5, 2, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 6 on PCM 2 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 6, 2, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 7 on PCM 3 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 7, 3, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 8 on PCM 3 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 8, 3, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 9 on PCM 4 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 9, 4, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 10 on PCM 4 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 10, 4, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 11 on PCM 5 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 11, 5, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 12 on PCM 5 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 12, 5, 2, s16le, + 48, 1000, 0, 0) + +# Passthrough capture pipeline 13 on PCM 6 using max 2 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 13, 6, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + +# playback DAI is SSP0 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, NoCodec-0, + PIPELINE_SOURCE_1, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, NoCodec-0, + PIPELINE_SINK_2, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 3, SSP, 1, NoCodec-1, + PIPELINE_SOURCE_3, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 4, SSP, 1, NoCodec-1, + PIPELINE_SINK_4, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP2 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 5, SSP, 2, NoCodec-2, + PIPELINE_SOURCE_5, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 6, SSP, 2, NoCodec-2, + PIPELINE_SINK_6, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP3 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, SSP, 3, NoCodec-3, + PIPELINE_SOURCE_7, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP3 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 8, SSP, 3, NoCodec-3, + PIPELINE_SINK_8, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP4 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 9, SSP, 4, NoCodec-4, + PIPELINE_SOURCE_9, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP4 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 10, SSP, 4, NoCodec-4, + PIPELINE_SINK_10, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP5 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 11, SSP, 5, NoCodec-5, + PIPELINE_SOURCE_11, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP5 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 12, SSP, 5, NoCodec-5, + PIPELINE_SINK_12, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is DMIC 0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 13, DMIC, 0, NoCodec-6, + PIPELINE_SINK_13, 2, s32le, + 48, 1000, 0, 0) + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) +PCM_DUPLEX_ADD(Port0, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) +PCM_DUPLEX_ADD(Port1, 1, PIPELINE_PCM_3, PIPELINE_PCM_4) +PCM_DUPLEX_ADD(Port2, 2, PIPELINE_PCM_5, PIPELINE_PCM_6) +PCM_DUPLEX_ADD(Port3, 3, PIPELINE_PCM_7, PIPELINE_PCM_8) +PCM_DUPLEX_ADD(Port4, 4, PIPELINE_PCM_9, PIPELINE_PCM_10) +PCM_DUPLEX_ADD(Port5, 5, PIPELINE_PCM_11, PIPELINE_PCM_12) +dnl PCM_CAPTURE_ADD(name, pipeline, capture) +PCM_CAPTURE_ADD(DMIC01, 6, PIPELINE_PCM_13) + +# +# BE configurations - overrides config in ACPI if present +# + +dnl DAI_CONFIG(type, dai_index, link_id, name, ssp_config/dmic_config) +DAI_CONFIG(SSP, 0, 0, NoCodec-0, + dnl SSP_CONFIG(format, mclk, bclk, fsync, tdm, ssp_config_data) + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + dnl SSP_CONFIG_DATA(type, dai_index, valid bits, mclk_id) + SSP_CONFIG_DATA(SSP, 0, 16))) + +DAI_CONFIG(SSP, 1, 1, NoCodec-1, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 1, 16))) + +DAI_CONFIG(SSP, 2, 2, NoCodec-2, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 16))) + +DAI_CONFIG(SSP, 3, 3, NoCodec-3, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 3, 16))) + +DAI_CONFIG(SSP, 4, 4, NoCodec-4, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 4, 16))) + +DAI_CONFIG(SSP, 5, 5, NoCodec-5, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 16))) + +DAI_CONFIG(DMIC, 0, 6, NoCodec-6, + dnl DMIC_CONFIG(driver_version, clk_min, clk_mac, duty_min, duty_max, + dnl sample_rate, + dnl fifo word length, type, dai_index, pdm controller config) + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + dnl DMIC_WORD_LENGTH(frame_format) + DMIC_WORD_LENGTH(s32le), DMIC, 0, + dnl PDM_CONFIG(type, dai_index, num pdm active, pdm tuples list) + dnl STEREO_PDM0 is a pre-defined pdm config for stereo capture + PDM_CONFIG(DMIC, 0, STEREO_PDM0))) + diff --git a/tools/topology/sof-apl-pcm512x.m4 b/tools/topology/sof-apl-pcm512x.m4 new file mode 100644 index 000000000000..0688c98ca5e5 --- /dev/null +++ b/tools/topology/sof-apl-pcm512x.m4 @@ -0,0 +1,122 @@ +# +# Topology for generic Apollolake UP^2 with pcm512x codec and HDMI. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') +include(`hda.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') + +DEBUG_START + +# +# Define the pipelines +# +# PCM0 ----> volume -----> SSP5 (pcm512x) +# PCM1 ----> volume -----> iDisp1 +# PCM2 ----> volume -----> iDisp2 +# PCM3 ----> volume -----> iDisp3 +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 2 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 2, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 3 on PCM 2 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 3, 2, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 4 on PCM 3 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 4, 3, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + +# playback DAI is SSP5 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# playback DAI is iDisp1 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 2, HDA, 0, iDisp1, + PIPELINE_SOURCE_2, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 3, HDA, 1, iDisp2, + PIPELINE_SOURCE_3, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp3 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 4, HDA, 2, iDisp3, + PIPELINE_SOURCE_4, s32le, + 48, 1000, 0, 0) + +# PCM Low Latency, id 0 +dnl PCM_PLAYBACK_ADD(name, pcm_id, playback) +PCM_PLAYBACK_ADD(Port5, 0, PIPELINE_PCM_1) +PCM_PLAYBACK_ADD(HDMI1, 1, PIPELINE_PCM_2) +PCM_PLAYBACK_ADD(HDMI2, 2, PIPELINE_PCM_3) +PCM_PLAYBACK_ADD(HDMI3, 3, PIPELINE_PCM_4) + +# +# BE configurations - overrides config in ACPI if present +# + +#SSP 5 (ID: 0) +DAI_CONFIG(SSP, 5, 0, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 3072000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 32, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 24))) + +# 3 HDMI/DP outputs (ID: 1,2,3) +dnl HDA_DAI_CONFIG(dai_index, link_id, name) +HDA_DAI_CONFIG(0, 1, iDisp1) +HDA_DAI_CONFIG(1, 2, iDisp2) +HDA_DAI_CONFIG(2, 3, iDisp3) + +DEBUG_END diff --git a/tools/topology/sof-apl-rt298.m4 b/tools/topology/sof-apl-rt298.m4 new file mode 100644 index 000000000000..e6dbec8137c5 --- /dev/null +++ b/tools/topology/sof-apl-rt298.m4 @@ -0,0 +1,106 @@ +# +# Topology for generic Apollolake UP^2 with pcm512x codec. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') +include(`hda.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume -----> SSP5 (rt298) +# PCM5 ----> volume (pipe 5) -----> iDisp1 (HDMI/DP playback, BE link 3) +# PCM6 ----> Volume (pipe 6) -----> iDisp2 (HDMI/DP playback, BE link 4) +# PCM7 ----> volume (pipe 7) -----> iDisp3 (HDMI/DP playback, BE link 5) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 5 on PCM 5 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 5, 5, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 6 on PCM 6 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 6, 6, 2, s16le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 7 on PCM 7 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 7, 7, 2, s16le, + 48, 1000, 0, 0) +# +# DAIs configuration +# + +# playback DAI is SSP5 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# playback DAI is iDisp1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 5, HDA, 3, iDisp1, + PIPELINE_SOURCE_5, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp2 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 6, HDA, 4, iDisp2, + PIPELINE_SOURCE_6, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp3 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, HDA, 5, iDisp3, + PIPELINE_SOURCE_7, 2, s32le, + 48, 1000, 0, 0) + +# PCM Low Latency, id 0 +PCM_PLAYBACK_ADD(Port5, 0, PIPELINE_PCM_1) +PCM_PLAYBACK_ADD(HDMI1, 5, PIPELINE_PCM_5) +PCM_PLAYBACK_ADD(HDMI2, 6, PIPELINE_PCM_6) +PCM_PLAYBACK_ADD(HDMI3, 7, PIPELINE_PCM_7) + +# +# BE configurations - overrides config in ACPI if present +# +# +# 3 HDMI/DP outputs (ID: 3,4,5) +DAI_CONFIG(SSP, 5, 0, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 3072000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 32, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 24))) + +HDA_DAI_CONFIG(3, 3, iDisp1) +HDA_DAI_CONFIG(4, 4, iDisp2) +HDA_DAI_CONFIG(5, 5, iDisp3) + diff --git a/tools/topology/sof-apl-tdf8532.m4 b/tools/topology/sof-apl-tdf8532.m4 new file mode 100644 index 000000000000..b8d1faa03d6c --- /dev/null +++ b/tools/topology/sof-apl-tdf8532.m4 @@ -0,0 +1,241 @@ +# +# Topology for generic Apollolake board with TDF8532 +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 -----> Volume -----> SSP4 +# PCM1 <----> Volume <----> SSP2(Dirana Pb/Cp) +# PCM2 <----> Volume <----> SSP0(BT HFP out/in) +# PCM3 <----- Volume <----- SSP1(HDMI in) +# PCM4 <----> Volume <----> SSP3(Modem out/in) +# PCM5 <----> Volume <----> SSP5(TestPin out/in) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 4 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 1, 0, 4, s32le, + 48, 1000, 0, 0, SSP, 4, s32le, 2) + +# Low Latency playback pipeline 2 on PCM 1 using max 8 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 2, 1, 8, s32le, + 48, 1000, 0, 0, SSP, 2, s32le, 2) + +# Low Latency capture pipeline 3 on PCM 1 using max 8 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 3, 1, 8, s32le, + 48, 1000, 0, 0, SSP, 2, s32le, 2) + +# Low Latency playback pipeline 4 on PCM 2 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 4, 2, 2, s16le, + 48, 1000, 0, 0, SSP, 0, s16le, 2) + +# Low Latency capture pipeline 5 on PCM 2 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 5, 2, 2, s16le, + 48, 1000, 0, 0, SSP, 0, s16le, 2) + +# Low Latency capture pipeline 6 on PCM 3 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 6, 3, 2, s16le, + 48, 1000, 0, 0, SSP, 1, s16le, 2) + +# Low Latency playback pipeline 7 on PCM 4 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 7, 4, 2, s16le, + 48, 1000, 0, 0, SSP, 3, s16le, 2) + +# Low Latency capture pipeline 8 on PCM 4 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 8, 4, 2, s16le, + 48, 1000, 0, 0, SSP, 3, s16le, 2) + +# Low Latency playback pipeline 9 on PCM 5 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 9, 5, 2, s16le, + 48, 1000, 0, 0, SSP, 5, s16le, 2) + +# Low Latency capture pipeline 10 on PCM 5 using max 2 channels of s16le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 10, 5, 2, s16le, + 48, 1000, 0, 0, SSP, 5, s16le, 2) + + +# +# DAIs configuration +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 4, SSP, 0, SSP0-Codec, + PIPELINE_SOURCE_4, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 5, SSP, 0, SSP0-Codec, + PIPELINE_SINK_5, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 6, SSP, 1, SSP1-Codec, + PIPELINE_SINK_6, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_2, 2, s32le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 3, SSP, 2, SSP2-Codec, + PIPELINE_SINK_3, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is SSP3 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, SSP, 3, SSP3-Codec, + PIPELINE_SOURCE_7, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP3 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 8, SSP, 3, SSP3-Codec, + PIPELINE_SINK_8, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP4 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 4, SSP4-Codec, + PIPELINE_SOURCE_1, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is SSP5 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 9, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_9, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP5 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 10, SSP, 5, SSP5-Codec, + PIPELINE_SINK_10, 2, s16le, + 48, 1000, 0, 0) + +# PCM Low Latency, id 0 +PCM_DUPLEX_ADD(Port0, 2, PIPELINE_PCM_4, PIPELINE_PCM_5) +PCM_CAPTURE_ADD(Port1, 3, PIPELINE_PCM_6) +PCM_DUPLEX_ADD(Port2, 1, PIPELINE_PCM_2, PIPELINE_PCM_3) +PCM_DUPLEX_ADD(Port3, 4, PIPELINE_PCM_7, PIPELINE_PCM_8) +PCM_PLAYBACK_ADD(Port4, 0, PIPELINE_PCM_1) +PCM_DUPLEX_ADD(Port5, 5, PIPELINE_PCM_9, PIPELINE_PCM_10) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 0, SSP0-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 16))) + +DAI_CONFIG(SSP, 1, 1, SSP1-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 1, 16))) + +DAI_CONFIG(SSP, 2, 2, SSP2-Codec, + SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 12288000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(8, 32, 255, 255), + SSP_CONFIG_DATA(SSP, 2, 32))) + +DAI_CONFIG(SSP, 3, 3, SSP3-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 3, 16))) + +DAI_CONFIG(SSP, 4, 4, SSP4-Codec, + SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 12288000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(8, 32, 15, 15), + SSP_CONFIG_DATA(SSP, 4, 32))) + +DAI_CONFIG(SSP, 5, 5, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 16))) + + +VIRTUAL_DAPM_ROUTE_IN(BtHfp_ssp0_in, SSP, 0, IN, 0) +VIRTUAL_DAPM_ROUTE_OUT(BtHfp_ssp0_out, SSP, 0, OUT, 1) +VIRTUAL_DAPM_ROUTE_IN(hdmi_ssp1_in, SSP, 1, IN, 2) +VIRTUAL_DAPM_ROUTE_IN(dirana_in, SSP, 2, IN, 3) +VIRTUAL_DAPM_ROUTE_IN(dirana_aux_in, SSP, 2, IN, 4) +VIRTUAL_DAPM_ROUTE_IN(dirana_tuner_in, SSP, 2, IN, 5) +VIRTUAL_DAPM_ROUTE_OUT(dirana_out, SSP, 2, OUT, 6) +VIRTUAL_DAPM_ROUTE_IN(Modem_ssp3_in, SSP, 3, IN, 7) +VIRTUAL_DAPM_ROUTE_OUT(Modem_ssp3_out, SSP, 3, OUT, 8) +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, SSP, 4, OUT, 9) +VIRTUAL_DAPM_ROUTE_IN(TestPin_ssp5_in, SSP, 5, IN, 10) +VIRTUAL_DAPM_ROUTE_OUT(TestPin_ssp5_out, SSP, 5, OUT, 11) +VIRTUAL_WIDGET(ssp0 Tx, 12) +VIRTUAL_WIDGET(ssp0 Rx, 13) +VIRTUAL_WIDGET(ssp1 Rx, 14) +VIRTUAL_WIDGET(ssp2 Tx, 15) +VIRTUAL_WIDGET(ssp2 Rx, 16) +VIRTUAL_WIDGET(ssp3 Tx, 17) +VIRTUAL_WIDGET(ssp3 Rx, 18) +VIRTUAL_WIDGET(ssp4 Tx, 19) +VIRTUAL_WIDGET(ssp5 Tx, 20) +VIRTUAL_WIDGET(ssp5 Rx, 21) diff --git a/tools/topology/sof-apl-wm8804.m4 b/tools/topology/sof-apl-wm8804.m4 new file mode 100644 index 000000000000..4dc15ebecc8c --- /dev/null +++ b/tools/topology/sof-apl-wm8804.m4 @@ -0,0 +1,55 @@ +# +# Topology for generic Apollolake UP^2 with wm8804 codec. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume -----> SSP5 (wm8804) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is SSP5 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 5, SSP5-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency, id 0 +PCM_PLAYBACK_ADD(Port5, 0, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +DAI_CONFIG(SSP, 5, 0, SSP5-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24576000, codec_mclk_in), + SSP_CLOCK(bclk, 3072000, codec_master), + SSP_CLOCK(fsync, 48000, codec_master), + SSP_TDM(2, 32, 3, 3), + SSP_CONFIG_DATA(SSP, 5, 24))) diff --git a/tools/topology/sof-bdw-rt286.m4 b/tools/topology/sof-bdw-rt286.m4 new file mode 100644 index 000000000000..848ca424cec2 --- /dev/null +++ b/tools/topology/sof-bdw-rt286.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Broadwell board with rt286. +# + +# Include topology builder +include(`pipeline.m4') +include(`utils.m4') +include(`dai.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Broadwell DSP configuration +include(`platform/intel/bdw.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP0 +# PCM1 -----> volume -----> SRC ---+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP0 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 96 frames per 2000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 96, 2000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-bdw-rt286" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 0 is our only pipeline DAI +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 0, Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24000000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 24))) diff --git a/tools/topology/sof-bdw-rt5640.m4 b/tools/topology/sof-bdw-rt5640.m4 new file mode 100644 index 000000000000..5280327dd034 --- /dev/null +++ b/tools/topology/sof-bdw-rt5640.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Broadwell board with rt5640. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Broadwell DSP configuration +include(`platform/intel/bdw.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP0 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP0 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 96 frames per 2000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 96, 2000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-bdw-rt5640" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 0 is our only pipeline DAI +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 0, Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24000000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 24))) diff --git a/tools/topology/sof-byt-da7213.m4 b/tools/topology/sof-byt-da7213.m4 new file mode 100644 index 000000000000..68fe7567b0e7 --- /dev/null +++ b/tools/topology/sof-byt-da7213.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Baytrail board with DA7213 codec. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`platform/intel/byt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-byt-da7212" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-byt-nocodec.m4 b/tools/topology/sof-byt-nocodec.m4 new file mode 100644 index 000000000000..ee4e93efac97 --- /dev/null +++ b/tools/topology/sof-byt-nocodec.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Baytrail board with no codec. +# + +# Include topology builder +include(`pipeline.m4') +include(`utils.m4') +include(`dai.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`platform/intel/byt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 (NoCodec) +# PCM2 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM1 <---- Volume <---- SSP2 (NoCodec) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-byt-nocodec" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, NoCodec-2, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, NoCodec-2, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 2, NoCodec-2, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-byt-rt5640.m4 b/tools/topology/sof-byt-rt5640.m4 new file mode 100644 index 000000000000..5e6cb0491b9e --- /dev/null +++ b/tools/topology/sof-byt-rt5640.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Baytrail board with RT5640. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`platform/intel/byt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-byt-rt5640" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-byt-rt5645.m4 b/tools/topology/sof-byt-rt5645.m4 new file mode 100644 index 000000000000..354104fc4eb2 --- /dev/null +++ b/tools/topology/sof-byt-rt5645.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Baytrail board with RT5645. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`platform/intel/byt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-byt-rt5645" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-byt-rt5651.m4 b/tools/topology/sof-byt-rt5651.m4 new file mode 100644 index 000000000000..ee9b70e69ace --- /dev/null +++ b/tools/topology/sof-byt-rt5651.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Baytrail board with no RT5651. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Baytrail DSP configuration +include(`platform/intel/byt.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-byt-rt5651" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-cht-max98090.m4 b/tools/topology/sof-cht-max98090.m4 new file mode 100644 index 000000000000..b88af17ea212 --- /dev/null +++ b/tools/topology/sof-cht-max98090.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic CHT/BSW board with Maxim 98090 codec +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Cherrytrail DSP configuration +include(`platform/intel/cht.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-cht-max98090" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_1, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SINK_2, 2, s16le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 1920000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 20, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 16))) diff --git a/tools/topology/sof-cht-nocodec.m4 b/tools/topology/sof-cht-nocodec.m4 new file mode 100644 index 000000000000..c56773a9655f --- /dev/null +++ b/tools/topology/sof-cht-nocodec.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic CherryTrail board with no codec. +# + +# Include topology builder +include(`pipeline.m4') +include(`utils.m4') +include(`dai.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include CherryTrail DSP configuration +include(`platform/intel/cht.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP2 (NoCodec) +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP2 (NoCodec) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-cht-nocodec" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 2 is our only pipeline DAI +# + +# playback DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 2, NoCodec-2, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP2 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 2, NoCodec-2, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 2, 0, NoCodec-2, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 24))) diff --git a/tools/topology/sof-cnl-rt274.m4 b/tools/topology/sof-cnl-rt274.m4 new file mode 100644 index 000000000000..3a0bce0ac9af --- /dev/null +++ b/tools/topology/sof-cnl-rt274.m4 @@ -0,0 +1,91 @@ +# +# Topology for generic Cannonlake board with RT274 +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/cnl.m4') + +# +# Define the pipelines +# +# PCM0 <---> volume <---> SSP0 +# +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s24le, + 48, 1000, 0, 0, SSP, 0, s24le, 2) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 2, 0, 2, s24le, + 48, 1000, 0, 0, SSP, 0, s24le, 2) + +# +# DAI configuration +# +# SSP port 0 is our only pipeline DAI +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, SSP0-Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, SSP0-Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Passthrough, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 1, SSP0-Codec, + SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 24000000, codec_mclk_in), + SSP_CLOCK(bclk, 4800000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(4, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 24))) + +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, SSP, 0, OUT, 0) +VIRTUAL_DAPM_ROUTE_OUT(codec1_out, SSP, 0, OUT, 1) +VIRTUAL_DAPM_ROUTE_OUT(ssp0 Tx, SSP, 0, OUT, 2) +VIRTUAL_DAPM_ROUTE_OUT(Capture, SSP, 0, OUT, 3) +VIRTUAL_DAPM_ROUTE_OUT(SoC DMIC, SSP, 0, OUT, 4) +VIRTUAL_DAPM_ROUTE_IN(codec0_in, SSP, 0, IN, 5) +VIRTUAL_DAPM_ROUTE_OUT(ssp2_out, SSP, 0, OUT, 6) +VIRTUAL_DAPM_ROUTE_IN(ssp2_in, SSP, 0, IN, 7) +VIRTUAL_DAPM_ROUTE_OUT(ssp1_out, SSP, 0, OUT, 8) +VIRTUAL_WIDGET(DMIC01 Rx, 9) +VIRTUAL_WIDGET(DMic, 10) +VIRTUAL_WIDGET(dmic01_hifi, 11) +VIRTUAL_WIDGET(ssp0 Rx, 12) +VIRTUAL_WIDGET(ssp1_out, 13) +VIRTUAL_WIDGET(ssp2_out, 14) +VIRTUAL_WIDGET(ssp2_in, 15) +VIRTUAL_WIDGET(ssp2 Rx, 16) +VIRTUAL_WIDGET(ssp2 Tx, 17) +VIRTUAL_WIDGET(Dummy Playback, 18) +VIRTUAL_WIDGET(Dummy Capture, 19) diff --git a/tools/topology/sof-glk-da7219.m4 b/tools/topology/sof-glk-da7219.m4 new file mode 100644 index 000000000000..0adcbcf6e7ab --- /dev/null +++ b/tools/topology/sof-glk-da7219.m4 @@ -0,0 +1,195 @@ +# +# Topology for GeminiLake with Dialog7219. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') +include(`hda.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include bxt DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume (pipe 1) -----> SSP1 (speaker - maxim98357a, BE link 0) +# PCM1 <---> volume (pipe 2,3) <----> SSP2 (headset - da7219, BE link 1) +# PCM99 <---- DMIC0 (dmic capture, BE link 2) +# PCM5 ----> volume (pipe 5) -----> iDisp1 (HDMI/DP playback, BE link 3) +# PCM6 ----> Volume (pipe 6) -----> iDisp2 (HDMI/DP playback, BE link 4) +# PCM7 ----> volume (pipe 7) -----> iDisp3 (HDMI/DP playback, BE link 5) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 2 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 2, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 3, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 4 on PCM 99 using max 4 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +#PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 4, 99, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 5 on PCM 5 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +# PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 5, 5, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 6 on PCM 6 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +# PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 6, 6, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 7 on PCM 7 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +# PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 7, 7, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 1, SSP1-Codec, + PIPELINE_SOURCE_1, 2, s16le, + 48, 1000, 0, 0) + +# playback DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 2, SSP, 2, SSP2-Codec, + PIPELINE_SOURCE_2, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is SSP1 using 2 periods +# Buffers use s16le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 3, SSP, 2, SSP2-Codec, + PIPELINE_SINK_3, 2, s16le, + 48, 1000, 0, 0) + +# capture DAI is DMIC0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 4, DMIC, 0, dmic01, + PIPELINE_SINK_4, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp1 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 5, HDA, 3, iDisp1, + PIPELINE_SOURCE_5, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 6, HDA, 4, iDisp2, + PIPELINE_SOURCE_6, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp3 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, HDA, 5, iDisp3, + PIPELINE_SOURCE_7, 2, s32le, + 48, 1000, 0, 0) + +PCM_PLAYBACK_ADD(Speakers, 0, PIPELINE_PCM_1) +PCM_DUPLEX_ADD(Headset, 1, PIPELINE_PCM_2, PIPELINE_PCM_3) +PCM_CAPTURE_ADD(DMIC01, 99, PIPELINE_PCM_4) +PCM_PLAYBACK_ADD(HDMI1, 5, PIPELINE_PCM_5) +PCM_PLAYBACK_ADD(HDMI2, 6, PIPELINE_PCM_6) +PCM_PLAYBACK_ADD(HDMI3, 7, PIPELINE_PCM_7) + +# +# BE configurations - overrides config in ACPI if present +# + +#SSP 1 (ID: 0) with 19.2 MHz mclk with MCLK_ID 1 (unused), 1.536 MHz blck +DAI_CONFIG(SSP, 1, 0, SSP1-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 1536000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 16, 3, 3), + SSP_CONFIG_DATA(SSP, 1, 16, 1))) + +#SSP 2 (ID: 1) with 19.2 MHz mclk with MCLK_ID 1, 1.92 MHz bclk +DAI_CONFIG(SSP, 2, 1, SSP2-Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 19200000, codec_mclk_in), + SSP_CLOCK(bclk, 1920000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 20, 3, 3), + SSP_CONFIG_DATA(SSP, 2, 16, 1))) + +# dmic01 (id: 2) +DAI_CONFIG(DMIC, 0, 2, dmic01, + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + DMIC_WORD_LENGTH(s32le), DMIC, 0, + # FIXME: what is the right configuration + # PDM_CONFIG(DMIC, 0, FOUR_CH_PDM0_PDM1))) + PDM_CONFIG(DMIC, 0, STEREO_PDM0))) + +# 3 HDMI/DP outputs (ID: 3,4,5) +HDA_DAI_CONFIG(3, 3, iDisp1) +HDA_DAI_CONFIG(4, 4, iDisp2) +HDA_DAI_CONFIG(5, 5, iDisp3) + +## remove warnings with SST hard-coded routes (FIXME) + +VIRTUAL_WIDGET(ssp5 Tx, 0) +VIRTUAL_WIDGET(ssp1 Rx, 1) +VIRTUAL_WIDGET(ssp1 Tx, 2) +VIRTUAL_WIDGET(DMIC01 Rx, 3) +VIRTUAL_WIDGET(DMic, 4) +VIRTUAL_WIDGET(dmic01_hifi, 5) +VIRTUAL_WIDGET(hif5-0 Output, 6) +VIRTUAL_WIDGET(hif6-0 Output, 7) +VIRTUAL_WIDGET(hif7-0 Output, 8) + +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, SSP, 0, OUT, 12) +VIRTUAL_DAPM_ROUTE_OUT(codec1_out, SSP, 0, OUT, 13) +VIRTUAL_DAPM_ROUTE_OUT(ssp1 Tx, SSP, 0, OUT, 14) +VIRTUAL_DAPM_ROUTE_IN(ssp1 Rx, SSP, 0, IN, 15) +VIRTUAL_DAPM_ROUTE_OUT(Capture, SSP, 0, OUT, 16) +VIRTUAL_DAPM_ROUTE_OUT(SoC DMIC, SSP, 0, OUT, 17) +VIRTUAL_DAPM_ROUTE_IN(codec0_in, SSP, 0, IN, 18) + + + + + diff --git a/tools/topology/sof-hda-generic.m4 b/tools/topology/sof-hda-generic.m4 new file mode 100644 index 000000000000..079fa1bb3847 --- /dev/null +++ b/tools/topology/sof-hda-generic.m4 @@ -0,0 +1,156 @@ +# +# Topology for SKL+ HDA Generic machine +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`hda.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include bxt DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 <---> volume (pipe 1,2) <----> HDA Analog (HDA Analog playback/capture) +# PCM1 <---> volume (pipe 3,4) <----> HDA Digital (HDA Digital playback/capture) +# PCM3 ----> volume (pipe 7) -----> iDisp1 (HDMI/DP playback, BE link 3) +# PCM4 ----> Volume (pipe 8) -----> iDisp2 (HDMI/DP playback, BE link 4) +# PCM5 ----> volume (pipe 9) -----> iDisp3 (HDMI/DP playback, BE link 5) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 3, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 4 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-capture.m4, + 4, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 7 on PCM 3 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 7, 3, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 8 on PCM 4 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 8, 4, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 9 on PCM 5 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-volume-playback.m4, + 9, 5, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is HDA Analog using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, HDA, 0, Analog Playback and Capture, + PIPELINE_SOURCE_1, 2, s32le, + 48, 1000, 0, 0) + +# capture DAI is HDA Analog using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, HDA, 0, Analog Playback and Capture, + PIPELINE_SINK_2, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is HDA Digital using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 3, HDA, 1, Digital Playback and Capture, + PIPELINE_SOURCE_3, 2, s32le, + 48, 1000, 0, 0) + +# capture DAI is HDA Digital using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 4, HDA, 1, Digital Playback and Capture, + PIPELINE_SINK_4, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp1 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, HDA, 3, iDisp1, + PIPELINE_SOURCE_7, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 8, HDA, 4, iDisp2, + PIPELINE_SOURCE_8, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp3 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 9, HDA, 5, iDisp3, + PIPELINE_SOURCE_9, 2, s32le, + 48, 1000, 0, 0) + +PCM_DUPLEX_ADD(HDA Analog, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) +PCM_DUPLEX_ADD(HDA Digital, 1, PIPELINE_PCM_3, PIPELINE_PCM_4) +PCM_PLAYBACK_ADD(HDMI1, 3, PIPELINE_PCM_7) +PCM_PLAYBACK_ADD(HDMI2, 4, PIPELINE_PCM_8) +PCM_PLAYBACK_ADD(HDMI3, 5, PIPELINE_PCM_9) + +# +# BE configurations - overrides config in ACPI if present +# + +# HDA outputs +HDA_DAI_CONFIG(0, 4, Analog Playback and Capture) +HDA_DAI_CONFIG(1, 5, Digital Playback and Capture) +# 3 HDMI/DP outputs (ID: 3,4,5) +HDA_DAI_CONFIG(3, 1, iDisp1) +HDA_DAI_CONFIG(4, 2, iDisp2) +HDA_DAI_CONFIG(5, 3, iDisp3) + + +VIRTUAL_DAPM_ROUTE_IN(codec0_in, HDA, 0, IN, 1) +VIRTUAL_DAPM_ROUTE_IN(codec1_in, HDA, 1, IN, 2) +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, HDA, 0, OUT, 3) +VIRTUAL_DAPM_ROUTE_OUT(codec1_out, HDA, 1, OUT, 4) + +# codec2 is not supported in dai links but it exists +# in dapm routes, so hack this one to HDA1 +VIRTUAL_DAPM_ROUTE_IN(codec2_in, HDA, 1, IN, 5) +VIRTUAL_DAPM_ROUTE_OUT(codec2_out, HDA, 1, OUT, 6) + +VIRTUAL_DAPM_ROUTE_OUT(iDisp1_out, HDA, 3, OUT, 7) +VIRTUAL_DAPM_ROUTE_OUT(iDisp2_out, HDA, 4, OUT, 8) +VIRTUAL_DAPM_ROUTE_OUT(iDisp3_out, HDA, 5, OUT, 9) diff --git a/tools/topology/sof-hsw-rt5640.m4 b/tools/topology/sof-hsw-rt5640.m4 new file mode 100644 index 000000000000..5a5fbc1661fc --- /dev/null +++ b/tools/topology/sof-hsw-rt5640.m4 @@ -0,0 +1,99 @@ +# +# Topology for generic Haswell board with RT5640. +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Haswell DSP configuration +include(`platform/intel/hsw.m4') + +# +# Define the pipelines +# +# PCM0 ----> volume ---------------+ +# |--low latency mixer ----> volume ----> SSP0 +# PCM1 -----> volume ----> SRC ----+ +# | +# Tone -----> volume ----+ +# +# PCM0 <---- Volume <---- SSP0 +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-low-latency-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# PCM Media Playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 1 +PIPELINE_PCM_ADD(sof/pipe-pcm-media.m4, + 3, 1, 2, s32le, + 192, 4000, 1, 0) + +# Tone Playback pipeline 5 using max 2 channels of s32le. +# Schedule 192 frames per 4000us deadline on core 0 with priority 2 +PIPELINE_ADD(sof/pipe-tone.m4, + 5, 2, s32le, + 192, 4000, 2, 0) + +# Connect pipelines together +SectionGraph."pipe-hsw-rt5640" { + index "0" + + lines [ + # media 0 + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_3) + #tone + dapm(PIPELINE_MIXER_1, PIPELINE_SOURCE_5) + ] +} + +# +# DAI configuration +# +# SSP port 0 is our only pipeline DAI +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, Codec, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, Codec, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Low Latency, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 0, Codec, + SSP_CONFIG(I2S, SSP_CLOCK(mclk, 24000000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 24))) diff --git a/tools/topology/sof-icl-dmic-4ch.m4 b/tools/topology/sof-icl-dmic-4ch.m4 new file mode 100644 index 000000000000..24bbd845bbfa --- /dev/null +++ b/tools/topology/sof-icl-dmic-4ch.m4 @@ -0,0 +1,68 @@ +# +# Topology for ICL Lake with direct attach digital microphones array +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Apollolake DSP configuration +include(`platform/intel/bxt.m4') +include(`platform/intel/dmic.m4') + +# +# Define the pipelines +# +# PCM6 <---- volume <----- DMIC01 (dmic0 capture) +# + +dnl PIPELINE_PCM_ADD(pipeline, +dnl pipe id, pcm, max channels, format, +dnl frames, deadline, priority, core) + + +# Passthrough capture pipeline 1 on PCM 1 using max 4 channels. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 1, 1, 4, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +dnl DAI_ADD(pipeline, +dnl pipe id, dai type, dai_index, dai_be, +dnl buffer, periods, format, +dnl frames, deadline, priority, core) + + +# capture DAI is DMIC 0 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 1, DMIC, 0, dmic01, + PIPELINE_SINK_1, 2, s32le, + 48, 1000, 0, 0) + +dnl PCM_DUPLEX_ADD(name, pcm_id, playback, capture) + +dnl PCM_CAPTURE_ADD(name, pipeline, capture) +PCM_CAPTURE_ADD(DMIC01, 1, PIPELINE_PCM_1) + +# +# BE configurations - overrides config in ACPI if present +# + +dnl DAI_CONFIG(type, dai_index, link_id, name, ssp_config/dmic_config) + +DAI_CONFIG(DMIC, 0, 1, dmic01, + DMIC_CONFIG(1, 500000, 4800000, 40, 60, 48000, + DMIC_WORD_LENGTH(s32le), DMIC, 0, + PDM_CONFIG(DMIC, 0, FOUR_CH_PDM0_PDM1))) diff --git a/tools/topology/sof-icl-nocodec.m4 b/tools/topology/sof-icl-nocodec.m4 new file mode 100644 index 000000000000..5801b6febac3 --- /dev/null +++ b/tools/topology/sof-icl-nocodec.m4 @@ -0,0 +1,69 @@ +# +# Topology for generic Icelake board with nocodec +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`ssp.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include Icelake DSP configuration +include(`platform/intel/icl.m4') + +# +# Define the pipelines +# +# PCM0 <---> Volume <---> SSP0 (NoCodec) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-playback.m4, + 1, 0, 2, s24le, + 48, 1000, 0, 0, SSP, 0, s24le, 2) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s24le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_DAI_ADD(sof/pipe-volume-capture.m4, + 2, 0, 2, s24le, + 48, 1000, 0, 0, SSP, 0, s24le, 2) + +# +# DAI configuration +# +# SSP port 0 is our only pipeline DAI +# + +# playback DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, SSP, 0, NoCodec-0, + PIPELINE_SOURCE_1, 2, s24le, + 48, 1000, 0, 0) + +# capture DAI is SSP0 using 2 periods +# Buffers use s24le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, SSP, 0, NoCodec-0, + PIPELINE_SINK_2, 2, s24le, + 48, 1000, 0, 0) + +# PCM Low Latency +PCM_DUPLEX_ADD(Passthrough, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) + +# +# BE configurations - overrides config in ACPI if present +# +DAI_CONFIG(SSP, 0, 0, NoCodec-0, + SSP_CONFIG(DSP_B, SSP_CLOCK(mclk, 38400000, codec_mclk_in), + SSP_CLOCK(bclk, 2400000, codec_slave), + SSP_CLOCK(fsync, 48000, codec_slave), + SSP_TDM(2, 25, 3, 3), + SSP_CONFIG_DATA(SSP, 0, 24))) diff --git a/tools/topology/sof-whl-hda.m4 b/tools/topology/sof-whl-hda.m4 new file mode 100644 index 000000000000..0eec9e4e0d91 --- /dev/null +++ b/tools/topology/sof-whl-hda.m4 @@ -0,0 +1,156 @@ +# +# HDA passthrough topology for WHL +# + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`hda.m4') + +# Include TLV library +include(`common/tlv.m4') + +# Include Token library +include(`sof/tokens.m4') + +# Include bxt DSP configuration +include(`platform/intel/bxt.m4') + +# +# Define the pipelines +# +# PCM0 <---> passthrough (pipe 1,2) <----> HDA Analog (HDA Analog playback/capture) +# PCM1 <---> passthrough (pipe 3,4) <----> HDA Digital (HDA Digital playback/capture) +# PCM3 ----> passthrough (pipe 7) -----> iDisp1 (HDMI/DP playback, BE link 3) +# PCM4 ----> passthrough (pipe 8) -----> iDisp2 (HDMI/DP playback, BE link 4) +# PCM5 ----> passthrough (pipe 9) -----> iDisp3 (HDMI/DP playback, BE link 5) +# + +# Low Latency playback pipeline 1 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, + 1, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 2 on PCM 0 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 2, 0, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 3 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, + 3, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency capture pipeline 4 on PCM 1 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-capture.m4, + 4, 1, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 7 on PCM 3 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, + 7, 3, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 8 on PCM 4 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, + 8, 4, 2, s32le, + 48, 1000, 0, 0) + +# Low Latency playback pipeline 9 on PCM 5 using max 2 channels of s32le. +# Schedule 48 frames per 1000us deadline on core 0 with priority 0 +PIPELINE_PCM_ADD(sof/pipe-passthrough-playback.m4, + 9, 5, 2, s32le, + 48, 1000, 0, 0) + +# +# DAIs configuration +# + +# playback DAI is HDA Analog using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 1, HDA, 0, Analog Playback and Capture, + PIPELINE_SOURCE_1, 2, s32le, + 48, 1000, 0, 0) + +# capture DAI is HDA Analog using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 2, HDA, 0, Analog Playback and Capture, + PIPELINE_SINK_2, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is HDA Digital using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 3, HDA, 1, Digital Playback and Capture, + PIPELINE_SOURCE_3, 2, s32le, + 48, 1000, 0, 0) + +# capture DAI is HDA Digital using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-capture.m4, + 4, HDA, 1, Digital Playback and Capture, + PIPELINE_SINK_4, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp1 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 7, HDA, 3, iDisp1, + PIPELINE_SOURCE_7, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp2 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 8, HDA, 4, iDisp2, + PIPELINE_SOURCE_8, 2, s32le, + 48, 1000, 0, 0) + +# playback DAI is iDisp3 using 2 periods +# Buffers use s32le format, with 48 frame per 1000us on core 0 with priority 0 +DAI_ADD(sof/pipe-dai-playback.m4, + 9, HDA, 5, iDisp3, + PIPELINE_SOURCE_9, 2, s32le, + 48, 1000, 0, 0) + +PCM_DUPLEX_ADD(HDA Analog, 0, PIPELINE_PCM_1, PIPELINE_PCM_2) +PCM_DUPLEX_ADD(HDA Digital, 1, PIPELINE_PCM_3, PIPELINE_PCM_4) +PCM_PLAYBACK_ADD(HDMI1, 3, PIPELINE_PCM_7) +PCM_PLAYBACK_ADD(HDMI2, 4, PIPELINE_PCM_8) +PCM_PLAYBACK_ADD(HDMI3, 5, PIPELINE_PCM_9) + +# +# BE configurations - overrides config in ACPI if present +# + +# HDA outputs +HDA_DAI_CONFIG(0, 4, Analog Playback and Capture) +HDA_DAI_CONFIG(1, 5, Digital Playback and Capture) +# 3 HDMI/DP outputs (ID: 3,4,5) +HDA_DAI_CONFIG(3, 1, iDisp1) +HDA_DAI_CONFIG(4, 2, iDisp2) +HDA_DAI_CONFIG(5, 3, iDisp3) + + +VIRTUAL_DAPM_ROUTE_IN(codec0_in, HDA, 0, IN, 1) +VIRTUAL_DAPM_ROUTE_IN(codec1_in, HDA, 1, IN, 2) +VIRTUAL_DAPM_ROUTE_OUT(codec0_out, HDA, 0, OUT, 3) +VIRTUAL_DAPM_ROUTE_OUT(codec1_out, HDA, 1, OUT, 4) + +# codec2 is not supported in dai links but it exists +# in dapm routes, so hack this one to HDA1 +VIRTUAL_DAPM_ROUTE_IN(codec2_in, HDA, 1, IN, 5) +VIRTUAL_DAPM_ROUTE_OUT(codec2_out, HDA, 1, OUT, 6) + +VIRTUAL_DAPM_ROUTE_OUT(iDisp1_out, HDA, 3, OUT, 7) +VIRTUAL_DAPM_ROUTE_OUT(iDisp2_out, HDA, 4, OUT, 8) +VIRTUAL_DAPM_ROUTE_OUT(iDisp3_out, HDA, 5, OUT, 9) diff --git a/tools/topology/sof/Makefile.am b/tools/topology/sof/Makefile.am new file mode 100644 index 000000000000..fc92591f738b --- /dev/null +++ b/tools/topology/sof/Makefile.am @@ -0,0 +1,14 @@ +EXTRA_DIST = \ + pipe-dai-capture.m4 \ + pipe-dai-playback.m4 \ + pipe-low-latency-capture.m4 \ + pipe-low-latency-playback.m4 \ + pipe-passthrough-capture.m4 \ + pipe-passthrough-playback.m4 \ + pipe-pcm-media.m4 \ + pipe-src-capture.m4 \ + pipe-src-playback.m4 \ + pipe-tone.m4 \ + pipe-volume-capture.m4 \ + pipe-volume-playback.m4 \ + tokens.m4 diff --git a/tools/topology/sof/pipe-dai-capture.m4 b/tools/topology/sof/pipe-dai-capture.m4 new file mode 100644 index 000000000000..c69d586ff19d --- /dev/null +++ b/tools/topology/sof/pipe-dai-capture.m4 @@ -0,0 +1,22 @@ +# DAI Capture connector + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# DAI definitions +# +W_DAI_IN(DAI_TYPE, DAI_INDEX, DAI_BE, DAI_FORMAT, 2, 0, 0) + +# +# DAI pipeline - always use 0 for DAIs +# +W_PIPELINE(N_DAI_IN, SCHEDULE_DEADLINE, SCHEDULE_PRIORITY, SCHEDULE_FRAMES, SCHEDULE_CORE, 0, pipe_dai_schedule_plat) + +# +# Graph connections to pipelines + +P_GRAPH(DAI_NAME, PIPELINE_ID, + LIST(` ', `dapm(DAI_BUF, N_DAI_IN)')) diff --git a/tools/topology/sof/pipe-dai-playback.m4 b/tools/topology/sof/pipe-dai-playback.m4 new file mode 100644 index 000000000000..804b180eb2ae --- /dev/null +++ b/tools/topology/sof/pipe-dai-playback.m4 @@ -0,0 +1,22 @@ +# DAI Playback connector + +# Include topology builder +include(`utils.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# DAI definitions +# +W_DAI_OUT(DAI_TYPE, DAI_INDEX, DAI_BE, DAI_FORMAT, 0, 2, 2) + +# +# DAI pipeline - always use 0 for DAIs +# +W_PIPELINE(N_DAI_OUT, SCHEDULE_DEADLINE, SCHEDULE_PRIORITY, SCHEDULE_FRAMES, SCHEDULE_CORE, 0, pipe_dai_schedule_plat) + +# +# Graph connections to pipelines + +P_GRAPH(DAI_NAME, PIPELINE_ID, + LIST(` ', `dapm(N_DAI_OUT, DAI_BUF)')) diff --git a/tools/topology/sof/pipe-eq-capture.m4 b/tools/topology/sof/pipe-eq-capture.m4 new file mode 100644 index 000000000000..752bc66330e8 --- /dev/null +++ b/tools/topology/sof/pipe-eq-capture.m4 @@ -0,0 +1,74 @@ +# Capture EQ Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_C <--- B1 <--- EQ_IIR 0 <-- B0 <-- sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`dai.m4') +include(`pipeline.m4') +include(`bytecontrol.m4') +include(`eq_iir.m4') + +# +# Controls +# + +# Use 50 Hz highpass response with +20 dB gain +include(`eq_iir_coef_highpass_50hz_20db_48khz.m4') + +# EQ Bytes control with max value of 255 +C_CONTROLBYTES(EQIIR, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), + , , , + CONTROLBYTES_MAX(, 316), + , + EQIIR_priv) + +# +# Components and Buffers +# + +# Host "Highpass Capture" PCM +# with 0 sink and 2 source periods +W_PCM_CAPTURE(PCM_ID, Highpass Capture, 0, 2, 2) + +# "EQ 0" has 2 sink period and 2 source periods +W_EQ_IIR(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "EQIIR")) + +# Capture Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_PASS_MEM_CAP) + +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_PASS_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_C <--- B1 <--- EQ_IIR 0 <-- B0 <-- sink DAI0 + +P_GRAPH(pipe-pass-capture-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(Highpass Capture PCM_ID, N_PCMC(PCM_ID))', + `dapm(N_PCMC(PCM_ID), N_BUFFER(1))', + `dapm(N_BUFFER(1), N_EQ_IIR(0))', + `dapm(N_EQ_IIR(0), N_BUFFER(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(0)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Highpass Capture PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Highpass Capture PCM_ID, COMP_FORMAT_NAME(PIPELINE_FORMAT), 48000, 48000, PIPELINE_CHANNELS, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) diff --git a/tools/topology/sof/pipe-eq-fir-volume-playback.m4 b/tools/topology/sof/pipe-eq-fir-volume-playback.m4 new file mode 100644 index 000000000000..8f6c645bb65e --- /dev/null +++ b/tools/topology/sof/pipe-eq-fir-volume-playback.m4 @@ -0,0 +1,97 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> B0 --> EQ 0 --> B1 --> Volume 0 --> B2 --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`dai.m4') +include(`mixercontrol.m4') +include(`bytecontrol.m4') +include(`pipeline.m4') +include(`eq_fir.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# EQ initial parameters, in this case flat response +CONTROLBYTES_PRIV(EQFIR_priv, +` bytes "0x18,0x00,0x00,0x00,0x02,0x00,0x01,0x00,' +` 0x00,0x00,0x00,0x00,0x04,0x00,0xff,0xff,' +` 0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00"' +) + +# EQ Bytes control with max value of 255 +C_CONTROLBYTES(EQFIR, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), + , , , + CONTROLBYTES_MAX(, 316), + , + EQFIR_priv) + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 2, 0, 2) + +# "Volume" has 2 source and 2 sink periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "Master Playback Volume PIPELINE_ID")) + +# "EQ 0" has 2 sink period and 2 source periods +W_EQ_FIR(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "EQFIR")) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(2, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(DAI_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --> B0 --> EQ 0 --> B1 --> Volume 0 --> B2 --> sink DAI0 + +P_GRAPH(pipe-pass-vol-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_EQ_FIR(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_EQ_FIR(0))', + `dapm(N_PGA(0), N_BUFFER(1))', + `dapm(N_BUFFER(2), N_PGA(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(2)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + + +# +# PCM Configuration + +# +PCM_CAPABILITIES(Passthrough Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-eq-iir-volume-playback.m4 b/tools/topology/sof/pipe-eq-iir-volume-playback.m4 new file mode 100644 index 000000000000..490835c15254 --- /dev/null +++ b/tools/topology/sof/pipe-eq-iir-volume-playback.m4 @@ -0,0 +1,101 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> B0 --> EQ 0 --> B1 --> Volume 0 --> B2 --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`dai.m4') +include(`mixercontrol.m4') +include(`bytecontrol.m4') +include(`pipeline.m4') +include(`eq_iir.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# EQ initial parameters, in this case flat response +CONTROLBYTES_PRIV(EQIIR_priv, +` bytes "0x38,0x00,0x00,0x00,0x02,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x9e,0x73,0x13,0x20,' +` 0x00,0x00,0x00,0x00,0xb2,0x7f,0x00,0x00"' +) + +# EQ Bytes control with max value of 255 +C_CONTROLBYTES(EQIIR, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), + , , , + CONTROLBYTES_MAX(, 316), + , + EQIIR_priv) + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 2, 0, 2) + +# "Volume" has 2 source and 2 sink periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "Master Playback Volume PIPELINE_ID")) + +# "EQ 0" has 2 sink period and 2 source periods +W_EQ_IIR(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "EQIIR")) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(2, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(DAI_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --> B0 --> EQ 0 --> B1 --> Volume 0 --> B2 --> sink DAI0 + +P_GRAPH(pipe-pass-vol-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_EQ_IIR(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_EQ_IIR(0))', + `dapm(N_PGA(0), N_BUFFER(1))', + `dapm(N_BUFFER(2), N_PGA(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(2)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + + +# +# PCM Configuration + +# +PCM_CAPABILITIES(Passthrough Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-eq-volume-playback.m4 b/tools/topology/sof/pipe-eq-volume-playback.m4 new file mode 100644 index 000000000000..fc40c4d01627 --- /dev/null +++ b/tools/topology/sof/pipe-eq-volume-playback.m4 @@ -0,0 +1,125 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> B0 --> EQ_IIR 0 --> B1 --> EQ_FIR 0 --> B2 --> Volume 0 --> B3 --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`dai.m4') +include(`mixercontrol.m4') +include(`bytecontrol.m4') +include(`pipeline.m4') +include(`eq_iir.m4') +include(`eq_fir.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# EQ initial parameters, in this case flat response +CONTROLBYTES_PRIV(EQIIR_priv, +` bytes "0x38,0x00,0x00,0x00,0x02,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,' +` 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,' +` 0x00,0x00,0x00,0x00,0x9e,0x73,0x13,0x20,' +` 0x00,0x00,0x00,0x00,0xb2,0x7f,0x00,0x00"' +) + +# EQ Bytes control with max value of 255 +C_CONTROLBYTES(EQIIR, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), + , , , + CONTROLBYTES_MAX(, 316), + , + EQIIR_priv) + +# EQ initial parameters, in this case flat response +CONTROLBYTES_PRIV(EQFIR_priv, +` bytes "0x18,0x00,0x00,0x00,0x02,0x00,0x01,0x00,' +` 0x00,0x00,0x00,0x00,0x04,0x00,0xff,0xff,' +` 0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00"' +) + +# EQ Bytes control with max value of 255 +C_CONTROLBYTES(EQFIR, PIPELINE_ID, + CONTROLBYTES_OPS(bytes, 258 binds the mixer control to bytes get/put handlers, 258, 258), + CONTROLBYTES_EXTOPS(258 binds the mixer control to bytes get/put handlers, 258, 258), + , , , + CONTROLBYTES_MAX(, 316), + , + EQFIR_priv) + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 2, 0, 2) + +# "Volume" has 2 source and 2 sink periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "Master Playback Volume PIPELINE_ID")) + +# "EQ 0" has 2 sink period and 2 source periods +W_EQ_IIR(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "EQIIR")) + +# "EQ 0" has 2 sink period and 2 source periods +W_EQ_FIR(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "EQFIR")) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(2, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(3, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(DAI_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host host PCM_P --> B0 --> EQ_IIR 0 --> B1 --> EQ_FIR 0 --> B2 --> Volume 0 --> B3 --> sink DAI0 + +P_GRAPH(pipe-pass-vol-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_EQ_IIR(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_EQ_IIR(0))', + `dapm(N_EQ_FIR(0), N_BUFFER(1))', + `dapm(N_BUFFER(2), N_EQ_FIR(0))', + `dapm(N_PGA(0), N_BUFFER(2))', + `dapm(N_BUFFER(3), N_PGA(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(3)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + +# +# PCM Configuration + +# +PCM_CAPABILITIES(Passthrough Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-low-latency-capture.m4 b/tools/topology/sof/pipe-low-latency-capture.m4 new file mode 100644 index 000000000000..897fe050c54d --- /dev/null +++ b/tools/topology/sof/pipe-low-latency-capture.m4 @@ -0,0 +1,67 @@ +# Low Latency Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_C <--B5-- volume(0C) <--B4-- source DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`mixercontrol.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(PCM PCM_ID Capture Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 40), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 0, 0), KCONTROL_CHANNEL(FR, 0, 1))) + +# +# Components and Buffers +# + +# Host "Low Latency Capture" PCM +# with 0 sink and 2 source periods +W_PCM_CAPTURE(PCM_ID, Low Latency Capture, 0, 2, 0) + +# "Capture Volume" has 2 sink and source periods for host and DAI ping-pong +W_PGA(0, PIPELINE_FORMAT, 2, 2, 0, LIST(` ', "PCM PCM_ID Capture Volume PIPELINE_ID")) + +# Capture Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM <--B1-- volume <--B0-- source DAI0 + +P_GRAPH(pipe-ll-capture-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(Low Latency Capture PCM_ID, N_PCMC(PCM_ID))', + `dapm(N_PCMC(PCM_ID), N_BUFFER(1))', + `dapm(N_BUFFER(1), N_PGA(0))', + `dapm(N_PGA(0), N_BUFFER(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(0)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Low Latency Capture PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Low Latency Capture PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 4, 192, 16384, 65536, 65536) diff --git a/tools/topology/sof/pipe-low-latency-playback.m4 b/tools/topology/sof/pipe-low-latency-playback.m4 new file mode 100644 index 000000000000..c316bf4940f7 --- /dev/null +++ b/tools/topology/sof/pipe-low-latency-playback.m4 @@ -0,0 +1,119 @@ +# Low Latency Pipeline +# +# Low Latency Playback PCM mixed into single sink pipe. +# Low latency Capture PCM. +# +# Pipeline Endpoints for connection are :- +# +# LL Playback Mixer (Mixer) +# LL Capture Volume B4 (DAI buffer) +# LL Playback Volume B3 (DAI buffer) +# +# +# host PCM_P --B0--> volume(0P) --B1--+ +# |--ll mixer(M) --B2--> volume(LL) ---B3--> sink DAI0 +# pipeline n+1 >---+ +# | +# pipeline n+2 >---+ +# | +# pipeline n+3 >---+ .....etc....more pipes can be mixed here +# + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`mixer.m4') +include(`mixercontrol.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(PCM PCM_ID Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(KCONTROL_CHANNEL(FL, 0, 0), KCONTROL_CHANNEL(FR, 0, 1))) + +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# +# Components and Buffers +# + +# Host "Low latency Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Low Latency Playback, 2, 0, 2) + +# "Playback Volume" has 1 sink period and 2 source periods for host ping-pong +W_PGA(0, PIPELINE_FORMAT, 1, 2, 1, LIST(` ', "PCM PCM_ID Playback Volume PIPELINE_ID")) + +# "Master Playback Volume" has 1 source and 2 sink periods for DAI ping-pong +W_PGA(1, PIPELINE_FORMAT, 2, 1, 1, LIST(` ', "Master Playback Volume PIPELINE_ID")) + +# Mixer 0 has 1 sink and source periods. +W_MIXER(0, PIPELINE_FORMAT, 1, 1, 1) + +# Low Latency Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(1, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS,SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) +W_BUFFER(2, COMP_BUFFER_SIZE(1, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) +W_BUFFER(3, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --B0--> volume(0P) --B1--+ +# |--ll mixer(M) --B2--> volume(LL) ---B3--> sink DAI0 +# pipeline n+1 >---+ +# | +# pipeline n+2 >---+ +# | +# pipeline n+3 >---+ .....etc....more pipes can be mixed here +# + +P_GRAPH(pipe-ll-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Low Latency Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_PGA(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_PGA(0))', + `dapm(N_MIXER(0), N_BUFFER(1))', + `dapm(N_BUFFER(2), N_MIXER(0))', + `dapm(N_PGA(1), N_BUFFER(2))', + `dapm(N_BUFFER(3), N_PGA(1))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(3)) +indir(`define', concat(`PIPELINE_MIXER_', PIPELINE_ID), N_MIXER(0)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Low Latency Playback PCM_ID) + +# +# PCM Configuration +# + + +# PCM capabilities supported by FW +PCM_CAPABILITIES(Low Latency Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-passthrough-capture.m4 b/tools/topology/sof/pipe-passthrough-capture.m4 new file mode 100644 index 000000000000..072b569456e0 --- /dev/null +++ b/tools/topology/sof/pipe-passthrough-capture.m4 @@ -0,0 +1,47 @@ +# Capture Passthrough Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_C <-- B0 <-- sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# Components and Buffers +# + +# Host "Passthrough Capture" PCM +# with 0 sink and 2 source periods +W_PCM_CAPTURE(PCM_ID, Passthrough Capture, 0, 2, 2) + +# Capture Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_PASS_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_C <-- B0 <-- sink DAI0 + +P_GRAPH(pipe-pass-capture-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(Passthrough Capture PCM_ID, N_PCMC(PCM_ID))', + `dapm(N_PCMC(PCM_ID), N_BUFFER(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(0)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Capture PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Passthrough Capture PCM_ID, COMP_FORMAT_NAME(PIPELINE_FORMAT), 48000, 48000, PIPELINE_CHANNELS, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) diff --git a/tools/topology/sof/pipe-passthrough-playback.m4 b/tools/topology/sof/pipe-passthrough-playback.m4 new file mode 100644 index 000000000000..b0ee4632bb7b --- /dev/null +++ b/tools/topology/sof/pipe-passthrough-playback.m4 @@ -0,0 +1,47 @@ +# Low Latency Passthrough Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> B0 --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 2, 0, 2) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_PASS_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --> B0 --> sink DAI0 + +P_GRAPH(pipe-pass-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(0)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Passthrough Playback PCM_ID, COMP_FORMAT_NAME(PIPELINE_FORMAT), 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) diff --git a/tools/topology/sof/pipe-pcm-media.m4 b/tools/topology/sof/pipe-pcm-media.m4 new file mode 100644 index 000000000000..ae2090db41ed --- /dev/null +++ b/tools/topology/sof/pipe-pcm-media.m4 @@ -0,0 +1,117 @@ +# Low Power PCM Media Pipeline +# +# Low power PCM media playback with SRC and volume. +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --B0--> volume(0P) --B1--> SRC -- B2 --> Endpoint Pipeline +# + +# Include topology builder +include(`utils.m4') +include(`src.m4') +include(`buffer.m4') +include(`pga.m4') +include(`mixercontrol.m4') +include(`pipeline.m4') +include(`pcm.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(PCM PCM_ID Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# +# SRC Configuration +# + +W_VENDORTUPLES(media_src_tokens, sof_src_tokens, LIST(` ', `SOF_TKN_SRC_RATE_OUT "48000"')) + +W_DATA(media_src_conf, media_src_tokens) + +# +# Components and Buffers +# + +# Host "Low latency Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Media Playback, 2, 0, 2) + +# "Playback Volume" has 2 sink period and 2 source periods for host ping-pong +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "PCM PCM_ID Playback Volume PIPELINE_ID")) + +# "SRC 0" has 2 sink and source periods. +W_SRC(0, PIPELINE_FORMAT, 2, 2, media_src_conf, 2) + +# Media Source Buffers to SRC, make them big enough to deal with 2 * rate. +W_BUFFER(0, COMP_BUFFER_SIZE(4, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1,COMP_BUFFER_SIZE(4, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) + +# Buffer B2 is on fixed rate sink side of SRC. Set it 1.5 * rate. +W_BUFFER(2, COMP_BUFFER_SIZE(3, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) + +# +# Pipeline Graph +# +# PCM --B0--> volume --B1--> SRC --> B2 --> Endpoint Pipeline +# + +P_GRAPH(pipe-media-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Media Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_PGA(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_PGA(0))', + `dapm(N_SRC(0), N_BUFFER(1))' + `dapm(N_BUFFER(2), N_SRC(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(2)) + +# +# Pipeline Configuration. +# + +W_PIPELINE(N_SRC(0), SCHEDULE_DEADLINE, SCHEDULE_PRIORITY, SCHEDULE_FRAMES, SCHEDULE_CORE, 1, pipe_media_schedule_plat) + +# +# PCM Configuration +# + +# PCM capabilities supported by FW + +PCM_CAPABILITIES(Media Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 8000, 192000, 2, PIPELINE_CHANNELS, 2, 32, 192, 262144, 8388608, 8388608) + +# PCM Low Latency Playback and Capture +SectionPCM.STR(Media Playback PCM_ID) { + + index STR(PIPELINE_ID) + + # used for binding to the PCM + id STR(PCM_ID) + + dai.STR(Media Playback PCM_ID) { + id STR(PCM_ID) + } + + # Playback and Capture Configuration + pcm."playback" { + + capabilities STR(Media Playback PCM_ID) + } +} diff --git a/tools/topology/sof/pipe-src-capture.m4 b/tools/topology/sof/pipe-src-capture.m4 new file mode 100644 index 000000000000..e151bf0dd0bc --- /dev/null +++ b/tools/topology/sof/pipe-src-capture.m4 @@ -0,0 +1,64 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> SRC --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`src.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# Components and Buffers +# + +# Host "Passthrough Capture" PCM +# with 4 sink and 0 source periods +W_PCM_CAPTURE(PCM_ID, Passthrough Capture, 4, 0, 2) + +# +# SRC Configuration +# + +W_VENDORTUPLES(media_src_tokens, sof_src_tokens, LIST(` ', `SOF_TKN_SRC_RATE_OUT "48000"')) + +W_DATA(media_src_conf, media_src_tokens) + +# "SRC" has 4 source and 4 sink periods +W_SRC(0, PIPELINE_FORMAT, 4, 4, media_src_conf, 2) + +# Capture Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(4, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(4, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P <-- B0 <-- SRC 0 <-- B1 <-- sink DAI0 + +P_GRAPH(pipe-pass-src-capture-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(Passthrough Capture PCM_ID, N_PCMC(PCM_ID))', + `dapm(N_PCMC(PCM_ID), N_BUFFER(0))', + `dapm(N_BUFFER(0), N_SRC(0))', + `dapm(N_SRC(0), N_BUFFER(1))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(1)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Capture PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Passthrough Capture PCM_ID, `S32_LE,S24_LE,S16_LE', 8000, 96000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) diff --git a/tools/topology/sof/pipe-src-playback.m4 b/tools/topology/sof/pipe-src-playback.m4 new file mode 100644 index 000000000000..8003b50288ed --- /dev/null +++ b/tools/topology/sof/pipe-src-playback.m4 @@ -0,0 +1,65 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> SRC --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`src.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`dai.m4') +include(`pipeline.m4') + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 3 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 3, 0, 2) + +# +# SRC Configuration +# + +W_VENDORTUPLES(media_src_tokens, sof_src_tokens, LIST(` ', `SOF_TKN_SRC_RATE_OUT "48000"')) + +W_DATA(media_src_conf, media_src_tokens) + +# "SRC" has 3 source and 3 sink periods +W_SRC(0, PIPELINE_FORMAT, 3, 3, media_src_conf, 2) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(3, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(3, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --> B0 --> SRC 0 --> B1 --> sink DAI0 + +P_GRAPH(pipe-pass-src-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_SRC(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_SRC(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(1)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Passthrough Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 8000, 192000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-tone.m4 b/tools/topology/sof/pipe-tone.m4 new file mode 100644 index 000000000000..fc5eb0099144 --- /dev/null +++ b/tools/topology/sof/pipe-tone.m4 @@ -0,0 +1,80 @@ +# Tone Generator +# +# Multi Frequency Tone Generator. +# +# Pipeline Endpoints for connection are :- +# +# Tone --B0--> volume --B1--> Endpoint Pipeline +# + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pga.m4') +include(`tone.m4') +include(`mixercontrol.m4') +include(`pipeline.m4') + +# +# Controls +# + +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Tone Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# Switch type Mixer Control with max value of 1 +C_CONTROLMIXER(Tone Switch, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 259 binds the mixer control to switch get/put handlers, 259, 259), + CONTROLMIXER_MAX(max 1 indicates switch type control, 1), + false, + , + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 2, 0), KCONTROL_CHANNEL(FR, 2, 1))) + +# +# Components and Buffers +# + +# "Tone 0" has 2 sink period and 0 source periods +W_TONE(0, PIPELINE_FORMAT, 2, 0, 0, LIST(` ', "Tone Switch PIPELINE_ID")) + +# "Tone Volume" has 2 sink period and 2 source periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 0, LIST(` ', "Tone Volume PIPELINE_ID")) + +# Low Latency Buffers +W_BUFFER(0,COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_COMP_MEM_CAP) + + +# +# Pipeline Graph +# +# Tone --B0--> volume --B1--> Endpoint Pipeline +# + +P_GRAPH(pipe-tone-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_BUFFER(0), N_TONE(0))', + `dapm(N_PGA(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_PGA(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(1)) + +# +# Pipeline Configuration. +# + +W_PIPELINE(N_TONE(0), SCHEDULE_DEADLINE, SCHEDULE_PRIORITY, SCHEDULE_FRAMES, SCHEDULE_CORE, 0, pipe_tone_schedule_plat) diff --git a/tools/topology/sof/pipe-volume-capture.m4 b/tools/topology/sof/pipe-volume-capture.m4 new file mode 100644 index 000000000000..a044ed6524f8 --- /dev/null +++ b/tools/topology/sof/pipe-volume-capture.m4 @@ -0,0 +1,70 @@ +# Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_C <-- B0 <-- Volume 0 <-- B1 <-- source DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`dai.m4') +include(`mixercontrol.m4') +include(`pipeline.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Capture Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# +# Components and Buffers +# + +# Host "Passthrough Capture" PCM +# with 0 sink and 2 source periods +W_PCM_CAPTURE(PCM_ID, Passthrough Capture, 0, 2, 2) + +# "Volume" has 2 source and 2 sink periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "Master Capture Volume PIPELINE_ID")) + +# Capture Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(DAI_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P <-- B0 <-- Volume 0 <-- B1 <-- sink DAI0 + +P_GRAPH(pipe-pass-vol-capture-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(Passthrough Capture PCM_ID, N_PCMC(PCM_ID))', + `dapm(N_PCMC(PCM_ID), N_BUFFER(0))', + `dapm(N_BUFFER(0), N_PGA(0))', + `dapm(N_PGA(0), N_BUFFER(1))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SINK_', PIPELINE_ID), N_BUFFER(1)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Capture PCM_ID) + +# +# PCM Configuration +# + +PCM_CAPABILITIES(Passthrough Capture PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/pipe-volume-playback.m4 b/tools/topology/sof/pipe-volume-playback.m4 new file mode 100644 index 000000000000..e373adc320d4 --- /dev/null +++ b/tools/topology/sof/pipe-volume-playback.m4 @@ -0,0 +1,71 @@ +# Low Latency Passthrough with volume Pipeline and PCM +# +# Pipeline Endpoints for connection are :- +# +# host PCM_P --> B0 --> Volume 0 --> B1 --> sink DAI0 + +# Include topology builder +include(`utils.m4') +include(`buffer.m4') +include(`pcm.m4') +include(`pga.m4') +include(`dai.m4') +include(`mixercontrol.m4') +include(`pipeline.m4') + +# +# Controls +# +# Volume Mixer control with max value of 32 +C_CONTROLMIXER(Master Playback Volume, PIPELINE_ID, + CONTROLMIXER_OPS(volsw, 256 binds the mixer control to volume get/put handlers, 256, 256), + CONTROLMIXER_MAX(, 32), + false, + CONTROLMIXER_TLV(TLV 32 steps from -90dB to +6dB for 3dB, vtlv_m90s3), + Channel register and shift for Front Left/Right, + LIST(` ', KCONTROL_CHANNEL(FL, 1, 0), KCONTROL_CHANNEL(FR, 1, 1))) + +# +# Components and Buffers +# + +# Host "Passthrough Playback" PCM +# with 2 sink and 0 source periods +W_PCM_PLAYBACK(PCM_ID, Passthrough Playback, 2, 0, 2) + +# "Volume" has 2 source and 2 sink periods +W_PGA(0, PIPELINE_FORMAT, 2, 2, 2, LIST(` ', "Master Playback Volume PIPELINE_ID")) + +# Playback Buffers +W_BUFFER(0, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(PIPELINE_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_HOST_MEM_CAP) +W_BUFFER(1, COMP_BUFFER_SIZE(2, + COMP_SAMPLE_SIZE(DAI_FORMAT), PIPELINE_CHANNELS, SCHEDULE_FRAMES), + PLATFORM_DAI_MEM_CAP) + +# +# Pipeline Graph +# +# host PCM_P --> B0 --> Volume 0 --> B1 --> sink DAI0 + +P_GRAPH(pipe-pass-vol-playback-PIPELINE_ID, PIPELINE_ID, + LIST(` ', + `dapm(N_PCMP(PCM_ID), Passthrough Playback PCM_ID)', + `dapm(N_BUFFER(0), N_PCMP(PCM_ID))', + `dapm(N_PGA(0), N_BUFFER(0))', + `dapm(N_BUFFER(1), N_PGA(0))')) + +# +# Pipeline Source and Sinks +# +indir(`define', concat(`PIPELINE_SOURCE_', PIPELINE_ID), N_BUFFER(1)) +indir(`define', concat(`PIPELINE_PCM_', PIPELINE_ID), Passthrough Playback PCM_ID) + + +# +# PCM Configuration + +# +PCM_CAPABILITIES(Passthrough Playback PCM_ID, `S32_LE,S24_LE,S16_LE', 48000, 48000, 2, PIPELINE_CHANNELS, 2, 16, 192, 16384, 65536, 65536) + diff --git a/tools/topology/sof/tokens.m4 b/tools/topology/sof/tokens.m4 new file mode 100644 index 000000000000..91298b89fff2 --- /dev/null +++ b/tools/topology/sof/tokens.m4 @@ -0,0 +1,90 @@ + +# +# SOF Tokens for differentiation. +# +# Differentiation can be done at the platform and machine level. +# +# Tokens are GUIDs + +# TODO: pre-process this with UAPI headers GNU cpp. + + +SectionVendorTokens."sof_buffer_tokens" { + SOF_TKN_BUF_SIZE "100" + SOF_TKN_BUF_CAPS "101" +} + +SectionVendorTokens."sof_dai_tokens" { + SOF_TKN_DAI_DMAC_CONFIG "153" + SOF_TKN_DAI_TYPE "154" + SOF_TKN_DAI_INDEX "155" + SOF_TKN_DAI_DIRECTION "156" +} + +SectionVendorTokens."sof_sched_tokens" { + SOF_TKN_SCHED_DEADLINE "200" + SOF_TKN_SCHED_PRIORITY "201" + SOF_TKN_SCHED_MIPS "202" + SOF_TKN_SCHED_CORE "203" + SOF_TKN_SCHED_FRAMES "204" + SOF_TKN_SCHED_TIMER "205" +} + +SectionVendorTokens."sof_volume_tokens" { + SOF_TKN_VOLUME_RAMP_STEP_TYPE "250" + SOF_TKN_VOLUME_RAMP_STEP_MS "251" +} + +SectionVendorTokens."sof_src_tokens" { + SOF_TKN_SRC_RATE_IN "300" + SOF_TKN_SRC_RATE_OUT "301" +} + +SectionVendorTokens."sof_pcm_tokens" { + SOF_TKN_PCM_DMAC_CONFIG "353" +} + +SectionVendorTokens."sof_comp_tokens" { + SOF_TKN_COMP_PERIOD_SINK_COUNT "400" + SOF_TKN_COMP_PERIOD_SOURCE_COUNT "401" + SOF_TKN_COMP_FORMAT "402" + SOF_TKN_COMP_PRELOAD_COUNT "403" +} + +SectionVendorTokens."sof_ssp_tokens" { + SOF_TKN_INTEL_SSP_CLKS_CONTROL "500" + SOF_TKN_INTEL_SSP_MCLK_ID "501" + SOF_TKN_INTEL_SSP_SAMPLE_BITS "502" + SOF_TKN_INTEL_SSP_FRAME_PULSE_WIDTH "503" + SOF_TKN_INTEL_SSP_QUIRKS "504" + SOF_TKN_INTEL_SSP_TDM_PADDING_PER_SLOT "505" +} + +SectionVendorTokens."sof_dmic_tokens" { + SOF_TKN_INTEL_DMIC_DRIVER_VERSION "600" + SOF_TKN_INTEL_DMIC_CLK_MIN "601" + SOF_TKN_INTEL_DMIC_CLK_MAX "602" + SOF_TKN_INTEL_DMIC_DUTY_MIN "603" + SOF_TKN_INTEL_DMIC_DUTY_MAX "604" + SOF_TKN_INTEL_DMIC_NUM_PDM_ACTIVE "605" + SOF_TKN_INTEL_DMIC_SAMPLE_RATE "608" + SOF_TKN_INTEL_DMIC_FIFO_WORD_LENGTH "609" +} + +SectionVendorTokens."sof_dmic_pdm_tokens" { + SOF_TKN_INTEL_DMIC_PDM_CTRL_ID "700" + SOF_TKN_INTEL_DMIC_PDM_MIC_A_Enable "701" + SOF_TKN_INTEL_DMIC_PDM_MIC_B_Enable "702" + SOF_TKN_INTEL_DMIC_PDM_POLARITY_A "703" + SOF_TKN_INTEL_DMIC_PDM_POLARITY_B "704" + SOF_TKN_INTEL_DMIC_PDM_CLK_EDGE "705" + SOF_TKN_INTEL_DMIC_PDM_SKEW "706" +} + +SectionVendorTokens."sof_tone_tokens" { + SOF_TKN_TONE_SAMPLE_RATE "800" +} + +SectionVendorTokens."sof_effect_tokens" { + SOF_TKN_EFFECT_TYPE "900" +} diff --git a/tools/tune/eq/eq_align.m b/tools/tune/eq/eq_align.m new file mode 100644 index 000000000000..71edfd632d85 --- /dev/null +++ b/tools/tune/eq/eq_align.m @@ -0,0 +1,52 @@ +function [am, offs, p] = eq_align(f, m, f_align, m_align) + +%% [am, offs, p] = eq_align(f, m, f_align, m_align) +% +% Move by adding/subtracting an offset to frequency response +% curve to cross desired frequency and magnitude, usually 997 Hz, 0 dB +% +% Input +% f - frequencies +% m - magnitude response +% +% Output +% am - aligned magnitude resposne +% offs - offset (gain) in decibels used +% p - index of f_align in f +% + +%% +% Copyright (c) 2016, 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 +% + +p = find(f < f_align, 1, 'last')+1; +offs = m_align-m(p); +am = m+offs; + +end diff --git a/tools/tune/eq/eq_alsactl_write.m b/tools/tune/eq/eq_alsactl_write.m new file mode 100644 index 000000000000..56b798889e1c --- /dev/null +++ b/tools/tune/eq/eq_alsactl_write.m @@ -0,0 +1,56 @@ +function eq_alsactl_write(fn, blob8) + +%% +% Copyright (c) 2016, 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 +% + +%% Write blob +fh = fopen(fn, 'w'); + +%% Pad blob length to multiple of four bytes +n_orig = length(blob8); +n_new = ceil(n_orig/4); +blob8_new = zeros(1, n_new*4); +blob8_new(1:n_orig) = blob8; + +%% Convert to 32 bit +blob32 = zeros(1, n_new, 'uint32'); +k = 2.^[0 8 16 24]; +for i=1:n_new + j = (i-1)*4; + blob32(i) = blob8_new(j+1)*k(1) + blob8_new(j+2)*k(2) ... + + blob8_new(j+3)*k(3) + blob8_new(j+4)*k(4); +end +for i=1:n_new-1 + fprintf(fh, '%ld,', blob32(i)); +end +fprintf(fh, '%ld,\n', blob32(end)); +fclose(fh); + +end diff --git a/tools/tune/eq/eq_blob_write.m b/tools/tune/eq/eq_blob_write.m new file mode 100644 index 000000000000..95f83854ba22 --- /dev/null +++ b/tools/tune/eq/eq_blob_write.m @@ -0,0 +1,49 @@ +function eq_blob_write(fn, blob8) + +%% +% Copyright (c) 2016, 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 +% + +%% Write blob +fh = fopen(fn, 'wb'); +fwrite(fh, blob8, 'uint8'); +fclose(fh); + +%% Print as 8 bit hex +nb = length(blob8); +nl = ceil(nb/16); +for i = 1:nl + m = min(16, nb-(i-1)*16); + for j = 1:m + fprintf(1, "%02x ", blob8((i-1)*16 + j)); + end + fprintf(1, "\n"); +end + +end diff --git a/tools/tune/eq/eq_coef_quant.m b/tools/tune/eq/eq_coef_quant.m new file mode 100644 index 000000000000..e56efca3350d --- /dev/null +++ b/tools/tune/eq/eq_coef_quant.m @@ -0,0 +1,50 @@ +function qc = eq_coef_quant(c, bits, qf) + +%% +% Copyright (c) 2016, 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 +% + +scale = 2^qf; +cmax = 2^(bits-1)-1; +cmin = -2^(bits-1); +qc = int64(round(c*scale)); +idx = find(qc > cmax); +if ~isempty(idx) + fprintf('Warning: Max. value of Q format is exceeded: %d (%d)\n', ... + qc(idx(1)), cmax); + qc(idx) = cmax; +end +idx = find(qc < cmin); +if ~isempty(idx) + fprintf('Warning: Min. value of Q format is exceeded: %d (%d)\n', ... + qc(idx(1)), cmin); + qc(idx) = cmin; +end + +end diff --git a/tools/tune/eq/eq_compute.m b/tools/tune/eq/eq_compute.m new file mode 100644 index 000000000000..57a6293c3556 --- /dev/null +++ b/tools/tune/eq/eq_compute.m @@ -0,0 +1,462 @@ +function eq = eq_compute( eq ) + +%% +% Copyright (c) 2016, 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 +% + +%% Sanity checks +if eq.enable_iir == 0 && eq.enable_fir == 0 + fprintf('Warning: Nothing to do. Please enable FIR or IIR!\n'); +end + +%% Extrapolate response to 0..fs/2, convert to logaritmic grid, and smooth +% with 1/N octave filter +eq = preprocess_responses(eq); + +%% Define target (e.g. speaker) response as parametric filter. This could also +% be numerical data interpolated to the grid. +if length(eq.parametric_target_response) > 0 + [eq.t_z, eq.t_p, eq.t_k] = eq_define_parametric_eq( ... + eq.parametric_target_response, eq.fs); + eq.t_db = eq_compute_response(eq.t_z, eq.t_p, eq.t_k, eq.f, eq.fs); +end + +if isempty(eq.t_db) + fprintf('Warning: No target response is defined.\n'); +end + +%% Align responses at some frequency and dB +[eq.m_db_s, offs] = eq_align(eq.f, eq.m_db_s, eq.f_align, eq.db_align); +eq.raw_m_db = eq.raw_m_db + offs; +eq.m_db = eq.m_db + offs; +eq.t_db = eq_align(eq.f, eq.t_db, eq.f_align, eq.db_align); + +%% Error to equalize = target - raw response, apply 1/N octave smoothing to +% soften the EQ shape +eq.err_db = eq.t_db - eq.m_db; +[eq.err_db_s, eq.logsmooth_noct] = logsmooth(eq.f, eq.err_db, eq.logsmooth_eq); + +%% Parametric IIR EQ definition +if eq.enable_iir + [eq.p_z, eq.p_p, eq.p_k] = eq_define_parametric_eq(eq.peq, eq.fs); + if max(length(eq.p_z), length(eq.p_p)) > 2*eq.iir_biquads_max + error('Maximum number of IIR biquads is exceeded'); + end +else + [eq.p_z, eq.p_p, eq.p_k] = tf2zp(1, 1); +end +[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = eq_compute_response(eq.p_z, ... + eq.p_p, eq.p_k, eq.f, eq.fs); + + +%% FIR EQ computation +% Find remaining responses error ater IIR for FIR to handle +if eq.fir_compensate_iir + eq.err2_db = eq.err_db_s-eq.iir_eq_db; +else + eq.err2_db = eq.err_db_s; +end + +if eq.enable_fir + [eq.t_fir_db, eq.fmin_fir, eq.fmax_fir] = ... + get_fir_target(eq.f, eq.err2_db, eq.fmin_fir, eq.fmax_fir, ... + eq.amin_fir, eq.amax_fir, eq.logsmooth_noct, eq.fir_autoband); + + if eq.fir_minph + eq.b_fir = compute_minph_fir(eq.f, eq.t_fir_db, ... + eq.fir_length, eq.fs, eq.fir_beta); + else + eq.b_fir = compute_linph_fir(eq.f, eq.t_fir_db, ... + eq.fir_length, eq.fs, eq.fir_beta); + end +else + eq.b_fir = 1; + eq.tfirdb = zeros(1,length(eq.f)); +end + +%% Update all responses +eq = eq_compute_tot_response(eq); + +%% Normalize +eq = eq_norm(eq); + +end + +function eq = preprocess_responses(eq) +%% Usually too narrow measurement without the lowest and highest frequencies +[f0, m0, gd0] = fix_response_dcnyquist_mult(eq.raw_f, eq.raw_m_db, ... + eq.raw_gd_s, eq.fs); + +%% Create dense logarithmic frequency grid, then average possible multiple +% measurements +[eq.f, eq.m_db, eq.gd_s, eq.num_responses] = map_to_logfreq_mult(f0, m0, ... + gd0, 1, eq.fs/2, eq.np_fine); + +%% Smooth response with 1/N octave filter for plotting +eq.m_db_s = logsmooth(eq.f, eq.m_db, eq.logsmooth_plot); + +if length(eq.target_m_db) > 0 + % Use target_m_db as dummy group delay, ignore other than magnitude + [f0, m0, ~] = fix_response_dcnyquist_mult(eq.target_f, ... + eq.target_m_db, [], eq.fs); + [~, eq.t_db, ~, ~] = map_to_logfreq_mult(f0, m0, [], 1, ... + eq.fs/2, eq.np_fine); +end +end + + +function [f_hz, m_db, gd_s] = fix_response_dcnyquist(f_hz0, m_db0, gd_s0, fs) +%% Append DC and Fs/2 if missing +f_hz = f_hz0; +m_db = m_db0; +gd_s = gd_s0; +if min(f_hz) > 0 + f_hz = [0 f_hz]; + m_db = [m_db(1) m_db]; % DC the same as 1st measured point + if length(gd_s) > 0 + gd_s = [gd_s(1) gd_s]; % DC the same as 1st measured point + end +end +if max(f_hz) < fs/2 + f_hz = [f_hz fs/2]; + m_db = [m_db m_db(end)]; % Fs/2 the same as last measured point + if length(gd_s) > 0 + gd_s = [gd_s gd_s(end)]; % Fs/2 the same as last measured point + end +end +end + +function [f_hz, m_db, gd_s] = fix_response_dcnyquist_mult(f_hz0, m_db0, ... + gd_s0, fs) + +if iscolumn(f_hz0) + f_hz0 = f_hz0.'; +end +if iscolumn(m_db0) + m_db0 = m_db0.'; +end +if iscolumn(gd_s0) + gd_s0 = gd_s0.'; +end + +s1 = size(f_hz0); +s2 = size(m_db0); +s3 = size(gd_s0); + +if s1(1) == 0 + error('Frequencies vector is empty'); +end +if (s1(1) ~= s2(1)) + error('There must be equal number of frequency and magnitude data'); +end +if (s1(2) ~= s2(2)) + error('There must be equal number of points in frequency, magnitude, and group delay data'); +end +if sum(s3) == 0 + gd_s0 = zeros(s2(1),s2(2)); +end +for i=1:s1(1) + [f_hz(i,:), m_db(i,:), gd_s(i,:)] = fix_response_dcnyquist(... + f_hz0(i,:), m_db0(i,:), gd_s0(i,:), fs); +end + +end + +function [f_hz, m_db, gd_s] = map_to_logfreq(f_hz0, m_db0, gd_s0, f1, f2, np) +%% Create logarithmic frequency vector and interpolate +f_hz = logspace(log10(f1),log10(f2), np); +m_db = interp1(f_hz0, m_db0, f_hz); +gd_s = interp1(f_hz0, gd_s0, f_hz); +m_db(end) = m_db(end-1); % Fix NaN in the end +gd_s(end) = gd_s(end-1); % Fix NaN in the end +end + +function [f_hz, mm_db, mgd_s, num] = map_to_logfreq_mult(f_hz0, m_db0, ... + gd_s0, f1, f2, np) + +s1 = size(f_hz0); +s2 = size(m_db0); +s3 = size(gd_s0); +if (s1(1) ~= s2(1)) + error('There must be equal number of frequency and magnitude data sets'); +end +if (s1(2) ~= s2(2)) + error('There must be equal number of points in frequency and magnitude data'); +end +num = s1(1); +if sum(s3) == 0 + gd_s0 = zeros(s2(1),s2(2)); +end +for i=1:num + [f_hz, m_db(i,:), gd_s(i,:)] = map_to_logfreq(f_hz0(i,:), ... + m_db0(i,:), gd_s0(i,:), f1, f2, np); +end + +if num > 1 + mm_db = mean(m_db); + mgd_s = mean(gd_s); +else + mm_db = m_db; + mgd_s = gd_s; +end +end + +function [ms_db, noct] = logsmooth(f, m_db, c) + +%% Create a 1/N octave smoothing filter +ind1 = find(f < 1000); +ind2 = find(f < 2000); +noct = ind2(end)-ind1(end); +n = 2*round(c*noct/2); +b_smooth = ones(1,n)*1/n; + +%% Smooth the response +tmp = filter(b_smooth, 1, m_db); +ms_db = [tmp(n/2+1:end) linspace(tmp(end), m_db(end), n/2)]; +ms_db(1:n) = ones(1,n)*ms_db(n); +end + +function [m_db, fmin_fir, fmax_fir] = get_fir_target(fhz, err2db, fmin_fir, ... + fmax_fir, amin_fir, amax_fir, noct, auto) + + +%% Find maximum in 1-6 kHz band +idx = find(fhz > 1e3, 1, 'first') - 1; +m_db = err2db - err2db(idx); +if auto + cf = [1e3 6e3]; + ind1 = find(fhz < cf(2)); + ind2 = find(fhz(ind1) > cf(1)); + ipeak = find(m_db(ind2) == max(m_db(ind2))) + ind2(1); + ind1 = find(fhz < cf(1)); + ind2 = find(m_db(ind1) > m_db(ipeak)); + if length(ind2) > 0 + fmin_fir = fhz(ind2(end)); + end + ind1 = find(fhz > cf(2)); + ind2 = find(m_db(ind1) > m_db(ipeak)) + ind1(1); + if length(ind2) > 0 + fmax_fir = fhz(ind2(1)); + end +end + +%% Find FIR target response +ind1 = find(fhz < fmin_fir); +ind2 = find(fhz > fmax_fir); +p1 = ind1(end)+1; +if length(ind2) > 0 + p2 = ind2(1)-1; +else + p2 = length(fhz); +end +m_db(ind1) = m_db(p1); +m_db(ind2) = m_db(p2); +ind = find(m_db > amax_fir); +m_db(ind) = amax_fir; +ind = find(m_db < amin_fir); +m_db(ind) = amin_fir; + +%% Smooth high frequency corner with spline +nn = round(noct/8); +x = [p2-nn p2-nn+1 p2+nn-1 p2+nn]; +if max(x) < length(m_db) + y = m_db(x); + xx = p2-nn:p2+nn; + yy = spline(x, y, xx); + m_db(p2-nn:p2+nn) = yy; +end + +%% Smooth low frequency corner with spline +nn = round(noct/8); +x = [p1-nn p1-nn+1 p1+nn-1 p1+nn]; +if min(x) > 0 + y = m_db(x); + xx = p1-nn:p1+nn; + yy = spline(x, y, xx); + m_db(p1-nn:p1+nn) = yy; +end + +end + +function b = compute_linph_fir(f_hz, m_db, taps, fs, beta) +if nargin < 5 + beta = 4; +end +if mod(taps,2) == 0 + fprintf('Warning: Even FIR length requested.\n'); +end +n_fft = 2*2^ceil(log(taps)/log(2)); +n_half = n_fft/2+1; +f_fft = linspace(0, fs/2, n_half); +m_lin = 10.^(m_db/20); +if f_hz(1) > 0 + f_hz = [0 f_hz]; + m_lin = [m_lin(1) m_lin]; +end +a_half = interp1(f_hz, m_lin, f_fft, 'linear'); +a = [a_half conj(a_half(end-1:-1:2))]; +h = real(fftshift(ifft(a))); +b0 = h(n_half-floor((taps-1)/2):n_half+floor((taps-1)/2)); +win = kaiser(length(b0), beta)'; +b = b0 .* win; +if length(b) < taps + % Append to even length + b = [b 0]; +end +end + +function b_fir = compute_minph_fir(f, m_db, fir_length, fs, beta) + +%% Design double length H^2 FIR +n = 2*fir_length+1; +m_lin2 = (10.^(m_db/20)).^2; +m_db2 = 20*log10(m_lin2); +blin = compute_linph_fir(f, m_db2, n, fs, beta); + +%% Find zeros inside unit circle +myeps = 1e-3; +hdzeros = roots(blin); +ind1 = find( abs(hdzeros) < (1-myeps) ); +minzeros = hdzeros(ind1); + +%% Find double zeros at unit circle +ind2 = find( abs(hdzeros) > (1-myeps) ); +outzeros = hdzeros(ind2); +ind3 = find( abs(outzeros) < (1+myeps) ); +circlezeros = outzeros(ind3); + +%% Get half of the unit circle zeros +if isempty(circlezeros) + %% We are fine ... +else + %% Eliminate double zeros + cangle = angle(circlezeros); + [sorted_cangle, ind] = sort(cangle); + sorted_czeros = circlezeros(ind); + pos = find(angle(sorted_czeros) > 0); + neg = find(angle(sorted_czeros) < 0); + pos_czeros = sorted_czeros(pos); + neg_czeros = sorted_czeros(neg(end:-1:1)); + h1 = []; + for i = 1:2:length(pos_czeros)-1 + x=mean(angle(pos_czeros(i:i+1))); + h1 = [h1' complex(cos(x),sin(x))]'; + end + h2 = []; + for i = 1:2:length(neg_czeros)-1; + x=mean(angle(neg_czeros(i:i+1))); + h2 = [h2' complex(cos(x),sin(x))]'; + end + halfcirclezeros = [h1' h2']'; + if length(halfcirclezeros)*2 < length(circlezeros)-0.1 + %% Replace the last zero pair + halfcirclezeros = [halfcirclezeros' complex(-1, 0)]'; + end + minzeros = [ minzeros' halfcirclezeros' ]'; +end + +%% Convert to transfer function +bmin = mypoly(minzeros); + +%% Scale peak in passhz to max m_db +hmin = freqz(bmin, 1, 512, fs); +b_fir = 10^(max(m_db)/20)*bmin/max(abs(hmin)); + +end + +function tf = mypoly( upolyroots ) + +% Sort roots to increasing angle to ensure more consistent behavior +aa = abs(angle(upolyroots)); +[sa, ind] = sort(aa); +polyroots = upolyroots(ind); + +n = length(polyroots); +n1 = 16; % do not change, hardwired to 16 code below + +if n < (2*n1+1) + % No need to split + tf = poly(polyroots); +else + % Split roots evenly to 16 poly computations + % The fist polys will rpb+1 roots and the rest + % rpb roots to compute + rpb = floor(n/n1); + rem = mod(n,n1); + i1 = zeros(1,n1); + i2 = zeros(1,n1); + i1(1) = 1; + for i = 1:n1-1; + if rem > 0 + i2(i) = i1(i)+rpb; + rem = rem-1; + else + i2(i) = i1(i)+rpb-1; + end + i1(i+1) = i2(i)+1; + end + i2(n1) = n; + tf101 = poly(polyroots(i1(1):i2(1))); + tf102 = poly(polyroots(i1(2):i2(2))); + tf103 = poly(polyroots(i1(3):i2(3))); + tf104 = poly(polyroots(i1(4):i2(4))); + tf105 = poly(polyroots(i1(5):i2(5))); + tf106 = poly(polyroots(i1(6):i2(6))); + tf107 = poly(polyroots(i1(7):i2(7))); + tf108 = poly(polyroots(i1(8):i2(8))); + tf109 = poly(polyroots(i1(9):i2(9))); + tf110 = poly(polyroots(i1(10):i2(10))); + tf111 = poly(polyroots(i1(11):i2(11))); + tf112 = poly(polyroots(i1(12):i2(12))); + tf113 = poly(polyroots(i1(13):i2(13))); + tf114 = poly(polyroots(i1(14):i2(14))); + tf115 = poly(polyroots(i1(15):i2(15))); + tf116 = poly(polyroots(i1(16):i2(16))); + % Combine coefficients with convolution + tf21 = conv(tf101, tf116); + tf22 = conv(tf102, tf115); + tf23 = conv(tf103, tf114); + tf24 = conv(tf104, tf113); + tf25 = conv(tf105, tf112); + tf26 = conv(tf106, tf111); + tf27 = conv(tf107, tf110); + tf28 = conv(tf108, tf109); + tf31 = conv(tf21, tf28); + tf32 = conv(tf22, tf27); + tf33 = conv(tf23, tf26); + tf34 = conv(tf24, tf25); + tf41 = conv(tf31, tf34); + tf42 = conv(tf32, tf33); + tf = conv(tf41, tf42); + + % Ensure the tf coefficents are real if rounding issues + tf = real(tf); +end + +end diff --git a/tools/tune/eq/eq_compute_response.m b/tools/tune/eq/eq_compute_response.m new file mode 100644 index 000000000000..e8a470466ca7 --- /dev/null +++ b/tools/tune/eq/eq_compute_response.m @@ -0,0 +1,72 @@ +function [m, ph, gd] = eq_compute_response(z, p, k, f, fs) + +%% +% Copyright (c) 2016, 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 +% + +switch nargin + case 3 + b = z; % 1st arg + f = p; % 2nd arg + fs = k; % 3rd arg + h = freqz(b, 1, f, fs); + m = 20*log10(abs(h)); + ph = 180/pi*angle(h); + + if length(b) == 1 + gd = zeros(1, length(f)); + else + if exist('OCTAVE_VERSION', 'builtin') + % grpdelay() has some issue so better to not show a plot + gd = NaN * zeros(1, length(f)); + else + gd = 1/fs*grpdelay(b, 1, f, fs); + end + end + case 5 + [b, a] = zp2tf(z, p, k); + h = freqz(b, a, f, fs); + m = 20*log10(abs(h)); + ph = 180/pi*angle(h); + + if length(z) == 0 && length(p) == 0 + gd = zeros(1, length(f)); + else + if exist('OCTAVE_VERSION', 'builtin') + % grpdelay() has some issue so better to not show a plot + gd = NaN * zeros(1, length(f)); + else + gd = 1/fs*grpdelay(b, a, f, fs); + end + end + otherwise + error('Incorrect input parameters'); +end + +end diff --git a/tools/tune/eq/eq_compute_tot_response.m b/tools/tune/eq/eq_compute_tot_response.m new file mode 100644 index 000000000000..250c3640c9ed --- /dev/null +++ b/tools/tune/eq/eq_compute_tot_response.m @@ -0,0 +1,50 @@ +function eq = eq_compute_tot_response(eq) + +%% +% Copyright (c) 2016, 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 +% + +% FIR response and combined IIR+FIR EQ +[eq.iir_eq_db, eq.iir_eq_ph, eq.iir_eq_gd] = eq_compute_response(eq.p_z, eq.p_p, eq.p_k, eq.f, eq.fs); +[eq.fir_eq_db, eq.fir_eq_ph, eq.fir_eq_gd] = eq_compute_response(eq.b_fir, eq.f, eq.fs); +eq.tot_eq_db = eq.iir_eq_db + eq.fir_eq_db; +eq.tot_eq_gd = eq.iir_eq_gd + eq.fir_eq_gd; + +% Simulated equalized result +eq.m_eqd = eq.m_db + eq.tot_eq_db; % Simulated response +eq.m_eqd_s = eq.m_db_s + eq.tot_eq_db; % Smoothed simulated response +eq.gd_eqd = eq.gd_s' + eq.tot_eq_gd; + +% Align +[eq.m_eqd_s, adjust, p] = eq_align(eq.f, eq.m_eqd_s, eq.f_align, eq.db_align); +eq.m_eqd = eq.m_eqd + adjust; +eq.m_eq_loss = eq.tot_eq_db(p); +eq.m_eqd_abs = eq.m_db_abs+eq.m_eq_loss; + +end diff --git a/tools/tune/eq/eq_defaults.m b/tools/tune/eq/eq_defaults.m new file mode 100644 index 000000000000..880e4e3c4db4 --- /dev/null +++ b/tools/tune/eq/eq_defaults.m @@ -0,0 +1,113 @@ +function p = eq_defaults + +%% +% Copyright (c) 2016, 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 +% + +% Misc +p.plot_figs = 0; +p.fn = 'configuration.txt'; +p.fs = 48e3; +p.f_align = 997; +p.db_align = 0; +p.logsmooth_plot = 1/3; % Smooth over 1/3 octaves +p.logsmooth_eq = 1/3; % Smooth over 1/3 octaves +p.np_fine = 5000; % 5000 point design grid + +% Parametric EQ IDs +p.PEQ_HP1 = 1; p.PEQ_HP2 = 2; p.PEQ_LP1 = 3; p.PEQ_LP2 = 4; +p.PEQ_LS1 = 5; p.PEQ_LS2 = 6; p.PEQ_HS1 = 7; p.PEQ_HS2 = 8; +p.PEQ_PN2 = 9; p.PEQ_LP4 = 10; p.PEQ_HP4 = 11; + +% FIR constraints +p.fmin_fir = 200; % +p.fmax_fir = 15e3; % +p.amax_fir = 20; +p.amin_fir = -20; +p.fir_beta = 8; +p.fir_length = 63; +p.fir_minph = 0; % 0 = linear phase, 1 = minimum phase +% Adjust fmin_fir, fmax_fir automatically for least gain loss in FIR +p.fir_autoband = 1; +p.enable_fir = 0; + +% IIR conf +p.iir_biquads_max = 8; +p.enable_iir = 0; + +% Initialize other fields those are computed later to allow use of struct +% arrays +p.raw_f = [10 100e3]; +p.raw_m_db = [0 0]; +p.raw_gd_s = []; +p.f = []; +p.m_db = []; +p.gd_s = []; +p.num_responses = 0; +p.m_db_s = []; +p.gd_s_s = []; +p.logsmooth_noct = 0; +p.t_z = []; +p.t_p = []; +p.t_k = []; +p.t_db = []; +p.m_db_abs = 0; +p.m_db_offs = 0; +p.raw_m_noalign_db = []; +p.err_db = []; +p.p_z = []; +p.p_p = []; +p.p_k = []; +p.iir_eq_db = []; +p.iir_eq_ph = []; +p.iir_eq_gd = []; +p.err2_db = []; +p.t_fir_db = []; +p.b_fir = []; +p.fir_eq_db = []; +p.fir_eq_ph = []; +p.fir_eq_gd = []; +p.tot_eq_db = []; +p.tot_eq_gd = []; +p.m_eqd = []; +p.gd_eqd = []; +p.m_eq_loss = 0; +p.m_eqd_abs = 0; +p.sim_m_db = []; +p.parametric_target_response = []; +p.target_f = [10 100e3]; +p.target_m_db = [0 0]; +p.fir_compensate_iir = 1; +p.p_fmin = 10; +p.p_fmax = 30e3; +p.name = ''; +p.norm_type = 'loudness'; % loudness/peak/1k +p.norm_offs_db = 0; + +end diff --git a/tools/tune/eq/eq_define_parametric_eq.m b/tools/tune/eq/eq_define_parametric_eq.m new file mode 100644 index 000000000000..2beecf2b34db --- /dev/null +++ b/tools/tune/eq/eq_define_parametric_eq.m @@ -0,0 +1,143 @@ +function [z, p, k] = eq_define_parametric_eq(peq, fs) + +%% +% Copyright (c) 2016, 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 +% + +% Parametric types +PEQ_HP1 = 1; PEQ_HP2 = 2; PEQ_LP1 = 3; PEQ_LP2 = 4; +PEQ_LS1 = 5; PEQ_LS2 = 6; PEQ_HS1 = 7; PEQ_HS2 = 8; +PEQ_PN2 = 9; PEQ_LP4 = 10; PEQ_HP4 = 11; + +sp = size(peq); +z = []; +p = []; +k = 1; +for i=1:sp(1) + type = peq(i,1); + f = peq(i,2); + g = peq(i,3); + Q = peq(i,4); + if f < fs/2 + a0 = []; + b0 = []; + z0 = []; + p0 = []; + k0 = []; + switch peq(i,1) + case PEQ_HP1, [z0, p0, k0] = butter(1, 2*f/fs, 'high'); + case PEQ_HP2, [z0, p0, k0] = butter(2, 2*f/fs, 'high'); + case PEQ_HP4, [z0, p0, k0] = butter(4, 2*f/fs, 'high'); + case PEQ_LP1, [z0, p0, k0] = butter(1, 2*f/fs); + case PEQ_LP2, [z0, p0, k0] = butter(2, 2*f/fs); + case PEQ_LP4, [z0, p0, k0] = butter(4, 2*f/fs); + case PEQ_LS1, [b0, a0] = low_shelf_1st(f, g, fs); + case PEQ_LS2, [b0, a0] = low_shelf_2nd(f, g, fs); + case PEQ_HS1, [b0, a0] = high_shelf_1st(f, g, fs); + case PEQ_HS2, [b0, a0] = high_shelf_2nd(f, g, fs); + case PEQ_PN2, [b0, a0] = peak_2nd(f, g, Q, fs); + otherwise + error('Unknown parametric EQ type'); + end + if length(a0) > 0 + [z0, p0, k0] = tf2zp(b0, a0); + end + if length(k0) > 0 + z = [z ; z0(:)]; + p = [p ; p0(:)]; + k = k * k0; + end + end +end +end + +function [b, a] = low_shelf_1st(fhz, gdb, fs) +zw = 2*pi*fhz; +w = wmap(zw, fs); +glin = 10^(gdb/20); +bs = [1 glin*w]; +as = [1 w]; +[b, a] = my_bilinear(bs, as, fs); +end + +function [b, a] = low_shelf_2nd(fhz, gdb, fs) +zw = 2*pi*fhz; +w = wmap(zw, fs); +glin = 10^(gdb/20); +bs = [1 w*sqrt(2*glin) glin*w^2]; +as = [1 w*sqrt(2) w^2]; +[b, a] = my_bilinear(bs, as, fs); +end + +function [b, a] = high_shelf_1st(fhz, gdb, fs) +zw = 2*pi*fhz; +w = wmap(zw, fs); +glin = 10^(gdb/20); +bs = [glin w]; +as = [1 w]; +[b, a] = my_bilinear(bs, as, fs); +end + +function [b, a] = high_shelf_2nd(fhz, gdb, fs) +zw = 2*pi*fhz; +w = wmap(zw, fs); +glin = 10^(gdb/20); +bs = [glin w*sqrt(2*glin) w^2]; +as = [1 w*sqrt(2) w^2]; +[b, a] = my_bilinear(bs, as, fs); +end + + +function [b, a] = peak_2nd(fhz, gdb, Q, fs) + % Reference http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt + A = 10^(gdb/40); % Square root of linear gain + wc = 2*pi*fhz/fs; + alpha = sin(wc)/(2*Q); + b0 = 1 + alpha * A; + b1 = -2 * cos(wc); + b2 = 1 - alpha * A; + a0 = 1 + alpha / A; + a1 = -2 * cos(wc); + a2 = 1 - alpha / A; + b = [b0 / a0 b1 / a0 b2 / a0]; + a = [1 a1 / a0 a2 / a0]; +end + +function [b, a] = my_bilinear(sb, sa, fs) +if exist('OCTAVE_VERSION', 'builtin') + [b, a] = bilinear(sb, sa, 1/fs); +else + [b, a] = bilinear(sb, sa, fs); +end +end + +function sw = wmap(w, fs) +t = 1/fs; +sw = 2/t*tan(w*t/2); +end diff --git a/tools/tune/eq/eq_fir_blob_merge.m b/tools/tune/eq/eq_fir_blob_merge.m new file mode 100644 index 000000000000..68764532210f --- /dev/null +++ b/tools/tune/eq/eq_fir_blob_merge.m @@ -0,0 +1,50 @@ +function bs = eq_fir_blob_merge(platform_max_channels, ... + number_of_responses_defined, assign_response, all_coefficients); + +%% Merge equalizer definition into a struct used by successive blob making +% functions. +% +% bs = eq_fir_blob_merge(platform_max_channels, number_of_responses_defined, ... +% assign_response, all_coefficients); +% + +%% +% Copyright (c) 2016, 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 +% + +if length(assign_response) ~= platform_max_channels + error("Incorrect length in EQ assign vector!"); +end + +bs.platform_max_channels = platform_max_channels; +bs.number_of_responses_defined = number_of_responses_defined; +bs.assign_response = assign_response; +bs.all_coefficients = all_coefficients; + +end diff --git a/tools/tune/eq/eq_fir_blob_pack.m b/tools/tune/eq/eq_fir_blob_pack.m new file mode 100644 index 000000000000..f8e647f25a11 --- /dev/null +++ b/tools/tune/eq/eq_fir_blob_pack.m @@ -0,0 +1,139 @@ +function blob8 = eq_fir_blob_pack(bs, endian) + +%% Pack equalizer struct to bytes +% +% blob8 = eq_fir_blob_pack(bs, endian) +% bs - blob struct +% endian - optional, use 'little' or 'big'. Defaults to little. +% + +%% +% Copyright (c) 2016, 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 +% + +if nargin < 2 + endian = 'little'; +end + +%% Endiannes of blob +switch lower(endian) + case 'little' + sh16 = [0 -8]; + sh32 = [0 -8 -16 -24]; + case 'big' + sh16 = [-8 0]; + sh32 = [-24 -16 -8 0]; + otherwise + error('Unknown endiannes'); +end + +%% Channels count must be even +if mod(bs.platform_max_channels, 2) > 0 + error("Channels # must be even"); +end + +%% Channels cound and assign vector length must be the same +if bs.platform_max_channels ~= length( bs.assign_response) + bs + error("Channels # and response assign length must match"); +end + +%% Coefficients vector length must be multiple of 4 +len = length(bs.all_coefficients); +len_no_header = len - 2 * bs.number_of_responses_defined; +if mod(len_no_header, 4) > 0 + bs + error("Coefficient data vector length must be multiple of 4"); +end + +%% Pack as 16 bits +nh16 = 4+bs.platform_max_channels; +h16 = zeros(1, nh16, 'int16'); +h16(3) = bs.platform_max_channels; +h16(4) = bs.number_of_responses_defined; +for i=1:bs.platform_max_channels + h16(4+i) = bs.assign_response(i); +end + +%% Merge header and coefficients, make even number of int16 to make it +% multiple of int32 +nc16 = length(bs.all_coefficients); +nb16 = ceil((nh16+nc16)/2)*2; +blob16 = zeros(1,nb16, 'int16'); +blob16(1:nh16) = h16; +blob16(nh16+1:nh16+nc16) = int16(bs.all_coefficients); + +%% Print as 16 bit hex +nl = ceil(nb16/16); +for i = 1:nl + m = min(16, nb16-(i-1)*16); + for j = 1:m + k = (i-1)*16 + j; + v = int32(blob16(k)); + if v < 0 + v = 65536+v; + end + fprintf(1, "%04x ", v); + end + fprintf(1, "\n"); +end +fprintf(1, "\n"); + + +%% Pack as 8 bits +nb8 = length(blob16)*2; +blob8 = zeros(1, nb8, 'uint8'); +j = 1; +for i = 1:length(blob16) + blob8(j:j+1) = w16b(blob16(i), sh16); + j = j+2; +end + +%% Add size into first four bytes +blob8(1:4) = w32b(nb8, sh32); + +%% Done +fprintf('Blob size is %d bytes.\n', nb8); + +end + + +function bytes = w16b(word, sh) +bytes = uint8(zeros(1,2)); +bytes(1) = bitand(bitshift(word, sh(1)), 255); +bytes(2) = bitand(bitshift(word, sh(2)), 255); +end + +function bytes = w32b(word, sh) +bytes = uint8(zeros(1,4)); +bytes(1) = bitand(bitshift(word, sh(1)), 255); +bytes(2) = bitand(bitshift(word, sh(2)), 255); +bytes(3) = bitand(bitshift(word, sh(3)), 255); +bytes(4) = bitand(bitshift(word, sh(4)), 255); +end diff --git a/tools/tune/eq/eq_fir_blob_quant.m b/tools/tune/eq/eq_fir_blob_quant.m new file mode 100644 index 000000000000..6d060032d364 --- /dev/null +++ b/tools/tune/eq/eq_fir_blob_quant.m @@ -0,0 +1,105 @@ +function fbr = eq_fir_blob_quant(b, bits) + +%% Quantize FIR coefficients and return vector with length, +% out shift, and coefficients to be used in the setup blob. +% +% fbr = eq_fir_blob_resp(b, bits) +% b - FIR coefficients +% bits - optional number of bits, defaults to 16 +% +% fbr - vector with length, in shift, out shift, and quantized coefficients +% + +%% +% Copyright (c) 2016, 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 +% + +if nargin < 2 + bits = 16; +end + +%% Quantize +[bq, shift] = eq_fir_quantize(b, bits); + +%% Check trailing zeros +nf = length(bq); +nz = nf; +while bq(nz) == 0 + nz = nz - 1; +end +if nz < nf + nb = nz + 1; + fprintf(1,'Note: Filter length was reduced to %d -> %d due to trailing zeros.\n', ... + nf, nb); + bq = bq(1:nb); +else + nb = nf; +end + +%% Make length multiple of four (optimized FIR core) +mod4 = mod(nb, 4); +if mod4 > 0 + pad = zeros(1,4-mod4); + bqp = [bq pad]; + nnew = length(bqp); + fprintf(1,'Note: Filter length was %d, padded length into %d.\n', nb, nnew); +else + nnew = nb; + bqp = bq; +end + +fbr = [nnew shift bqp]; + +end + +function [bq, shift] = eq_fir_quantize(b, bits) + +% [bq, shift] = eq_fir_quantize(b, bits) +% +% Inputs +% b - FIR coefficients +% bits - number bits for 2s complement coefficient +% +% Outputs +% bq - quantized coefficients +% shift - shift right parameter to apply after FIR computation to +% compensate for coefficients scaling +% + +scale = 2^(bits-1); + +%% Output shift for coefficients +m = max(abs(b)); +shift = -ceil(log(m+1/scale)/log(2)); +bsr = b*2^shift; + +%% Quantize to Q1.bits-1 format, e.g. Q1.15 for 16 bits +bq = eq_coef_quant(bsr, bits, bits-1); + +end diff --git a/tools/tune/eq/eq_iir_blob_merge.m b/tools/tune/eq/eq_iir_blob_merge.m new file mode 100644 index 000000000000..c05fe67c40b1 --- /dev/null +++ b/tools/tune/eq/eq_iir_blob_merge.m @@ -0,0 +1,52 @@ +function bs = eq_iir_blob_merge(platform_max_channels, ... + number_of_responses_defined, ... + assign_response, ... + all_coefficients); + +%% Merge equalizer definition into a struct used by successive blob making +% functions. +% +% bs = eq_iir_blob_merge(platform_max_channels, number_of_responses_defined, ... +% assign_response, all_coefficients); +% + +%% +% Copyright (c) 2016, 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 +% + +if length(assign_response) ~= platform_max_channels + error("Assign response does not match channels count!"); +end + +bs.platform_max_channels = platform_max_channels; +bs.number_of_responses_defined = number_of_responses_defined; +bs.assign_response = assign_response; +bs.all_coefficients = all_coefficients; + +end diff --git a/tools/tune/eq/eq_iir_blob_pack.m b/tools/tune/eq/eq_iir_blob_pack.m new file mode 100644 index 000000000000..3f33cb709afb --- /dev/null +++ b/tools/tune/eq/eq_iir_blob_pack.m @@ -0,0 +1,92 @@ +function blob8 = eq_iir_blob_pack(bs, endian) + +%% Pack equalizer struct to bytes +% +% blob8 = eq_iir_blob_pack(bs, endian) +% bs - blob struct +% endian - optional, use 'little' or 'big'. Defaults to little. +% + +%% +% Copyright (c) 2016, 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 +% + +if nargin < 2 + endian = 'little'; +end + +%% Channels count and assign vector lengths must be the same +if bs.platform_max_channels ~= length( bs.assign_response) + bs + error("Channels # and response assign length must match"); +end + +%% Shift values for little/big endian +switch lower(endian) + case 'little' + sh = [0 -8 -16 -24]; + case 'big' + sh = [-24 -16 -8 0]; + otherwise + error('Unknown endiannes'); +end + +%% Pack as 8 bits, header +nbytes_head = (3+bs.platform_max_channels)*4; +nbytes_coef = length(bs.all_coefficients)*4; +nbytes = nbytes_head + nbytes_coef; +blob8 = uint8(zeros(1,nbytes)); + +j = 1; +blob8(j:j+3) = w2b(nbytes, sh); j=j+4; +blob8(j:j+3) = w2b(bs.platform_max_channels, sh); j=j+4; +blob8(j:j+3) = w2b(bs.number_of_responses_defined, sh); j=j+4; + +for i=1:bs.platform_max_channels + blob8(j:j+3) = w2b(int32(bs.assign_response(i)), sh); + j=j+4; +end + +%% Pack coefficients +for i=1:length(bs.all_coefficients) + blob8(j:j+3) = w2b(int32(bs.all_coefficients(i)), sh); + j=j+4; +end +fprintf('Blob size is %d bytes.\n', nbytes); + + +end + +function bytes = w2b(word, sh) +bytes = uint8(zeros(1,4)); +bytes(1) = bitand(bitshift(word, sh(1)), 255); +bytes(2) = bitand(bitshift(word, sh(2)), 255); +bytes(3) = bitand(bitshift(word, sh(3)), 255); +bytes(4) = bitand(bitshift(word, sh(4)), 255); +end diff --git a/tools/tune/eq/eq_iir_blob_quant.m b/tools/tune/eq/eq_iir_blob_quant.m new file mode 100644 index 000000000000..0c19fb313db7 --- /dev/null +++ b/tools/tune/eq/eq_iir_blob_quant.m @@ -0,0 +1,144 @@ +function iir_resp = eq_iir_blob_quant(eq_z, eq_p, eq_k) + +%% Convert IIR coefficients to 2nd order sections and quantize +% +% iir_resp = eq_iir_blob_quant(z, p, k) +% +% z - zeros +% p - poles +% k - gain +% +% iir_resp - vector to setup an IIR equalizer with number of sections, shifts, +% and quantized coefficients +% + +%% +% Copyright (c) 2016, 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 +% + +%% Settings +bits_iir = 32; % Q2.30 +qf_iir = 30; +bits_gain = 16; % Q2.14 +qf_gain = 14; +scale_max = -6; % dB, scale biquads peak gain to this +plot_pz = 0; +plot_fr = 0; + +%% Convert IIR to 2nd order sections +% This a simple implementation of zp2sos() function. It is not used here due +% to utilization of rather strong scaling and resulting low SNR with the +% available word length in EQ in SOF. This poles and zeros allocation to +% biquads is base only in ascending sort of angular frequency. +sz = length(eq_z); +sp = length(eq_p); +sk = length(eq_k); +nb = max(sz, sp)/2; +az = angle(eq_z); +ap = angle(eq_p); +[~, iz] = sort(abs(az)); +[~, ip] = sort(abs(ap)); +eq_z = eq_z(iz); +eq_p = eq_p(ip); +sos = zeros(nb, 6); +for i = 1:nb + j = 2*(i-1)+1; + if i == 1 + [b, a] = zp2tf(eq_z(j:j+1), eq_p(j:j+1), eq_k); + else + [b, a] = zp2tf(eq_z(j:j+1), eq_p(j:j+1), 1); + end + sos(i,1:3) = b; + sos(i,4:6) = a; +end +gain = 1; + +%% Convert 2nd order sections to SOF parameters format and scale the biquads +% with criteria below (Gain max -6 dB at any frequency). Then calculate +% scaling shifts and finally gain multiplier for output. +sz = size(sos); +nbr_sections = sz(1); +n_section_header = 2; +n_section = 7; +iir_resp = int32(zeros(1,n_section_header+nbr_sections*n_section)); +iir_resp(1) = nbr_sections; +iir_resp(2) = nbr_sections; % Note: All sections in series + +scale_max_lin = 10^(scale_max/20); +for n=1:nbr_sections + b = sos(n,1:3); + a = sos(n,4:6); + if plot_pz + figure + zplane(b,a); + tstr = sprintf('SOS %d poles and zeros', n); + title(tstr); + end + + np = 1024; + [h, w] = freqz(b, a, np); + hm = max(abs(h)); + scale = scale_max_lin/hm; + gain_remain = 1/scale; + gain = gain*gain_remain; + b = b * scale; + ma = max(abs(a)); + mb = max(abs(b)); + if plot_fr + figure + [h, w] = freqz(b, a, np); + plot(w, 20*log10(abs(h))); grid on; + xlabel('Frequency (w)'); + ylabel('Magnitude (dB)'); + tstr = sprintf('SOS %d frequency response', n); + title(tstr); + end + + %% Apply remaining gain at last section output + if n == nbr_sections + section_shift = -fix(log(gain)/log(2)); + section_gain= gain/2^(-section_shift); + else + section_shift = 0; + section_gain = 1; + end + + %% Note: Invert sign of a! + %% Note: a(1) is omitted, it's always 1 + m = n_section_header+(n-1)*n_section+1; + iir_resp(m:m+1) = eq_coef_quant(-a(3:-1:2), bits_iir, qf_iir); + iir_resp(m+2:m+4) = eq_coef_quant( b(3:-1:1), bits_iir, qf_iir); + iir_resp(m+5) = section_shift; + iir_resp(m+6) = eq_coef_quant( section_gain, bits_gain, qf_gain); + + %fprintf('sec=%d, shift=%d, gain=%f\n', n, section_shift, section_gain); + +end + +end diff --git a/tools/tune/eq/eq_norm.m b/tools/tune/eq/eq_norm.m new file mode 100644 index 000000000000..47b40d9a5fca --- /dev/null +++ b/tools/tune/eq/eq_norm.m @@ -0,0 +1,114 @@ +function eq = eq_norm(eq) + +%% +% Copyright (c) 2016, 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 +% + +%% Normalize loudness of EQ by computing weighted average of linear +% response. Find scale need to make the average one. +w_lin = level_norm_fweight(eq.f); +m_lin_fir = 10.^(eq.fir_eq_db/20); +m_lin_iir = 10.^(eq.iir_eq_db/20); +i1k = find(eq.f > 1e3, 1, 'first') - 1; +m_max_fir = max(eq.fir_eq_db); +m_max_iir = max(eq.iir_eq_db); +sens_fir = sum(m_lin_fir.*w_lin)/sum(w_lin); +sens_iir = sum(m_lin_iir.*w_lin)/sum(w_lin); +g_offs = 10^(eq.norm_offs_db/20); + +%% Determine scaling gain +switch lower(eq.norm_type) + case 'loudness' + g_fir = 1/sens_fir; + g_iir = 1/sens_iir; + case '1k' + g_fir = 1/m_lin_fir(i1k); + g_iir = 1/m_lin_iir(i1k); + + case 'peak' + g_fir = 10^(-m_max_fir/20); + g_iir = 10^(-m_max_iir/20); + otherwise + error('Requested normalization is not supported'); +end + +%% Adjust FIR and IIR gains if enabled +if eq.enable_fir && eq.enable_iir + eq.b_fir = eq.b_fir * g_fir * g_offs; + eq.p_k = eq.p_k * g_iir * g_offs; +end +if eq.enable_fir && eq.enable_iir == 0 + eq.b_fir = eq.b_fir * g_fir * g_offs; +end +if eq.enable_fir == 0 && eq.enable_iir + eq.p_k = eq.p_k * g_iir * g_offs; +end + +%% Re-compute response after adjusting gain +eq = eq_compute_tot_response(eq); + +end + +function m_lin = level_norm_fweight(f) + +%% w_lin = level_norm_fweight(f) +% +% Provides frequency weight that is useful in normalization of +% loudness of effect like equalizers. The weight consists of pink noise +% like spectral shape that attenuates higher frequencies 3 dB per +% octave. The low frequencies are shaped by 2nd order high-pass +% response at 20 Hz and higher frequencies by 3rd order low-pass at 20 +% kHz. +% +% Note: This weight may have similarity with a standard defined test signal +% characteristic for evaluating music player output levels but this is not +% an implementation of it. This weight may help in avoiding a designed EQ to +% exceed safe playback levels in othervise compliant device. +% +% Input f - frequencies vector in Hz +% +% Output w_lin - weight curve, aligned to peak of 1.0 in the requested f +% + +[z_hp, p_hp] = butter(2, 22.4,'high','s'); +[z_lp, p_lp] = butter(3, 22.4e3,'s'); +z_bp = conv(z_hp, z_lp); +p_bp = conv(p_hp, p_lp); +h = freqs(z_bp, p_bp, f); +m0 = 20*log10(abs(h)); +noct = log(max(f)/min(f))/log(2); +att = 3*noct; +nf = length(f); +w = zeros(1,nf); +w = w - linspace(0,att,nf); +m = m0 + w; +m = m-max(m); +m_lin = 10.^(m/20); + +end diff --git a/tools/tune/eq/eq_plot.m b/tools/tune/eq/eq_plot.m new file mode 100644 index 000000000000..95968c4cf34c --- /dev/null +++ b/tools/tune/eq/eq_plot.m @@ -0,0 +1,178 @@ +function eq_plot(eq, fn) + +%% +% Copyright (c) 2016, 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 +% + +if nargin < 2 + fn = 1; +end + +%% Raw measured response +if length(eq.raw_m_db) > 2 + % Raw without EQ + fh=figure(fn); fn = fn+1; + f1 = min(eq.raw_f); + f2 = max(eq.raw_f); + i1 = find(eq.f > f1, 1, 'first') - 1; + i2 = find(eq.f > f2, 1, 'first') - 1; + idx = i1:i2; + semilogx(eq.f(idx), eq.m_db(idx), eq.f(idx), eq.m_db_s(idx)); + grid on; + ax=axis; axis([eq.p_fmin eq.p_fmax min(max(ax(3:4), -40), 20)]); + legend('Raw','Smoothed'); + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + tstr = sprintf('Imported frequency response: %s', eq.name); + title(tstr); + + % Simulated with EQ + fh=figure(fn); fn = fn+1; + semilogx(eq.f(idx), eq.m_eqd(idx), eq.f(idx), eq.m_eqd_s(idx)); + grid on; + ax=axis; axis([eq.p_fmin eq.p_fmax min(max(ax(3:4), -40), 20)]); + legend('Raw','Smoothed'); + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + tstr = sprintf('Simulated frequency response: %s', eq.name); + title(tstr); +end + +%% Filter responses +fh=figure(fn); fn = fn+1; +i1k = find(eq.f > 1e3, 1, 'first') - 1; +offs_tot = -eq.tot_eq_db(i1k); +offs_fir = -eq.fir_eq_db(i1k); +offs_iir = -eq.iir_eq_db(i1k); +if eq.enable_fir && eq.enable_iir + semilogx(eq.f, eq.err_db_s, eq.f, eq.tot_eq_db + offs_tot, ... + eq.f, eq.iir_eq_db + offs_iir, '--',... + eq.f, eq.fir_eq_db + offs_fir, '--'); + legend('Target', 'Combined', 'IIR', 'FIR', 'Location', 'NorthWest'); +end +if eq.enable_fir && eq.enable_iir == 0 + semilogx(eq.f, eq.err_db_s, eq.f, eq.fir_eq_db + offs_fir); + legend('Target', 'FIR', 'Location', 'NorthWest'); +end +if eq.enable_fir == 0 && eq.enable_iir + semilogx(eq.f, eq.err_db_s, eq.f, eq.iir_eq_db + offs_iir); + legend('Target', 'IIR', 'Location', 'NorthWest'); +end +grid on; +ax=axis; axis([eq.p_fmin eq.p_fmax min(max(ax(3:4), -40), 40)]); +xlabel('Frequency (Hz)'); +ylabel('Magnitude (dB)'); +tstr = sprintf('Filter target vs. achieved response: %s', eq.name); +title(tstr); + +%% FIR filter +if length(eq.b_fir) > 1 + % Response + fh=figure(fn); fn = fn+1; + semilogx(eq.f, eq.fir_eq_db); + grid on; + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + ax = axis; axis([eq.p_fmin eq.p_fmax max(ax(3:4), -40)]); + tstr = sprintf('FIR filter normalized response: %s', eq.name); + title(tstr); + + % Impulse response / coefficients + fh=figure(fn); fn = fn+1; + stem(eq.b_fir); + grid on; + xlabel('Coefficient #'); + ylabel('Coefficient value'); + tstr = sprintf('FIR filter impulse response: %s', eq.name); + title(tstr); + +end + +%% IIR filter +if length(eq.p_z) > 1 || length(eq.p_p) > 1 + % Response + fh=figure(fn); fn = fn+1; + semilogx(eq.f, eq.iir_eq_db); + grid on; + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + ax = axis; axis([eq.p_fmin eq.p_fmax max(ax(3:4), -40)]); + tstr = sprintf('IIR filter normalized response: %s', eq.name); + title(tstr); + + % Polar + fh=figure(fn); fn = fn+1; + zplane(eq.p_z, eq.p_p); + grid on; + tstr = sprintf('IIR zeros and poles: %s', eq.name); + title(tstr); + + % Impulse + ti = 50e-3; + x = zeros(1, ti * round(eq.fs)); + x(1) = 1; + sos = zp2sos(eq.p_z, eq.p_p, eq.p_k); + y = sosfilt(sos, x); + fh=figure(fn); fn = fn+1; + t = (0:(length(x)-1)) / eq.fs; + plot(t, y); + grid on; + xlabel('Time (s)'); + ylabel('Sample value'); + tstr = sprintf('IIR filter impulse response: %s', eq.name); + title(tstr); +end + +%% Group delay +if ~exist('OCTAVE_VERSION', 'builtin') + % Skip plot if running in Octave due to incorrect result + fh=figure(fn); fn = fn+1; + if eq.enable_fir && eq.enable_iir + semilogx(eq.f, eq.tot_eq_gd * 1e3, ... + eq.f, eq.fir_eq_gd * 1e3, '--', ... + eq.f, eq.iir_eq_gd * 1e3, '--'); + legend('Combined','FIR','IIR'); + end + if eq.enable_fir && eq.enable_iir == 0 + semilogx(eq.f, eq.fir_eq_gd * 1e3); + legend('FIR'); + end + if eq.enable_fir == 0 && eq.enable_iir + semilogx(eq.f, eq.iir_eq_gd * 1e3); + legend('IIR'); + end + grid on; + xlabel('Frequency (Hz)'); + ylabel('Group delay (ms)'); + ax = axis; axis([eq.p_fmin eq.p_fmax ax(3:4)]); + tstr = sprintf('Filter group delay: %s', eq.name); + title(tstr); +end + +end diff --git a/tools/tune/eq/eq_tplg_write.m b/tools/tune/eq/eq_tplg_write.m new file mode 100644 index 000000000000..fc6f13236842 --- /dev/null +++ b/tools/tune/eq/eq_tplg_write.m @@ -0,0 +1,67 @@ +function eq_tplg_write(fn, blob8, eqtype, comment) + +%% +% 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 +% + +if nargin < 4 + comment = 'Exported EQ'; +end + +%% Pad blob length to multiple of four bytes +n_orig = length(blob8); +n_new = ceil(n_orig/4)*4; +blob8_new = zeros(1, n_new); +blob8_new(1:n_orig) = blob8; + +%% Write blob +fh = fopen(fn, 'w'); +nl = 8; +fprintf(fh, '# %s %s\n', comment, date()); +fprintf(fh, 'CONTROLBYTES_PRIV(EQ%s_priv,\n', upper(eqtype)); +fprintf(fh, '` bytes "'); +for i = 1:nl:n_new + if i > 1 + fprintf(fh, '` '); + end + for j = 0:nl-1 + n = i + j; + if n < n_new + fprintf(fh, '0x%02x,', blob8_new(n)); + end + if n == n_new + fprintf(fh, '0x%02x"', blob8_new(n)); + end + end + fprintf(fh, '''\n'); +end +fprintf(fh, ')\n'); +fclose(fh); + +end diff --git a/tools/tune/eq/example_fir_eq.m b/tools/tune/eq/example_fir_eq.m new file mode 100644 index 000000000000..2186ea6a2296 --- /dev/null +++ b/tools/tune/eq/example_fir_eq.m @@ -0,0 +1,115 @@ +%% Design demo EQs and bundle them to parameter block + +%% +% Copyright (c) 2016, 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 +% + +function example_fir_eq() + +ascii_blob_fn = 'example_fir_eq.txt'; +binary_blob_fn = 'example_fir_eq.blob'; +tplg_blob_fn = 'example_fir_eq.m4'; +endian = 'little'; +fs = 48e3; + +%% Design FIR loudness equalizer +eq_loud = loudness_fir_eq(fs); + +%% Define a passthru EQ with one tap +b_pass = 1; + +%% Quantize filter coefficients for both equalizers +bq_pass = eq_fir_blob_quant(b_pass); +bq_loud = eq_fir_blob_quant(eq_loud.b_fir); + +%% Build blob +platform_max_channels = 4; % Setup max 4 channels EQ +assign_response = [1 1 1 1]; % Switch to response #1 +num_responses = 2; % Two responses pass, loud +bm = eq_fir_blob_merge(platform_max_channels, ... + num_responses, ... + assign_response, ... + [ bq_pass bq_loud ]); + +%% Pack and write file +bp = eq_fir_blob_pack(bm, endian); +eq_alsactl_write(ascii_blob_fn, bp); +eq_blob_write(binary_blob_fn, bp); +eq_tplg_write(tplg_blob_fn, bp, 'FIR'); + +end + +function eq = loudness_fir_eq(fs) + +%% Derived from Fletcher-Munson curves for 80 and 60 phon +f = [ 20,21,22,24,25,27,28,30,32,34,36,38,40,43,45,48,51,54,57,60,64, ... + 68,72,76,81,85,90,96,102,108,114,121,128,136,144,153,162,171, ... + 182,192,204,216,229,243,257,273,289,306,324,344,364,386,409, ... + 434,460,487,516,547,580,614,651,690,731,775,821,870,922,977, ... + 1036,1098,1163,1233,1307,1385,1467,1555,1648,1747,1851,1962, ... + 2079,2203,2335,2474,2622,2779,2945,3121,3308,3505,3715,3937, ... + 4172,4421,4686,4966,5263,5577,5910,6264,6638,7035,7455,7901, ... + 8373,8873,9404,9966,10561,11193,11861,12570,13322,14118,14962, ... + 15856,16803,17808,18872,20000]; + +m = [ 0.00,-0.13,-0.27,-0.39,-0.52,-0.64,-0.77,-0.89,-1.02,-1.16, ... + -1.31,-1.46,-1.61,-1.76,-1.91,-2.07,-2.24,-2.43,-2.64,-2.85, ... + -3.04,-3.21,-3.35,-3.48,-3.62,-3.78,-3.96,-4.16,-4.35,-4.54, ... + -4.72,-4.90,-5.08,-5.26,-5.45,-5.64,-5.83,-6.02,-6.19,-6.37, ... + -6.57,-6.77,-6.98,-7.19,-7.40,-7.58,-7.76,-7.92,-8.08,-8.25, ... + -8.43,-8.60,-8.76,-8.92,-9.08,-9.23,-9.38,-9.54,-9.69,-9.84, ... + -9.97,-10.09,-10.18,-10.26,-10.33,-10.38,-10.43,-10.48,-10.54, ... + -10.61,-10.70,-10.78,-10.85,-10.91,-10.95,-10.98,-11.02, ... + -11.05,-11.07,-11.10,-11.11,-11.11,-11.10,-11.10,-11.11, ... + -11.14,-11.17,-11.20,-11.21,-11.22,-11.21,-11.20,-11.20, ... + -11.21,-11.21,-11.20,-11.17,-11.11,-11.02,-10.91,-10.78, ... + -10.63,-10.46,-10.25,-10.00,-9.72,-9.39,-9.02,-8.62,-8.19, ... + -7.73,-7.25,-6.75,-6.25,-5.75,-5.28,-4.87,-4.54,-4.33,-4.30]; + +%% Design EQ +eq = eq_defaults(); +eq.fs = fs; +eq.target_f = f; % Set EQ frequency response target: frequency vector +eq.target_m_db = m; % Set EQ frequency response target: magnitude +eq.norm_type = 'loudness'; % Can be loudness/peak/1k to select normalize criteria +eq.norm_offs_db = 0; % E.g. -1 would leave 1 dB headroom if used with peak + +eq.enable_fir = 1; % By default both FIR and IIR disabled, enable one +eq.fir_beta = 3.5; % Use with care, low value can corrupt +eq.fir_length = 136; % Gives just < 316 bytes +eq.fir_autoband = 0; % Select manually frequency limits +eq.fmin_fir = 100; % Equalization starts from 100 Hz +eq.fmax_fir = 20e3; % Equalization ends at 20 kHz +eq.fir_minph = 1; % If no linear phase required, check result carefully if 1 +eq = eq_compute(eq); + +%% Plot +eq_plot(eq); + +end diff --git a/tools/tune/eq/example_iir_eq.m b/tools/tune/eq/example_iir_eq.m new file mode 100644 index 000000000000..0345bcf46829 --- /dev/null +++ b/tools/tune/eq/example_iir_eq.m @@ -0,0 +1,128 @@ +%% Design effect EQs and bundle them to parameter block + +%% +% Copyright (c) 2016, 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 +% + +function example_iir_eq() + +blob_fn = 'example_iir_eq.blob'; +alsa_fn = 'example_iir_eq.txt'; +tplg_fn = 'example_iir_eq.m4'; +endian = 'little'; +fs = 48e3; + +%% Design IIR loudness equalizer +eq_loud = loudness_iir_eq(fs); + +%% Define a passthru IIR EQ equalizer +[z_pass, p_pass, k_pass] = tf2zp([1 0 0],[1 0 0]); + +%% Quantize and pack filter coefficients plus shifts etc. +bq_pass = eq_iir_blob_quant(z_pass, p_pass, k_pass); +bq_loud = eq_iir_blob_quant(eq_loud.p_z, eq_loud.p_p, eq_loud.p_k); + +%% Build blob +platform_max_channels = 4; % Setup max 4 channels EQ +assign_response = [1 1 1 1]; % Switch to response #1 +num_responses = 2; % Two responses: pass, loud +bm = eq_iir_blob_merge(platform_max_channels, ... + num_responses, ... + assign_response, ... + [bq_pass bq_loud]); + +%% Pack and write file +bp = eq_iir_blob_pack(bm); +eq_blob_write(blob_fn, bp); +eq_alsactl_write(alsa_fn, bp); +eq_tplg_write(tplg_fn, bp, 'IIR'); + +end + +%% + +function eq = loudness_iir_eq(fs) + +%% Derived from Fletcher-Munson curves for 80 and 60 phon +f = [ 20,21,22,24,25,27,28,30,32,34,36,38,40,43,45,48,51,54,57,60,64, ... + 68,72,76,81,85,90,96,102,108,114,121,128,136,144,153,162,171, ... + 182,192,204,216,229,243,257,273,289,306,324,344,364,386,409, ... + 434,460,487,516,547,580,614,651,690,731,775,821,870,922,977, ... + 1036,1098,1163,1233,1307,1385,1467,1555,1648,1747,1851,1962, ... + 2079,2203,2335,2474,2622,2779,2945,3121,3308,3505,3715,3937, ... + 4172,4421,4686,4966,5263,5577,5910,6264,6638,7035,7455,7901, ... + 8373,8873,9404,9966,10561,11193,11861,12570,13322,14118,14962, ... + 15856,16803,17808,18872,20000]; + +m = [ 0.00,-0.13,-0.27,-0.39,-0.52,-0.64,-0.77,-0.89,-1.02,-1.16, ... + -1.31,-1.46,-1.61,-1.76,-1.91,-2.07,-2.24,-2.43,-2.64,-2.85, ... + -3.04,-3.21,-3.35,-3.48,-3.62,-3.78,-3.96,-4.16,-4.35,-4.54, ... + -4.72,-4.90,-5.08,-5.26,-5.45,-5.64,-5.83,-6.02,-6.19,-6.37, ... + -6.57,-6.77,-6.98,-7.19,-7.40,-7.58,-7.76,-7.92,-8.08,-8.25, ... + -8.43,-8.60,-8.76,-8.92,-9.08,-9.23,-9.38,-9.54,-9.69,-9.84, ... + -9.97,-10.09,-10.18,-10.26,-10.33,-10.38,-10.43,-10.48,-10.54, ... + -10.61,-10.70,-10.78,-10.85,-10.91,-10.95,-10.98,-11.02, ... + -11.05,-11.07,-11.10,-11.11,-11.11,-11.10,-11.10,-11.11, ... + -11.14,-11.17,-11.20,-11.21,-11.22,-11.21,-11.20,-11.20, ... + -11.21,-11.21,-11.20,-11.17,-11.11,-11.02,-10.91,-10.78, ... + -10.63,-10.46,-10.25,-10.00,-9.72,-9.39,-9.02,-8.62,-8.19, ... + -7.73,-7.25,-6.75,-6.25,-5.75,-5.28,-4.87,-4.54,-4.33,-4.30]; + +%% Get defaults for equalizer design +eq = eq_defaults(); +eq.fs = fs; +eq.target_f = f; +eq.target_m_db = m; +eq.enable_iir = 1; +eq.norm_type = 'loudness'; +eq.norm_offs_db = 0; + +%% Manually setup low-shelf and high shelf parametric equalizers +% +% Parametric EQs are PEQ_HP1, PEQ_HP2, PEQ_LP1, PEQ_LP2, PEQ_LS1, +% PEQ_LS2, PEQ_HS1, PEQ_HS2 = 8, PEQ_PN2, PEQ_LP4, and PEQ_HP4. +% +% Parametric EQs take as second argument the cutoff frequency in Hz +% and as second argument a dB value (or NaN when not applicable) . The +% Third argument is a Q-value (or NaN when not applicable). +eq.peq = [ ... + eq.PEQ_LS1 40 +2 NaN ; ... + eq.PEQ_LS1 80 +3 NaN ; ... + eq.PEQ_LS1 200 +3 NaN ; ... + eq.PEQ_LS1 400 +3 NaN ; ... + eq.PEQ_HS2 13000 +7 NaN ; ... + ]; + +%% Design EQ +eq = eq_compute(eq); + +%% Plot +eq_plot(eq); + +end diff --git a/tools/tune/eq/example_spk_eq.m b/tools/tune/eq/example_spk_eq.m new file mode 100644 index 000000000000..d829e0256e9f --- /dev/null +++ b/tools/tune/eq/example_spk_eq.m @@ -0,0 +1,155 @@ +function example_spk_eq() + +%% Design an example speaker equalizer with the provided sample data +% This equalizer by default uses a FIR and IIR components those should be +% both in the speaker pipeline. +% +% Note that IIR should be first since the included band-pass response provides +% signal headroom. + +%% +% Copyright (c) 2016, 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 +% + +%% Get defaults for equalizer design +eq = eq_defaults(); + +%% Settings for this EQ +eq.fs = 48e3; % Default sample rate in SOF +eq.enable_fir = 1; % Try enabling and disabling FIR part +eq.enable_iir = 1; % Try enabling and disabling IIR part +eq.norm_type = 'peak'; % Scale filters to have peak at 0 dB +eq.norm_offs_db = 0; % Can be used to control gain +eq.p_fmin = 100; % With this data start plots from 100 Hz +eq.p_fmax = 20e3; % and end to 20 kHz. + +%% Get acousticial frequency response measurement data. This is +% a quite typical response for a miniature speaker. Alternatively +% the response could be read from spreadsheet column format that is +% commonly supported by audio measurement equipment. Then extract +% the frequency and magnitude columns. E.g. +% +% data = xlsread('spkr.xlsx', 1, 'A5:B78'); +% eq.raw_f = data(:,1); +% eq.raw_m_db = data(:,2); + +eq.raw_f = [ ... + 298.533, 316.232, 334.971, 354.813, 375.838, 398.106, ... + 421.699, 446.685, 473.153, 501.186, 530.887, 562.342, ... + 595.663, 630.958, 668.345, 707.946, 749.895, 794.329, ... + 841.397, 891.252, 944.062, 1000, 1059.26, 1122.02, ... + 1188.5, 1258.93, 1333.52, 1412.54, 1496.24, 1584.9, ... + 1678.81, 1778.28, 1883.65, 1995.27, 2113.49, 2238.72, ... + 2371.38, 2511.89, 2660.73, 2818.39, 2985.39, 3162.28, ... + 3349.66, 3548.14, 3758.38, 3981.08, 4216.97, 4466.84, ... + 4731.52, 5011.88, 5308.85, 5623.42, 5956.63, 6309.58, ... + 6683.45, 7079.47, 7498.95, 7943.3, 8413.97, 8912.52, ... + 9440.62, 10000, 10592.6, 11220.2, 11885, 12589.3, ... + 13335.2, 14125.4, 14962.4, 15849, 16788.1, 17782.8, ... + 18836.5, 19952.7 ... +]; + +eq.raw_m_db = [ ... + 58.1704, 60.074, 60.4541, 61.3079, 62.8198, 64.3749, ... + 65.1556, 66.512, 67.5916, 68.6344, 69.9276, 70.7658, ... + 71.1125, 72.0627, 73.5348, 75.4887, 77.3088, 79.1541, ... + 80.9627, 82.0607, 81.943, 81.2228, 81.9497, 83.1848, ... + 84.3375, 85.4993, 86.4642, 87.1179, 87.4424, 87.53, ... + 85.7425, 85.0095, 82.9405, 82.9242, 82.7327, 83.6423, ... + 83.2839, 82.4201, 84.1403, 84.6485, 83.9274, 83.3366, ... + 83.3005, 84.2598, 85.1544, 86.015, 86.6519, 87.2118, ... + 87.5498, 88.1742, 88.5215, 88.3801, 89.8762, 91.4418, ... + 93.1845, 94.3355, 95.0918, 95.0258, 94.0337, 91.1068, ... + 88.7303, 87.4853, 86.2916, 83.037, 79.8056, 78.2022, ... + 76.0341, 74.5674, 69.2288, 56.1308, 68.697, 69.687, ... + 68.0005, 64.698 ... +]; + +%% With parametric IIR EQ try to place peaking EQ at +% resonant frequencies 1.4 kHz and 7.5 kHz. The gain +% and Q values were experimented manually. Additionally +% The lowest and highest frequeciens below and above speaker +% capability are attenuated with high-pass and low-pass +% filtering. +if eq.enable_iir; + eq.peq = [ ... + eq.PEQ_HP2 100 NaN NaN; ... + eq.PEQ_PN2 1480 -7 2.0; ... + eq.PEQ_PN2 7600 -11 1.3; ... + eq.PEQ_LP2 14500 NaN NaN; ... + ]; +end + +%% With FIR EQ try to flatten frequency response within +% 1 - 13 kHz frequency band. +if eq.enable_fir + eq.fir_minph = 1; + eq.fir_beta = 4; + eq.fir_length = 63; + eq.fir_autoband = 0; + eq.fmin_fir = 900; + eq.fmax_fir = 10700; +end + +%% Design EQ +eq = eq_compute(eq); + +%% Plot +eq_plot(eq, 1); + +%% Export FIR part +platform_max_channels = 2; % Identical two speakers +assign_response = [0 0]; % Switch to response #0 +num_responses = 1; % Single response +if eq.enable_fir + bq_fir = eq_fir_blob_quant(eq.b_fir); + bm_fir = eq_fir_blob_merge(platform_max_channels, ... + num_responses, ... + assign_response, ... + [ bq_fir ]); + bp_fir = eq_fir_blob_pack(bm_fir); + eq_alsactl_write('example_spk_eq_fir.txt', bp_fir); + eq_blob_write('example_spk_eq_fir.blob', bp_fir); + eq_tplg_write('example_spk_eq_fir.m4', bp_fir, 'FIR'); +end + +%% Export IIR part +if eq.enable_iir + bq_iir = eq_iir_blob_quant(eq.p_z, eq.p_p, eq.p_k); + bm_iir = eq_iir_blob_merge(platform_max_channels, ... + num_responses, ... + assign_response, ... + [ bq_iir ]); + bp_iir = eq_iir_blob_pack(bm_iir); + eq_alsactl_write('example_spk_eq_iir.txt', bp_iir); + eq_blob_write('example_spk_eq_iir.blob', bp_iir); + eq_tplg_write('example_spk_eq_iir.m4', bp_iir, 'IIR'); +end + +end diff --git a/tools/tune/eq/mls_freq_resp.m b/tools/tune/eq/mls_freq_resp.m new file mode 100644 index 000000000000..b4ad8e211586 --- /dev/null +++ b/tools/tune/eq/mls_freq_resp.m @@ -0,0 +1,412 @@ +function [f, m_db] = mls_freq_resp(id) +%% Measure frequency response with MLS test signal +% +% [f, m] = mls_freq_resp(id) +% +% Input parameters +% id - A string identifier for test case. An id 'selftest' is for special +% usage. It calculates response of filtered MLS signal and computes +% the measurement vs. known. Deviation is reported as error. It can +% be useful if the internal MLS measurement parameters are adjusted. +% +% Output parameters +% f - Frequency vector in Hz +% m - Measured magnitude responses in dB +% +% Configuration (edit these): +% mls_play_config.txt +% mls_rec_config.txt +% +% The script will return also a text CSV format file with name mls-.txt. +% + +%% +% 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 +% + +%% Settings +np = 1024; % Number of frequency points to use +f_lo = 100; % Lower frequency limit for analysis +f_hi = 20e3; % Upper frequency limit for analysis +t_tot = 10e-3; % MLS analysis window length in s +t_mls_s = 1.0; % MLS test signal length in s +a_mls_db = -10; % MLS test signal amplitude in dB +fs = 48e3; % Sample rate in Hz +bits = 16; % Audio format to use (bits) +fmt = 'S16_LE'; % Audio format to use (ALSA) +dir = '/tmp'; % Directory for temporary files +capture_level_max_db = -1; % Expected max. level +capture_level_min_db = -30; % Expacted min. level + +%% Get device identifier to use +if nargin < 1 + id = 'unknown'; +end + +if strcmp(id, 'selftest') + selftest = 1; + % Just some simulated speaker response to use as self test case + stb = [ 0.341762453, -0.915611126, 0.482465118, ... + 1.017612317, -1.722527013, 0.711608745, ... + 0.630608859, -0.813609935, 0.267690582, ]; + sta = [ 1.000000000, -3.931695128, 6.630812276, ... + -6.339248735, 3.800407709, -1.559376698, ... + 0.619626250, -0.317702349, 0.097453451, ]; +else + selftest = 0; +end +measfn = sprintf('mls-%s.wav', id); +csvfn = sprintf('mls-%s.txt', id); + +%% Paths +addpath('../../test/audio/test_utils'); + +%% MLS +n_mls = round(fs*t_mls_s); +mls = 10^(a_mls_db/20) * (2 * mlsp12(1, n_mls) - 1); +mlsfn = 'mls-ref.wav'; +audiowrite(mlsfn, mls, fs); + +%% Chip markers and parameters for find sync +[x1, m1] = sync_chirp(fs, 'up'); +[x2, m2] = sync_chirp(fs, 'down'); +fnd.fs = fs; % Sample rate +fnd.sm = 3; % Max seek from start +fnd.em = 3; % Max seek from end +fnd.idle_t = 2; % max idle in start or end +fnd.mark_t = m1.t; % Marker length +fnd.nf = 1; % One signal (amplitude) +fnd.na = 1; % One signal (frequency) +fnd.tl = t_mls_s; % Length of signal +fnd.mt = 0.1; % Threshold length to issue error +fnd.is = 0; % Ignore from start +fnd.ie = 0; % Ignore from end + +%% Merge markers and MLS +z = zeros(n_mls + m1.n + m2.n, 1); +i1 = m1.n + 1; +i2 = m1.n + n_mls; +z(1:i1 - 1) = x1; +z(i1:i2) = mls; +z(i2 + 1:end) = x2; + +%% Get config +rec_cfg = meas_remote_rec_config(fs, fmt); +play_cfg = meas_remote_play_config; + +%% Capture MLS from all playback channel at time +mixfn = 'mlsmix.wav'; +recfn = 'recch.wav'; +y = []; +for i=1:play_cfg.nch + fprintf('\n'); + fprintf('Measure playback channel %d\n', i); + if selftest + tz =zeros(2*fs+length(z), 1); % Pad 2s + tz(fs:fs+length(z)-1) = z; + t = filter(stb, sta, tz); % Filter with test response + r = t(:) * ones(1, rec_cfg.nch); % Copy to all channels + else + x = zeros(length(z), play_cfg.nch); + x(:,i) = z; + mixdfn = sprintf('%s/%s', dir, mixfn); + audiowrite(mixdfn, x, fs, 'BitsPerSample', bits); + copy_playback(mixdfn, play_cfg); + tcap = floor(3 + t_mls_s); + remote_capture(recfn, rec_cfg, tcap); + pause(1); + remote_play(mixfn, play_cfg); + pause(3); + r = get_recording(recfn, rec_cfg); + end + [d, nt] = find_test_signal(r(:,1), fnd); + for j = 1:rec_cfg.nch + y(:, rec_cfg.nch*(i-1) + j) = r(d:d + nt -1, j); + end + m = 20*log10(max(abs(r))); + fprintf('Peak levels for capture channels (dB):'); + for j = 1:rec_cfg.nch + fprintf(' %5.1f', m(j)); + end + fprintf('\n'); + if max(m) > capture_level_max_db + fprintf('Warning: The recording level is too loud.\n'); + end + if min(m) < capture_level_min_db + fprintf('Warning: The recording level is too silent.\n'); + end + +end +audiowrite(measfn, y, fs, 'BitsPerSample', bits); +fprintf('\n'); +fprintf('Done.\n'); + +[f, m_db, b] = mls_calc_resp(csvfn, mlsfn, measfn, t_tot, np, f_lo, f_hi); + +[f, m_db] = apply_mic_calibration(f, m_db, rec_cfg); + +figure +idx = find(f>1e3, 1, 'first') - 1; +m_db_align = m_db - m_db(idx); +semilogx(f, m_db_align); +ax=axis(); axis([f_lo f_hi ax(3:4)]); +grid on; +xlabel('Frequency (Hz)'); +ylabel('Magnitude (dB)'); + +if selftest + title('Measured vs. reference response'); + h = freqz(stb, sta, f, fs); + ref_db = 20*log10(abs(h)); + ref_db_align = ref_db - ref_db(idx); + hold on; + plot(f, ref_db_align, 'r--'); + hold off; + idx = find(f < f_hi); + idx = find(f(idx) > f_lo); + m_lin = 10.^(m_db_align(idx)/20); + ref_lin = 10.^(ref_db_align(idx)/20); + err_lin = m_lin - ref_lin; + e_rms = sqrt(mean(err_lin.^2)); + e_db = 20*log10(e_rms); + figure; + semilogx(f(idx), 20*log10(abs(err_lin))) + grid on; + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + title('Observed Error in self test'); + if e_db < -30 + fprintf('Passed self test. '); + else + fprintf('Failed self test. '); + end + fprintf('Response RMS error is %4.1f dB.\n', e_db); +end + +end + +function copy_playback(fn, cfg) + if cfg.ssh + cmd = sprintf('scp %s %s:%s/', fn, cfg.user, cfg.dir); + fprintf('Remote copy: %s\n', cmd); + system(cmd); + else + %cmd = sprintf('cp %s %s/', fn, cfg.dir); + %fprintf('Local copy: %s\n', cmd); + end +end + +function y = get_recording(fn, cfg) + if cfg.ssh + cmd = sprintf('scp %s:%s/%s %s', cfg.user, cfg.dir, fn, fn); + fprintf('Remote copy: %s\n', cmd); + else + cmd = sprintf('cp %s/%s %s', cfg.dir, fn, fn); + fprintf('Local copy: %s\n', cmd); + end + system(cmd); + y = audioread(fn); + delete(fn); +end + +function remote_play(fn, cfg) + if cfg.ssh + cmd = sprintf('ssh %s aplay -D%s %s/%s', cfg.user, cfg.dev, cfg.dir, fn); + fprintf('Remote play: %s\n', cmd); + else + cmd = sprintf('aplay -D%s %s/%s', cfg.dev, cfg.dir, fn); + fprintf('Local play: %s\n', cmd); + end + system(cmd); +end + +function remote_capture(fn, cfg, t) + if cfg.ssh + cmd = sprintf('ssh %s arecord -q -D%s %s -d %d %s/%s &', ... + cfg.user, cfg.dev, cfg.fmt, t, cfg.dir, fn); + fprintf('Remote capture: %s\n', cmd); + else + cmd = sprintf('arecord -q -D%s %s -d %d %s/%s &', ... + cfg.dev, cfg.fmt, t, cfg.dir, fn); + fprintf('Local capture: %s\n', cmd); + end + system(cmd); +end + +function play = meas_remote_play_config() + source mls_play_config.txt; + fprintf('\nThe setttings for remote playback are\n'); + fprintf('Use ssh : %d\n', play.ssh); + fprintf('User : %s\n', play.user); + fprintf('Directory : %s\n', play.dir); + fprintf('Device : %s\n', play.dev); + fprintf('Channels : %d\n', play.nch); +end + +function rec = meas_remote_rec_config(fs, fmt) + source mls_rec_config.txt; + rec.fmt = sprintf('-t wav -c %d -f %s -r %d', ... + rec.nch, fmt, fs); + + fprintf('\nThe setttings for remote capture are\n'); + fprintf('Use ssh : %d\n', rec.ssh); + fprintf('User : %s\n', rec.user); + fprintf('Directory : %s\n', rec.dir); + fprintf('Device : %s\n', rec.dev); + fprintf('format : %s\n', rec.fmt); + fprintf('Channels : %d\n', rec.nch); + fprintf('Calibration Data : %s\n', rec.cal); + + if length(rec.cal) > 0 + if exist(rec.cal, 'file') + [rec.cf, rec.cm, rec.sens, rec.cs] = get_calibration(rec.cal); + else + error('The calibration file does not exist'); + end + else + rec.cf = []; + rec.cm = []; + rec.sens = []; + rec.cs = ''; + end +end + +% The syntax of ASCII text calibration data is such that first line is +% text string sometimes within "" or text line about Sensitivity. Such +% lines are read and stored to description text. The sensitivty is extracted +% and printed if success but currently it is not utilized by the code. +% +% The next lines are for +% measurement data for microphone. If there are more than two numbers +% per line the other than two first columns are ignored. This code +% applies inverse of calibration data for measured response calibration. + +function [f, m, sens, desc] = get_calibration(fn) + fh = fopen(fn, 'r'); + if fh < 0 + error('Cannot open calibration data file'); + end + n = 1; + f = []; + m = []; + sens =[]; + desc = ''; + str = fgets(fh); + idx = findstr(str, '"'); + while length(idx) > 0 + line = str(idx(1)+1:idx(2)-1); + desc = sprintf('%s%s ', desc, line); + str = fgets(fh); + idx = findstr(str, '"'); + end + if length(strfind(str, 'Sens')) + desc = str; + str = fgets(fh); + end + while str ~= -1 + d=sscanf(str,'%f'); + f(n) = d(1); + m(n) = d(2); + n = n + 1; + str = fgets(fh); + end + + % Strip possible linefeed from description end + if double(desc(end)) == 10 + desc = desc(1:end-1); + end + fprintf('Calibration Info : %s\n', desc); + i1 = strfind(desc, 'Sens Factor ='); + i2 = strfind(desc, 'dB'); + if length(i1) == 1 && length(i2) == 1 + sens = sscanf(desc(i1+13:i2-1), '%f'); + fprintf('Calibration Sens : %6.2f dB\n', sens); + end + + fprintf('Calibration range: %.2f .. %.2f Hz\n', min(f), max(f)); + fprintf('Calibration range: %.2f .. %.2f dB\n', min(m), max(m)); + + figure; + semilogx(f, m); + grid on; + title(desc); + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); +end + +function [x, seed] = mlsp12(seed, n) + +% Based on book Numerical Recipes in C, chapter 7.4 Generation of +% random bits method II p. 298-299 example and 12 bit primitive +% polynomial (12, 6, 4, 1, 0) + + x = zeros(1,n); + ib1 = 2^(1-1); + ib4 = 2^(4-1); + ib6 = 2^(6-1); + ib12 = 2^(12-1); + mask = ib1 + ib4 + ib6 + ib12; + + for i = 1:n + if bitand(seed, ib12) + seed = bitor(bitxor(seed, mask) * 2 , ib1); + x(i) = 1; + else + seed = seed * 2; + x(i) = 0; + end + end +end + +%% Calibration apply function +% Resample microphone calibration data into used grid and +% then subtract calibration response from measured +% response. + +function [cal_f, cal_m_db] = apply_mic_calibration(f, m_db, rec) + + if length(rec.cm) > 0 + if ~isvector(rec.cm) + error('Calibration can be for one channel only'); + end + mic_m_db = interp1(rec.cf, rec.cm, f, 'linear'); + nans = isnan(mic_m_db); + idx = find(nans == 0); + cal_f = f(idx); + cal_db = mic_m_db(idx); + s = size(m_db); + for i = 1:s(2) + cal_m_db(:,i) = m_db(idx,i) - cal_db(:); + end + else + cal_m_db = m_db; + cal_f = f; + end + +end diff --git a/tools/tune/eq/mls_play_config.txt b/tools/tune/eq/mls_play_config.txt new file mode 100644 index 000000000000..5f7a8d0e3ae3 --- /dev/null +++ b/tools/tune/eq/mls_play_config.txt @@ -0,0 +1,5 @@ +play.ssh = 0; % Set to use remote ssh commands +play.user = ''; % Set user@domain for ssh +play.dir = '/tmp'; % directory for temporary files +play.dev = 'hw:0,0'; % Audio device for playback +play.nch = 2; % Number of playback channels to test diff --git a/tools/tune/eq/mls_rec_config.txt b/tools/tune/eq/mls_rec_config.txt new file mode 100644 index 000000000000..95c77ab6061c --- /dev/null +++ b/tools/tune/eq/mls_rec_config.txt @@ -0,0 +1,16 @@ +%% Recording device configuration + +rec.ssh = 0; % Set to 1 for remote capture +rec.user = ''; % Set to user@domain for ssh +rec.dir = '/tmp'; % Directory for temporary files +rec.dev = 'hw:0,0'; % Audio capture device +rec.nch = 2; % Number audio capture channels to use + +% Use '' if calibration is not needed. Otherwise set to +% e.g. '1234567.txt'. Such calibration data format is supported for +% some reasonably priced measurement microphones. The ASCII text +% calibration data file is the measured frequency response of the used +% microphone. Lines in the beginning those start with character " are +% treated as comment. The successive lines should be +% number pairs. Their unit must be Hz and dB. +rec.cal = ''; diff --git a/tools/tune/src/README b/tools/tune/src/README new file mode 100644 index 000000000000..e135f9a21979 --- /dev/null +++ b/tools/tune/src/README @@ -0,0 +1,36 @@ +Sample rate converter (SRC) Setup Tools +======================================= + +This is a tool to set up SRC conversions sample rates list, define +quality related parameters, and test the C implementation for a number +of objective audio quality parameters. + +The tools need GNU Octave version 4.0.0 or later with octave-signal +package. + +src_std_int32.m +--------------- + +This script creates the default coefficient set and contains nothing +else but call for src_generate. + +src_tiny_int16.m +---------------- + +This script creates the tiny coefficient set. The script contains an +example how to customize the input/output rates matrix and in a simple +way the scale conversions quality. More controlled quality adjust can +be done by editing file src_param.m directly. Note that int16 +presentation for SRC coefficients will degrade even the default +quality. + +src_generate.m +-------------- + +Creates the header files to include to C into directory "include". A +report of create modes is written to directory "reports". The +coefficients need to be copied to directory +sof.git/src/include/sof/audio/coefficients/src. + +The default quality of SRC is defined in module src_param.m. The +quality impacts the complexity and coefficents tables size of SRC. diff --git a/tools/tune/src/src_export_coef.m b/tools/tune/src/src_export_coef.m new file mode 100644 index 000000000000..f6fdbb40ba23 --- /dev/null +++ b/tools/tune/src/src_export_coef.m @@ -0,0 +1,212 @@ +function success=src_export_coef(src, ctype, vtype, hdir, profile) + +% src_export_coef - Export FIR coefficients +% +% success=src_export_coef(src, ctype, hdir, profile) +% +% src - src definition struct +% ctype - 'float','int32', or 'int24' +% vtype - 'float','int32_t' +% hdir - directory for header files +% profile - string to append to filename +% + +% Copyright (c) 2016, 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 +% + +if nargin < 5 + profile = ''; +end + +if src.L == src.M + success = 0; +else + pbi = round(src.c_pb*1e4); + sbi = round(src.c_sb*1e4); + if isempty(profile) + hfn = sprintf('%s/src_%s_%d_%d_%d_%d.h', ... + hdir, ctype, src.L, src.M, pbi, sbi); + else + hfn = sprintf('%s/src_%s_%s_%d_%d_%d_%d.h', ... + hdir, profile, ctype, src.L, src.M, pbi, sbi); + end + vfn = sprintf('src_%s_%d_%d_%d_%d_fir', ctype, src.L, src.M, pbi, sbi); + sfn = sprintf('src_%s_%d_%d_%d_%d', ctype, src.L, src.M, pbi, sbi); + + fprintf('Exporting %s ...\n', hfn); + fh = fopen(hfn, 'w'); + + switch ctype + case 'float' + fprintf(fh, 'const %s %s[%d] = {\n', ... + vtype, vfn, src.filter_length); + fprintf(fh,'\t%16.9e', src.coefs(1)); + for n=2:src.filter_length + fprintf(fh, ',\n'); + fprintf(fh,'\t%16.9e', src.coefs(n)); + end + fprintf(fh,'\n\n};'); + case 'int32' + print_int_coef(src, fh, vtype, vfn, 32); + case 'int24' + print_int_coef(src, fh, vtype, vfn, 24); + case 'int16' + print_int_coef(src, fh, vtype, vfn, 16); + otherwise + error('Unknown type %s !!!', ctype); + end + + fprintf(fh, '\n'); + switch ctype + case 'float' + fprintf(fh, 'struct src_stage %s = {\n', sfn); + fprintf(fh, '\t%d, %d, %d, %d, %d, %d, %d, %d, %f,\n\t%s};\n', ... + src.idm, src.odm, src.num_of_subfilters, ... + src.subfilter_length, src.filter_length, ... + src.blk_in, src.blk_out, src.halfband, ... + src.gain, vfn); + case { 'int16' 'int24' 'int32' } + fprintf(fh, 'struct src_stage %s = {\n', sfn); + fprintf(fh, '\t%d, %d, %d, %d, %d, %d, %d, %d, %d,\n\t%s};\n', ... + src.idm, src.odm, src.num_of_subfilters, ... + src.subfilter_length, src.filter_length, ... + src.blk_in, src.blk_out, src.halfband, ... + src.shift, vfn); + otherwise + error('Unknown type %s !!!', ctype); + end + %fprintf(fh, '\n'); + fclose(fh); + success = 1; +end + +end + +function print_int_coef(src, fh, vtype, vfn, nbits) + fprintf(fh, 'const %s %s[%d] = {\n', ... + vtype, vfn, src.filter_length); + + cint = coef_quant(src, nbits); + fprintf(fh,'\t%d', cint(1)); + for n=2:src.filter_length + fprintf(fh, ',\n'); + fprintf(fh,'\t%d', cint(n)); + end + fprintf(fh,'\n\n};'); +end + +function cint = coef_quant(src, nbits) + + sref = 2^(nbits-1); + pmax = sref-1; + nmin = -sref; + + if nbits > 16 + %% Round() is OK + cint0 = round(sref*src.coefs); + else + %% Prepare to optimize coefficient quantization + fs = max(src.fs1, src.fs2); + f = linspace(0, fs/2, 1000); + + %% Test sensitivity for stopband and find the most sensitive + % coefficients + sbf = linspace(src.f_sb,fs/2, 500); + n = src.filter_length; + psens = zeros(1,n); + bq0 = round(sref*src.coefs); + h = freqz(bq0/sref/src.L, 1, sbf, fs); + sb1 = 20*log10(sqrt(sum(h.*conj(h)))); + for i=1:n + bq = src.coefs; + bq(i) = round(sref*bq(i))/sref; + %tbq = bq; %tbq(i) = bq(i)+1; + h = freqz(bq, 1, sbf, fs); + psens(i) = sum(h.*conj(h)); + end + [spsens, pidx] = sort(psens, 'descend'); + + %% Test quantization in the found order + % The impact to passband is minimal so it's not tested + bi = round(sref*src.coefs); + bi0 = bi; + dl = -1:1; + nd = length(dl); + msb = zeros(1,nd); + for i=pidx + bit = bi; + for j=1:nd + bit(i) = bi(i) + dl(j); + h = freqz(bit, 1, sbf, fs); + msb(j) = sum(h.*conj(h)); + end + idx = find(msb == min(msb), 1, 'first'); + bi(i) = bi(i) + dl(idx); + end + h = freqz(bi/sref/src.L, 1, sbf, fs); + sb2 = 20*log10(sqrt(sum(h.*conj(h)))); + + %% Plot to compare + if 0 + f = linspace(0, fs/2, 1000); + h1 = freqz(src.coefs/src.L, 1, f, fs); + h2 = freqz(bq0/sref/src.L, 1, f, fs); + h3 = freqz(bi/sref/src.L, 1, f, fs); + figure; + plot(f, 20*log10(abs(h1)), f, 20*log10(abs(h2)), f, 20*log10(abs(h3))); + grid on; + fprintf('Original = %4.1f dB, optimized = %4.1f dB, delta = %4.1f dB\n', ... + sb1, sb2, sb1-sb2); + end + cint0 = bi; + end + + + %% Re-order coefficients for filter implementation + cint = zeros(src.filter_length,1); + for n = 1:src.num_of_subfilters + i11 = (n-1)*src.subfilter_length+1; + i12 = i11+src.subfilter_length-1; + cint(i11:i12) = cint0(n:src.num_of_subfilters:end); + end + + %% Done check for no overflow + max_fix = max(cint); + min_fix = min(cint); + if (max_fix > pmax) + printf('Fixed point coefficient %d exceeded %d\n.', max_fix, pmax); + error('Something went wrong!'); + end + if (min_fix < nmin) + printf('Fixed point coefficient %d exceeded %d\n.', min_fix, nmax); + error('Something went wrong!'); + end + + +end diff --git a/tools/tune/src/src_export_defines.m b/tools/tune/src/src_export_defines.m new file mode 100644 index 000000000000..63fb4c28f7d5 --- /dev/null +++ b/tools/tune/src/src_export_defines.m @@ -0,0 +1,66 @@ +function src_export_defines(defs, ctype, hdir, profile) + +% src_export_defines - Exports the constants to header files +% +% src_export_defines(defs, ctype, hdir) +% +% defs - defs struct +% ctype - e.g. 'int24' appended to file name +% hdir - directory for header file +% profile - string to append to file name +% + + +% Copyright (c) 2016, 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 +% + +if nargin < 4 + profile = ''; +end + +if isempty(profile) + hfn = sprintf('src_%s_define.h', ctype); +else + hfn = sprintf('src_%s_%s_define.h', profile, ctype); +end +fh = fopen(fullfile(hdir,hfn), 'w'); +fprintf(fh, '/* SRC constants */\n'); +fprintf(fh, '#define MAX_FIR_DELAY_SIZE %d\n', defs.fir_delay_size); +fprintf(fh, '#define MAX_OUT_DELAY_SIZE %d\n', defs.out_delay_size); +fprintf(fh, '#define MAX_BLK_IN %d\n', defs.blk_in); +fprintf(fh, '#define MAX_BLK_OUT %d\n', defs.blk_out); +fprintf(fh, '#define NUM_IN_FS %d\n', defs.num_in_fs); +fprintf(fh, '#define NUM_OUT_FS %d\n', defs.num_out_fs); +fprintf(fh, '#define STAGE1_TIMES_MAX %d\n', defs.stage1_times_max); +fprintf(fh, '#define STAGE2_TIMES_MAX %d\n', defs.stage2_times_max); +fprintf(fh, '#define STAGE_BUF_SIZE %d\n', defs.stage_buf_size); +fprintf(fh, '#define NUM_ALL_COEFFICIENTS %d\n', defs.sum_filter_lengths); +fclose(fh); + +end diff --git a/tools/tune/src/src_export_table_2s.m b/tools/tune/src/src_export_table_2s.m new file mode 100644 index 000000000000..7772b9369205 --- /dev/null +++ b/tools/tune/src/src_export_table_2s.m @@ -0,0 +1,190 @@ +function sfl = src_export_table_2s(fs_in, fs_out, l_2s, m_2s, ... + pb_2s, sb_2s, taps_2s, ctype, vtype, ppath, hdir, profile) + +% src_export_table_2s - Export src setup table +% +% src_export_table_2s(fs_in, fs_out, l, m, pb, sb, ctype, vtype, hdir, profile) +% +% The parameters are used to differentiate files for possibly many same +% conversion factor filters with possibly different characteristic. +% +% fs_in - input sample rates +% fs_out - output sample rates +% l - interpolation factors +% m - decimation factors +% pb - passband widths +% sb - stopband start frequencies +% ctype - coefficient quantization +% vtype - C variable type +% ppath - print directory prefix to header file name include +% hdir - directory for header files +% profile - string to append to file name +% + +% Copyright (c) 2016, 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 +% + +if nargin < 12 + profile = ''; +end + +if isempty(profile) + hfn = sprintf('src_%s_table.h', ctype); +else + hfn = sprintf('src_%s_%s_table.h', profile, ctype); +end +fh = fopen(fullfile(hdir,hfn), 'w'); + +fprintf(fh, '/* SRC conversions */\n'); +sfl = 0; +n_in = length(fs_in); +n_out = length(fs_out); +i=1; +all_modes = zeros(2*n_in*n_out, 7); +for n=1:2 + for b=1:n_out + for a=1:n_in + all_modes(i,:) = [ l_2s(n,a,b) m_2s(n,a,b) ... + pb_2s(n,a,b) sb_2s(n,a,b) n a b ]; + i=i+1; + end + end +end + +all_modes_sub = all_modes(:,1:4); +[unique_modes, ia] = unique(all_modes_sub,'rows'); +sm = size(unique_modes); + +if isempty(profile) + prof_ctype = ctype; +else + prof_ctype = sprintf('%s_%s', profile, ctype); +end +for i=1:sm(1) + um_tmp = unique_modes(i,:); + if isequal(um_tmp(1:2),[1 1]) || isequal(um_tmp(1:2),[0 0]) + else + fprintf(fh, '#include <%ssrc_%s_%d_%d_%d_%d.h>\n', ... + ppath, prof_ctype, um_tmp(1:4)); + + n = all_modes(ia(i), 5); + a = all_modes(ia(i), 6); + b = all_modes(ia(i), 7); + sfl = sfl +taps_2s(n, a, b); % Count sum of filter lengths + end +end +fprintf(fh,'\n'); + +fprintf(fh, '/* SRC table */\n'); +switch ctype + case 'float' + fprintf(fh, '%s fir_one = 1.0;\n', vtype); + fprintf(fh, 'struct src_stage src_double_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, 1.0, &fir_one };\n'); + fprintf(fh, 'struct src_stage src_double_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0.0, &fir_one };\n'); + case 'int16' + scale16 = 2^15; + fprintf(fh, '%s fir_one = %d;\n', vtype, round(scale16*0.5)); + fprintf(fh, 'struct src_stage src_int16_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, -1, &fir_one };\n'); + fprintf(fh, 'struct src_stage src_int16_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, &fir_one };\n'); + case 'int24' + scale24 = 2^23; + fprintf(fh, '%s fir_one = %d;\n', vtype, round(scale24*0.5)); + fprintf(fh, 'struct src_stage src_int24_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, -1, &fir_one };\n'); + fprintf(fh, 'struct src_stage src_int24_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, &fir_one };\n'); + case 'int32' + scale32 = 2^31; + fprintf(fh, '%s fir_one = %d;\n', vtype, round(scale32*0.5)); + fprintf(fh, 'struct src_stage src_int32_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, -1, &fir_one };\n'); + fprintf(fh, 'struct src_stage src_int32_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, &fir_one };\n'); + otherwise + error('Unknown coefficient type!'); +end + +fprintf(fh, 'int src_in_fs[%d] = {', n_in); +j = 1; +for i=1:n_in + fprintf(fh, ' %d', fs_in(i)); + if i < n_in + fprintf(fh, ','); + end + j = j + 1; + if (j > 8) + fprintf(fh, '\n\t'); + j = 1; + end +end +fprintf(fh, '};\n'); + +fprintf(fh, 'int src_out_fs[%d] = {', n_out); +j = 1; +for i=1:n_out + fprintf(fh, ' %d', fs_out(i)); + if i < n_out + fprintf(fh, ','); + end + j = j + 1; + if (j > 8) + fprintf(fh, '\n\t'); + j = 1; + end +end +fprintf(fh, '};\n'); + +for n = 1:2 + fprintf(fh, 'struct src_stage *src_table%d[%d][%d] = {\n', ... + n, n_out, n_in); + i = 1; + for b = 1:n_out + fprintf(fh, '\t{'); + for a = 1:n_in + fprintf(fh, ' &src_%s_%d_%d_%d_%d', ... + ctype, l_2s(n,a,b), m_2s(n,a,b), ... + pb_2s(n,a,b), sb_2s(n,a,b)); + if a < n_in + fprintf(fh, ','); + end + i = i + 1; + if i > 2 + fprintf(fh, '\n\t'); + i = 1; + end + end + fprintf(fh, '}'); + if b < n_out + fprintf(fh, ',\n'); + else + fprintf(fh, '\n'); + end + end + fprintf(fh, '};\n'); +end + +fclose(fh); + +end diff --git a/tools/tune/src/src_factor1_lm.m b/tools/tune/src/src_factor1_lm.m new file mode 100644 index 000000000000..54e9173e3f84 --- /dev/null +++ b/tools/tune/src/src_factor1_lm.m @@ -0,0 +1,44 @@ +function [l, m] = src_factor1_lm(fs1, fs2) + +% factor1_lm - factorize input and output sample rates ratio to fraction l/m +% +% [l, m] = factor1_lm(fs1, fs2) +% +% fs1 - input sample rate +% fs2 - output sample rate +% + +% Copyright (c) 2016, 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 +% + +k = gcd(fs1, fs2); +l = fs2/k; +m = fs1/k; + +end diff --git a/tools/tune/src/src_factor2_lm.m b/tools/tune/src/src_factor2_lm.m new file mode 100644 index 000000000000..6ac86020d438 --- /dev/null +++ b/tools/tune/src/src_factor2_lm.m @@ -0,0 +1,155 @@ +function [l1, m1, l2, m2] = src_factor2_lm(fs1, fs2) + +% factor2_lm - factorize input and output sample rates ratio to fraction l1/m2*l2/m2 +% +% [l1, m1, l2, m2] = factor2_lm(fs1, fs2) +% +% fs1 - input sample rate +% fs2 - output sample rate +% + +% Copyright (c) 2016, 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 +% + + +%% The same sample rate? +if abs(fs1-fs2) < eps + l1 = 1; m1 = 1; l2 = 1; m2 = 1; + return +end + +%% Find fraction, and factorize +k = gcd(fs1, fs2); +l = fs2/k; +m = fs1/k; +[l01, l02] = factor2(l); +[m01, m02] = factor2(m); + +%% Hand fixing for some ratios, guide to reuse some common filters +if (l==147) && (m==640) + l01 = 7; m01 = 8; l02 = l/l01; m02 = m/m01; % 192 to 44.1 +end +if (l==147) && (m==320) + l01 = 7; m01 = 8; l02 = l/l01; m02 = m/m01; % 96 to 44.1 +end +if (l==147) && (m==160) + l01 = 7; m01 = 8; l02 = l/l01; m02 = m/m01; % 48 to 44.1 +end +if (l==160) && (m==147) + l01 = 8; m01 = 7; l02 = l/l01; m02 = m/m01; % 44.1 to 48 +end +if (l==320) && (m==147) + l01 = 8; m01 = 7; l02 = l/l01; m02 = m/m01; % 44.1 to 96 +end +if (l==4) && (m==3) + l01 = 4; m01 = 3; l02 = l/l01; m02 = m/m01; % 24 to 32, no 2 stage +end +if (l==3) && (m==4) + l01 = 3; m01 = 4; l02 = l/l01; m02 = m/m01; % 24 to 32, no 2 stage +end + + +r11 = l01/m01; +r22 = l02/m02; +r12 = l01/m02; +r21 = l02/m01; +fs3 = [r11 r12 r21 r22].*fs1; + + +if fs1 > fs2 % Decrease sample rate, dont go below output rate + idx = find(fs3 >= fs2); + if length(idx) < 1 + error('Cant factorise interpolations'); + end + fs3_possible = fs3(idx); + delta = fs3_possible-fs2; % Fs3 that is nearest to fs2 + idx = find(delta == min(delta), 1, 'first'); + fs3_min = fs3_possible(idx); + idx = find(fs3 == fs3_min, 1, 'first'); + switch idx + case 1, l1 = l01; m1 = m01; l2 = l02; m2 = m02; + case 2, l1 = l01; m1 = m02; l2 = l02; m2 = m01; + case 3, l1 = l02; m1 = m01; l2 = l01; m2 = m02; + case 4, l1 = l02; m1 = m02; l2 = l01; m2 = m01; + end +else % Increase sample rate, don't go below input rate + idx = find(fs3 >= fs1); + if length(idx) < 1 + error('Cant factorise interpolations'); + end + fs3_possible = fs3(idx); + delta = fs3_possible-fs1; % Fs2 that is nearest to fs1 + idx = find(delta == min(delta), 1, 'first'); + fs3_min = fs3_possible(idx); + idx = find(fs3 == fs3_min, 1, 'first'); + switch idx + case 1, l1 = l01; m1 = m01; l2 = l02; m2 = m02; + case 2, l1 = l01; m1 = m02; l2 = l02; m2 = m01; + case 3, l1 = l02; m1 = m01; l2 = l01; m2 = m02; + case 4, l1 = l02; m1 = m02; l2 = l01; m2 = m01; + end +end + +%% If 1st stage is 1:1 +if (l1 == 1) && (m1 == 1) + l1 = l2; + m1 = m2; + l2 = 1; + m2 = 1; +end + +f1=l/m; +f2=l1/m1*l2/m2; +if abs(f1 - f2) > 1e-6 + error('Bug in factorization code!'); +end + +end + + +function [a, b]=factor2(c) +x = round(sqrt(c)); +t1 = x:2*x; +d1 = c./t1; +idx1 = find(d1 == floor(d1), 1, 'first'); +a1 = t1(idx1); +t2 = x:-1:floor(x/2); +d2 = c./t2; +idx2 = find(d2 == floor(d2), 1, 'first'); +a2 = t2(idx2); +if (a1-x) < (x-a2) + a = a1; +else + a = a2; +end +b = c/a; +end + + + diff --git a/tools/tune/src/src_find_l0m0.m b/tools/tune/src/src_find_l0m0.m new file mode 100644 index 000000000000..2a360a363a90 --- /dev/null +++ b/tools/tune/src/src_find_l0m0.m @@ -0,0 +1,71 @@ +function [l0, m0] = src_find_l0m0(L, M) + +% find_l0m0 - find l0, m0 to meet -l0*L + m0*M == 1 +% +% [l0, m0] = find_l0m0(L, M) +% +% L - interpolatation factor +% M - decimation factor +% + +% Copyright (c) 2016, 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 +% + +if M == 1 + l0 = 0; + m0 = 1; + return +end + +if L == 1 + l0 = 1; + m0 = 0; + return +end + +l0 = []; +m0 = []; +for lt=1:4*L + mt = (1+lt*L)/M; % Check if -lt*L + mt*M == 1 + if floor(mt) == mt + l0 = [l0 lt]; + m0 = [m0 mt]; + end +end + +s = l0+m0; +idx = find(s == min(s), 1, 'first'); +l0 = l0(idx); +m0 = m0(idx); + +if -l0*L + m0*M ~= 1 + error('Something went wrong!'); +end + +end diff --git a/tools/tune/src/src_generate.m b/tools/tune/src/src_generate.m new file mode 100644 index 000000000000..b01b29ddb062 --- /dev/null +++ b/tools/tune/src/src_generate.m @@ -0,0 +1,311 @@ +function src_generate(fs_in, fs_out, ctype, fs_inout, profile, qc) + +% src_generate - export src conversions for given fs_in and fs_out +% +% src_generate(fs_in, fs_out <, ctype, fs_inout>>) +% +% fs_in - vector of input sample rates (M) +% fs_out - vector of output sample rates (N) +% ctype - coefficient type, use 'int16','int24', 'int32', or 'float' +% fs_inout - matrix of supported conversions (MxN), +% 0 = no support, 1 = supported +% % +% if ctype is omitted then ctype defaults to 'int16'. +% +% If fs_inout matrix is omitted this script will compute coefficients +% for all fs_in <-> fs_out combinations. +% +% Copyright (c) 2016, 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 +% + +if (nargin == 1) || (nargin > 6) + error('Incorrect arguments for function!'); +end +if nargin == 0 + %% Default input and output rates + fs_in = [8e3 11025 12e3 16e3 18900 22050 24e3 32e3 44100 48e3 ... + 64e3 88.2e3 96e3 176400 192e3]; + + fs_out = [8e3 11025 12e3 16e3 18900 22050 24e3 32e3 44100 48e3]; + + fs_inout = [ 0 0 0 1 0 0 1 1 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 1 0 0 0 0 0 1 1 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 1 0 0 1 0 0 0 1 0 1 ; ... + 1 0 0 1 0 0 1 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 1 1 1 1 0 1 1 1 1 0 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ; ... + 0 0 0 0 0 0 0 0 0 1 ]; + + ctype = 'int32'; + profile = 'std'; + qc = 1.0; +else + if nargin < 3 + ctype = 'int16'; + end + if nargin < 4 + fs_inout = ones(length(fs_in), length(fs_out)); + end + if nargin < 5 + profile = ''; + end + if nargin < 6 + qc = 1.0; + end +end + +sio = size(fs_inout); +if (length(fs_in) ~= sio(1)) || (length(fs_out) ~= sio(2)) + error('Sample rates in/out matrix size mismatch!'); +end + +%% Exported coefficients type int16, int24, int32, float + +switch ctype + case 'int16' + coef_label = 'int16'; + coef_ctype = 'int16_t'; + coef_bits = 16; + coef_bytes = 2; + case 'int24' + coef_label = 'int24'; + coef_ctype = 'int32_t'; + coef_bits = 24; + coef_bytes = 4; + case 'int32' + coef_label = 'int32'; + coef_ctype = 'int32_t'; + coef_bits = 32; + coef_bytes = 4; + case 'float' + coef_label = 'float'; coef_ctype = 'float'; + coef_bits = 24; + coef_bytes = 4; + otherwise + error('Request for incorrect coefficient type'); +end +data_bytes = 4; + +hdir = mkdir_check('include'); +rdir = mkdir_check('reports'); + +%% Find fractional conversion factors +nfsi = length(fs_in); +nfso = length(fs_out); +l_2s = zeros(2, nfsi, nfso); +m_2s = zeros(2, nfsi, nfso); +mops_2s = zeros(2, nfsi, nfso); +pb_2s = zeros(2,nfsi, nfso); +sb_2s = zeros(2,nfsi, nfso); +taps_2s = zeros(2,nfsi, nfso); +defs.fir_delay_size = 0; +defs.out_delay_size = 0; +defs.blk_in = 0; +defs.blk_out = 0; +defs.num_in_fs = nfsi; +defs.num_out_fs = nfso; +defs.stage1_times_max = 0; +defs.stage2_times_max = 0; +defs.stage_buf_size = 0; +h = 1; +for b = 1:nfso + for a = 1:nfsi + fs1 = fs_in(a); + fs2 = fs_out(b); + [l1, m1, l2, m2] = src_factor2_lm(fs1, fs2); + fs3 = fs1*l1/m1; + cnv1 = src_param(fs1, fs3, coef_bits, qc); + cnv2 = src_param(fs3, fs2, coef_bits, qc); + if (fs2 < fs1) + % When decimating 1st stage passband can be limited + % for wider transition band + f_pb = fs2*cnv2.c_pb; + cnv1.c_pb = f_pb/min(fs1,fs3); + end + if (fs2 > fs1) + % When interpolating 2nd stage passband can be limited + % for wider transition band + f_pb = fs1*cnv1.c_pb; + cnv2.c_pb = f_pb/min(fs2,fs3); + end + if fs_inout(a,b) > 0 || (a == b) + if cnv2.fs1-cnv2.fs2 > eps + % Allow half ripple for dual stage SRC parts + cnv1.rp = cnv1.rp/2; + cnv2.rp = cnv2.rp/2; + end + src1 = src_get(cnv1); + src2 = src_get(cnv2); + k = gcd(src1.blk_out, src2.blk_in); + stage1_times = src2.blk_in/k; + stage2_times = stage1_times*src1.blk_out/src2.blk_in; + defs.stage1_times_max = max(defs.stage1_times_max, stage1_times); + defs.stage2_times_max = max(defs.stage2_times_max, stage2_times); + l_2s(:,a,b) = [src1.L src2.L]; + m_2s(:,a,b) = [src1.M src2.M]; + mops_2s(:,a,b) = [src1.MOPS src2.MOPS]; + pb_2s(:,a,b) = [round(1e4*src1.c_pb) round(1e4*src2.c_pb)]; + sb_2s(:,a,b) = [round(1e4*src1.c_sb) round(1e4*src2.c_sb)]; + taps_2s(:,a,b) = [src1.filter_length src2.filter_length]; + defs.fir_delay_size = max(defs.fir_delay_size, src1.fir_delay_size); + defs.out_delay_size = max(defs.out_delay_size, src1.out_delay_size); + defs.blk_in = max(defs.blk_in, src1.blk_in); + defs.blk_out = max(defs.blk_out, src1.blk_out); + defs.fir_delay_size = max(defs.fir_delay_size, src2.fir_delay_size); + defs.out_delay_size = max(defs.out_delay_size, src2.out_delay_size); + defs.blk_in = max(defs.blk_in, src2.blk_in); + defs.blk_out = max(defs.blk_out, src2.blk_out); + defs.stage_buf_size = max(defs.stage_buf_size, src1.blk_out*stage1_times); + src_export_coef(src1, coef_label, coef_ctype, hdir, profile); + src_export_coef(src2, coef_label, coef_ctype, hdir, profile); + end + end +end + +%% Export modes table +defs.sum_filter_lengths = src_export_table_2s(fs_in, fs_out, l_2s, m_2s, ... + pb_2s, sb_2s, taps_2s, coef_label, coef_ctype, ... + 'sof/audio/coefficients/src/', hdir, profile); +src_export_defines(defs, coef_label, hdir, profile); + +%% Print 2 stage conversion factors +fn = sprintf('%s/src_2stage.txt', rdir); +fh = fopen(fn,'w'); +fprintf(fh,'\n'); +fprintf(fh,'Dual stage fractional SRC: Ratios\n'); +fprintf(fh,'%8s, ', 'in \ out'); +for b = 1:nfso + fprintf(fh,'%12.1f, ', fs_out(b)/1e3); +end +fprintf(fh,'\n'); +for a = 1:nfsi + fprintf(fh,'%8.1f, ', fs_in(a)/1e3); + for b = 1:nfso + cstr = print_ratios(l_2s, m_2s, a, b); + fprintf(fh,'%12s, ', cstr); + end + fprintf(fh,'\n'); +end +fprintf(fh,'\n'); + +%% Print 2 stage MOPS +fprintf(fh,'Dual stage fractional SRC: MOPS\n'); +fprintf(fh,'%8s, ', 'in \ out'); +for b = 1:nfso + fprintf(fh,'%8.1f, ', fs_out(b)/1e3); +end +fprintf(fh,'\n'); +for a = 1:nfsi + fprintf(fh,'%8.1f, ', fs_in(a)/1e3); + for b = 1:nfso + mops = sum(mops_2s(:,a,b)); + if sum(l_2s(:,a,b)) < eps + mops_str = 'x'; + else + mops_str = sprintf('%.2f', mops); + end + fprintf(fh,'%8s, ', mops_str); + end + fprintf(fh,'\n'); +end +fprintf(fh,'\n'); + +%% Print 2 stage MOPS per stage +fprintf(fh,'Dual stage fractional SRC: MOPS per stage\n'); +fprintf(fh,'%10s, ', 'in \ out'); +for b = 1:nfso + fprintf(fh,'%10.1f, ', fs_out(b)/1e3); +end +fprintf(fh,'\n'); +for a = 1:nfsi + fprintf(fh,'%10.1f, ', fs_in(a)/1e3); + for b = 1:nfso + mops = mops_2s(:,a,b); + if sum(l_2s(:,a,b)) < eps + mops_str = 'x'; + else + mops_str = sprintf('%.2f+%.2f', mops(1), mops(2)); + end + fprintf(fh,'%10s, ', mops_str); + end + fprintf(fh,'\n'); +end +fprintf(fh,'\n'); + +fprintf(fh,'Coefficient RAM %.1f kB\n', ... + defs.sum_filter_lengths*coef_bytes/1024); +fprintf(fh,'Max. data RAM %.1f kB\n', ... + (defs.fir_delay_size + defs.out_delay_size+defs.stage_buf_size) ... + * data_bytes/1024); + +fprintf(fh,'\n'); +fclose(fh); +type(fn); + +end + +function d = mkdir_check(d) +if exist(d) ~= 7 + mkdir(d); +end +end + +function cstr = print_ratios(l_2s, m_2s, a, b) +l1 = l_2s(1,a,b); +m1 = m_2s(1,a,b); +l2 = l_2s(2,a,b); +m2 = m_2s(2,a,b); +if l1+m2+l2+m2 == 0 + cstr = 'x'; +else + if m2 == 1 + if l2 == 1 + cstr2 = ''; + else + cstr2 = sprintf('*%d', l2); + end + else + cstr2 = sprintf('*%d/%d', l2, m2); + end + if m1 == 1 + cstr1 = sprintf('%d', l1); + else + cstr1 = sprintf('%d/%d', l1, m1); + end + cstr = sprintf('%s%s', cstr1, cstr2); +end +end diff --git a/tools/tune/src/src_get.m b/tools/tune/src/src_get.m new file mode 100644 index 000000000000..4520af99a850 --- /dev/null +++ b/tools/tune/src/src_get.m @@ -0,0 +1,254 @@ +function src = src_get(cnv) + +% src_get - calculate coefficients for a src +% +% src = src_get(cnv); +% +% cnv - src parameters +% src - src result +% + +% Copyright (c) 2016, 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 +% + +use_firpm = 0; +use_remez = 0; +use_kaiser = 0; +switch lower(cnv.design) + case 'firpm' + if exist('OCTAVE_VERSION', 'builtin') + use_remez = 1; + else + use_firpm = 1; + end + case 'kaiser' + use_kaiser = 1; + otherwise + error('Unknown FIR design request!'); +end + +if abs(cnv.fs1-cnv.fs2) < 1 + %% Return minimum needed for scripts to work + src.L=1; + src.M=1; + src.odm=1; + src.idm=1; + src.MOPS=0; + src.c_pb = 0; + src.c_sb = 0; + src.fir_delay_size = 0; + src.out_delay_size = 0; + src.blk_in = 1; + src.blk_out = 1; + src.gain = 1; + src.filter_length = 0; + return +end + +%% fractional SRC parameters +[L, M] = src_factor1_lm(cnv.fs1, cnv.fs2); +src.L = L; +src.M = M; +src.num_of_subfilters = L; +[src.idm src.odm] = src_find_l0m0(src.L, src.M); +min_fs = min(cnv.fs1,cnv.fs2); +src.f_pb = min_fs*cnv.c_pb; +src.f_sb = min_fs*cnv.c_sb; +src.c_pb = cnv.c_pb; +src.c_sb = cnv.c_sb; +src.fs1 = cnv.fs1; +src.fs2 = cnv.fs2; +src.rp = cnv.rp; +src.rs = cnv.rs; + +%% FIR PM design +fs3 = src.L*cnv.fs1; +f = [src.f_pb src.f_sb]; +a = [1 0]; + +% Kaiser fir is not equiripple, can allow more ripple in the passband +% lower freq. +dev = [(10^(cnv.rp/20)-1)/(10^(cnv.rp/20)+1) 10^(-cnv.rs/20)]; +[kn0, kw, kbeta, kftype] = kaiserord(f, a, dev, fs3); +if use_firpm + %dev = [(10^(cnv.rp/20)-1)/(10^(cnv.rp/20)+1) 10^(-cnv.rs/20)]; + [n0,fo,ao,w] = firpmord(f,a,dev,fs3); + n0 = round(n0*0.95); % Decrease order to 95% +end +if use_remez + n0 = round(kn0*0.60); % Decrease order to 70% + fo = [0 2*f/fs3 1]; + ao = [1 1 0 0]; + w = [1 dev(1)/dev(2)]; +end +if use_kaiser + n0 = round(kn0*0.70); % Decrease order to 70% +end + +% Constrain filter length to be a suitable multiple. Multiple of +% interpolation factor ensures that all subfilters are equal length. +% Make each sub-filter order multiple of N helps in making efficient +% implementation. +nfir_increment = src.num_of_subfilters * cnv.filter_length_mult; + +nsf0 = (n0+1)/nfir_increment; +if nsf0 > floor(nsf0) + n = (floor(nsf0)+1)*nfir_increment-1; +else + n = n0; +end + +src.subfilter_length = (n+1)/src.num_of_subfilters; +src.filter_length = n+1; +nfir = n; +f_sb = linspace(src.f_sb, fs3/2, 500); +stopband_ok = 0; +need_to_stop = 0; +delta = 100; +n_worse = 0; +n_worse_max = 20; +n = 1; +n_max = 100; +dn = ones(1, n_max)*1000; +fn = zeros(1, n_max); +while (stopband_ok) == 0 && (n < n_max) + if use_firpm || use_remez + if nfir > 1800 + b = fir1(nfir, kw, kftype, kaiser(nfir+1, kbeta)); + else + if use_firpm + b = firpm(nfir,fo,ao,w); + else + b = remez(nfir,fo,ao,w); + end + end + else + b = fir1(nfir, kw, kftype, kaiser(nfir+1, kbeta)); + end + m_b = max(abs(b)); + %sref = 2^(cnv.coef_bits-1); + %bq = round(b*sref/m_b)*m_b/sref; + bq = b; + h_sb = freqz(bq, 1, f_sb, fs3); + m_sb = 20*log10(abs(h_sb)); + delta_prev = delta; + delta = cnv.rs+max(m_sb); + fprintf('Step=%3d, Delta=%f dB, N=%d\n', n, delta, nfir); + dn(n) = delta; + fn(n) = nfir; + if delta < 0 + stopband_ok = 1; + else + if delta_prev < delta + n_worse = n_worse+1; + if n_worse > n_worse_max + need_to_stop = 1; % No improvement, reverse + idx = find(dn == min(dn), 1, 'first'); + nfir = fn(idx); + else + nfir = nfir + nfir_increment; + end + else + if need_to_stop == 0 + nfir = nfir + nfir_increment; + else + stopband_ok = 1; % Exit after reverse + fprintf('Warning: Filter stop band could not be '); + fprintf('reached.\n', cnv.coef_bits); + end + end + end + n = n + 1; +end + +f_p = linspace(0, fs3/2, 2000); +m_db = 20*log10(abs(freqz(bq, 1, f_p, fs3))); +i_pb = find(f_p < src.f_pb); +g_pb = max(m_db(i_pb)); +g_att_lin = 10^(-g_pb/20); + +if 1 + p_ymin = floor((-cnv.rs-50)/10)*10; + p_ymax = 10; + figure; + clf; + plot(f_p, m_db); + grid on; + xlabel('Frequency (Hz)'); + ylabel('Magnitude (dB)'); + axis([0 fs3/2 p_ymin p_ymax]); + hold on + plot([src.f_sb src.f_sb],[p_ymin p_ymax], 'r--'); + plot([0 fs3],[-cnv.rs -cnv.rs], 'r--'); + hold off + axes('Position', [ 0.58 0.7 0.3 0.2]); + box on; + plot(f_p(i_pb), m_db(i_pb)); + axis([0 src.f_pb -cnv.rp-0.01 cnv.rp+0.01]); + hold on + plot([0 src.f_pb], +0.5*cnv.rp*ones(1,2), 'r--'); + plot([0 src.f_pb], -0.5*cnv.rp*ones(1,2), 'r--'); + hold off + grid on; + box off; +end + +src.subfilter_length = ceil((nfir+1)/src.num_of_subfilters); +src.filter_length = src.subfilter_length*src.num_of_subfilters; +src.b = zeros(src.filter_length,1); +src.gain = 1; +src.b(1:nfir+1) = b*src.L*g_att_lin; +m = max(abs(src.b)); +gmax = (32767/32768)/m; +maxshift = floor(log(gmax)/log(2)); +src.b = src.b * 2^maxshift; +src.gain = 1/2^maxshift; +src.shift = maxshift; + +%% Reorder coefficients +if 1 + src.coefs = src.b; +else + src.coefs = zeros(src.filter_length,1); + for n = 1:src.num_of_subfilters + i11 = (n-1)*src.subfilter_length+1; + i12 = i11+src.subfilter_length-1; + src.coefs(i11:i12) = src.b(n:src.num_of_subfilters:end); + end +end + +src.halfband = 0; +src.blk_in = M; +src.blk_out = L; +src.MOPS = cnv.fs1/M*src.filter_length/1e6; +src.fir_delay_size = src.subfilter_length + ... + (src.num_of_subfilters-1)*src.idm + src.blk_in; +src.out_delay_size = (src.num_of_subfilters-1)*src.odm + 1; + +end diff --git a/tools/tune/src/src_param.m b/tools/tune/src/src_param.m new file mode 100644 index 000000000000..49e935ce0096 --- /dev/null +++ b/tools/tune/src/src_param.m @@ -0,0 +1,87 @@ +function cnv = src_param(fs1, fs2, coef_bits, q) + +% src_param - get converter parameters +% +% cnv = src_param(fs1, fs2, coef_bits, q) +% +% fs1 - input rate +% fs2 - output rate +% coef_bits - word length identifier +% q - quality scale filter bandwidth and stopband attenuation, +% 1 is default +% + +% Copyright (c) 2016, 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 +% + +% Note: firpm design with rs 93 dB, or kaiser with 69 dB rs is fair quality. +% Both give about -80 dB THD+N with 24 bit coefficients. With 16 bit +% coefficients THD+N is limited to about -76 dB. + +if nargin < 4 + q = 1.0; +end + +%% Copy input parameters +cnv.fs1 = fs1; +cnv.fs2 = fs2; +cnv.coef_bits = coef_bits; + +%% FIR design +cnv.design = 'kaiser'; % Use firpm or kaiser + +%% Default SRC quality +cnv.c_pb = q * 22/48; % Gives 22 kHz BW @ 48 kHz +cnv.c_sb = 0.5; % Start stopband at Fs/2 +cnv.rs = 70; % Stopband attenuation in dB +cnv.rp = 0.1; % Passband ripple in dB +cnv.rp_tot = 0.1; % Max +/- passband ripple allowed, used in test script only + +%% Constrain sub-filter lengths. Make subfilters lengths multiple of four +% is a good assumption for processors. +cnv.filter_length_mult = 4; + +%% Exceptions for quality +if min(fs1, fs2) > 80e3 + cnv.c_pb = 30e3/min(fs1, fs2); % 30 kHz BW for > 80 kHz +end + +%% Sanity checks +if cnv.c_pb > 0.49 + error('Too wide passband'); +end +if cnv.c_pb < 0.15 + error('Too narrow passband'); +end +if cnv.rs > 160 + error('Too large stopband attenuation'); +end +if cnv.rs < 40 + error('Too low stopband attenuation'); +end diff --git a/tools/tune/src/src_std_int32.m b/tools/tune/src/src_std_int32.m new file mode 100644 index 000000000000..125ae9637449 --- /dev/null +++ b/tools/tune/src/src_std_int32.m @@ -0,0 +1,30 @@ +% Copyright (c) 2016, 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 +% + +src_generate(); diff --git a/tools/tune/src/src_tiny_int16.m b/tools/tune/src/src_tiny_int16.m new file mode 100644 index 000000000000..be310fbb8e21 --- /dev/null +++ b/tools/tune/src/src_tiny_int16.m @@ -0,0 +1,41 @@ +% Copyright (c) 2016, 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 +% + +fs1 = [8e3 16e3 24e3 32e3 44.1e3 48e3]; +fs2 = [8e3 16e3 24e3 32e3 44.1e3 48e3]; +fsm = [0 0 0 0 0 1; ... + 0 0 0 0 0 1; ... + 0 0 0 0 0 1; ... + 0 0 0 0 0 1; ... + 0 0 0 0 0 1; ... + 1 1 1 1 1 0; ... + ]; +fmt = 'int16'; profile = 'tiny'; q = 0.75; + +src_generate(fs1, fs2, fmt, fsm, profile, q);