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

Software mixer configuration #1411

Open
iVolt1 opened this issue Feb 1, 2022 · 5 comments
Open

Software mixer configuration #1411

iVolt1 opened this issue Feb 1, 2022 · 5 comments

Comments

@iVolt1
Copy link

iVolt1 commented Feb 1, 2022

Resolved, see below.

Hi. Thanks for the great project any help that can be provided here.

I have been trying for days to get a working software volume control for my DietPi JustBoom Digi Zero DAC local audio output. The DAC does not have hardware volume controls and I have not had luck with various versions of softvol, dmix etc. There are very few references as to how the three device/mixer names in asound.conf should map to the also config in /etc/owntone.conf.

Local audio output

audio {
nickname = "Computer"
# Type of the output (alsa, pulseaudio, dummy or disabled)
type = "alsa"
# Audio PCM device name for local audio output - ALSA only
card = "???"
# Mixer channel to use for volume control - ALSA only
# If not set, PCM will be used if available, otherwise Master.
mixer = "???"
# Mixer device to use for volume control - ALSA only
# If not set, the value for "card" will be used.
mixer_device = "???"
...
}

There is a reat write up in using dmix at https://github.com/owntone/owntone-server/blob/master/README_ALSA.md but it does not go into using a software volume control, however it does go into using an equalizer which is something the JustBoom Digi Zero is capable of so I may eventually go that route.

This is the softvol suggestion on the JustBoom website for the Digi Zero that I have not been able to get a working mixer with. It shows how to use it for mpd and shairport-sync but I would think something similar would work for owntone although I did try many permutations of the config without success.

Create or edit /etc/asound.conf or ~/.asound.conf to contain the following:

pcm.softvol {
type softvol
slave {
pcm "plughw:" # Typically device number 0 (if onboard audio is disabled) or else device number 1
}
control {
name "softvol-mixer" # The name of your mixer-device in /etc/mpd.conf
card 0
}
}

pcm.!default {
type plug
slave.pcm "softvol"
}

Then edit the audio output section of /etc/mpd.conf to contain the following:

audio_output {
type "alsa"
name "JustBoom Digi Zero"
device "softvol"
mixer_type "software"
mixer_device "softvol-mixer"
}

This will allow you to adjust the output level from the digital output and prevent clipping as it might occur in your DAC.

To make this work with Shairport-sync, enter the following as your Alsa output device:

alsa =
{
output_device = "softvol";
}

@ejurgensen
Copy link
Member

I understand your question is what values to use for card, mixer and mixer_device in the config file? I don't really have the answer, ALSA can be pretty tricky, but I wanted to mention that if you set the log level to "info" then OwnTone's log should list available cards and mixers on startup. Perhaps that helps?

@iVolt1
Copy link
Author

iVolt1 commented Feb 2, 2022

Thanks for the reply. I know the alsa asound.conf is tricky and I have read about everything I can to get software volume control working. I am hoping someone can use this information to get a working software volume control even for a a DCA that does have mixer pvolume control.

Shairport-sync will default to software mixing if there is no hardware pvolume control available, so that code may be of help.

MPD configurations are similar to owntone's and I tried to follow the MPD software volume asound.conf example at https://wiki.debian.org/mpd, but could not get it to take in owntone. MPD even has a mixer type for software mixing.

I get 'no mixers found' for the JustBoom Digi Zero and a cmedia USB DAC that I have:

[ INFO] laudio: Available ALSA playback mixer(s) on hw:0 CARD=sndrpijustboomd (snd_rpi_justboom_digi): (no mixers found)

They both have mixers per amixer but neither has pvolume capability. This is for the Digi Zero:

root@DietPi:# amixer
Simple mixer control 'Tx Source',0
Capabilities: enum
Items: 'S/PDIF RX' 'AIF'
Item0: 'AIF'
root@DietPi:
#

