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

Audio: Volume: Fix ongoing gain ramp stop and wrong final gain #8950

Merged
merged 5 commits into from
Apr 11, 2024

Conversation

singalsu
Copy link
Collaborator

In IPC4 the individual channel gains are passed in separate messages. One channel may have started to ramp to a new gain while a new channel gain arrives for other channel. If the gain is same as the previous control value, the ongoing ramp is stopped and the gain remains at a transition value.

@singalsu
Copy link
Collaborator Author

Draft - there's also other bug to fix with no ramp happening at times.

}

for (i = 0; i < channels_count; i++) {
if (cd->volume[i] != cd->tvolume[i])
Copy link
Member

Choose a reason for hiding this comment

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

"In IPC4 the individual channel gains are passed in separate messages."

Is this really something we want to support?

I don't really see how this might work if someone wants to e.g. implement a pan effect by moving a sound from the left to the right in a continuous motion?

Isn't it a classic requirement that such changes need to be handled in an 'atomic' way where all parameters are updated at the same time?

Maybe my perception is twisted by attending SDCA meetings where such volume/EQ changes are handled with a 'commit register' with all parameters flipped at once. Or I must be missing something...

Copy link
Collaborator Author

@singalsu singalsu Mar 18, 2024

Choose a reason for hiding this comment

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

We could have a new "linux volume" component with different UUID to overcome this limitation while "gain" can be kept as-is an IPC4 compatible. The peakvolume/gain also has overhead from unused features in Linux.

There is already support for mute switch (that Windows is not using) that can control any number of channels atomically. The same kind of ALSA mixercontrol (vs. gain/peakvolume set large config) could control the volume with no delays from channel to channel. But this would need a new kernel.

@singalsu
Copy link
Collaborator Author

Still, checking but looks like MCPS is not impacted. But need more tests to be sure.

Here's switch control before and after:
Screenshot from 2024-03-18 19-06-46
Screenshot from 2024-03-18 18-38-39

controls were

amixer cset name='Dmic0 Capture Switch' on
sleep 1
amixer cset name='Dmic0 Capture Switch' on,on,on,off
sleep 1
amixer cset name='Dmic0 Capture Switch' on,on,off,off
sleep 1
amixer cset name='Dmic0 Capture Switch' on,off,off,off
sleep 1
amixer cset name='Dmic0 Capture Switch' off,off,off,off
sleep 1
amixer cset name='Dmic0 Capture Switch' off,off,off,on
sleep 1
amixer cset name='Dmic0 Capture Switch' off,off,on,on
sleep 1
amixer cset name='Dmic0 Capture Switch' off,on,on,on
sleep 1
amixer cset name='Dmic0 Capture Switch' on,on,on,on
sleep 1
amixer cset name='Dmic0 Capture Switch' off


Here's volume control before and after:
Screenshot from 2024-03-18 18-43-38
Screenshot from 2024-03-18 18-37-55

controls were

amixer cset name='Post Mixer Analog Playback Volume' 45
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 45,40
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 40,45
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 0
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 45
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 1,45
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 45,1
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 45
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 40,38
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 39,41
sleep 1
amixer cset name='Post Mixer Analog Playback Volume' 45

@singalsu singalsu force-pushed the fix_gain_channels_fail branch 2 times, most recently from 38b9400 to 4211121 Compare March 20, 2024 15:50
@singalsu singalsu marked this pull request as ready for review March 21, 2024 09:01
In IPC4 the individual channel gains are passed in separate
messages. One channel may have started to ramp to a new gain
while a new channel gain arrives for other channel. If the
gain is same as the previous control value, the ongoing ramp
is stopped and the gain remains at a transition value.

The incorrect code is not fixed but instead the volume_set_volume()
function is simplified. When a volume control is received, it is
assumed that pass-through mode is disabled and ramp is prepared. If
the control is received but gains are not changed, the ramp mode
is finished and pass-through is restored in ramp function.

The volume_set_switch() function is updated similarly to ensure
similar operation.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The linear slope coefficient calculation is moved to a separate
function. Two functional changes are done.

- The ramp_coef for channel is set to zero if there is no
  transition for the channel. The ensure of non-zero coefficient
  is only needed if there is a transition that is so slow that
  the slope coefficient would round to zero. If this function is
  called for equal volume and tvolume for channel, the ramp_coef
  remains zero, and not smallest non-zero value.
- The handling of ramp disable with zero initial_ramp is changed
  to similar as for windows fade. The set of coefficient to
  volume delta (a large value for large volume jump) is not correct
  even if it appeared to work. It is a remain from old code where
  ramp was not a function of time but a constant step added.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The "is_same_volume=true" was returned if target volumes for
all channels are the same. The check omitted the fact that
start volumes for ramp can be different, e.g. one channel is
attenuated while others are 0 dB.

This change fixes the random ignore of volume ramp and smooth
transition when a volume control is changed.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This ensures that volume for a channel changes immediately
after receiving the control if ramp duration is zero or if
type is no fade.

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
The volume process function for pass-through can be changed
when all ramps are completed. This change that avoids processing
function lookup in worst case every 128 us is measured to
save in TGL platform about 1 MCPS from CPU_PEAK(MAX).

Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
@singalsu
Copy link
Collaborator Author

singalsu commented Apr 5, 2024

No updates, just rebase to restart CI.

@singalsu singalsu requested a review from lyakh April 5, 2024 07:43
Copy link
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Looks great!

src/audio/volume/volume_ipc4.c Show resolved Hide resolved
src/audio/volume/volume.c Show resolved Hide resolved
src/audio/volume/volume.c Show resolved Hide resolved
@kv2019i
Copy link
Collaborator

kv2019i commented Apr 10, 2024

@wszypelt The quildbuild check seems to be stuck, can you check?

@wszypelt
Copy link

@kv2019i Sure, I'm already looking into it

@kv2019i
Copy link
Collaborator

kv2019i commented Apr 10, 2024

@singalsu Hmm, SDW MTL config has failed in SOF driver CI runs and when I look back, the same SDW target failed in previous PR testing (build ids 39443 and 39061 ). At the same time, SDW MTL passes for other PRs at least today. so this is somewhat suspicious. Let me trigger the SOF CI once more.

@kv2019i
Copy link
Collaborator

kv2019i commented Apr 10, 2024

SOFCI TEST

@singalsu
Copy link
Collaborator Author

singalsu commented Apr 11, 2024

@singalsu Hmm, SDW MTL config has failed in SOF driver CI runs and when I look back, the same SDW target failed in previous PR testing (build ids 39443 and 39061 ). At the same time, SDW MTL passes for other PRs at least today. so this is somewhat suspicious. Let me trigger the SOF CI once more.

It shows "NotTested" for SDW. Strange if it runs for other PRs!

@kv2019i
Copy link
Collaborator

kv2019i commented Apr 11, 2024

Now passing, proceeding with merge.

@kv2019i kv2019i merged commit b6aa921 into thesofproject:main Apr 11, 2024
44 of 45 checks passed
@singalsu singalsu deleted the fix_gain_channels_fail branch August 21, 2024 08:04
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