4

In Sound Settings I can choose between analogue and digital output. When I choose "Digital Output (S/PDIF)" I have to decrease the volume every time after I boot up. What could I do for saving these settings automatically (at shut down)?

These are the settings when I shut down:

enter image description here

And it looks like this after booting:

enter image description here

What becomes saved automatically is whether I chose analogue or digital output, and also the volume settings of analogue output become stored.

Card and Chip, Settings

I don't use an extra sound card; I have the ASRock M3N78D mainboard and lshw prints following:

*-multimedia
          Beschreibung: Audio device
          Produkt: MCP72XE/MCP72P/MCP78U/MCP78S High Definition Audio
          Hersteller: NVIDIA Corporation
          Physische ID: 7
          Bus-Informationen: pci@0000:00:07.0
          Version: a1
          Breite: 32 bits
          Uhr: 66MHz
          Fähigkeiten: pm bus_master cap_list
          Konfiguration: driver=snd_hda_intel latency=0 maxlatency=5 mingnt=2
          Ressourcen: irq:21 memory:fbd78000-fbd7bfff

Starting alsamixer shows me "Chip: VIA VT1718S".

This is the output from aplay -l:

**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: NVidia [HDA NVidia], Gerät 0: VT1718S Analog [VT1718S Analog]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
Karte 0: NVidia [HDA NVidia], Gerät 1: VT1718S Digital [VT1718S Digital]
  Sub-Geräte: 0/1
  Sub-Gerät #0: subdevice #0
Karte 0: NVidia [HDA NVidia], Gerät 2: VT1718S HP [VT1718S HP]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0

This is output from pactl stat:

Server-Name: pulseaudio
Server-Version: 1.1
Standard-Sample-Angabe: s16le 2ch 44100Hz
Standard-Kanalzuordnung: front-left,front-right
Standard-Sink: alsa_output.pci-0000_00_07.0.iec958-stereo
Standard-Quelle: alsa_input.pci-0000_00_07.0.analog-stereo

This is the output from amixer:

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback 0 - 42
  Mono: Playback 0 [0%] [-63.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 42
  Mono:
  Front Left: Playback 42 [100%] [0.00dB] [on]
  Front Right: Playback 42 [100%] [0.00dB] [on]
Simple mixer control 'PCM',0
  Capabilities: pvolume penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 253 [99%] [0.40dB]
  Front Right: Playback 253 [99%] [0.40dB]
Simple mixer control 'PCM Loopback',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 24 [77%] [1.50dB] [off]
  Front Right: Playback 24 [77%] [1.50dB] [off]
Simple mixer control 'Front',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 42
  Mono:
  Front Left: Playback 39 [93%] [-4.50dB] [on]
  Front Right: Playback 39 [93%] [-4.50dB] [on]
Simple mixer control 'Front Mic',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [12.00dB] [off]
  Front Right: Playback 31 [100%] [12.00dB] [off]
Simple mixer control 'Front Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 3 [100%] [30.75dB]
  Front Right: 3 [100%] [30.75dB]
Simple mixer control 'Surround',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 42
  Mono:
  Front Left: Playback 42 [100%] [0.00dB] [on]
  Front Right: Playback 42 [100%] [0.00dB] [on]
Simple mixer control 'Center',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback 0 - 42
  Mono: Playback 42 [100%] [0.00dB] [on]
Simple mixer control 'LFE',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined penum
  Playback channels: Mono
  Limits: Playback 0 - 42
  Mono: Playback 42 [100%] [0.00dB] [on]
Simple mixer control 'Side',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 42
  Mono:
  Front Left: Playback 42 [100%] [0.00dB] [on]
  Front Right: Playback 42 [100%] [0.00dB] [on]
Simple mixer control 'Line',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'CD',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958 Default PCM',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 28 [90%] [25.50dB] [on]
  Front Right: Capture 28 [90%] [25.50dB] [on]
Simple mixer control 'Capture',1
  Capabilities: cvolume cswitch penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 31
  Front Left: Capture 0 [0%] [-16.50dB] [on]
  Front Right: Capture 0 [0%] [-16.50dB] [on]
Simple mixer control 'Digital',0
  Capabilities: cvolume penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 120
  Front Left: Capture 60 [50%] [0.00dB]
  Front Right: Capture 60 [50%] [0.00dB]
Simple mixer control 'Dynamic Power-Control',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Independent HP',0
  Capabilities: enum
  Items: 'OFF' 'ON'
  Item0: 'OFF'
Simple mixer control 'Input Source',0
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line' 'CD' 'Stereo Mixer'
  Item0: 'Front Mic'
Simple mixer control 'Input Source',1
  Capabilities: cenum
  Items: 'Front Mic' 'Rear Mic' 'Line' 'CD' 'Stereo Mixer'
  Item0: 'Stereo Mixer'
Simple mixer control 'Loopback Mixing',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Rear Mic',0
  Capabilities: pvolume pswitch penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 31 [100%] [12.00dB] [off]
  Front Right: Playback 31 [100%] [12.00dB] [off]
Simple mixer control 'Rear Mic Boost',0
  Capabilities: volume penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]

Oddities

When I switch to "Analogue Output" while listening to music, the speakers connected to the digital output can be used, too, but then the volume is by 100% and I can't adjust it - only when I switch back to "Digital Output" or if I use alsamixer and dim "PCM".

