Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for v2.3-rc1 #6270

Merged
merged 10 commits into from
Sep 8, 2022
2 changes: 1 addition & 1 deletion src/audio/google_hotword_detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static struct comp_dev *ghd_create(const struct comp_driver *drv,
cd->event.event_type = SOF_CTRL_EVENT_KD;
cd->event.num_elems = 0;

cd->msg = ipc_msg_init(cd->event.rhdr.hdr.cmd, cd->event.rhdr.size);
cd->msg = ipc_msg_init(cd->event.rhdr.hdr.cmd, cd->event.rhdr.hdr.size);
if (!cd->msg) {
comp_err(dev, "ghd_create(): ipc_msg_init failed");
goto cd_fail;
Expand Down
7 changes: 0 additions & 7 deletions src/audio/module_adapter/module/cadence.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,6 @@ cadence_codec_process(struct processing_module *mod,

static int cadence_codec_reset(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct cadence_codec_data *cd = codec->private;
int ret;
Expand All @@ -675,12 +674,6 @@ static int cadence_codec_reset(struct processing_module *mod)
rfree(cd->self);
cd->self = NULL;

ret = cadence_codec_prepare(mod);
if (ret) {
comp_err(dev, "cadence_codec_reset() error %x: could not re-prepare codec after reset",
ret);
}

return ret;
}

Expand Down
7 changes: 4 additions & 3 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ int module_reset(struct processing_module *mod)
md->cfg.size = 0;
rfree(md->cfg.data);

/* module resets itself to the initial condition after prepare()
* so let's change its state to reflect that.
/*
* reset the state to allow the module's prepare callback to be invoked again for the
* subsequent triggers
*/
md->state = MODULE_IDLE;
md->state = MODULE_INITIALIZED;

return 0;
}
Expand Down
12 changes: 5 additions & 7 deletions src/audio/module_adapter/module/passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,20 @@ passthrough_codec_process(struct processing_module *mod,

static int passthrough_codec_reset(struct processing_module *mod)
{
struct module_data *codec = &mod->priv;

comp_info(mod->dev, "passthrough_codec_reset()");

/* nothing to do */
rfree(codec->mpd.in_buff);
rfree(codec->mpd.out_buff);
return 0;
}

static int passthrough_codec_free(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;

comp_info(dev, "passthrough_codec_free()");

rfree(codec->mpd.in_buff);
rfree(codec->mpd.out_buff);

/* Nothing to do */
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions src/audio/module_adapter/module/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static inline void init_ramp(struct vol_data *cd, uint32_t curve_duration, uint3
/* In IPC4 driver sends curve_duration in hundred of ns - it should be
* converted into ms value required by firmware
*/
cd->initial_ramp = Q_MULTSR_32X32(curve_duration,
cd->initial_ramp = Q_MULTSR_32X32((int64_t)curve_duration,
Q_CONVERT_FLOAT(1.0 / 10000, 31), 0, 31, 0);

if (!cd->initial_ramp) {
Expand Down Expand Up @@ -840,7 +840,7 @@ static int volume_set_config(struct processing_module *mod, uint32_t config_id,
comp_info(dev, "volume_set_config(), channel = %d, value = %u",
ch, val);
if (ch >= SOF_IPC_MAX_CHANNELS) {
comp_err(dev, "volume_ctrl_set_cmd(), illegal channel = %d",
comp_err(dev, "volume_set_config(), illegal channel = %d",
ch);
return -EINVAL;
}
Expand Down Expand Up @@ -932,7 +932,7 @@ static int volume_set_config(struct processing_module *mod, uint32_t config_id,

/* return if more fragments are expected or if the module is not prepared */
if ((pos != MODULE_CFG_FRAGMENT_LAST && pos != MODULE_CFG_FRAGMENT_SINGLE) ||
md->state < MODULE_IDLE)
md->state < MODULE_INITIALIZED)
return 0;

cdata = (struct ipc4_peak_volume_config *)ASSUME_ALIGNED(fragment, 8);
Expand All @@ -946,7 +946,7 @@ static int volume_set_config(struct processing_module *mod, uint32_t config_id,
switch (config_id) {
case IPC4_VOLUME:
if (cdata->channel_id == IPC4_ALL_CHANNELS_MASK) {
for (i = 0; i < cd->channels; i++) {
for (i = 0; i < cd->base.audio_fmt.channels_count; i++) {
set_volume_ipc4(cd, i, cdata->target_volume,
cdata->curve_type,
cdata->curve_duration);
Expand Down
12 changes: 4 additions & 8 deletions src/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,10 @@ static int selector_init(struct processing_module *mod)
{
struct module_data *md = &mod->priv;
struct module_config *cfg = &md->cfg;
struct comp_dev *dev = mod->dev;
struct comp_data *cd;
int ret;

comp_dbg(dev, "selector_init()");
comp_dbg(mod->dev, "selector_init()");

cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd));
if (!cd)
Expand Down Expand Up @@ -700,9 +699,8 @@ static void set_selector_params(struct comp_dev *dev,
static int selector_free(struct processing_module *mod)
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;

comp_dbg(dev, "selector_free()");
comp_dbg(mod->dev, "selector_free()");

rfree(cd);

Expand Down Expand Up @@ -764,9 +762,8 @@ static int selector_process(struct processing_module *mod,
{
struct comp_data *cd = module_get_private_data(mod);
uint32_t avail_frames = input_buffers[0].size;
struct comp_dev *dev = mod->dev;

comp_dbg(dev, "selector_process()");
comp_dbg(mod->dev, "selector_process()");

if (!avail_frames)
return PPL_STATUS_PATH_STOP;
Expand Down Expand Up @@ -871,9 +868,8 @@ static int selector_prepare(struct processing_module *mod)
static int selector_reset(struct processing_module *mod)
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;

comp_info(dev, "selector_reset()");
comp_info(mod->dev, "selector_reset()");

cd->source_period_bytes = 0;
cd->sink_period_bytes = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/tdfb/tdfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ static int tdfb_prepare(struct comp_dev *dev)
/* The max. amount of processing need to be limited for sound direction
* processing. Max frames is used in tdfb_direction_init() and copy().
*/
cd->max_frames = Q_MULTSR_32X32(dev->frames, TDFB_MAX_FRAMES_MULT_Q14, 0, 14, 0);
cd->max_frames = Q_MULTSR_16X16((int32_t)dev->frames, TDFB_MAX_FRAMES_MULT_Q14, 0, 14, 0);
comp_info(dev, "dev_frames = %d, max_frames = %d", dev->frames, cd->max_frames);

/* Initialize tracking */
Expand Down
14 changes: 7 additions & 7 deletions src/audio/tdfb/tdfb_direction.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int tdfb_direction_init(struct tdfb_comp_data *cd, int32_t fs, int ch_count)
/* Calculate max lag to search and allocate delay line for cross correlation
* compute. Add one to make sure max possible lag is in search window.
*/
cd->direction.max_lag = Q_MULTSR_32X32(fs, t_max, 0, 15, 0) + 1;
cd->direction.max_lag = Q_MULTSR_32X32((int64_t)fs, t_max, 0, 15, 0) + 1;
n = (cd->max_frames + (2 * cd->direction.max_lag + 1)) * ch_count;
cd->direction.d_size = n * sizeof(int16_t);
cd->direction.d = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, cd->direction.d_size);
Expand Down Expand Up @@ -291,7 +291,7 @@ static void level_update(struct tdfb_comp_data *cd, int frames, int ch_count, in
ambient = cd->direction.level_ambient;
shift = (level < ambient) ? FAST_LEVEL_SHIFT : SLOW_LEVEL_SHIFT;
ambient = (level >> shift) - (ambient >> shift) + ambient;
thr = sat_int32(Q_MULTS_32X32(ambient >> 32, POWER_THRESHOLD, 31, 10, 31));
thr = sat_int32(Q_MULTS_32X32(ambient >> 32, POWER_THRESHOLD, 31, 10, 31)); /* int64_t */
cd->direction.level_ambient = ambient;
cd->direction.trigger <<= 1;
if (cd->direction.level > thr)
Expand Down Expand Up @@ -391,8 +391,8 @@ static void theoretical_time_differences(struct tdfb_comp_data *cd, int16_t az)

sin_az = sin_fixed_16b(Q_SHIFT_LEFT((int32_t)az, 12, 28)); /* Q1.15 */
cos_az = cos_fixed_16b(Q_SHIFT_LEFT((int32_t)az, 12, 28)); /* Q1.15 */
src_x = Q_MULTSR_32X32((int32_t)cos_az, SOURCE_DISTANCE, 15, 12, 12);
src_y = Q_MULTSR_32X32((int32_t)sin_az, SOURCE_DISTANCE, 15, 12, 12);
src_x = Q_MULTSR_16X16((int32_t)cos_az, SOURCE_DISTANCE, 15, 12, 12);
src_y = Q_MULTSR_16X16((int32_t)sin_az, SOURCE_DISTANCE, 15, 12, 12);

for (i = 0; i < n_mic; i++)
d[i] = distance_from_source(cd, i, src_x, src_y, 0);
Expand Down Expand Up @@ -491,8 +491,8 @@ static void iterate_source_angle(struct tdfb_comp_data *cd)
az += 360;
}

az_slow = Q_MULTSR_32X32((int32_t)az, SLOW_AZ_C1, 12, 15, 12) +
Q_MULTSR_32X32((int32_t)cd->direction.az_slow, SLOW_AZ_C2, 12, 15, 12);
az_slow = Q_MULTSR_16X16((int32_t)az, SLOW_AZ_C1, 12, 15, 12) +
Q_MULTSR_16X16((int32_t)cd->direction.az_slow, SLOW_AZ_C2, 12, 15, 12);
cd->direction.az_slow = unwrap_radians(az_slow);
}

Expand All @@ -510,7 +510,7 @@ static int convert_angle_to_enum(struct tdfb_comp_data *cd)
/* Update azimuth enum with radians to degrees to enum step conversion. First
* convert radians to deg, subtract angle offset, and make angles positive.
*/
deg = Q_MULTS_32X32((int32_t)cd->direction.az_slow, COEF_RAD_TO_DEG, 12, 9, 0) -
deg = Q_MULTS_16X16((int32_t)cd->direction.az_slow, COEF_RAD_TO_DEG, 12, 9, 0) -
cd->config->angle_enum_offs;

/* Divide and round to enum angle scale, remove duplicate 0 and 360 degree angle
Expand Down
12 changes: 12 additions & 0 deletions src/include/sof/audio/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@
/* Alternative version since compiler does not allow (x >> -1) */
#define Q_SHIFT_LEFT(x, src_q, dst_q) ((x) << ((dst_q) - (src_q)))

/* Fractional multiplication with shift
* Note that the parameters px and py must be cast to (int32_t) if other type.
*/
#define Q_MULTS_16X16(px, py, qx, qy, qp) \
((px) * (py) >> (((qx) + (qy) - (qp))))

/* Fractional multiplication with shift and round
* Note that the parameters px and py must be cast to (int32_t) if other type.
*/
#define Q_MULTSR_16X16(px, py, qx, qy, qp) \
((((px) * (py) >> ((qx) + (qy) - (qp) - 1)) + 1) >> 1)

/* Fractional multiplication with shift
* Note that the parameters px and py must be cast to (int64_t) if other type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ struct module_interface {
/**
* Module specific reset procedure, called as part of module_adapter component
* reset in .reset(). This should reset all parameters to their initial stage
* but leave allocated memory intact.
* and free all memory allocated during prepare().
*/
int (*reset)(struct processing_module *mod);
/**
* Module specific free procedure, called as part of module_adapter component
* free in .free(). This should free all memory allocated by module.
* free in .free(). This should free all memory allocated during module initialization.
*/
int (*free)(struct processing_module *mod);
};
Expand Down
6 changes: 3 additions & 3 deletions src/include/sof/drivers/dmic.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ extern const struct dai_driver dmic_driver;

static inline int dmic_get_unmute_ramp_from_samplerate(int rate)
{
int time_ms;
int32_t time_ms;

time_ms = Q_MULTSR_32X32((int32_t)rate, LOGRAMP_TIME_COEF_Q15, 0, 15, 0) +
LOGRAMP_TIME_OFFS_Q0;
time_ms = sat_int32(Q_MULTSR_32X32((int64_t)rate, LOGRAMP_TIME_COEF_Q15, 0, 15, 0) +
LOGRAMP_TIME_OFFS_Q0);
if (time_ms > LOGRAMP_TIME_MAX_MS)
return LOGRAMP_TIME_MAX_MS;

Expand Down
2 changes: 1 addition & 1 deletion src/include/sof/math/fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static inline void icomplex16_shift(struct icomplex16 *input, int16_t n, struct
{
int n_rnd = -n - 1;

if (n > 0) {
if (n >= 0) {
/* need saturation handling */
output->real = sat_int16((int32_t)input->real << n);
output->imag = sat_int16((int32_t)input->imag << n);
Expand Down
11 changes: 8 additions & 3 deletions src/math/fft/fft_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
{
struct icomplex16 tmp1;
struct icomplex16 tmp2;
struct icomplex16 *inb = plan->inb16;
struct icomplex16 *outb = plan->outb16;
struct icomplex16 *inb;
struct icomplex16 *outb;
int depth;
int top;
int bottom;
Expand All @@ -32,7 +32,12 @@ void fft_execute_16(struct fft_plan *plan, bool ifft)
int m;
int n;

if (!plan || !plan->bit_reverse_idx || !inb || !outb)
if (!plan || !plan->bit_reverse_idx)
return;

inb = plan->inb16;
outb = plan->outb16;
if (!inb || !outb)
return;

/* convert to complex conjugate for ifft */
Expand Down
11 changes: 8 additions & 3 deletions src/math/fft/fft_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
{
struct icomplex32 tmp1;
struct icomplex32 tmp2;
struct icomplex32 *inb = plan->inb32;
struct icomplex32 *outb = plan->outb32;
struct icomplex32 *inb;
struct icomplex32 *outb;
int depth;
int top;
int bottom;
Expand All @@ -33,7 +33,12 @@ void fft_execute_32(struct fft_plan *plan, bool ifft)
int m;
int n;

if (!plan || !plan->bit_reverse_idx || !inb || !outb)
if (!plan || !plan->bit_reverse_idx)
return;

inb = plan->inb32;
outb = plan->outb32;
if (!inb || !outb)
return;

/* convert to complex conjugate for ifft */
Expand Down