Skip to content

Commit

Permalink
google_rtc_audio_procesing: Clean up the mock, add busy waiting
Browse files Browse the repository at this point in the history
Remove the code from the mock rig, most of it was dead anyway.  Place
the actual data copy into the execute_aec() step instead, where it can
be expressed much more simply.

Also add a "duty cycle" tunable in Kconfig where the mock will spin on
the CPU when enabled to consume time proportional to its block size,
to better emulate the processing overhead for validation uses.

Signed-off-by: Andy Ross <andyross@google.com>
  • Loading branch information
andyross committed Dec 16, 2023
1 parent a39494f commit 68e8e72
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 103 deletions.
8 changes: 8 additions & 0 deletions src/audio/google/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ config GOOGLE_RTC_AUDIO_PROCESSING_MOCK
Mock Google real-time communication audio processing.
It allows for compilation check and basic audio flow checking.

config GOOGLE_RTC_AUDIO_PROCESSING_MOCK_DUTY_PCT
int "Active computation fraction for AEC mock"
default 50
help
The mock rig will spin to emulate processing on the CPU.
This tunable represents the percent of one (real time) block
that is spend "computing" the mocked AEC results.

endif # COMP_GOOGLE_RTC_AUDIO_PROCESSING

endmenu
23 changes: 22 additions & 1 deletion src/audio/google/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,29 @@ static int google_rtc_audio_processing_reset(struct processing_module *mod)
return 0;
}

static inline void execute_aec(struct google_rtc_audio_processing_comp_data *cd)
static inline void mock_copy(struct google_rtc_audio_processing_comp_data *cd)
{
int f, c;

for (c = 0; c < CHAN_MAX; c++)
for (f = 0; f < cd->num_frames; f++)
cd->refout_buffers[c][f] = cd->raw_mic_buffers[c][f];

#ifdef __ZEPHYR__
int64_t dt = (1000000L / 100) * cd->num_frames
* CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MOCK_DUTY_PCT
/ CONFIG_COMP_GOOGLE_RTC_AUDIO_PROCESSING_SAMPLE_RATE_HZ;

k_busy_wait((int32_t) dt);
#endif
}

