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

Tools: Add more robustness to check_volume_levels.m measure #985

Merged

Conversation

singalsu
Copy link
Contributor

No description provided.

@singalsu singalsu requested a review from a team as a code owner November 22, 2022 19:01
tools/check_volume_levels.m Outdated Show resolved Hide resolved
@singalsu
Copy link
Contributor Author

@aiChaoSONG @marc-hb I still get these "[WARNING] SOF_TEST_TOP_PID=1531 already defined, multiple lib.sh inclusions?". I see only one line source "$TESTDIR/case-lib/lib.sh" in the script. How can I fix it?

@singalsu singalsu force-pushed the volume_levels_check_add_control_robustness branch from 5c10589 to 06fd766 Compare November 23, 2022 10:31
Copy link

@ShriramShastry ShriramShastry left a comment

Choose a reason for hiding this comment

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

Looks good !!

tools/check_volume_levels.m Outdated Show resolved Hide resolved
@singalsu singalsu force-pushed the volume_levels_check_add_control_robustness branch from 06fd766 to cf00256 Compare November 23, 2022 13:20
ShriramShastry
ShriramShastry previously approved these changes Nov 23, 2022
Copy link

@ShriramShastry ShriramShastry left a comment

Choose a reason for hiding this comment

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

I am fine with the changes. Thank you!!

Copy link
Contributor

@btian1 btian1 left a comment

Choose a reason for hiding this comment

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

not clear with below statement:

This patch delays the check window if the gain settling seems
to be still happening in the beginning of level check window.
The settling is detected with differential of gain.

Could you use short sentence to describe?

@aiChaoSONG
Copy link

@aiChaoSONG @marc-hb I still get these "[WARNING] SOF_TEST_TOP_PID=1531 already defined, multiple lib.sh inclusions?". I see only one line source "$TESTDIR/case-lib/lib.sh" in the script. How can I fix it?

sof-test will write PID to a lock file in case you run multiple test case at the same time. maybe you interrupt the test, and the lock file not deleted? try manually delete the lock file /tmp/sof-test-cardX.lock, X is the sof card ID.

@singalsu
Copy link
Contributor Author

not clear with below statement:

This patch delays the check window if the gain settling seems to be still happening in the beginning of level check window. The settling is detected with differential of gain.

Could you use short sentence to describe?

By window I mean an acceptance criteria over time and gain in decibels. E.g. x milliseconds to y milliseconds, measured gain within a +/- b decibels. Actually I'm not evaluating every point in window but compute average gain from that measure window and compare to required. Any fail will fail the entire test.

By computing the differential of measured gain, I see from the values if the gain is constant or changing. The added code is shifting the measurement window to later in time if the gain is not constant in in the beginning.

Did this explain better - should I add this to commit message?

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 28, 2022

@aiChaoSONG @marc-hb I still get these "[WARNING] SOF_TEST_TOP_PID=1531 already defined, multiple lib.sh inclusions?". I see only one line source "$TESTDIR/case-lib/lib.sh" in the script. How can I fix it?

sof-test will write PID to a lock file in case you run multiple test case at the same time. maybe you interrupt the test, and the lock file not deleted? try manually delete the lock file /tmp/sof-test-cardX.lock, X is the sof card ID.

No, that would be a different error message. SOF_TEST_TOP_PID=1531 already defined really means that the variable SOF_TEST_TOP_PID is already defined which is a serious sof-test coding problem, just look at git grep -C 5 SOF_TEST_TOP_PID and see for yourself.

I don't see how this could be related to matlab changes though. @singalsu is that independent of this PR? Can you reproduce with the current main branch and if yes please share how exactly in a new, different sof-test issue.

andrula-song
andrula-song previously approved these changes Nov 29, 2022
@singalsu
Copy link
Contributor Author

I don't see how this could be related to matlab changes though. @singalsu is that independent of this PR? Can you reproduce with the current main branch and if yes please share how exactly in a new, different sof-test issue.

The error is not printed if I remove from test end line sof-kernel-log-check.sh "$KERNEL_CHECKPOINT". It's added in commit 8af0a79. Maybe something that it needs is missing.

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 29, 2022

@singalsu if you have a deterministic reproduction without this PR please file a new sof-test bug with complete reproduction steps.

@singalsu
Copy link
Contributor Author

@singalsu if you have a deterministic reproduction without this PR please file a new sof-test bug with complete reproduction steps.

I will but it requires merge of this PR. The script does not proceed to last line where sof-kernel-log-check.sh is called if there is a test fail. Or in other words the Matlab part of test always fails without this improvement. Somehow things (controls) happen in DUT slower than before and failure rate is 100%. Also we don't have tests for control latencies trend, as an idea for future.

@singalsu singalsu force-pushed the volume_levels_check_add_control_robustness branch from cf00256 to 7ca9e2d Compare November 30, 2022 14:49
@singalsu
Copy link
Contributor Author

