-
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
Open
singalsu
wants to merge
6
commits into
thesofproject:main
Choose a base branch
from
singalsu:add_complex_polar_convert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
75ede56
Math: Rename square root function sqrt_int16() to sofm_sqrt_int16()
singalsu 33c0682
Math: Add 32-bit square root function sofm_sqrt_int32()
singalsu 828688d
Math: Separate icomplex16 and icomplex32 structs from FFT
singalsu 46f1a35
Math: Add functions to/from polar format for complex numbers
singalsu 4d3f3ba
Test: ztest: Add test sof.unit.math.complex
singalsu fe02408
Audio: stft_process: Add conversion to polar format and back
singalsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| #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__ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wouldn't be better to let a conflict to manifest itself (multiple definition error) so that we are aware of the redundant functionality?
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.
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).