Skip to content

Commit

Permalink
up_down_mixer: refactore
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdobrowolski committed Sep 27, 2023
1 parent 7b6ef00 commit e81e99e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 101 deletions.
173 changes: 72 additions & 101 deletions src/audio/up_down_mixer/up_down_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Author: Adrian Warecki <adrian.warecki@intel.com>

#include <sof/audio/coefficients/up_down_mixer/up_down_mixer.h>
#include <sof/audio/up_down_mixer/up_down_mixer_manifest.h>
#include <sof/audio/up_down_mixer/up_down_mixer.h>
#include <sof/audio/buffer.h>
#include <sof/audio/format.h>
Expand All @@ -28,64 +29,31 @@
#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <rimage/sof/user/manifest.h>
#include <sof/audio/module_adapter/library/module_api_ver.h>

LOG_MODULE_REGISTER(up_down_mixer, CONFIG_SOF_LOG_LEVEL);

/* these ids aligns windows driver requirement to support windows driver */
/* 42f8060c-832f-4dbf-b247-51e961997b34 */
DECLARE_SOF_RT_UUID("up_down_mixer", up_down_mixer_comp_uuid, 0x42f8060c, 0x832f,
0x4dbf, 0xb2, 0x47, 0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34);
DECLARE_SOF_RT_UUID("up_down_mixer", up_down_mixer_comp_uuid, 0x42f8060c,
0x832f, 0x4dbf, 0xb2, 0x47, 0x51, 0xe9, 0x61, 0x99, 0x7b, 0x34);

DECLARE_TR_CTX(up_down_mixer_comp_tr, SOF_UUID(up_down_mixer_comp_uuid),
LOG_LEVEL_INFO);

#define ADSP_BUILD_INFO_FORMAT 0

struct sof_module_api_build_info udm_build_info __attribute__((section(".buildinfo"))) = {
ADSP_BUILD_INFO_FORMAT,
{
((0x3FF & 5) << 20) |
((0x3FF & 0) << 10) |
((0x3FF & 0) << 0)
}
};

extern struct module_interface up_down_mixer_interface;

void *loadable_udm_entry_point(void *mod_cfg, void *parent_ppl, void **mod_ptr)
{
return &up_down_mixer_interface;
}

__attribute__((section(".module")))
const struct sof_man_module_manifest udm_manifest = {
.module = {
.name = "UPDWMIX",
.uuid = {0x0C, 0x06, 0xF8, 0x42, 0x2F, 0x83, 0xBF, 0x4D,
0xB2, 0x47, 0x51, 0xE9, 0x61, 0x99, 0x7B, 0x34},
.entry_point = (uint32_t)loadable_udm_entry_point,
.type = { .load_type = SOF_MAN_MOD_TYPE_MODULE,
.domain_ll = 1 },
.affinity_mask = 1,
}
};
LOG_LEVEL_INFO);

int32_t custom_coeffs[UP_DOWN_MIX_COEFFS_LENGTH];

