Bug 374919

Summary: Volume Feedback doesn't work
Product: [Unmaintained] plasma-pa Reporter: jethawk
Component: generalAssignee: David Rosca <nowrep>
Status: RESOLVED FIXED    
Severity: normal CC: plasma-bugs-null
Priority: NOR    
Version First Reported In: 5.8.5   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 5.8.6
Sentry Crash Report:
Attachments: Notification Sounds

Description jethawk 2017-01-11 16:56:27 UTC
On my system with plasma-pa 5.8.5 there's no volume feedback when scrolling up/down mouse wheel over the applet icon. The Volume feedback option is checked. I have no problems with playing sound files and system notifications work fine too. Also, I can hear the tone when I run the following command:
$ canberra-gtk-play -i audio-volume-change -d "Volume Control Feedback Sound"
Comment 1 David Rosca 2017-01-11 17:00:04 UTC
It is played through "Notification Sounds" stream, so it must be unmuted and have non-zero volume.
Comment 2 jethawk 2017-01-11 17:09:44 UTC
Created attachment 103354 [details]
Notification Sounds

If I understand you correctly, Notification Sounds is set to 100% but still no tone I can hear. Please see the screen shot.
Comment 3 David Rosca 2017-01-11 17:11:42 UTC
Yes, that's correct. I'm not sure what might be wrong. Can you please run plasmashell in terminal and upload output when scrolling mouse over volume icon / using volume shortcuts?
Comment 4 jethawk 2017-01-11 17:29:09 UTC
Thanks for the very quick replies by the way!
I restarted plasmashell from the terminal and see absolutely nothing when scrolling the mouse wheel. I also tried to run plasmawindowed org.kde.plasma.volume. Same thing. No output when scrolling.
Comment 5 jethawk 2017-01-11 21:36:48 UTC
I spent a little time playing with volumefeedback.cpp and recompiling plasma-pa. Suddenly, reassigning sinkIndex to 0 in void VolumeFeedback::play(quint32 sinkIndex) seem to help:

char dev[64];
sinkIndex = 0; // <---
snprintf(dev, sizeof(dev), "%lu", (unsigned long) sinkIndex);
ca_context_change_device(m_context, dev);

Didn't investigate that further though... Any ideas?
Comment 6 David Rosca 2017-01-11 21:40:33 UTC
You can try to add a debug statement and print the sinkIndex that it tries to use, and check which sink it is with "pactl list sinks".

It should play the volume feedback on the "preferred sink" - the device that is displayed in applet tooltip and is controlled with volume shortcuts.
Comment 7 jethawk 2017-01-11 21:56:22 UTC
Ok, tried to print sinkIndex. It's always equal to 2 in my case.
Meanwhile, pactl list sinks shows the following:

Sink #0
        State: SUSPENDED
        Name: alsa_output.pci-0000_00_1b.0.analog-stereo
        Description: Built-in Audio Analog Stereo
        Driver: module-alsa-card.c
        Sample Specification: s16le 2ch 44100Hz
        Channel Map: front-left,front-right
        Owner Module: 8
        Mute: no
        Volume: front-left: 49151 /  75% / -7.50 dB,   front-right: 49151 /  75% / -7.50 dB
                balance 0.00
        Base Volume: 65536 / 100% / 0.00 dB
        Monitor Source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
        Latency: 0 usec, configured 0 usec
        Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
        Properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = "ALC272 Analog"
                alsa.id = "ALC272 Analog"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "1"
                alsa.card_name = "HDA Intel PCH"
                alsa.long_card_name = "HDA Intel PCH at 0xe9614000 irq 34"
                alsa.driver_name = "snd_hda_intel"
                device.bus_path = "pci-0000:00:1b.0"
                sysfs.path = "/devices/pci0000:00/0000:00:1b.0/sound/card1"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "8c20"
                device.product.name = "8 Series/C220 Series Chipset High Definition Audio Controller"
                device.form_factor = "internal"
                device.string = "front:1"
                device.buffering.buffer_size = "352800"
                device.buffering.fragment_size = "176400"
                device.access_mode = "mmap+timer"
                device.profile.name = "analog-stereo"
                device.profile.description = "Analog Stereo"
                device.description = "Built-in Audio Analog Stereo"
                alsa.mixer_name = "Realtek ALC272"
                alsa.components = "HDA:10ec0272,17aa367b,00100002"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        Ports:
                analog-output-speaker: Speakers (priority: 10000)
                analog-output-headphones: Headphones (priority: 9000, not available)
        Active Port: analog-output-speaker
        Formats:
                pcm
Comment 8 jethawk 2017-01-12 14:14:26 UTC
Let me share a bit more of my findings about the issue.
According to applet/contents/ui/main.qml it seems that playFeedback() function is called each time we increase/decrease volume.
In playFeedback() sinkIndex = sinkModel.preferredSink.cardIndex when no args are passed to the function.

In PA I have Card #2 and alsa_output.pci-0000_00_1b.0.analog-stereo is the default sink:

$ pacmd list-sinks 
1 sink(s) available.
  * index: 0
        name: <alsa_output.pci-0000_00_1b.0.analog-stereo>
        driver: <module-alsa-card.c>
        flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE 
        priority: 9959
        volume: front-left: 55705 /  85% / -4.24 dB,   front-right: 55705 /  85% / -4.24 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 0
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 1837.50 ms
        card: 2 <alsa_card.pci-0000_00_1b.0>
...

$ pactl info
...
Default Channel Map: front-left,front-right
Default Sink: alsa_output.pci-0000_00_1b.0.analog-stereo
Default Source: alsa_input.pci-0000_00_1b.0.analog-stereo
...

So I suppose this is why I get sinkIndex = 2 and things don't work for me. What do you think?
Comment 9 David Rosca 2017-01-12 14:20:49 UTC
Yes, that's it, thanks for the investigation! :)

Changing sinkModel.preferredSink.cardIndex to sinkModel.preferredSink.index in playFeedback() in applet code should fix it.
Comment 10 David Rosca 2017-01-12 14:52:30 UTC
https://phabricator.kde.org/D4105
Comment 11 jethawk 2017-01-12 15:00:58 UTC
Thanks for the suggestion! sinkModel.preferredSink.index in playFeedback() fix did the trick on my system. It was a big challenge for me to dig into the code with absolutely no experience in C++/Qt! :D
Comment 12 David Rosca 2017-01-24 12:12:46 UTC
Git commit 27c8c9aa84b42640bbc65ea64f15cbdf4b6705e3 by David Rosca.
Committed on 12/01/2017 at 14:51.
Pushed by drosca into branch 'Plasma/5.8'.

Pass correct index to playFeedback

It expects index of the sink, not card index.
FIXED-IN: 5.8.6

Differential Revision: https://phabricator.kde.org/D4105

M  +1    -1    applet/contents/ui/ListItemBase.qml
M  +1    -1    applet/contents/ui/main.qml

https://commits.kde.org/plasma-pa/27c8c9aa84b42640bbc65ea64f15cbdf4b6705e3