Hifi Shield 2 hardware volume control

Moderators: odroid, mdrjr

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: 227
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: 43
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: odroid-x2

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: 227
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: 227
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: 18
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: 227
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: 21357
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: 43
Joined: Tue May 21, 2013 10:46 am
languages_spoken: english
ODROIDs: odroid-x2

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: 227
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: 21357
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: 35
Joined: Fri Jan 06, 2017 6:33 pm
languages_spoken: english, dutch, german


Return to HiFi Shield DAC

Who is online

Users browsing this forum: No registered users and 1 guest