Sound Open Firmware
Loading...
Searching...
No Matches
smart_amp.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 *
3 * Copyright(c) 2020 Maxim Integrated All rights reserved.
4 *
5 * Author: Ryan Lee <ryans.lee@maximintegrated.com>
6 *
7 * Copyright(c) 2023 Google LLC.
8 *
9 * Author: Pin-chih Lin <johnylin@google.com>
10 */
11
12#ifndef __SOF_AUDIO_DSM_H__
13#define __SOF_AUDIO_DSM_H__
14
15#include <sof/platform.h>
16#include <sof/audio/component.h>
17
18/* Smart Amplifier component is a two-layer structured design, i.e. generic
19 * layer and inner model layer. The latter can have various implementations
20 * respectively for Amplifier solution suppliers, while the former is the common
21 * part of Smart Amp process adaptable for all solutions.
22 *
23 * In structural aspect, one can regard generic layer as the glue code that
24 * wraps inner model in a SOF component. Ops are defined for interaction between
25 * two layers. Inner model is the solution-specific modular code, which may have
26 * static libraries linked as needed. The structure is figured below:
27 *
28 * SRC(FF) SINK(OUT) +-SRC(FB) bytectl
29 * +- SMART_AMP |^ comp ops | ^ | ^|
30 * | +------------------v|-------------v---------|------v-----------|v---------+
31 * | | Generic Layer (chan remap/fmt conv) || |
32 * | | (memory mgr)--+------> :::::::::BUFFERS::::::::::::: |+> CONFIG |
33 * | +------------------|-|^-----------|---------^------|-----------^|---------+
34 * | | || mod ops | | | ||
35 * | +------------------v-v|-----------v---------|------v-----------|v---------+
36 * | | Inner Model :::::::::::::::::::::BUFFERS::::::::::::::::::::::: |
37 * | | (solution-specific impl/wrapper) |+> MODEL |
38 * | +------------------------------|^------------------------------^----------+
39 * +--- v| lib ops | CALDATA
40 * Static Libs (as needed) ----------+
41 * Note:
42 * - FF(Feed-Forward): un-processed playback frame source
43 * - FB(Feedback): feedback reference frame source (from the capture pipeline)
44 *
45 * As illustrated above, generic layer handles the cross-communication for inner
46 * model and SOF pipeline flow, as well as the smart-amp common tasks including:
47 * 1. Channel remapping for input/output frames
48 * 2. Frame format conversion for input/output frames. It allows inner model to
49 * work with different format from SOF audio stream.
50 * (Now it only allows the bitdepth of inner model format >= SOF stream,
51 * e.g. inner model: S32_LE, SOF stream: S16_LE)
52 * 3. Full-management of runtime memory. That is, dynamic memory buffers either
53 * required by generic layer or inner model will be allocated/owned/released
54 * by generic layer.
55 * More details are stated in the comment of each struct/function later.
56 */
57
58/* Maximum number of channels for algorithm in */
59#define SMART_AMP_FF_MAX_CH_NUM 2
60/* Maximum number of channels for algorithm out */
61#define SMART_AMP_FF_OUT_MAX_CH_NUM 4
62/* Maximum number of channels for feedback */
63#define SMART_AMP_FB_MAX_CH_NUM 4
64
65#define SMART_AMP_FRM_SZ 48 /* frames per 1ms */
66#define SMART_AMP_FF_BUF_SZ (SMART_AMP_FRM_SZ * SMART_AMP_FF_MAX_CH_NUM)
67#define SMART_AMP_FB_BUF_SZ (SMART_AMP_FRM_SZ * SMART_AMP_FB_MAX_CH_NUM)
68
69#define SMART_AMP_FF_BUF_DB_SZ\
70 (SMART_AMP_FF_BUF_SZ * SMART_AMP_FF_MAX_CH_NUM)
71#define SMART_AMP_FB_BUF_DB_SZ\
72 (SMART_AMP_FB_BUF_SZ * SMART_AMP_FB_MAX_CH_NUM)
73
74struct inner_model_ops;
75
76/* The common base for inner model data structs. Inner model should declare its
77 * model data struct while putting this base as the leading member of struct, e.g.
78 * struct solution_foo_mod_data {
79 * struct smart_amp_mod_data_base base;
80 * uint32_t foo_version;
81 * struct foo_parameter_set;
82 * ...
83 * };
84 *
85 * Then implement mod_data_create() in its own C file, e.g.
86 * struct smart_amp_mod_data_base *mod_data_create(const struct comp_dev *dev)
87 * {
88 * struct solution_foo_mod_data *foo;
89 * foo = rzalloc(SOF_MEM_FLAG_USER, sizeof(*foo));
90 * assert(foo);
91 * foo->base.dev = dev;
92 * foo->base.mod_ops = foo_ops; // declared somewhere as static const
93 * ...
94 * return &foo->base;
95 * }
96 */
98 const struct comp_dev *dev; /* for logger tracing use only */
99 const struct inner_model_ops *mod_ops;
100};
101
102/* The struct of memory buffer managed by generic layer. */
104 void *data;
105 uint32_t size;
106};
107
108/* For memory allocation, generic layer plays the active role that queries the
109 * required memory size for inner model (then allocate and assign back) in
110 * some specific moments, i.e. once before and after model initialized. Inner
111 * model should consider buffers located and allocated onto 3 memory blocks in
112 * terms of usage:
113 * PRIVATE - allocated before model init - for libraries internal usage
114 * FRAME - allocated after model init - for audio frame buffer usage
115 * PARAM - allocated after model init - for parameter blob usage
116 */
123
124/* The intermediate audio data buffer in generic layer. */
127 uint32_t channels;
128 uint16_t frame_fmt;
129 union {
130 uint32_t consumed; /* for source (in frames) */
131 uint32_t produced; /* for sink (in frames) */
132 };
133};
134
135/******************************************************************************
136 * Generic functions: *
137 * The implementation is placed in smart_amp_generic.c *
138 ******************************************************************************/
139
140typedef void (*smart_amp_src_func)(struct smart_amp_mod_stream *src_mod,
141 uint32_t frames,
142 const struct audio_stream __sparse_cache *src,
143 const int8_t *chan_map);
144
145typedef void (*smart_amp_sink_func)(const struct smart_amp_mod_stream *sink_mod,
146 uint32_t frames,
147 const struct audio_stream __sparse_cache *sink);
148
155
156extern const struct smart_amp_func_map src_sink_func_map[];
157
160
161/******************************************************************************
162 * Inner model operations (mod ops): *
163 * Model implementations are mutual exclusive (separated by Kconfig). It *
164 * must be only one solution applicable per build. The solution-specific *
165 * implementation is placed in its own C file smart_amp_${SOLUTION}.c *
166 ******************************************************************************/
167
178
179/* All ops are mandatory. */
189 int (*init)(struct smart_amp_mod_data_base *mod);
190
203 enum smart_amp_mod_memblk blk);
204
216 enum smart_amp_mod_memblk blk,
217 struct smart_amp_buf *buf);
218
238 const uint16_t **mod_fmts, int *num_mod_fmts);
239
256 int (*set_fmt)(struct smart_amp_mod_data_base *mod, uint16_t mod_fmt);
257
271 uint32_t frames,
272 struct smart_amp_mod_stream *in,
273 struct smart_amp_mod_stream *out);
274
286 uint32_t frames,
287 struct smart_amp_mod_stream *in);
288
299 struct sof_ipc_ctrl_data *cdata, uint32_t size);
300
310 struct sof_ipc_ctrl_data *cdata);
311
320 int (*reset)(struct smart_amp_mod_data_base *mod);
321};
322
323#endif
Component API definition.
Platform API definition.
smart_amp_mod_memblk
Definition smart_amp.h:117
@ MOD_MEMBLK_PRIVATE
Definition smart_amp.h:118
@ MOD_MEMBLK_FRAME
Definition smart_amp.h:119
@ MOD_MEMBLK_MAX
Definition smart_amp.h:121
@ MOD_MEMBLK_PARAM
Definition smart_amp.h:120
void(* smart_amp_sink_func)(const struct smart_amp_mod_stream *sink_mod, uint32_t frames, const struct audio_stream __sparse_cache *sink)
Definition smart_amp.h:145
smart_amp_sink_func smart_amp_get_sink_func(uint16_t comp_fmt, uint16_t mod_fmt)
void(* smart_amp_src_func)(struct smart_amp_mod_stream *src_mod, uint32_t frames, const struct audio_stream __sparse_cache *src, const int8_t *chan_map)
Definition smart_amp.h:140
struct smart_amp_mod_data_base * mod_data_create(const struct comp_dev *dev)
Creates the self-declared model data struct.
const struct smart_amp_func_map src_sink_func_map[]
smart_amp_src_func smart_amp_get_src_func(uint16_t comp_fmt, uint16_t mod_fmt)
Audio stream is a circular buffer aware of audio format of the data in the buffer so provides API for...
Definition audio_stream.h:52
Audio component base device "class".
Definition component.h:645
Definition smart_amp.h:180
int(* set_config)(struct smart_amp_mod_data_base *mod, struct sof_ipc_ctrl_data *cdata)
Sets config data to model.
Definition smart_amp.h:309
int(* fb_proc)(struct smart_amp_mod_data_base *mod, uint32_t frames, struct smart_amp_mod_stream *in)
Runs the feedback process.
Definition smart_amp.h:285
int(* query_memblk_size)(struct smart_amp_mod_data_base *mod, enum smart_amp_mod_memblk blk)
Returns the required bytesize for the specific memblk.
Definition smart_amp.h:202
int(* set_fmt)(struct smart_amp_mod_data_base *mod, uint16_t mod_fmt)
Sets the frame format after resolved.
Definition smart_amp.h:256
int(* init)(struct smart_amp_mod_data_base *mod)
Initializes model.
Definition smart_amp.h:189
int(* get_supported_fmts)(struct smart_amp_mod_data_base *mod, const uint16_t **mod_fmts, int *num_mod_fmts)
Returns the list of supported frame formats.
Definition smart_amp.h:237
int(* set_memblk)(struct smart_amp_mod_data_base *mod, enum smart_amp_mod_memblk blk, struct smart_amp_buf *buf)
Sets the allocated memblk info.
Definition smart_amp.h:215
int(* ff_proc)(struct smart_amp_mod_data_base *mod, uint32_t frames, struct smart_amp_mod_stream *in, struct smart_amp_mod_stream *out)
Runs the feed-forward process.
Definition smart_amp.h:270
int(* reset)(struct smart_amp_mod_data_base *mod)
Resets model.
Definition smart_amp.h:320
int(* get_config)(struct smart_amp_mod_data_base *mod, struct sof_ipc_ctrl_data *cdata, uint32_t size)
Gets config data from model.
Definition smart_amp.h:298
Definition smart_amp.h:103
uint32_t size
Definition smart_amp.h:105
void * data
Definition smart_amp.h:104
Definition smart_amp.h:149
smart_amp_sink_func sink_func
Definition smart_amp.h:153
uint16_t comp_fmt
Definition smart_amp.h:150
smart_amp_src_func src_func
Definition smart_amp.h:152
uint16_t mod_fmt
Definition smart_amp.h:151
Definition smart_amp.h:97
const struct comp_dev * dev
Definition smart_amp.h:98
const struct inner_model_ops * mod_ops
Definition smart_amp.h:99
Definition smart_amp.h:125
uint32_t channels
Definition smart_amp.h:127
uint32_t produced
Definition smart_amp.h:131
uint16_t frame_fmt
Definition smart_amp.h:128
uint32_t consumed
Definition smart_amp.h:130
struct smart_amp_buf buf
Definition smart_amp.h:126
Generic control data.
Definition control.h:120
#define __sparse_cache
Definition compiler_attributes.h:11