Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/audio/volume/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ static vol_zc_func vol_get_zc_function(struct comp_dev *dev,
*/
static void volume_set_alignment(struct sof_source *source)
{
const int channels = source_get_channels(source);
const unsigned int channels = source_get_channels(source);

/* The source buffer in HiFi5 processing version needs 16 bytes alignment. The
* macro SOF_FRAME_BYTE_ALIGN is set in common.h to the requirement align.
Expand Down
2 changes: 1 addition & 1 deletion src/audio/volume/volume.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct sof_ipc_ctrl_value_chan;
* circular buffer views and only performs the gain scaling.
*/
typedef void (*vol_scale_func)(struct processing_module *mod, struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation);
struct cir_buf_sink *sink, size_t frames, uint32_t attenuation);

/**
* \brief volume interface for function getting nearest zero crossing frame
Expand Down
184 changes: 97 additions & 87 deletions src/audio/volume/volume_arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@ static inline int16_t vol_mult_s16(int16_t x, int32_t vol)
}

static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation)
struct cir_buf_sink *sink, size_t frames, uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int16_t *x = source->ptr;
int16_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

if (nch == 2) {
const int32_t vol_l = cd->volume[0];
const int32_t vol_r = cd->volume[1];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s16(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s16(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
const uint32_t in0 = *(const uint32_t *)&x[i + 0];
const uint32_t in1 = *(const uint32_t *)&x[i + 2];
const int16_t out_l0 = vol_mult_s16((int16_t)in0, vol_l);
Expand All @@ -81,12 +82,13 @@ static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source
const int32_t vol = cd->volume[0];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s16(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s16(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
const uint32_t in0 = *(const uint32_t *)&x[i + 0];
const uint32_t in1 = *(const uint32_t *)&x[i + 2];
const int16_t out0 = vol_mult_s16((int16_t)in0, vol);
Expand All @@ -107,13 +109,14 @@ static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source
}
} else {
while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s16(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s16(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

for (int j = 0; j < nch; j++) {
for (unsigned int j = 0; j < nch; j++) {
const int32_t vol = cd->volume[j];
for (int i = j; i < n; i += nch) {
for (size_t i = j; i < n; i += nch) {
y[i] = vol_mult_s16(x[i], vol);
}
}
Expand All @@ -127,19 +130,19 @@ static void vol_s16_to_s16(struct processing_module *mod, struct cir_buf_source

static void vol_passthrough_s16_to_s16(struct processing_module *mod,
struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames,
struct cir_buf_sink *sink, size_t frames,
uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int16_t *x = source->ptr;
int16_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s16(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s16(x, source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s16(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

memcpy_s(y, n * sizeof(int16_t), x, n * sizeof(int16_t));
remaining_samples -= n;
Expand All @@ -164,25 +167,26 @@ static inline int32_t vol_mult_s24(int32_t x, int32_t vol)
}

static void vol_s24_to_s24(struct processing_module *mod, struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation)
struct cir_buf_sink *sink, size_t frames, uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

if (nch == 2) {
const int32_t vol_l = cd->volume[0];
const int32_t vol_r = cd->volume[1];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
y[i + 0] = vol_mult_s24(x[i + 0], vol_l);
y[i + 1] = vol_mult_s24(x[i + 1], vol_r);
y[i + 2] = vol_mult_s24(x[i + 2], vol_l);
Expand All @@ -199,13 +203,14 @@ static void vol_s24_to_s24(struct processing_module *mod, struct cir_buf_source
}
} else {
while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

for (int j = 0; j < nch; j++) {
for (unsigned int j = 0; j < nch; j++) {
const int32_t vol = cd->volume[j];
for (int i = j; i < n; i += nch) {
for (size_t i = j; i < n; i += nch) {
y[i] = vol_mult_s24(x[i], vol);
}
}
Expand All @@ -219,19 +224,19 @@ static void vol_s24_to_s24(struct processing_module *mod, struct cir_buf_source

static void vol_passthrough_s24_to_s24(struct processing_module *mod,
struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames,
struct cir_buf_sink *sink, size_t frames,
uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

memcpy_s(y, n * sizeof(int32_t), x, n * sizeof(int32_t));
remaining_samples -= n;
Expand All @@ -256,25 +261,26 @@ static inline int32_t vol_mult_s32(int32_t x, int32_t vol)
}

static void vol_s32_to_s32(struct processing_module *mod, struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation)
struct cir_buf_sink *sink, size_t frames, uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

if (nch == 2) {
const int32_t vol_l = cd->volume[0];
const int32_t vol_r = cd->volume[1];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
y[i + 0] = vol_mult_s32(x[i + 0], vol_l);
y[i + 1] = vol_mult_s32(x[i + 1], vol_r);
y[i + 2] = vol_mult_s32(x[i + 2], vol_l);
Expand All @@ -291,13 +297,14 @@ static void vol_s32_to_s32(struct processing_module *mod, struct cir_buf_source
}
} else {
while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

for (int j = 0; j < nch; j++) {
for (unsigned int j = 0; j < nch; j++) {
const int32_t vol = cd->volume[j];
for (int i = j; i < n; i += nch) {
for (size_t i = j; i < n; i += nch) {
y[i] = vol_mult_s32(x[i], vol);
}
}
Expand All @@ -311,19 +318,19 @@ static void vol_s32_to_s32(struct processing_module *mod, struct cir_buf_source

static void vol_passthrough_s32_to_s32(struct processing_module *mod,
struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames,
struct cir_buf_sink *sink, size_t frames,
uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const int32_t *x = source->ptr;
int32_t *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

memcpy_s(y, n * sizeof(int32_t), x, n * sizeof(int32_t));
remaining_samples -= n;
Expand All @@ -335,16 +342,16 @@ static void vol_passthrough_s32_to_s32(struct processing_module *mod,

#if CONFIG_FORMAT_FLOAT
static void vol_float_to_float(struct processing_module *mod, struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames, uint32_t attenuation)
struct cir_buf_sink *sink, size_t frames, uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const float *x = source->ptr;
float *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;
float vol_f[PLATFORM_MAX_CHANNELS];

for (int j = 0; j < nch; j++) {
for (unsigned int j = 0; j < nch; j++) {
#if COMP_VOLUME_Q8_16
vol_f[j] = (float)cd->volume[j] * (1.0f / 65536.0f);
#elif COMP_VOLUME_Q1_31
Expand All @@ -359,12 +366,13 @@ static void vol_float_to_float(struct processing_module *mod, struct cir_buf_sou
const float vol_r = vol_f[1];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
y[i + 0] = x[i + 0] * vol_l;
y[i + 1] = x[i + 1] * vol_r;
y[i + 2] = x[i + 2] * vol_l;
Expand All @@ -383,12 +391,13 @@ static void vol_float_to_float(struct processing_module *mod, struct cir_buf_sou
const float vol = vol_f[0];

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

int i = 0;
for (; i <= n - 4; i += 4) {
size_t i = 0;
for (; i + 4 <= n; i += 4) {
y[i + 0] = x[i + 0] * vol;
y[i + 1] = x[i + 1] * vol;
y[i + 2] = x[i + 2] * vol;
Expand All @@ -404,13 +413,14 @@ static void vol_float_to_float(struct processing_module *mod, struct cir_buf_sou
}
} else {
while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x,
source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

for (int j = 0; j < nch; j++) {
for (unsigned int j = 0; j < nch; j++) {
const float vol = vol_f[j];
for (int i = j; i < n; i += nch) {
for (size_t i = j; i < n; i += nch) {
y[i] = x[i] * vol;
}
}
Expand All @@ -424,19 +434,19 @@ static void vol_float_to_float(struct processing_module *mod, struct cir_buf_sou

static void vol_passthrough_float_to_float(struct processing_module *mod,
struct cir_buf_source *source,
struct cir_buf_sink *sink, uint32_t frames,
struct cir_buf_sink *sink, size_t frames,
uint32_t attenuation)
{
struct vol_data *cd = module_get_private_data(mod);
const float *x = source->ptr;
float *y = sink->ptr;
const int nch = cd->channels;
int remaining_samples = frames * nch;
const unsigned int nch = cd->channels;
size_t remaining_samples = frames * nch;

while (remaining_samples) {
const int nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const int nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
int n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));
const size_t nmax_src = cir_buf_samples_without_wrap_s32(x, source->buf_end);
const size_t nmax_snk = cir_buf_samples_without_wrap_s32(y, sink->buf_end);
size_t n = MIN(remaining_samples, MIN(nmax_src, nmax_snk));

memcpy_s(y, n * sizeof(float), x, n * sizeof(float));
remaining_samples -= n;
Expand Down
Loading
Loading