Hifi Shield 2 hardware volume control

Moderators: mdrjr, odroid

Hifi Shield 2 hardware volume control

Unread postby gkkpch » Tue Dec 27, 2016 2:19 am

Hi,
Is there a way to limit hardware volume on Hifi Shield 2 to avoid serious clipping and distortion?
Currently using Volumio (which uses amixer) let's you go up to 100%, which corresponds to an amixer volume level way higher than 0dB (201).
I would like the driver to be changed in such a way, that amixer uses values between 0 and 255 but actually uses 0 dB as 100%
Nobody should go over 0dB anyway and from my experience the Hifi Shield/ Shield Plus don't have this issue.
Could you do this for us, or otherwise, can you show us how/where to change the driver code ourselves?

-Gé-
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby cap00k » Tue Dec 27, 2016 12:12 pm

https://github.com/hardkernel/linux/blo ... #L233-L234

SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2,
PCM512x_DIGITAL_VOLUME_3, 0, 207, 1, digital_tlv),

Its volume control range is -103dB ~ +24dB in 0.5dB step.
Refer the datasheet Page 45.
http://www.ti.com/lit/ds/symlink/pcm5242.pdf

It is not easy to make a simple formula equation.
cap00k
 
Posts: 52
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Mon Feb 06, 2017 2:24 am

Finally had the time to implement this, works like a charm.
Thanks!!

- Gé --
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Thu Feb 09, 2017 1:44 am

gkkpch wrote:Finally had the time to implement this, works like a charm.
Thanks!!

- Gé --

Actually it does not work like a charm (forgot to swithc to digital), it does not have any effect.
What could be wrong?
The application uses amixer and just raises it back to 255, blasting the amp if you're not careful.
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby john8329 » Sat Feb 11, 2017 10:44 am

I too would like to limit the volume. Has anyone got this working? I can figure out how to compile the driver myself but ideally would like confirmation before I started down that path.

John
john8329
 
Posts: 19
Joined: Mon Feb 16, 2015 11:39 pm
languages_spoken: english

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Fri Feb 17, 2017 6:20 am

I have been experimenting with the volume limit set in the driver to 207 (supposed to be ~0dB).
The DAC would still play at full blast with distortion, so just to make sure I lowered from

Code: Select all
SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2,
PCM512x_DIGITAL_VOLUME_3, 0, 207, 1, digital_tlv),

to
Code: Select all
SOC_DOUBLE_R_TLV("Digital Playback Volume", PCM512x_DIGITAL_VOLUME_2,
PCM512x_DIGITAL_VOLUME_3, 0, 160, 1, digital_tlv),

and did
Code: Select all
 volumio@volumio:~$ amixer -c 1 sset Digital 120
Simple mixer control 'Digital',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 160
  Mono:
  Front Left: Playback 120 [75%] [-43.50dB] [on]
  Front Right: Playback 120 [75%] [-43.50dB] [on]

it shows me a setting for 120 out of 160, already a bit loud but no distortion.
Then changed to 100%
Code: Select all
volumio@volumio:~$ amixer -c 1 sset Digital 160
Simple mixer control 'Digital',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 160
  Mono:
  Front Left: Playback 160 [100%] [-23.50dB] [on]
  Front Right: Playback 160 [100%] [-23.50dB] [on]


This looks OK, limited to 160 at 100% but the problem is, the DAC blasts at full volume with heavy distortion proving the setting does nothing!
I expect there is an error in the driver and as we use Digital out in Volumio, people do not consider this acceptable.
Could someone at Hardkernel please investigate this?

-- Gé --
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby odroid » Fri Feb 17, 2017 2:08 pm

We will check it early next week.
User avatar
odroid
Site Admin
 
Posts: 23637
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Hifi Shield 2 hardware volume control

Unread postby cap00k » Mon Feb 20, 2017 11:04 am

It is a setting value for audio measurement of HiFi-Shield2 in the link.
http://www.hardkernel.com/main/products/prdt_info.php?g_code=G147589529288
Code: Select all
root@odroid:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ODROIDHDMI [ODROID-HDMI], device 0: SPDIF PCM dit-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: ODROIDDAC2 [ODROID-DAC2], device 0: aml i2s pcm512x-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@odroid:~# amixer -c 1 sset Analogue 0
Simple mixer control 'Analogue',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 1
  Mono:
  Front Left: Playback 0 [0%] [-6.00dB]
  Front Right: Playback 0 [0%] [-6.00dB]
root@odroid:~# amixer -c 1 sset Digital 201
Simple mixer control 'Digital',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 255
  Mono:
  Front Left: Playback 201 [79%] [-3.00dB] [on]
  Front Right: Playback 201 [79%] [-3.00dB] [on]
root@odroid:~# amixer -c 1 sset Deemphasis on
Simple mixer control 'Deemphasis',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
root@odroid:~#

It is also a recommended setting.
The HW gain of the op-amp connected to the RCA output is about +10 dB.

Hardware volume/mixer settings
Analogue : -6.00 dB (amixer -c 1 sset Analogue 0)
Digital : -3.00 dB (amixer -c 1 sset Digital 201)
Deemphasis Filter : On (amixer -c 1 sset Deemphasis on)

Software volume settings
Volumio UI volume : software volume 100 (maximum full scale)
cap00k
 
Posts: 52
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: ODROID

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Mon Feb 20, 2017 7:51 pm

Perhaps you missed my point, I'm well aware of the settings.
Reality is, that any application (like ours) can use amixer to increase and decrease volume.
That said, you can use scale 1-255, so "amixer -c 1 sset Digital 255" will still set to a level way higher than should be.
Even when you limit the driver to 207 as was suggested.
That leads me to the conclusion, something is not working the way it should.
Our digital volume control works with all known DACs on other platforms.
With the Hifi Shield 2 on C2 it does not and we cannot adapt that for just one single DAC.

-- Gé --
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby odroid » Tue Feb 21, 2017 1:57 pm

Let's clarify the terms first.

Software volume control in audio rendering software
Digital volume control in the DAC HW
Analog volume control in the DAC HW

Do you mean the Analog volume control should support from 0 to 100 without distortion/clamping?
User avatar
odroid
Site Admin
 
Posts: 23637
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Hifi Shield 2 hardware volume control

Unread postby barturblits » Wed Feb 22, 2017 10:19 am

Same safety concern here.
I am reading up on dac's and alsa control, and if I understand correctly, audio professionals need dacs with higher sensitivy than consumers for recording purposes. Seems some dacs have hard sensitivity switches for -10dB (consumer/playback) and + 4dB (professional/recording). Our dac seems to be configured for (or not protected against) high sensitive professional recording. For consumer playback I would like a safer option, some kind of hardcoded 0dB gain limit in the kernel (module). Might be an idea to have two kernel variants or only use the professional gain settings in the rt kernel. I suspect you can change it with DECLARE_TLV_DB_SCALE but I have no idea what values to use. More reading first.

Edit:

They had the same problems with the pcm512x with the pi.
it looks like they first hard coded it to 0dB but later they introduced a manual override parameter to make it possible to get the +24dB gain.

src and example patch:
http://forums.slimdevices.com/showthrea ... (alsa-only)/page292&highlight=SqueezeLite
https://github.com/respeaker/lede/blob/ ... h-Hi.patch
barturblits
 
Posts: 51
Joined: Fri Jan 06, 2017 6:33 pm
languages_spoken: english, dutch, german

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Wed Mar 08, 2017 8:03 am

I meant Digital Volume control, it really needs to be limited to 0dB.
This is what normal use requires, we cannot use the +24dB gain TI implemented as it only leads to very heavy distortion.
Currently we have no way to limit the the amlogic driver going up to +24dB.
It renders Volumio's volume levels for ODROIDDAC2 uncontrollable
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby barturblits » Wed Mar 08, 2017 9:43 pm

I did some reading on pro and consumer audio and I can only conclude that HK made a mistake. Or they should have given the hifi hield 2 balanced XLR output connectors when using +24dB / +4dBU OR they should have set the output to 0dB / -10dBV when using RCA. I cannot find any equipment which accepts +24dB on RCA. II also looked at converters but they are all balanced XLR +24dB / +4dBU to unbalanced RCA 0dB / -10dBV and vice versa. There are no RCA +24dB / +4dBU to RCA 0dB / -10dBV converters. So it seems like a production error.
barturblits
 
Posts: 51
Joined: Fri Jan 06, 2017 6:33 pm
languages_spoken: english, dutch, german

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Fri Mar 10, 2017 4:03 am

@barturblits: luckily it is not a hardware issue. I tested a driver patch with limiting the volume through "snd_soc_limit_volume" and the problem is now eliminated as far as I can judge.
This what I get now, no distortion, no clipping.
Code: Select all
volumio@volumio:~$ amixer sget Digital -c 1
Simple mixer control 'Digital',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 207
  Mono:
  Front Left: Playback 207 [100%] [0.00dB] [on]
  Front Right: Playback 207 [100%] [0.00dB] [on]

A Volumio test version with a patched DAC2 driver for C2 is now available on http://oph.mdrjr.net/gkkpch/

@odroid: I prepared the following patch for 3.14.79, could someone please please verifiy this and include?

Code: Select all
diff --git a/sound/soc/aml/m8/odroid_dac2.c b/sound/soc/aml/m8/odroid_dac2.c
index fb8c153..72edb3c 100644
--- a/sound/soc/aml/m8/odroid_dac2.c
+++ b/sound/soc/aml/m8/odroid_dac2.c
@@ -50,6 +50,24 @@
 
 #define DRV_NAME "odroid_dac2"
 
+static bool digital_gain_0db_limit = true;
+
+static int odroid_dac2_init(struct snd_soc_pcm_runtime *rtd)
+{
+       if (digital_gain_0db_limit)
+       {
+               int ret;
+               struct snd_soc_card *card = rtd->card;
+               struct snd_soc_codec *codec = rtd->codec;
+
+               ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
+               if (ret < 0)
+                       dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
+       }
+
+       return 0;
+}
+
 static int dac2_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
@@ -104,6 +122,7 @@ static struct snd_soc_dai_link dac2_dai_link[] = {
                .codec_name = "pcm512x.1-004c",
                .codec_dai_name = "pcm512x-hifi",
                .ops = &odroid_ops,
+               .init = odroid_dac2_init,
        },
 };
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Sat Mar 11, 2017 2:59 am

Nearly identical patch for C1+

Code: Select all
diff --git a/sound/soc/aml/m8/odroid_dac2.c b/sound/soc/aml/m8/odroid_dac2.c
index 81f98ec..f4eaf32 100644
--- a/sound/soc/aml/m8/odroid_dac2.c
+++ b/sound/soc/aml/m8/odroid_dac2.c
@@ -56,6 +56,24 @@
 
 #define DRV_NAME "odroid_dac2"
 
+static bool digital_gain_0db_limit = true;
+
+static int odroid_dac2_init(struct snd_soc_pcm_runtime *rtd)
+{
+       if (digital_gain_0db_limit)
+       {
+               int ret;
+               struct snd_soc_card *card = rtd->card;
+               struct snd_soc_codec *codec = rtd->codec;
+
+               ret = snd_soc_limit_volume(codec, "Digital Playback Volume", 207);
+               if (ret < 0)
+                       dev_warn(card->dev, "Failed to set volume limit: %d\n", ret);
+       }
+
+       return 0;
+}
+
 static int dac2_hw_params(struct snd_pcm_substream *substream,
     struct snd_pcm_hw_params *params)
 {
@@ -209,6 +227,7 @@ static struct snd_soc_dai_link dac2_dai_link[] = {
         .codec_name = "pcm512x.1-004c",
         .codec_dai_name = "pcm512x-hifi",
         .ops = &odroid_ops,
+        .init = odroid_dac2_init,
     },
 };
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby barturblits » Sat Mar 11, 2017 5:34 am

Successfully tested with volumio and ubuntu, Hifi Shield 2 now rocks :-D.
Changed the systemd file accordingly in Ubuntu, disabled pulse and now directly on alsa.
barturblits
 
Posts: 51
Joined: Fri Jan 06, 2017 6:33 pm
languages_spoken: english, dutch, german

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Sat Mar 18, 2017 7:13 am

Noticed C2 kernel has been patched 2 days ago, many thanks!
Now waiting for the C1+ ;) (nearly identical patch)
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby gkkpch » Tue Mar 21, 2017 9:43 pm

I noticed the C1+ kernel has been patched too, thanks!!
User avatar
gkkpch
 
Posts: 239
Joined: Mon Feb 25, 2013 11:47 pm
Location: Switzerland
languages_spoken: english, dutch, german
ODROIDs: Odroid-C1+, Odroid-C1+ HiFi shield, Odroid-C1, Odroid-X2

Re: Hifi Shield 2 hardware volume control

Unread postby odroid » Wed Mar 22, 2017 7:07 am

Thank you for the patches and confirmation. :D
User avatar
odroid
Site Admin
 
Posts: 23637
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID

Re: Hifi Shield 2 hardware volume control

Unread postby john8329 » Sun Apr 02, 2017 6:00 am

Thanks to both of you...it is nice to have the full volume range now on my arch linux mpd server!
john8329
 
Posts: 19
Joined: Mon Feb 16, 2015 11:39 pm
languages_spoken: english


Return to HiFi Shield DAC

Who is online

Users browsing this forum: No registered users and 1 guest