static int set_downmix_coefficients(struct processing_module *mod,
const struct ipc4_audio_format *format,
const enum ipc4_channel_config out_channel_config,
const downmix_coefficients downmix_coefficients)
{
const struct ipc4_audio_format *format,
const enum ipc4_channel_config out_channel_config,
const downmix_coefficients downmix_coefficients) {
struct up_down_mixer_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
int ret;

if (cd->downmix_coefficients) {
ret = memcpy_s(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients,
sizeof(int32_t) * UP_DOWN_MIX_COEFFS_LENGTH);
ret = memcpy_s(&custom_coeffs, sizeof(custom_coeffs),
downmix_coefficients,
sizeof(int32_t) * UP_DOWN_MIX_COEFFS_LENGTH);

if (ret < 0)
return ret;
Expand All @@ -111,13 +79,15 @@ static int set_downmix_coefficients(struct processing_module *mod,
break;
case IPC4_CHANNEL_CONFIG_QUATRO:
if (out_channel_config == IPC4_CHANNEL_CONFIG_MONO) {
cd->downmix_coefficients = (format->depth == IPC4_DEPTH_16BIT) ?
k_quatro_mono_scaled_lo_ro_downmix16bit :
k_quatro_mono_scaled_lo_ro_downmix32bit;
cd->downmix_coefficients =
(format->depth == IPC4_DEPTH_16BIT) ?
k_quatro_mono_scaled_lo_ro_downmix16bit :
k_quatro_mono_scaled_lo_ro_downmix32bit;
} else { /*out_channel_config == IPC4_CHANNEL_CONFIG_STEREO*/
cd->downmix_coefficients = (format->depth == IPC4_DEPTH_16BIT) ?
k_half_scaled_lo_ro_downmix16bit :
k_half_scaled_lo_ro_downmix32bit;
cd->downmix_coefficients =
(format->depth == IPC4_DEPTH_16BIT) ?
k_half_scaled_lo_ro_downmix16bit :
k_half_scaled_lo_ro_downmix32bit;
}
break;
case IPC4_CHANNEL_CONFIG_4_POINT_0:
Expand All @@ -144,8 +114,7 @@ static int set_downmix_coefficients(struct processing_module *mod,
}

static up_down_mixer_routine select_mix_out_stereo(struct comp_dev *dev,
const struct ipc4_audio_format *format)
{
const struct ipc4_audio_format *format) {
if (format->depth == IPC4_DEPTH_16BIT) {
switch (format->ch_cfg) {
case IPC4_CHANNEL_CONFIG_MONO:
Expand Down Expand Up @@ -209,8 +178,7 @@ static up_down_mixer_routine select_mix_out_stereo(struct comp_dev *dev,
}

static up_down_mixer_routine select_mix_out_mono(struct comp_dev *dev,
const struct ipc4_audio_format *format)
{
const struct ipc4_audio_format *format) {
if (format->depth == IPC4_DEPTH_16BIT) {
switch (format->ch_cfg) {
case IPC4_CHANNEL_CONFIG_STEREO:
Expand Down Expand Up @@ -260,8 +228,7 @@ static up_down_mixer_routine select_mix_out_mono(struct comp_dev *dev,
}

static up_down_mixer_routine select_mix_out_5_1(struct comp_dev *dev,
const struct ipc4_audio_format *format)
{
const struct ipc4_audio_format *format) {
if (format->depth == IPC4_DEPTH_16BIT) {
switch (format->ch_cfg) {
case IPC4_CHANNEL_CONFIG_MONO:
Expand Down Expand Up @@ -294,10 +261,9 @@ static up_down_mixer_routine select_mix_out_5_1(struct comp_dev *dev,
}

static int init_mix(struct processing_module *mod,
const struct ipc4_audio_format *format,
enum ipc4_channel_config out_channel_config,
const downmix_coefficients downmix_coefficients)
{
const struct ipc4_audio_format *format,
enum ipc4_channel_config out_channel_config,
const downmix_coefficients downmix_coefficients) {
struct up_down_mixer_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;

Expand All @@ -315,8 +281,8 @@ static int init_mix(struct processing_module *mod,

} else if (out_channel_config == IPC4_CHANNEL_CONFIG_STEREO) {
/* DOWN_MIX */
if (format->interleaving_style != IPC4_CHANNELS_INTERLEAVED ||
format->depth == IPC4_DEPTH_8BIT)
if (format->interleaving_style != IPC4_CHANNELS_INTERLEAVED
|| format->depth == IPC4_DEPTH_8BIT)
return -EINVAL;

/* Select dowm mixing routine. */
Expand All @@ -334,10 +300,11 @@ static int init_mix(struct processing_module *mod,
/* Update audio format. */
cd->out_fmt[0].channels_count = 6;
cd->out_fmt[0].ch_cfg = IPC4_CHANNEL_CONFIG_5_POINT_1;
cd->out_fmt[0].ch_map = create_channel_map(IPC4_CHANNEL_CONFIG_5_POINT_1);
cd->out_fmt[0].ch_map = create_channel_map(
IPC4_CHANNEL_CONFIG_5_POINT_1);

} else if (out_channel_config == IPC4_CHANNEL_CONFIG_7_POINT_1 &&
format->ch_cfg == IPC4_CHANNEL_CONFIG_STEREO) {
} else if (out_channel_config == IPC4_CHANNEL_CONFIG_7_POINT_1
&& format->ch_cfg == IPC4_CHANNEL_CONFIG_STEREO) {
/* Select up mixing routine. */
cd->mix_routine = upmix32bit_2_0_to_7_1;

Expand All @@ -355,11 +322,11 @@ static int init_mix(struct processing_module *mod,
cd->in_channel_map = format->ch_map;
cd->in_channel_config = format->ch_cfg;

return set_downmix_coefficients(mod, format, out_channel_config, downmix_coefficients);
return set_downmix_coefficients(mod, format, out_channel_config,
downmix_coefficients);
}

static int up_down_mixer_free(struct processing_module *mod)
{
static int up_down_mixer_free(struct processing_module *mod) {
struct up_down_mixer_data *cd = module_get_private_data(mod);

rfree(cd->buf_in);
Expand All @@ -369,8 +336,7 @@ static int up_down_mixer_free(struct processing_module *mod)
return 0;
}

static int up_down_mixer_init(struct processing_module *mod)
{
static int up_down_mixer_init(struct processing_module *mod) {
struct module_config *dst = &mod->priv.cfg;
const struct ipc4_up_down_mixer_module_cfg *up_down_mixer = dst->init_data;
struct module_data *mod_data = &mod->priv;
Expand All @@ -395,24 +361,26 @@ static int up_down_mixer_init(struct processing_module *mod)

switch (up_down_mixer->coefficients_select) {
case DEFAULT_COEFFICIENTS:
cd->out_channel_map = create_channel_map(up_down_mixer->out_channel_config);
cd->out_channel_map = create_channel_map(
up_down_mixer->out_channel_config);
ret = init_mix(mod, &mod->priv.cfg.base_cfg.audio_fmt,
up_down_mixer->out_channel_config, NULL);
up_down_mixer->out_channel_config, NULL);
break;
case CUSTOM_COEFFICIENTS:
cd->out_channel_map = create_channel_map(up_down_mixer->out_channel_config);
cd->out_channel_map = create_channel_map(
up_down_mixer->out_channel_config);
ret = init_mix(mod, &mod->priv.cfg.base_cfg.audio_fmt,
up_down_mixer->out_channel_config, up_down_mixer->coefficients);
up_down_mixer->out_channel_config, up_down_mixer->coefficients);
break;
case DEFAULT_COEFFICIENTS_WITH_CHANNEL_MAP:
cd->out_channel_map = up_down_mixer->channel_map;
ret = init_mix(mod, &mod->priv.cfg.base_cfg.audio_fmt,
up_down_mixer->out_channel_config, NULL);
up_down_mixer->out_channel_config, NULL);
break;
case CUSTOM_COEFFICIENTS_WITH_CHANNEL_MAP:
cd->out_channel_map = up_down_mixer->channel_map;
ret = init_mix(mod, &mod->priv.cfg.base_cfg.audio_fmt,
up_down_mixer->out_channel_config, up_down_mixer->coefficients);
up_down_mixer->out_channel_config, up_down_mixer->coefficients);
break;
default:
comp_err(dev, "up_down_mixer_init(): unsupported coefficient type");
Expand All @@ -427,16 +395,14 @@ static int up_down_mixer_init(struct processing_module *mod)

return 0;

err:
up_down_mixer_free(mod);
err: up_down_mixer_free(mod);
return ret;
}

/* just stubs for now. Remove these after making these ops optional in the module adapter */
static int up_down_mixer_prepare(struct processing_module *mod,
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks)
{
struct sof_source __sparse_cache **sources, int num_of_sources,
struct sof_sink __sparse_cache **sinks, int num_of_sinks) {
struct up_down_mixer_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;

Expand All @@ -448,15 +414,13 @@ static int up_down_mixer_prepare(struct processing_module *mod,
return 0;
}

static int up_down_mixer_reset(struct processing_module *mod)
{
static int up_down_mixer_reset(struct processing_module *mod) {
return 0;
}

static int up_down_mixer_process(struct processing_module *mod,
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers, int num_output_buffers)
{
struct input_stream_buffer *input_buffers, int num_input_buffers,
struct output_stream_buffer *output_buffers, int num_output_buffers) {
struct up_down_mixer_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
uint32_t source_bytes, sink_bytes;
Expand All @@ -465,34 +429,41 @@ static int up_down_mixer_process(struct processing_module *mod,
comp_dbg(dev, "up_down_mixer_process()");

mix_frames = audio_stream_avail_frames(mod->input_buffers[0].data,
mod->output_buffers[0].data);
mod->output_buffers[0].data);

source_bytes = mix_frames * audio_stream_frame_bytes(mod->input_buffers[0].data);
sink_bytes = mix_frames * audio_stream_frame_bytes(mod->output_buffers[0].data);
source_bytes = mix_frames
* audio_stream_frame_bytes(mod->input_buffers[0].data);
sink_bytes = mix_frames
* audio_stream_frame_bytes(mod->output_buffers[0].data);

if (source_bytes) {
uint32_t sink_sample_bytes;

audio_stream_copy_to_linear(mod->input_buffers[0].data, 0, cd->buf_in, 0,
source_bytes /
audio_stream_sample_bytes(mod->input_buffers[0].data));
audio_stream_copy_to_linear(mod->input_buffers[0].data, 0, cd->buf_in,
0,
source_bytes
/ audio_stream_sample_bytes(
mod->input_buffers[0].data));

cd->mix_routine(cd, (uint8_t *)cd->buf_in, source_bytes, (uint8_t *)cd->buf_out);
cd->mix_routine(cd, (uint8_t *) cd->buf_in, source_bytes,
(uint8_t *) cd->buf_out);

sink_sample_bytes = audio_stream_sample_bytes(mod->output_buffers[0].data);
audio_stream_copy_from_linear(cd->buf_out, 0, mod->output_buffers[0].data, 0,
sink_bytes / sink_sample_bytes);
sink_sample_bytes = audio_stream_sample_bytes(
mod->output_buffers[0].data);
audio_stream_copy_from_linear(cd->buf_out, 0,
mod->output_buffers[0].data, 0, sink_bytes / sink_sample_bytes);
mod->output_buffers[0].size = sink_bytes;
mod->input_buffers[0].consumed = source_bytes;
}

return 0;
}

static struct module_interface up_down_mixer_interface = {
.init = up_down_mixer_init,
.prepare = up_down_mixer_prepare,
.process_audio_stream = up_down_mixer_process,
.reset = up_down_mixer_reset,
.free = up_down_mixer_free
};
static struct module_interface up_down_mixer_interface = { .init =
up_down_mixer_init, .prepare = up_down_mixer_prepare,
.process_audio_stream = up_down_mixer_process, .reset =
up_down_mixer_reset, .free = up_down_mixer_free };

void *loadable_udm_entry_point(void *mod_cfg, void *parent_ppl, void **mod_ptr) {
return &up_down_mixer_interface;
}
40 changes: 40 additions & 0 deletions src/include/sof/audio/up_down_mixer/up_down_mixer_manifest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Pawel Dobrowolski <pawelx.dobrowolski@intel.com>
*/

#ifndef __UP_DOWN_MIXER_MANIFEST_H__
#define __UP_DOWN_MIXER_MANIFEST_H__

#include <rimage/sof/user/manifest.h>
#include <sof/audio/module_adapter/library/module_api_ver.h>

#define ADSP_BUILD_INFO_FORMAT 0

struct sof_module_api_build_info udm_build_info __attribute__((section(".buildinfo"))) = {
ADSP_BUILD_INFO_FORMAT,
{
((0x3FF & SOF_MODULE_API_MAJOR_VERSION) << 20) |
((0x3FF & SOF_MODULE_API_MIDDLE_VERSION) << 10) |
((0x3FF & SOF_MODULE_API_MINOR_VERSION) << 0)
}
};

extern struct module_interface up_down_mixer_interface;

__attribute__((section(".module")))
const struct sof_man_module_manifest udm_manifest = {
.module = {
.name = "UPDWMIX",
.uuid = {0x0C, 0x06, 0xF8, 0x42, 0x2F, 0x83, 0xBF, 0x4D,
0xB2, 0x47, 0x51, 0xE9, 0x61, 0x99, 0x7B, 0x34},
.entry_point = (uint32_t)loadable_udm_entry_point,
.type = { .load_type = SOF_MAN_MOD_TYPE_MODULE,
.domain_ll = 1 },
.affinity_mask = 1,
}
};

#endif /* __UP_DOWN_MIXER_MANIFEST_H__ */

0 comments on commit e81e99e

Please sign in to comment.