Skip to content

Commit

Permalink
google_rtc_audio_processing: Cache frame size from source/sink
Browse files Browse the repository at this point in the history
Don't query the frame size every time it's used, cache it in the
component struct to save a few cycles.

This also permits a workaround: on MTL the mic stream lies about its
format, claiming s26_le when it's really s32_le.  We can leave the
existing format error in place and just use our own configuration for
now.

Signed-off-by: Andy Ross <[email protected]>
  • Loading branch information
andyross committed Dec 12, 2023
1 parent 56def96 commit e68502c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/audio/google/google_rtc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ struct google_rtc_audio_processing_comp_data {
int aec_reference_source;
int raw_microphone_source;
struct comp_buffer *ref_comp_buffer;
int ref_frame_bytes;
int out_frame_bytes;
};

#if CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS == 16
Expand Down Expand Up @@ -605,14 +607,24 @@ static int google_rtc_audio_processing_prepare(struct processing_module *mod,
if (mic_fmt != bits_fmt(CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS)) {
comp_err(dev, "Mic stream must be %d bit samples\n",
CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS);
ret = -EINVAL;

// FIXME: squash for now, the streams lie. See below.
//ret = -EINVAL;
}

if (mic_fmt != out_fmt) {
comp_err(dev, "Mismatched in/out frame format");
ret = -EINVAL;
}

// FIXME: the streams have a bad format on MTL, so we can't
// use this API. Compute by hand.
//
//cd->ref_frame_bytes = source_get_frame_bytes(sources[cd->aec_reference_source]);
//cd->out_frame_bytes = sink_get_frame_bytes(sinks[0]);
cd->ref_frame_bytes = sizeof(mic_sample_t) * source_get_channels(sources[cd->aec_reference_source]);
cd->out_frame_bytes = cd->ref_frame_bytes;

/* Blobs sent during COMP_STATE_READY is assigned to blob_handler->data
* directly, so comp_is_new_data_blob_available always returns false.
*/
Expand Down Expand Up @@ -775,7 +787,7 @@ static int mod_process(struct processing_module *mod, struct sof_source **source
* samples so AEC compares the most recent values.
*/
if (ref_ok && fref > fmic)
source_release_data(ref, (fref - fmic) * source_get_frame_bytes(ref));
source_release_data(ref, (fref - fmic) * cd->ref_frame_bytes);

for (frames_rem = frames; frames_rem; frames_rem -= n) {
n = MIN(frames_rem, cd->num_frames - cd->buffered_frames);
Expand Down Expand Up @@ -812,7 +824,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod,
* Currently the topology sets IBS incorrectly
*/
if (ref_ok && (source_get_data_available(ref)
< cd->num_frames * source_get_frame_bytes(ref)))
< cd->num_frames * cd->ref_frame_bytes))
return false;

if (source_get_data_available(mic) < source_get_min_available(mic))
Expand All @@ -821,7 +833,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod,
/* Output comes out all at once, the output sink much have
* space for the full block
*/
if (sink_get_free_size(out) < cd->num_frames * sink_get_frame_bytes(out))
if (sink_get_free_size(out) < cd->num_frames * cd->out_frame_bytes)
return false;

return true;
Expand Down

0 comments on commit e68502c

Please sign in to comment.