Skip to content
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

src_lite: fix 32kHz to 16kHz conversion issue #9348

Merged
merged 5 commits into from
Aug 21, 2024

Conversation

tobonex
Copy link
Contributor

@tobonex tobonex commented Aug 6, 2024

Fix issue where 32kHz to 16kHz conversion would give incorrect frequency signal. src_polyphase_init function was using wrong coefficient matrix while checking for equal frequencies resulting in no conversion.

In more detail:
Conversion matrices are saved in src_param struct in src_prepare function. But src_polyphase_init used hard-coded matrix for normal src (src_lite uses a different one). src_polyphase_init used incorrect matrix with indices for correct matrix (idx_in = 0, idx_out = 0), and those in the normal src matrix translate to frequencies 8k and 8k (instead of 32k and 16k), and so the if statement checking for equal frequencies was incorrectly true.

Regression started at 7ee322f

Fix issue where 32kHz to 16kHz conversion would give incorrect frequency
signal. src_polyphase_init function was using wrong coefficient matrix
while checking for equal frequencies resulting in no conversion.

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
@tobonex tobonex marked this pull request as ready for review August 7, 2024 06:55
@tobonex tobonex requested review from lyakh and kv2019i August 7, 2024 06:59
n_stages = (src->stage2->filter_length == 1) ? 1 : 2;
if (src_in_fs[p->idx_in] == src_out_fs[p->idx_out])
if (p->in_fs[p->idx_in] == p->out_fs[p->idx_out])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is directly modifying the check added in commit 914c415 , can you @singalsu check?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be an issue in setup tables for src_lite since there some differences to normal. As far as I know they were hand-edited from some old version of normal SRC, while tables for normal SRC are all script generated. There's multiple ways to check for 1:1 conversion and this probably works for both src and src_lite. I'll test with normal SRC in testbench if this is OK, so it could be approved. I doubt anyone wants to do another hand edit round for src-lite. So please wait until I can check this. There's is no SOF CI coverage for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more specific. There should be a script like this for src-lite to be able to re-generate them if we would change anything into core functions: https://github.com/thesofproject/sof/blob/main/src/audio/src/tune/sof_src_ipc4_int32.m . Remove the rates combinations not needed and run the generator in Matlab or Octave.

Could you @tobonex please create a similar script and see if it would fix this issue? Without such script existing maintenance of src-lite is hard.

Copy link
Collaborator

@lyakh lyakh Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also to remind, that src_lite was actually unused until 7ee322f

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobonex Maybe not familiar with Matlab? If you can make e.g. with spreadsheet a matrix of what in/our rates should be supported by src_lite, I can generate the new coefficients for you to test. I do see that possible in rates are 32, 44.1, and 48 kHz and possible out rates are 16 and 48 kHz. But are all in-out combinations supported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu I'm familliar with matlab. Not so familliar with SRC though , so I feel like I'm lacking some context.
The thing I want to change here is still an issue I think : using hardcoded src table even when src_lite is used. Still, got octave running, I can try to create the script and check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu Added the generator for src_lite, and regenerated coef files. This by itself does not fix the issue, so the change in the if statement is still needed. However I'm guessing we still want the new files anyway so I added new commits.

Comment on lines +23 to +42
const int32_t fir_one = 1073741824;
const struct src_stage src_int32_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, -1, &fir_one };
const struct src_stage src_int32_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, &fir_one };
const int src_in_fs[3] = { 32000, 44100, 48000};
const int src_out_fs[2] = { 16000, 48000};
const struct src_stage * const src_table1[2][3] = {
{ &src_int32_1_2_4535_5000, &src_int32_10_21_3455_5000,
&src_int32_1_3_4535_5000},
{ &src_int32_3_2_4535_5000,
&src_int32_8_7_4535_5000, &src_int32_1_1_0_0
}
};

const struct src_stage * const src_table2[2][3] = {
{ &src_int32_1_1_0_0, &src_int32_16_21_4535_5000,
&src_int32_1_1_0_0},
{ &src_int32_1_1_0_0,
&src_int32_20_21_4167_5000, &src_int32_1_1_0_0
}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be in SRC lite C flle ?

src/audio/src/tune/sof_src_lite_int32.m Outdated Show resolved Hide resolved
src/audio/src/tune/sof_src_lite_int32.m Outdated Show resolved Hide resolved
@singalsu
Copy link
Collaborator

singalsu commented Aug 15, 2024

What are the targets for SRC-lite? Should SRC and SRC-lite be mutually exclusive in build? If yes, then there should be C pre-processor macros to error such Kconfig. If like it seems with TGL that both are enabled there is a conflict with global configuration tables. The SRC and SRC-lite sources should be better separated to avoid random "win" of the configuration tables with same name to happen. Currently the conversions may use totally wrong filters coefficients. At least it's demonstrated that in and out rates table is corrupt. SRC is breaking SRC-lite, and I'm pretty sure the opposite may have also happened.

@tobonex tobonex requested a review from marc-hb as a code owner August 16, 2024 11:43
Add a coef generator for src_lite.

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
Add new src_lite coef files generated by the new .m generator.

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
Renaming src.c, as this filename will have a different purpose. File
src_common.c will contain common functions for all src types.

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
@tobonex tobonex force-pushed the src_lite_conversion_fix branch 2 times, most recently from 7d05073 to fefb68d Compare August 16, 2024 14:39
Defines for normal src and src_lite were not separated correctly. Added new
variables so those values can be different depending on the type of src
being used. Those are assigned in prepare function in a new src.c file,
similarly to src_lite.c

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
Copy link
Collaborator

@singalsu singalsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tobonex ! This version works well for real device (tested with sof-hda-benchmark-src32.tplg and sof-hda-benchmark-src_lite32.tplg) and src_test.m with testbench.

@lgirdwood lgirdwood merged commit 3a4c9db into thesofproject:main Aug 21, 2024
43 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants