This is an automated archive made by the Lemmit Bot.
The original was posted on /r/homeassistant by /u/byjosue113 on 2024-10-10 14:42:42+00:00.
I’m planning a home renovation and have whole house audio in my plans, but as you may know it is prohibitively expensive so I’ve been running tests with what I have, the initial idea was to use a separate amp per room and have an ESP32 using LMS but I tried using a NUC and separating the two channels in the jack output which worked well and you can easily run two instances of squeezelite for that purpose assigning one audio device to each instance.
But then for every 2 channels I’d need to get a DAC and also get a lot of amplifiers or a big amplifier with tons of outputs and then it came to my mind that I could just use an AV Receiver, if you have a 5.1 AVR you have 5 speakers or separate rooms you can power, and if it has more channels even more, the best part ? You get a DAC too, I just plugged a NUC with an HDMI cable to an AVR I have in the living room and it worked like a charm(after a whole afternoon of messing with it) so I decided to share how I did it, in case anyone on a tight budget wants to do something like that since I honestly did not find a ton of information about this topic.
Worth noting. I did this in a NUC running Ubuntu Server but any Linux distro should work fine I think. I also suggest having two command lines open so that you can edit the ALSA file in one and then run some commands we’ll need in the other.
1. Edit the ALSA file with the following command in your first terminal
nano ~/.asoundrc
- After connecting the AV Receiver to our machine we then run the following command in our second terminal, note that in case it does not run you may need to install
alsa-utils
aplay -l
That command should give you something like this:
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC283 Analog [ALC283 Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HISENSE]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
In my case the device I’m interested in is the HISENSE, yours may say a different name, we need the name after card 0
and the number after device, in this case PCH let’s call it device name and 3, let’s call it device number. I’m not sure if this changes from device to device, but just to be sure that’s how I did it.
3. In the ALSA File we’re going to paste this and substitute the values with got in the previous step:
pcm.shared_dmix {
type dmix
ipc_key 1024
slave {
pcm "hw:,"
channels 6 # 6 channels for 5.1 surround sound 8 channels for 7.1
}
}
4. Next step is to find which number is assigned to each channel, I think this may be standard, but better be sure, you can check that with the following command:
speaker-test -D hw:CARD=PCH,DEV=3 -c 6 -l 1
-D
-c
-l
For the device name just take what we got before and put it in that format or you can run aplay -L | grep DEV=
(Note the capital L
)and copy the one starting with hw:
Now this should give us the number of each channels as they are tested, like this:
Playback device is hw:CARD=PCH,DEV=3
Stream parameters are 48000Hz, S16_LE, 6 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 22 to 349525
Period size range from 11 to 174762
Using max buffer size 349524
Periods = 4
was set period_size = 87381
was set buffer_size = 349524
0 - Front Left
4 - Front Center
1 - Front Right
3 - Rear Right
2 - Rear Left
5 - LFE
Time per period = 10.968638
5. Now for the last step you can paste this template under the dmix in your ALSA file
# Zone 1 Front Left
pcm.zone_1 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
# Front Left (1.0)
ttable.1.0 1
}
}
# Zone 2 Front Right
pcm.zone_2 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
# Front Right (1.1)
ttable.1.1 1
}
}
# Zone 3 Center
pcm.zone_3 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
ttable.1.4 1
}
}
# Zone 4 Rear Left
pcm.zone_4 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
ttable.1.2 1
}
}
# Zone 5 Rear Right
pcm.zone_5 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
ttable.1.3 1
}
}
Here as you can see for each one of the zones we have a line ttable
, what we want to do is change the second number by the number of the channel you want to use for that given zone, this should work for a 5.1 system with 5 amplified channels(since the LFE channel just goes to the subwoofer).
This is how you use it:
ttable.v.s x
Where:
v
: Channel of the virtual device that the the other channel will be mapped to. Set to 0 unless you want to have two channels mapped to one virtual device for stereo. In that case you’d do it like this:
pcm.zone_1 {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix_51"
slave.channels 6
ttable.0.0 1 # Left fron channel mapped to left front channel
ttable.1.1 1 # Right fron channel mapped to right front channel
}
}
s
: Mapped channel from
x
: volume or influence of the channel, a value between 0 and 1, can be used to make sure you have even volume across speakers or simply to limit how loud the speakers can be and prevent damage to you amp or speakers.
Feel free to delete the comments I used to name each channel and also change the names of each zone.
Eg:
pcm.living_room {
type plug
slave.pcm {
type route
slave.pcm "shared_dmix"
slave.channels 6
ttable.0.1 1
}
}
This would use the front right speaker as a device named living_room
. To make sure they are working properly you can use the same command we used to get the audio channels. For this example you can run
speaker-test -D living_room -l 1
- All of that being said I’m no expert and this is just what I learned tinkering until I got something that worked, if you know more than I do and I messed up somewhere please let me know, I hope this is helpful to someone that’s looking to do something like this in a budget. I looked everywhere I could not find a way of achieving this so after digging for weeks I figured that I’d share it with the community.