When I choose "Digital Output" in Audio Settings and start alsamixer, changing the "Master" volume doesn't have any impact. "S/PDIF" and "S/PDIF D" are shown there, too, but both are set to "00" and I can't modify them ...

When I adjust the volume to a normal level (i.e. 40%) and run sudo alsactl store and reboot, the volume icon in the panel doesn't show 100%, but the sound comes with 100% - until I scroll down above the icon: Then it jumps immediately to 39%.

Oyibo
  • 1,917
Jakob
  • 10,789

4 Answers4

2

I've got the same problem. Analog is saved/restored but SPDIF is always the full blow after startup. I'm not particularly fond of a workaround of setting the volume to zero or low at login as I'm mostly annoyed by the startup sound at the login screen, blowing out my windows. I haven't really found the solution, but things got better. This is what I did:

  • I thought maybe the problem originates from the fact the analog output is device 0 of card 0, while digital is device 1 (of card 0). (XiFi chip or something) and store/restore procedure only stores the first. However alsactl store/restore (re)stores the 'complete' state with all the volume levels.
  • I concluded its alsa not saving/restoring the state of the spdif output (card:0, device:1) as 'alsactl store' / '... restore' has no effect on the spdif channel. It remains where its at.
  • running 'alsactl store' after selecting SPDIF in the sound control panel gives me a different /var/lib/alsa/asouns.state file. Not sure what this leads to but maybe alsa sees different volume controls depending on which output is selected in the control panel?
  • alsactl -f /var/lib/alsa/asound.state store seems to work (gives me a new asouns.state)
  • alsactl -f /var/lib/alsa/asound.state restore gives me: "alsactl: set_control:1464: Cannot write control '2:0:0:IEC958 Playback Default:0' : Operation not permitted"
  • I figured out IEC958 is the is indeed the digital output.
  • Stopped my music player: Error dissapeared
  • installed pavucontrol, selected default output
  • removed /var/lib/alsa/asound.state
  • reboot
  • volume slider is now restored on a restart, actual volume is not it seems

Maybe it helps someone.. at least remove your asound.state and see if it helps.

0

I don't know of any way to do this "properly", but you might be able to add a startup script to do the job. Using the program "amixer", I can produce output that lists the settings of the sound outputs between 0 and 64, including the "Master" channel. Right before shutting down, this could be parsed (using regex perhaps?) to store the volume in a file. When the system is booted again, the command "amixer set CHANNEL VALUE" could be issued to set the volume to the stored value.

By adding this to a shell script (typically a startup job in /etc/init.d) you could have it done automatically, which should make it appear seamless. I've used these startup scripts before to do other things, and I see no reason at all why it couldn't solve your problem as well.

Details:

The first step would be to create a shell script that is capable of changing the volume. At present I do not have the time nor all the detailed knowledge to write it for you, but if you know a bit about scripting, or if you can find a good tutorial, it shouldn't be that hard. I will be glad to help out if you have problems. Below is a template that you can use.

#! /bin/sh

start(){
    # This function is called on startup
    # This is where you will need to read the volume from a file and call amixer
}

stop(){
    # This function is called on shutdown
    # This is where amixer is called and the volume is saved to file
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    *)
        echo "Usage: avolumesaver {start|stop}"
        exit 1
esac

exit 0

Basically the start function is called whenever the system is started, and the stop function is called before shutting down. You can do whatever you need inside those functions. You should open an editor as root ("sudo gedit" at the terminal) and then save the file as "/etc/init.d/avolumesaver". After doing so, you will need to issue the following commands:

chmod a+x /etc/init.d/avolumesaver
update-rc.d avolumesaver defaults

The first line will make the script executable. The second line converts it into an upstart job. Technically, this simply means that some symbolic links are created, but it is a good idea to use update-rc.d and not try to add the links yourself.

After doing this, you can edit /etc/init.d/avolumesaver until you have achieved what you want. You can test the functionality without actually rebooting by issuing the following command (after making it an upstart job):

service avolumesaver start
service avolumesaver stop
Kalle Elmér
  • 9,216
0

I've asked similiar question here. Maybe it could help.

It sets volume level to a particular value after every login. It works with PulseAudio and digital output.

  1. Copy default pulse config file to your home location:

    cp /etc/pulse/default.pa ~/.pulse

  2. In your config file locate the following line:

    load-module module-always-sink

    Immediately after the above line, add the following line:

    set-sink-volume 0 {your-volume-level-here}

    Volume level is a number in a range 0..65535. For example:

    set-sink-volume 0 32768

0

I'm hoping this will help someone out.. I've always had this issue and i just fixed it on ubuntu 13:10 (Pear Os 8). inside the /etc/pulse/default.pa file there is a line to select alsa sink..that is the key for me.This is what i had to change mine to to make it save volumes...

### Load audio drivers statically
### (it's probably better to not load these drivers manually, but instead
### use module-udev-detect -- see below -- for doing this automatically)
load-module module-alsa-sink
load-module module-alsa-sink device=hw:0,1
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#load-module module-null-sink
#load-module module-pipe-sink

Now on the line load-module module-alsa-sink device=hw:0,1 you may have to change your PCM location using aplay -l examples here https://wiki.archlinux.org/index.php/PulseAudio/Examples

your numbers will be hw:X(card number),X(Device Number)

I hope others read this and get their sound working as this has been a huge pain for me for years.