10-10-2020, 04:14 AM
You can also throw software volume control in the mix for cards that don't have hardware volume control. If you upped the bit depth (not to be confused with upsampling) to the max the card can handle you can give yourself like 48 dB of headroom before you have to start throwing away bit. This is superior to librespot's builtin software volume because gain reduction and volume control is done in 16 bit therefor it throws away bits.
This is basically the asound.config I use but I just override default so it's system wide. I use the settings in the example because I run librespot on a pi zero and a hifiberry dac+ zero.
works like a charm.
the only thing that could be tricky is that there are 2 versions of 24 bit, S24_LE which is exactly what it looks like and S24_3LE which is mostly used by USB DACs.
Code:
###############################################################################
pcm.hqstereo20 {
@args [
SAMPLE_RATE FORMAT SAMPLE_RATE_CONVERTER
BUFFER_PERIODS BUFFER_PERIOD_TIME VOL_MIN_DB
VOL_MAX_DB VOL_RESOLUTION VOL_NAME
]
# Sampling rate in Hz:
# 44100, 48000, 88200, 96000...
# Defaults to 44.1 kHz (CD Quality).
@args.SAMPLE_RATE {
type integer
default 44100
}
# Format:
# S16_LE, S24_LE, S24_3LE, S32_LE...
# Defaults to S16_LE (CD Quality).
@args.FORMAT {
type string
default S16_LE
}
# Resampling algorithm.
# Defaults to samplerate_linear.
@args.SAMPLE_RATE_CONVERTER {
type string
default samplerate_linear
}
# Periods per buffer.
@args.BUFFER_PERIODS {
type integer
default 4
}
# Period size in time.
# Defaults to 125ms (0.125 sec).
# BUFFER_PERIODS * BUFFER_PERIOD_TIME = buffer time/size
@args.BUFFER_PERIOD_TIME {
type integer
default 125000
}
# Minimal dB value of the software volume control.
@args.VOL_MIN_DB {
type real
default -51.0
}
# Maximal dB value of the software volume control.
@args.VOL_MAX_DB {
type real
default 0.0
}
# How many steps between min and max volume.
@args.VOL_RESOLUTION {
type integer
default 256
}
# The name of the software volume control.
# If your card does not have hardware volume control
# naming it PCM will cause most apps that use alsa volume
# to use the software volume control.
@args.VOL_NAME {
type string
default Softvol
}
type plug
rate_converter $SAMPLE_RATE_CONVERTER
slave {
channels 2
rate $SAMPLE_RATE
format $FORMAT
pcm {
type softvol
min_dB $VOL_MIN_DB
max_dB $VOL_MAX_DB
resolution $VOL_RESOLUTION
control {
name $VOL_NAME
card {
@func refer
name defaults.ctl.card
}
}
slave {
format $FORMAT
pcm {
type dmix
ipc_key 1024
ipc_perm 0660
ipc_gid audio
slowptr true
hw_ptr_alignment roundup
slave {
pcm {
type hw
card {
@func refer
name defaults.pcm.card
}
device {
@func refer
name defaults.pcm.device
}
subdevice {
@func refer
name defaults.pcm.subdevice
}
channels 2
rate $SAMPLE_RATE
format $FORMAT
}
channels 2
period_size 0
buffer_size 0
buffer_time 0
period_time $BUFFER_PERIOD_TIME
periods $BUFFER_PERIODS
rate $SAMPLE_RATE
format $FORMAT
}
bindings {
0 0
1 1
}
}
}
}
}
}
###############################################################################
# Change to the card number or name that you want to be the default control card.
# Default: 0
defaults.ctl.card 0
# Change to the card number or name that you want to be the default playback card.
# It should usually be the same as defaults.ctl.card.
# Default: 0
defaults.pcm.card 0
# Change to the device number that you want to be the default device on the default card.
# 0 or 1 is usually the correct device number.
# Default: 0
defaults.pcm.device 0
# Change to the subdevice number that you want to be the default subdevice on the default device.
# Should rarely need to be changed.
# Default: -1
defaults.pcm.subdevice -1
pcm.spotify {
type plug
# Optional args:
# SAMPLE_RATE: default: 44100
# FORMAT: default: S16_LE
# SAMPLE_RATE_CONVERTER: default: samplerate_linear
# BUFFER_PERIODS: default: 4
# BUFFER_PERIOD_TIME: default: 125000
# VOL_MIN_DB: default: -51.0
# VOL_MAX_DB: default: 0.0
# VOL_RESOLUTION: default: 256
# VOL_NAME: default: Softvol
# Example:
# hifiberry dac+ zero on a pi zero.
# slave.pcm "hqstereo20:FORMAT=S32_LE,BUFFER_PERIOD_TIME=250000,VOL_MIN_DB=-48.0,VOL_NAME=PCM"
slave.pcm "hqstereo20"
}
###############################################################################
This is basically the asound.config I use but I just override default so it's system wide. I use the settings in the example because I run librespot on a pi zero and a hifiberry dac+ zero.
works like a charm.
the only thing that could be tricky is that there are 2 versions of 24 bit, S24_LE which is exactly what it looks like and S24_3LE which is mostly used by USB DACs.