-
Notifications
You must be signed in to change notification settings - Fork 350
Audio: stft_process: Add conversion to polar format and back #10496
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
base: main
Are you sure you want to change the base?
Changes from all commits
4b941bd
a67172c
f789fa1
5a29646
086250f
6f3c68d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,30 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| config COMP_STFT_PROCESS | ||
| tristate "Template example component" | ||
| tristate "STFT processing component" | ||
| default n | ||
| select MATH_FFT | ||
| select MATH_32BIT_FFT | ||
| select MATH_FFT_MULTI | ||
| help | ||
| Select for stft_process component. Reason for existence | ||
| is to provide a minimal component example and use as | ||
| placeholder in processing pipelines. As example processing | ||
| it swaps or reverses the channels when the switch control | ||
| is enabled. | ||
| Select for stft_process component. STFT acronym means | ||
| short term Fourier transform. It converts audio | ||
| to multiple FFTs with selected FFT size, hop, and | ||
| window function. Possible signal processing can be | ||
| done in it in frequency domain for FFTs that is | ||
| efficient for more complex signal processing techniques. | ||
| The component converts then the frequency domain | ||
| version of signal back to normal PCM audio stream | ||
| with inverse STFT. | ||
|
|
||
| if COMP_STFT_PROCESS | ||
|
|
||
| config STFT_PROCESS_MAGNITUDE_PHASE | ||
| bool "Convert FFTs to polar magnitude and phase" | ||
| default n | ||
| help | ||
| Select for processing in polar magnitude and phase | ||
| domain. Such complex values format is common for | ||
| frequency domain signal processing. | ||
|
|
||
| endif # COMP_STFT_PROCESS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2020-2026 Intel Corporation. | ||
| // | ||
| // Author: Amery Song <chao.song@intel.com> | ||
| // Keyon Jie <yang.jie@linux.intel.com> | ||
|
|
||
| #include <sof/audio/format.h> | ||
| #include <sof/common.h> | ||
| #include <stdint.h> | ||
|
|
||
| #ifndef __SOF_ICOMPLEX16_H__ | ||
| #define __SOF_ICOMPLEX16_H__ | ||
|
|
||
| /* Note: the add of packed attribute to icmplex16 would significantly increase | ||
| * processing time of fft_execute_16() so it is not done. The optimized versions of | ||
| * FFT for HiFi will need a different packed data structure vs. generic C. | ||
| * | ||
| * TODO: Use with care with other than 16-bit FFT internals. Access with intrinsics | ||
| * will requires packed and aligned data. Currently there is no such usage in SOF. | ||
| */ | ||
|
|
||
| /** | ||
| * struct icomplex16 - Storage for a normal complex number. | ||
| * @param real The real part in Q1.15 fractional format. | ||
| * @param imag The imaginary part in Q1.15 fractional format. | ||
| */ | ||
| struct icomplex16 { | ||
| int16_t real; | ||
| int16_t imag; | ||
| }; | ||
|
|
||
| /* | ||
| * Helpers for 16 bit FFT calculation | ||
| */ | ||
| static inline void icomplex16_add(const struct icomplex16 *in1, const struct icomplex16 *in2, | ||
| struct icomplex16 *out) | ||
| { | ||
| out->real = in1->real + in2->real; | ||
| out->imag = in1->imag + in2->imag; | ||
| } | ||
|
|
||
| static inline void icomplex16_sub(const struct icomplex16 *in1, const struct icomplex16 *in2, | ||
| struct icomplex16 *out) | ||
| { | ||
| out->real = in1->real - in2->real; | ||
| out->imag = in1->imag - in2->imag; | ||
| } | ||
|
|
||
| static inline void icomplex16_mul(const struct icomplex16 *in1, const struct icomplex16 *in2, | ||
| struct icomplex16 *out) | ||
| { | ||
| int32_t real = (int32_t)in1->real * in2->real - (int32_t)in1->imag * in2->imag; | ||
| int32_t imag = (int32_t)in1->real * in2->imag + (int32_t)in1->imag * in2->real; | ||
|
|
||
| out->real = Q_SHIFT_RND(real, 30, 15); | ||
| out->imag = Q_SHIFT_RND(imag, 30, 15); | ||
| } | ||
|
|
||
| /* complex conjugate */ | ||
| static inline void icomplex16_conj(struct icomplex16 *comp) | ||
| { | ||
| comp->imag = sat_int16(-((int32_t)comp->imag)); | ||
| } | ||
|
|
||
| /* shift a complex n bits, n > 0: left shift, n < 0: right shift */ | ||
| static inline void icomplex16_shift(const struct icomplex16 *input, int16_t n, | ||
| struct icomplex16 *output) | ||
| { | ||
| int n1, n2; | ||
|
|
||
| if (n >= 0) { | ||
| /* need saturation handling */ | ||
| output->real = sat_int16((int32_t)input->real << n); | ||
| output->imag = sat_int16((int32_t)input->imag << n); | ||
| } else { | ||
| n1 = -n; | ||
| n2 = 1 << (n1 - 1); | ||
| output->real = sat_int16(((int32_t)input->real + n2) >> n1); | ||
| output->imag = sat_int16(((int32_t)input->imag + n2) >> n1); | ||
| } | ||
| } | ||
|
|
||
| #endif /* __SOF_ICOMPLEX16_H__ */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,32 @@ | ||
| /* SPDX-License-Identifier: BSD-3-Clause | ||
| * | ||
| * Copyright(c) 2021 Intel Corporation. All rights reserved. | ||
| * Copyright(c) 2021-2026 Intel Corporation. | ||
| * | ||
| * Author: Shriram Shastry <malladi.sastry@linux.intel.com> | ||
| * | ||
| */ | ||
|
|
||
| #ifndef __SOF_MATH__SQRTLOOKUP__H | ||
| #define __SOF_MATH__SQRTLOOKUP__H | ||
| #ifndef __SOF_MATH_SQRT_H__ | ||
| #define __SOF_MATH_SQRT_H__ | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| uint16_t sqrt_int16(uint16_t u); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't be better to let a conflict to manifest itself (multiple definition error) so that we are aware of the redundant functionality?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, we are already aware of some feature duplication in C/maths libraries. The C/maths lib versions are non xtensa optimized and always max precision for type. i.e. we use a different name as we only need to perform maths effort to the quality desired for the audio format (as any extra effort would be wasted MCPS). |
||
| #endif | ||
| /** | ||
| * sofm_sqrt_int16() - Calculate 16-bit fractional square root function. | ||
| * @param u Input value in Q4.12 format, from 0 to 16.0. | ||
| * @return Calculated square root of n in Q4.12 format, from 0 to 4.0. | ||
| */ | ||
| uint16_t sofm_sqrt_int16(uint16_t u); | ||
|
|
||
| /** | ||
| * sofm_sqrt_int32() - Calculate 32-bit fractional square root function. | ||
| * @param n Input value in Q2.30 format, from 0 to 2.0. | ||
| * @return Calculated square root of n in Q2.30 format. | ||
| * | ||
| * The input range of square root function is matched with Q1.31 | ||
| * complex numbers range where the magnitude squared can be to 2.0. | ||
| * The function returns zero for non-positive input values. | ||
| */ | ||
| int32_t sofm_sqrt_int32(int32_t n); | ||
|
|
||
| #endif /* __SOF_MATH_SQRT_H__ */ | ||
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.
The same include change needs to be applied to mfcc_hifi3.c too.
Currently the NVL build is failing because of this.
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.
@singalsu fyi.
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.
Thanks for pointing it out @abonislawski and @lgirdwood ! It should be fixed now, I'll check the CI test build results.