-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add copier gain feature #9323
Add copier gain feature #9323
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not the easiest PR to review I am afraid.
81e9bd2
to
da2e26f
Compare
d393fb2
to
4721304
Compare
4721304
to
65c2b12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check these ideas. Also, First make good C version to save effort from HiFi code revisions.
I think zipper noise risk and non-uniform gains update rate are my main concerns. Also I share view with other reviewers about code duplicate where common library would work.
src/audio/copier/copier_gain.h
Outdated
uint64_t gain_env; /**< Gain envelope for fade-in calculated in high precision */ | ||
uint64_t step_i64; /**< Step for fade-in envelope in high precision */ | ||
uint16_t container; /**< Size of sample container (in number of bits) */ | ||
uint16_t chanels_count; /**< Number of channels */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like many of these members don't need fixed bit-sizes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain this further?
{ | ||
struct copier_gain_params *gain_params = dd->gain_data; | ||
|
||
if (fade_period == GAIN_DEFAULT_FADE_PERIOD) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explained below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't "resolve" conversations before any change was made
65c2b12
to
5f2278f
Compare
src/audio/copier/copier_generic.c
Outdated
step_i64_to_i16 = gain_params->step_i64 >> I64_TO_I16_SHIFT; | ||
|
||
/* lower precision step for HIFI SIMD fade-in calculation, converted to Q16 format */ | ||
gain_params->step_f16 = (MAX_GAIN_COEFFS_CNT / gain_params->chanels_count) * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could calculate inverse of channels count in initialize and use fractional multiply to calculate the division here and below after few lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copier_gain_set_fade_params()
is called only once when instantiating Copier module. The loop below has maximum 4 iterations (MAX_GAIN_COEFFS_CNT=4). From my perspective, using an inverse of channels and fractional multiply will lead to insignificant performance gains with less code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm removing copier gain for DMIC dai from this PR. I'll create another one for DMIC interface specific changes.
@singalsu @plbossart @lgirdwood Is it possible to merge this PR as is to unblock Mic Privacy feature? I'll prepare common gain library as a next step.
src/audio/copier/copier_generic.c
Outdated
step_i64_to_i16 = gain_params->step_i64 >> I64_TO_I16_SHIFT; | ||
|
||
/* lower precision step for HIFI SIMD fade-in calculation, converted to Q16 format */ | ||
gain_params->step_f16 = (MAX_GAIN_COEFFS_CNT / gain_params->chanels_count) * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copier_gain_set_fade_params()
is called only once when instantiating Copier module. The loop below has maximum 4 iterations (MAX_GAIN_COEFFS_CNT=4). From my perspective, using an inverse of channels and fractional multiply will lead to insignificant performance gains with less code readability.
{ | ||
struct copier_gain_params *gain_params = dd->gain_data; | ||
|
||
if (fade_period == GAIN_DEFAULT_FADE_PERIOD) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explained below
5f2278f
to
71e89bc
Compare
71e89bc
to
74948d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - could you please verify the CI results? I see several failures - not sure if it is related to this PR.
for (i = 0; i < nmax; i += nch) | ||
dst_tmp[i] = q_multsr_sat_16x16(dst_tmp[i], gain, | ||
GAIN_Q10_INT_SHIFT); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering: with these 2 nested loops, the way it's done here where the external loop is over channels, and it looks like the buffer is organised like "s0ch0, s0ch1, s1ch0, s1ch1,..." we access the buffer with buf[0], buff[2],... buff[n], buff[1], buff[3],... buff[2*n-1]
. Wouldn't it be more cache-efficient to scan channels inside samples. But then of course we'd have to get a different value of gain
on every iteration... Probably wouldn't be faster in the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question on structure alignment that may well be beneficial in other places too but if needed can be added as next steps.
uint64_t gain_env; /**< Gain envelope for fade-in calculated in high precision */ | ||
uint64_t step_i64; /**< Step for fade-in envelope in high precision */ | ||
uint16_t channels_count; /**< Number of channels */ | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this structure need aligned for SIMD data size/width i.e. if not aligned in memory on SIMD HiFi data width size then CC will generate extra code for IO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lgirdwood This structure is allocated once and I thought rzalloc()
guarantees it is 64bit aligned (DCACHE_LINE_SIZE).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good otherwise but please check the 32 bit mute
Prepare infrastructure for copier gain feature. Add basic configuration scenario. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
Add HIFI and generic versions of gain processing for 32-bit and 16-bit container size. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
Add methods to update gain coefficients in runtime by handling DMA CONTROL IPC message being sent to specific dai device based on provided node id. Check for unity gain flag. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
74948d2
to
147b33a
Compare
Add gain configuration and apply gain processing in copier dai. Signed-off-by: Ievgen Ganakov <ievgen.ganakov@intel.com>
147b33a
to
f3b47bf
Compare
@lgirdwood It seems it is ready to be merged |
This PR introduces the Copier Gain feature which will be used by DMIC and with Microphone Privacy.
Gain algorithm utilizes Xtensa HiFi3 instruction set for efficient audio processing and has following modes:
Gain has an option to change gain coefficients in runtime using DMA Control IPC message, therefore has dependency on
#9156: [DNM] basefw: Add handling of IPC4_DMA_CONTROL messages
Common use cases: