[How to do instruction] Loudness compensated volume control with CamillaDSP - Printable Version +- Moode Forum (https://moodeaudio.org/forum) +-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3) +--- Forum: FAQ and Guides (https://moodeaudio.org/forum/forumdisplay.php?fid=9) +--- Thread: [How to do instruction] Loudness compensated volume control with CamillaDSP (/showthread.php?tid=5112) |
Loudness compensated volume control with CamillaDSP - roderickvd - 10-10-2022 The human ear is not equally responsive across the audio range. It is more sensitive to mid-frequencies than to the lower and higher frequencies. This situation becomes more pronounced at low volume levels. This is exactly what a loudness compensated volume control does: the more the volume is turned down, the more the bass and treble are boosted so it sounds the same. [attachment=3001] [attachment=3003] This post shows how to implement such a volume control for a wide variety of audio renderers by using the Alsa dummy driver and the wonderful CamillaDSP that are all aboard on moOde already. The working principle is that the renderers set their volume in the dummy's mixer, which we continuously monitor with a script called dummyvol2cdsp, and forward to CamillaDSP using a websocket. And with this guide, it should sound more complicated than it really is :-) You must have SSH enabled and know your way around the command line. Set up Alsa dummy driver First, set up the Alsa dummy driver. Later we will use its mixer control as a proxy to CamillaDSP's volume filters. Code: # sudo su - Optional: make the dummy mixer control the system-wide default. This helps to immediately show the dummy mixer controls with amixer and alsamixer, for example. Code: # echo "defaults.ctl.card 0" >> /etc/alsa/conf.d/00-defaults.conf Now reboot and verify that the dummy driver is set up correctly: Code: # reboot Set up CamillaDSP loudness filters Now at the other end of the chain we add volume filters to CamillaDSP. You can use a Volume filter or a Loudness filter. The loudness filter in fact is a volume filter, but with extra parameters and functionality to apply loudness correction when the volume is lowered. The relevant configuration lines are as follows. Read on on how to configure this via the web interface. Code: devices: A few notes on these values:
CamillaDSP is now ready to get its volume settings over a websocket. We will get to that later. Set up audio renderers Warning: during this step turn your amplifier off! Risk of damage and/or injury! If you start playback, it will output at full volume and the volume slider will do nothing yet! AirPlay: Change the following lines in /etc/shairport-sync.conf. The lines are commented by the default, uncomment them. Code: mixer_control_name = “Master”; Spotify: Edit /var/www/inc/renderer.php. The first line you have to change, the second you have to add immediately after: Code: ' --mixer alsa' . MPD: I do not use MPD so am not certain. But editing /etc/mpd.conf like this should do it: Code: audio_output { Bluetooth: Not supported yet. It requires bluez-alsa v4.0.0 or higher: https://github.com/Arkq/bluez-alsa/pull/390 and moOde 8.2.1 has v3.0.0. In the meantime its software volume control works fine, just not with loudness correction. Others: Unknown, I do not use them. But if you find out, drop a reply and I will add it to this post! Set up dummyvol2cdsp dummvol2cdsp is a Python script that runs in the background, monitoring the dummy mixer control and forwards its volume setting to CamillaDSP over a websocket. It also provides a cubic volume control to maximise the usable range of the volume sliders. First install the pyalsaaudio library: Code: # sudo su - Now download `dummyvol2cdsp.py` from https://github.com/roderickvd/dummyvol2cdsp and put it somewhere. This guide assumes /home/pi/dummyvol2cdsp.py. At the top of the script, there are some user-configurable settings. The defaults should be sane. Don't forget to make the script executable, then launch it to start testing: Code: # chmod a+x /home/pi/dummyvol2cdsp.py Open another terminal, launch alsamixer and change the volume. You should now see the script printing lines like alsa=49% cubic=-50.5 dB. If it also prints along the lines of setting cdsp volume failed: [Errno 111] Connection refused, that means that CamillaDSP is not running yet. A likely cause is that playback has not started yet (regardless of whether an audio renderer is connected or not). If you see volume settings being printed without errors, then look at the CamillaDSP GUI via the web interface and change the volume again. Under Volume at the left, you should see the volume changes coming in. Now everything is working, hit Ctrl+C to exit. Then edit /etc/rc.local to launch dummyvol2cdsp in the background when booting. The following lines should just be before the final exit 0 at the bottom: Code: # Forward Alsa dummy mixer volume to CamillaDSP Finally, reboot and verify that volume changes are still being forwarded to CamillaDSP. If you have convinced yourself volume changes are coming in properly, you can now turn up the amplifier again -- in small steps, just as a final precaution. Congratulations, you have yourself a working loudness-corrected volume control! FAQ Q: Which volume type should I set in moOde's audio configuration? Hardware, software, anything else? A: For the supported renderers I do not think it really matters. Principally the dummy driver is a hardware control, but it is not related to the output device. MPD should be set to hardware, but still overwrites the mixer device with the output device instead of the dummy device. Q: How do I use my DAC's hardware volume control then? A: You cannot. CamillaDSP does this in software only. Here is the good news: sound-quality wise, that will the best. CamillaDSP uses a 64-bit floating point pipeline which is better than any DAC does in hardware. Then running your DAC at full line level will improve dynamic range to your amplifier (unless the connection is balanced, in which case it will not matter). You may only miss out on fancy readings from your DAC's display or comfort of using your DAC's remote. If anyone has any tips or tricks to share, please reply and I will add it to this post. RE: Loudness compensated volume control with CamillaDSP - Tim Curtis - 10-11-2022 Pretty cool :-) A loudness compensation feature for MPD and all the renderers is quite sophisticated and very desirable since Low Level Listening (LLL) is a common usage scenario. So basically we configure MPD and the renderers to use the ALSA Dummy device as mixer and then a daemon monitors it and proxies volume changes to Camilla, right? Is dummvol2cdsp in a Git repo? RE: Loudness compensated volume control with CamillaDSP - roderickvd - 10-11-2022 (10-11-2022, 02:26 AM)Tim Curtis Wrote: Pretty cool :-) A loudness compensation feature for MPD and all the renderers is quite sophisticated and very desirable since Low Level Listening (LLL) is a common usage scenario. Thanks! Certainly scratches my own itch and that of others too I imagine. I have always loudness correction that for its bass boost. Audyssey EQ pulls off the same trick, although a bit more sophisticated. I also thought about making a tight integration with moOde and its UI. Of course this would be a much larger effort. What do you think? Quote:So basically we configure MPD and the renderers to use the ALSA Dummy device as mixer and then a daemon monitors it and proxies volume changes to Camilla, right? Exactly. It could even be easier, but I would need your expertise with Alsa configuration files. Would it be possible to slave the dummy mixer control to the output device? In this case you could do it system-wide without touching any of the renderers. Quote:Is dummvol2cdsp in a Git repo? I will make it so tonight. If it helps I could do any or more of the following: - make it into a daemon - have it accept command line options or environment variables - parse variables from a configuration file Let me know. RE: Loudness compensated volume control with CamillaDSP - Tim Curtis - 10-11-2022 I don't have much experience with Camilla but what happens to volume without the Dummy mixer and volume proxy config? Isn't it still processed by Camilla before it outputs the PCM stream to the device? RE: Loudness compensated volume control with CamillaDSP - roderickvd - 10-11-2022 (10-11-2022, 10:33 AM)Tim Curtis Wrote: I don't have much experience with Camilla but what happens to volume without the Dummy mixer and volume proxy config? Isn't it still processed by Camilla before it outputs the PCM stream to the device? In that case CamillaDSP does no volume attenuation, and does all other processing at 0.0 dB. Before the PCM “enters” CamillaDSP it is up to the renderer to control the volume. Because CamillaDSP is a plug-in to Alsa and not an output device, it offers no Alsa mixer itself. RE: Loudness compensated volume control with CamillaDSP - Tim Curtis - 10-11-2022 (10-11-2022, 12:21 PM)roderickvd Wrote:(10-11-2022, 10:33 AM)Tim Curtis Wrote: I don't have much experience with Camilla but what happens to volume without the Dummy mixer and volume proxy config? Isn't it still processed by Camilla before it outputs the PCM stream to the device? I don't think Camilla is an ALSA plugin (LADSPA) but rather a standalone application that does DSP. On Linux it's fed by an ALSA output plugin named alsa-cdsp. My understanding is that its purpose is to automatically configure the correct source sample rate in Camilla when song files of varying sample rates are being played. I'm still a bit confused about volume handling though because Camilla can do things like EQ which manipulates volume and the Pipeline editor also has a volume Mixer tab. RE: Loudness compensated volume control with CamillaDSP - roderickvd - 10-11-2022 (10-11-2022, 02:41 PM)Tim Curtis Wrote:(10-11-2022, 12:21 PM)roderickvd Wrote:(10-11-2022, 10:33 AM)Tim Curtis Wrote: I don't have much experience with Camilla but what happens to volume without the Dummy mixer and volume proxy config? Isn't it still processed by Camilla before it outputs the PCM stream to the device? Yes and no:
Quote:I'm still a bit confused about volume handling though because Camilla can do things like EQ which manipulates volume and the Pipeline editor also has a volume Mixer tab. I can imagine. It may help to recognise that CamillaDSP's mixer is not the same as an Alsa mixer. In CamillaDSP:
[attachment=3005] In this screenshot you see CamillaDSP's current volume setting alongside the defined loudnessvol filter. How this works is that Loudness filter "listens" to this volume setting and does the actual attenuation. You could also have used a simple Volume filter of course: [attachment=3006] To reiterate, the volume setting at the top left (here: -21.2 dB) is just the setting. By itself it does not attenuation. It needs a filter for that, and the filter must be hooked into the pipeline. By default CamillaDSP's volume is set to 0.0 dB. It requires manipulation to make it anything else: be it the volume slider in CamillaDSP's GUI, be it dummyvol2cdsp or some other means. CamillaDSP does not provide a Alsa mixer control for volume control. Hopefully this clears things up? Let me know if you have any further questions. CamillaDSP is an amazing tool in the shed and I can heartily recommend it. RE: Loudness compensated volume control with CamillaDSP - roderickvd - 10-11-2022 GitHub repository for dummyvol2cdsp: https://github.com/roderickvd/dummyvol2cdsp. I updated the original post. RE: Loudness compensated volume control with CamillaDSP - Tim Curtis - 10-11-2022 Nice :-) Yes alsa-cdsp does not do resampling but IIRC it update the camilla config with the source sample rate before piping the output to Camilla because Camilla itself does not do sample rate switching on-the-fly. Correct? I love learning curves ;-) RE: Loudness compensated volume control with CamillaDSP - roderickvd - 10-12-2022 (10-11-2022, 11:44 PM)Tim Curtis Wrote: Yes alsa-cdsp does not do resampling but IIRC it update the camilla config with the source sample rate before piping the output to Camilla because Camilla itself does not do sample rate switching on-the-fly. Correct? CamillaDSP does rate detection itself (and so does switch on the fly). I believe that alsa-cdsp can help by "hinting" the incoming sample rate but it's not necessary. Do you think it is possible to slave the Alsa dummy mixer to _audioout? My asoundrc-fu is not up to par. |