Skip to content

Commit

Permalink
Add 2 channel intermediate PCM
Browse files Browse the repository at this point in the history
This allows us to use ALSA automatic mono -> stereo conversions.
  • Loading branch information
linknum23 committed Mar 15, 2023
1 parent 4359361 commit c074116
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
80 changes: 32 additions & 48 deletions config/asound.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,57 +85,41 @@ pcm.dmixer {
# Attenuate to 28% to avoid amplifier clipping
# For now leaving at 64% to maximize SNR before the amplifiers, and to leave
# some headroom for per-zone attenuation settings
# A 2 channel intermediate PCM layer is added to each plug output below
# this enables automatic mono -> stereo conversions since
# ALSA does not understand how to convert mono to 8 channels.
# In that case the mono input would be mapped to the first (left) channel,
# with nothing playing out the right channel.
pcm.ch1 {
type plug
slave.pcm "dmixer"
slave.channels 8
ttable.0.6 0.64
ttable.1.7 0.64
type plug
slave.pcm {
type route
slave.pcm "dmixer"
slave.channels 8
ttable.0.6 0.64
ttable.1.7 0.64
}
slave.channels 2
}
pcm.ch2 {
type plug
slave.pcm "dmixer"
slave.channels 8
ttable.0.0 0.64
ttable.1.1 0.64
type plug
slave.pcm {
type route
slave.pcm "dmixer"
slave.channels 8
ttable.0.0 0.64
ttable.1.1 0.64
}
slave.channels 2
}
pcm.ch3 {
type plug
slave.pcm "dmixer"
slave.channels 8
ttable.0.4 0.64
ttable.1.5 0.64
}

# Duplicate mono streams to stereo
# - `speaker-test` only plays one mono output at a time
# - fmradio.py only proceses mono and alsa cannot automatically map
# to stereo for syntetic outputs ch1, ch2, and ch3
pcm.ch0m2s {
type route
slave.pcm "ch0"
slave.channels 2
ttable.0.0 1
ttable.0.1 1
}
pcm.ch1m2s {
type route
slave.pcm "ch1"
slave.channels 2
ttable.0.0 1
ttable.0.1 1
}
pcm.ch2m2s {
type route
slave.pcm "ch2"
slave.channels 2
ttable.0.0 1
ttable.0.1 1
}
pcm.ch3m2s {
type route
slave.pcm "ch3"
slave.channels 2
ttable.0.0 1
ttable.0.1 1
type plug
slave.pcm {
type route
slave.pcm "dmixer"
slave.channels 8
ttable.0.4 0.64
ttable.1.5 0.64
}
slave.channels 2
}
2 changes: 1 addition & 1 deletion streams/fmradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def main():
# alsa output stage
# - convert mono output -> stereo using alsa routes chXm2s
# - normally mono conversion happens automatically but only the left channel was playing for ch1, ch2, and ch3
aplay_args = ['aplay', '-r', '171000', '-f', 'S16_LE', '--device', f'{args.output}m2s']
aplay_args = ['aplay', '-r', '171000', '-f', 'S16_LE', '--device', f'{args.output}']

rtlfm_proc = subprocess.Popen(args=rtlfm_args, bufsize=1024, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
redsea_proc = subprocess.Popen(args=redsea_args, bufsize=1024, stdin=rtlfm_proc.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down

0 comments on commit c074116

Please sign in to comment.