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.

If the output channels count is not matching, the input or
reference channels index is wrapped. If output channels count
is less than input channels, the remaining channels are
ignored.

The mixed samples are saturated to avoid nasty sounding overflows.

Signed-off-by: Seppo Ingalsuo <[email protected]>
  • Loading branch information
singalsu committed Oct 10, 2023
1 parent 9bf36b8 commit a79dc2f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 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,28 @@ 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. If the number of input
* channels and reference channels is equal or higher than output then
* matching channels are mixed. If output channels count is higher than
* input or reference, the mic or reference channels indices to mix are
* restarted from zero. This is nothing like real AEC operation but a
* scheme to mix to every channel for testing.
*/
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((int32_t)mic[im++] + ref[ir++]);
if (im == state->num_capture_channels)
im = 0;

if (ir == state->num_aec_reference_channels)
ir = 0;
}

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

0 comments on commit a79dc2f

Please sign in to comment.