Specifying some kind of hardware mixer seems to be a requirement for local audio to function in owntone, so here I set mixer = "Tx Source" even though it does not have pvolume. This configuration works, but there is no volume control in the web interface. I also tried a DragonFly Black DAC that has hardware pvolume control and volume control worked in the web interface.

Local audio output

audio {
# Name - used in the speaker list in Remote
nickname = "Computer"

    # Type of the output (alsa, pulseaudio, dummy or disabled)
    type = "alsa"

    # Mixer channel to use for volume control - ALSA only
    # If not set, PCM will be used if available, otherwise Master.
    mixer = "Tx Source"

    # Mixer device to use for volume control - ALSA only
    # If not set, the value for "card" will be used.
    mixer_device = "hw:0"

}

Thanks again!

@iVolt1
Copy link
Author

iVolt1 commented Feb 2, 2022

I found a working configuration thanks to this discussion and links:
mikebrady/shairport-sync#651
https://github.com/hifiberry/beocreate-tools/blob/master/enable-hifiberry
https://gist.github.com/tuomashamalainen/9667641007564892c491a8173fa4d11c

The key mappings are:
card = "softvol" is them name from 'pcm.softvol'.
mixer = "Master" is the name from 'name "Master"'.
mixer_device = "hw:0" is the original card hardware name 'hw:0".

Local audio output:
audio {

Name - used in the speaker list in Remote

nickname = "Computer"

# Type of the output (alsa, pulseaudio, dummy or disabled)
type = "alsa"

# Audio PCM device name for local audio output - ALSA only
card = "softvol"
# Mixer channel to use for volume control - ALSA only
# If not set, PCM will be used if available, otherwise Master.
mixer = "Master"

# Mixer device to use for volume control - ALSA only
# If not set, the value for "card" will be used.
mixer_device = "hw:0"

}

With the asound.conf below amixer could find the mixer:

root@DietPi:# amixer
Simple mixer control 'Master',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 255
Front Left: 145 [57%]
Front Right: 145 [57%]
Simple mixer control 'Tx Source',0
Capabilities: enum
Items: 'S/PDIF RX' 'AIF'
Item0: 'AIF'
root@DietPi:
#

asound.conf:

pcm.JustBoomDigiZero {
type hw
card 0
device 0
}
pcm.dmixer {
type dmix
ipc_key 1024
ipc_perm 0666
slave.pcm "JustBoomDigiZero"
slave {
period_time 0
period_size 5513
buffer_size 22052
rate 44100
}
bindings {
0 0
1 1
}
}
ctl.dmixer {
type hw
card 0
}
pcm.softvol {
type softvol
slave.pcm "dmixer"
control {
name "Master"
card 0
}
min_dB -90.2
max_dB 0.0
}
pcm.!default {
type plug
slave.pcm "softvol"
}

These
period_size 5513
buffer_size 22052
were derived from running:
sox -n -c 2 -r 44100 -b 16 -C 128 /tmp/sine441.wav synth 30 sin 500-100 fade h 0.2 30 0.2
immediately followed by this which makes a descending tone which may be loud:
aplay -v -Dhw:0 /tmp/sine441.wav

There is good discussion on volume scale in the first link above. I have kept these at what were in the second link.
min_dB -90.2
max_dB 0.0

The name JustBoomDigiZero is just a placeholder that is not expressed elsewhere so can be anything you want.

It looks like no code changes are needed for software volume in owntone. Maybe defaulting to software mixing if hardware mixing like shairport would be a good thing to help users not have to go through all this extra configuration. Otherwise I hope this will help add to the owntone alsa documentation.

Thanks again for helping me work though this.

@wangdongfreesky
Copy link

I have the same problem as him, but it hasn't been resolved. I hope we can solve the problem without hardware volume control. Very urgent

@wangdongfreesky
Copy link

wangdongfreesky commented May 4, 2024

It is recommended to add a software mixer to the local audio, as for sound cards without volume control, this is completely impossible in Docker @ejurgensen

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

No branches or pull requests

3 participants