static void execute_aec(struct google_rtc_audio_processing_comp_data *cd)
{
#if CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MOCK
mock_copy(cd);
#endif

/* Note that reference input and mic output share the same
* buffer for efficiency
*/
Expand Down
104 changes: 2 additions & 102 deletions src/audio/google/google_rtc_audio_processing_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,7 @@
#include "google_rtc_audio_processing.h"
#include "google_rtc_audio_processing_sof_message_reader.h"

#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include <rtos/alloc.h>
#include "ipc/topology.h"

#define GOOGLE_RTC_AUDIO_PROCESSING_FREQENCY_TO_PERIOD_FRAMES 100
#define GOOGLE_RTC_AUDIO_PROCESSING_MS_PER_SECOND 1000

struct GoogleRtcAudioProcessingState {
int num_capture_channels;
int num_aec_reference_channels;
int num_output_channels;
int num_frames;
float *aec_reference;
};
static int dummy_state;

static void SetFormats(GoogleRtcAudioProcessingState *const state,
int capture_sample_rate_hz,
Expand All @@ -31,18 +15,6 @@ static void SetFormats(GoogleRtcAudioProcessingState *const state,
int render_sample_rate_hz,
int num_render_channels)
{
state->num_capture_channels = num_capture_input_channels;
state->num_output_channels = num_capture_output_channels;
state->num_frames = capture_sample_rate_hz /
GOOGLE_RTC_AUDIO_PROCESSING_FREQENCY_TO_PERIOD_FRAMES;

state->num_aec_reference_channels = num_render_channels;
rfree(state->aec_reference);
state->aec_reference = rballoc(0,
SOF_MEM_CAPS_RAM,
sizeof(state->aec_reference[0]) *
state->num_frames *
state->num_aec_reference_channels);
}

void GoogleRtcAudioProcessingAttachMemoryBuffer(uint8_t *const buffer,
Expand All @@ -62,43 +34,15 @@ GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreateWithConfig(int capt
const uint8_t *const config,
int config_size)
{
struct GoogleRtcAudioProcessingState *s =
rballoc(0, SOF_MEM_CAPS_RAM, sizeof(GoogleRtcAudioProcessingState));
if (!s)
return NULL;

s->aec_reference = NULL;
SetFormats(s,
capture_sample_rate_hz,
num_capture_input_channels,
num_capture_output_channels,
render_sample_rate_hz,
num_render_channels);

if (!s->aec_reference) {
rfree(s);
return NULL;
}
return s;
return &dummy_state;
}

GoogleRtcAudioProcessingState *GoogleRtcAudioProcessingCreate(void)
{
return GoogleRtcAudioProcessingCreateWithConfig(CONFIG_COMP_GOOGLE_RTC_AUDIO_PROCESSING_SAMPLE_RATE_HZ,
1,
1,
CONFIG_COMP_GOOGLE_RTC_AUDIO_PROCESSING_SAMPLE_RATE_HZ,
2,
NULL,
0);
}

void GoogleRtcAudioProcessingFree(GoogleRtcAudioProcessingState *state)
{
if (state != NULL) {
rfree(state->aec_reference);
rfree(state);
}
}

int GoogleRtcAudioProcessingSetStreamFormats(GoogleRtcAudioProcessingState *const state,
Expand All @@ -108,12 +52,6 @@ int GoogleRtcAudioProcessingSetStreamFormats(GoogleRtcAudioProcessingState *cons
int render_sample_rate_hz,
int num_render_channels)
{
SetFormats(state,
capture_sample_rate_hz,
num_capture_input_channels,
num_capture_output_channels,
render_sample_rate_hz,
num_render_channels);
return 0;
}

Expand All @@ -126,9 +64,6 @@ int GoogleRtcAudioProcessingParameters(GoogleRtcAudioProcessingState *const stat

int GoogleRtcAudioProcessingGetFramesizeInMs(GoogleRtcAudioProcessingState *state)
{
return state->num_frames *
GOOGLE_RTC_AUDIO_PROCESSING_MS_PER_SECOND /
CONFIG_COMP_GOOGLE_RTC_AUDIO_PROCESSING_SAMPLE_RATE_HZ;
}

int GoogleRtcAudioProcessingReconfigure(GoogleRtcAudioProcessingState *const state,
Expand All @@ -142,36 +77,12 @@ int GoogleRtcAudioProcessingProcessCapture_float32(GoogleRtcAudioProcessingState
const float * const *src,
float * const *dest)
{
float *ref = state->aec_reference;
float **mic = (float **)src;
int n, chan;

for (chan = 0; chan < state->num_output_channels; chan++) {
for (n = 0; n < state->num_frames; ++n) {
float mic_save = mic[chan][n]; /* allow same in/out buffer */

if (chan < state->num_aec_reference_channels)
dest[chan][n] = mic_save + ref[n + (chan * state->num_frames)];
else
dest[chan][n] = mic_save;
}
}
return 0;
}

int GoogleRtcAudioProcessingAnalyzeRender_float32(GoogleRtcAudioProcessingState * const state,
const float * const *data)
{
const size_t buffer_size =
sizeof(state->aec_reference[0])
* state->num_frames;
int channel;

for (channel = 0; channel < state->num_aec_reference_channels; channel++) {
memcpy_s(&state->aec_reference[channel * state->num_frames], buffer_size,
data[channel], buffer_size);
}

return 0;
}

Expand All @@ -189,15 +100,4 @@ void GoogleRtcAudioProcessingParseSofConfigMessage(uint8_t *message,
bool *aec_reference_delay_present,
bool *mic_gain_present)
{
*google_rtc_audio_processing_config = NULL;
*google_rtc_audio_processing_config_size = 0;
*num_capture_input_channels = 1;
*num_capture_output_channels = 1;
*aec_reference_delay = 0;
*mic_gain = 1;
*google_rtc_audio_processing_config_present = false;
*num_capture_input_channels_present = false;
*num_capture_output_channels_present = false;
*aec_reference_delay_present = false;
*mic_gain_present = false;
}

0 comments on commit 68e8e72

Please sign in to comment.