@btian1 I improved the commit text of first commit, no other changes, is it OK now?

All, can you please re-review. The previous accepts were dropped from force push.

@singalsu singalsu force-pushed the volume_levels_check_add_control_robustness branch from 7ca9e2d to 83bb3fa Compare December 7, 2022 17:47
@singalsu
Copy link
Contributor Author

singalsu commented Dec 7, 2022

The PR update adds 4th commit that avoids need for parallel SOF repo checkout.

btian1
btian1 previously approved these changes Dec 15, 2022
@singalsu
Copy link
Contributor Author

@ShriramShastry you approve got cleared, can you please check again. There's only the one " " add to 1st commit.

@singalsu
Copy link
Contributor Author

@marc-hb I just checked that this passed with SOF v2.2 on UP2. I had to make a small change to the shell wrapper since the loopback I2S device in sof-apl-nocodec.tplg is no more hw:0,0 but hw:0,2:

diff --git a/test-case/check-volume-levels.sh b/test-case/check-volume-levels.sh
index 0695320..d819835 100755
--- a/test-case/check-volume-levels.sh
+++ b/test-case/check-volume-levels.sh
@@ -40,7 +40,7 @@ setup_kernel_check_point
 tplg=${OPT_VAL['t']}
 
 TPLGREADER="$TESTDIR"/tools/sof-tplgreader.py
-PCM_ID=0
+PCM_ID=2
 CAP_FORMAT="S16_LE"
 CAP_RATE="48000"
 VOL_P30DB=80

I'd like to make fixes incrementally and address the finding of loopback I2S a separate patch. Its not impacting the Matlab code of this PR.

Also need to make the test to work with a test subset if there is no more mute switch, since those have been removed from IPC4 topologies.

x = zeros(n, 1);
x(:,1) = amp(1)*sin(2*pi*f(1)*t);
for i=2:length(f)
x(:,1) = x(:,1) + amp(i)*sin(2*pi*f(i)*t+ph(i))';
Copy link

@ShriramShastry ShriramShastry Feb 23, 2023

Choose a reason for hiding this comment

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

I think x(:,1) is no longer needed , Just x is sufficient
I am thinking it's like below snippet

x = zeros(10,1);
y = linspace(-10,10,10);
x = y + 102.34

y assigns some linearly separated data to replace the loop x equation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's now simplified to just x . I was apparently worried about vector orientations when doing this and did not clean up afterwards. The mixing of sine preserved the vector and did not make it a 2D matrix (a pitfall with Matlab language with column and row vectors).

ShriramShastry
ShriramShastry previously approved these changes Feb 23, 2023
Copy link

@ShriramShastry ShriramShastry left a comment

Choose a reason for hiding this comment

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

A minor comment !! If it is fine with you.


x = zeros(n, 1);
x(:,1) = amp(1)*sin(2*pi*f(1)*t);
for i=2:length(f)

Choose a reason for hiding this comment

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

Why is the loop initialized from 2 rather than 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because the first frequency f(1) sine wave is mixed before the loop. Any additional frequencies f(2) to f(end) are mixed in the loop. But yes, it can be simplified to e.g.

	x = zeros(n, 1);
	for i=1:length(f)
		x(:,1) = x(:,1) + amp(i)*sin(2*pi*f(i)*t+ph(i))';
	end

@singalsu
Copy link
Contributor Author

singalsu commented Mar 3, 2023

@ShriramShastry I updated the tone generator function as you proposed. Can you please review again?

I just checked on UP2 sof-apl-nocodec.tplg that the updated code works and test passes so the change was OK.

Next PR for volume checker should be to add support for IPC4 topologies without switch control, and solve the discovery of looped back I2S PCMs, or get the PCM IDs externally.

Copy link

@ShriramShastry ShriramShastry left a comment

Choose a reason for hiding this comment

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

A few sanity-related comments have been added.

Kindly include space where it is needed. The implementation looks to have improved significantly.

Thank you

if max(abs(dg)) > dg_tol
n_idx = length(idx);
dg_rev = dg(end:-1:1);
idx_add = length(dg) - find(abs(dg_rev) > 0.1, 1, 'first') + 1;
Copy link

@ShriramShastry ShriramShastry Mar 3, 2023

Choose a reason for hiding this comment

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

Can 0.1 be superseded by dg_tol?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it can be the same

gains = meas.levels - lm.sine_dbfs;
sv = size(tc.volumes);
for j = 1:sv(2)
for i = 1:sv(1)
% Initial location to test

Choose a reason for hiding this comment

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

could you please add a space between ts = tc.vctimes(i)+tc.meas(1); as ts = tc.vctimes(i) + tc.meas(1);

% sof/tools/test/audio/test_utils/multitone.m
function x = multitone( fs, f, amp, tlength )
n = round(fs*tlength);
t = (0:n-1)/fs;

Choose a reason for hiding this comment

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

