Skip to content

Commit

Permalink
Audio: Google RTC audio processing: Mix all channels in mockup
Browse files Browse the repository at this point in the history
With this change e.g. in all 2ch case all output channels are
mixed with matching microphone and reference channels. It helps
with testing to hear and see that the mockup works.

The mix is done for matching microphone, reference and output
channels indices. With e.g. less reference channels, the remaining
output channels are passed directly from microphone.

The mixed samples are saturated to avoid nasty sounding overflows.

Signed-off-by: Lionel Koenig <lionelk@google.com>
Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
  • Loading branch information
singalsu committed Oct 23, 2023
1 parent 6b6bcb6 commit 22b18be
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/audio/google/google_rtc_audio_processing_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <string.h>
#include <stdint.h>

#include <sof/audio/format.h>
#include <sof/math/numbers.h>
#include <rtos/alloc.h>
#include "ipc/topology.h"

Expand Down Expand Up @@ -145,11 +147,23 @@ int GoogleRtcAudioProcessingProcessCapture_int16(GoogleRtcAudioProcessingState *
int16_t *ref = state->aec_reference;
int16_t *mic = (int16_t *) src;
int16_t *out = dest;
int n;
int n, io, im, ir;

/* Mix input and reference channels to output. The matching channels numbers
* are mixed. If e.g. microphone and output channels count is 4, and reference
* has 2 channels, output channels 3 and 4 are copy of microphone channels 3 and 4,
* and output channels 1 and 2 are sum of microphone and reference.
*/
memset(dest, 0, sizeof(int16_t) * state->num_output_channels * state->num_frames);
for (n = 0; n < state->num_frames; ++n) {
*out = *mic + *ref;
im = 0;
ir = 0;
for (io = 0; io < state->num_output_channels; io++) {
out[io] = sat_int16(
(im < state->num_capture_channels ? (int32_t)mic[im++] : 0) +
(ir < state->num_aec_reference_channels ? (int32_t)ref[ir++] : 0));
}

ref += state->num_aec_reference_channels;
out += state->num_output_channels;
mic += state->num_capture_channels;
Expand Down

0 comments on commit 22b18be

Please sign in to comment.