Skip to content

Commit d77a98e

Browse files
committed
Mixer: Remove attenuation and apply saturation to mixed audio
This patch removes the down scaling of inputs to preserve the signal level non-modified in mixing. The 64 bit mix is saturated (clamp) to prevent overflow. It is recommended to instead use in topology volume components with safe gain set in the inputs of mixer (-6/-9.5/-12 dB for 2/3/4 inputs) if saturation in mixing must be prevented. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 3a29be9 commit d77a98e

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

src/audio/mixer.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <sof/stream.h>
3737
#include <sof/alloc.h>
3838
#include <sof/audio/component.h>
39+
#include <sof/audio/format.h>
3940

4041
#define trace_mixer(__e) trace_event(TRACE_CLASS_MIXER, __e)
4142
#define tracev_mixer(__e) tracev_event(TRACE_CLASS_MIXER, __e)
@@ -66,15 +67,13 @@ static void mix_n(struct comp_dev *dev, struct comp_buffer *sink,
6667
val[1] = 0;
6768
for (j = 0; j < num_sources; j++) {
6869
src = sources[j]->r_ptr;
69-
70-
/* TODO: clamp */
7170
val[0] += src[i];
7271
val[1] += src[i + 1];
7372
}
7473

75-
/* TODO: best place for attenuation ? */
76-
dest[i] = (val[0] >> (num_sources >> 1));
77-
dest[i + 1] = (val[1] >> (num_sources >> 1));
74+
/* Saturate to 32 bits */
75+
dest[i] = sat_int32(val[0]);
76+
dest[i + 1] = sat_int32(val[1]);
7877
}
7978
}
8079

0 commit comments

Comments
 (0)