can you please add space for the operation t = (0:n-1)/fs; like t = (0:n-1) / fs;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but wouldn't then this be more consistent with even more spaces t = (0 : n - 1) / fs; ?

I admit I'm lazy to type spaces and this kind of not-all-spaces typed equations are everywhere. There is no Matlab style guide and e.g. "indent code" in Matlab IDE is not touching these. Also Octave Mode in Emacs differs from Matlab's indentations. But we can when applicable use SOF C style.

t = (0:n-1)/fs;
nf = length(f);
if nf > 1
ph = rand(nf, 1)*2*pi;

Choose a reason for hiding this comment

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

I think we can do a space for rand(nf, 1)2pi; like rand(nf, 1) * 2 * pi;


x = zeros(n, 1);
for i=1:length(f)
x = x + amp(i)*sin(2*pi*f(i)*t+ph(i))';
Copy link

@ShriramShastry ShriramShastry Mar 3, 2023

Choose a reason for hiding this comment

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

can you please a space for the equation x = x + amp(i) * sin(2 * pi *f(i) * t + ph(i))';

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 3, 2023

Kindly include space where it is needed.

There seems to be a couple matlab beautifiers available, @ShriramShastry can you please recommend one? If no formatter is good then at least some codestyle document reference. Consistency is good but it needs to be well defined, we cannot have codestyle discussions repeats in every pull request.

Also: please do NOT reformat every matlab file and destroy git history. We need a reference for new and modified code, not for old, unchanged code. Too late.
https://wiki.openstack.org/wiki/GitCommitMessages#Things_to_avoid_when_creating_commits

This patch delays the check window if the gain settling seems
to be still happening in the beginning of level check window.
The settling is detected with differential of gain.

The window means acceptance criteria over time as gain in
decibels. E.g. x milliseconds to y milliseconds, measured
gain within a +/- b decibels. The average gain from the measure
window is computed and compare to required. Any fail will
fail the entire test.

The differential of measured gain shows if the gain is constant
or changing. The added code is shifting the measurement window
to later in time if the gain is not constant in in the beginning.

The delay in gain settling can be caused by random alsamixer
controls apply delay. Also a very long gain ramp makes the settling
to appear later.

Signed-off-by: Seppo Ingalsuo <[email protected]>
If a test fails, it's easiest to examine the result graphically.
Pass to command line the failed wav files names and last argument
set to one to see the observed levels.

Signed-off-by: Seppo Ingalsuo <[email protected]>
Matlab requires switch - end, endswitch is not accepted.

Signed-off-by: Seppo Ingalsuo <[email protected]>
This patch adds local functions multitone() and level_dbfs() to
script check_volume_levels.m to avoid need for SOF repository.
The added functions are small and simple so the duplication is
not an issue.

Signed-off-by: Seppo Ingalsuo <[email protected]>
There's no functional changes, only added blanks between
arithmetic operations, comma separated lists, and ":" operator.

Signed-off-by: Seppo Ingalsuo <[email protected]>
@singalsu singalsu force-pushed the volume_levels_check_add_control_robustness branch from 1218c95 to 5eec116 Compare March 7, 2023 12:16
@singalsu
Copy link
Contributor Author

singalsu commented Mar 7, 2023

@ShriramShastry The last commit contains the style changes for non-impacted code. Sine generator style changes are in the commit that adds it.

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 10, 2023

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 13, 2023

@ShriramShastry all good now?
If there are any whitespace / style issues left they can addressed later. This PR has been under review for a few months now...

Only suspend/resume failures on one device in https://sof-ci.01.org/softestpr/PR985/build164/devicetest/index.html, everything else OK.

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 13, 2023

I learned that @ShriramShastry has been out of office. I looked at the changes since he last approved: https://github.com/thesofproject/sof-test/compare/d79bf2af7aeae751ff728c2585d37677f0663424..5eec1168b4ad26f19a744d69a00ea0fbe620eacf

I found only whitespace changes + this for loop change that he requested earlier https://github.com/thesofproject/sof-test/compare/d79bf2af7aeae751ff728c2585d37677f0663424..1218c95eaa5de33a300073367d823089c9f0b1e5

Merging.

@marc-hb marc-hb merged commit 32d9fe9 into thesofproject:main Mar 13, 2023
@marc-hb
Copy link
Collaborator

marc-hb commented Mar 14, 2023

@singalsu if you have a deterministic reproduction without this PR please file a new sof-test bug with complete reproduction steps.

I will but it requires merge of this PR. The script does not proceed to last line where sof-kernel-log-check.sh is called if there is a test fail. Or in other words the Matlab part of test always fails without this improvement. Somehow things (controls) happen in DUT slower than before and failure rate is 100%. Also we don't have tests for control latencies trend, as an idea for future.

@singalsu can you still reproduce?

@marc-hb
Copy link
Collaborator

marc-hb commented Apr 17, 2023

SOF_TEST_TOP_PID=17709 already defined just spotted in totally unrelated:

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.

6 participants