diff options
author | Dana Conrad <dconrad@fastmail.com> | 2021-07-31 10:15:12 -0500 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-08-07 14:21:47 +0000 |
commit | 16b009825608164b17dabd877c78123a667b4981 (patch) | |
tree | e7c88e07ddadff4b62802f561e8c9a83c90ae925 /firmware | |
parent | 57293f1fd9d091145059293d88bb15c8749bb596 (diff) | |
download | rockbox-16b009825608164b17dabd877c78123a667b4981.tar.gz rockbox-16b009825608164b17dabd877c78123a667b4981.zip |
ErosQ Native: Add DC Offset to PCM data
A small negative offset seems to silence all
play/pause clicking on the PCM5102A.
Also adding PCM soft muting, and muting the headphone amp
when the headphones are detected as removed. This has been
tested to not cause any unintended side effects on the
line out.
Also confirmed the numerical dB values are (approx.) correct.
Change-Id: I689d68887c86add9cc5e0ccb0c7de01aaa69b4d9
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/audio/eros_qn_codec.c | 24 | ||||
-rw-r--r-- | firmware/export/eros_qn_codec.h | 3 | ||||
-rw-r--r-- | firmware/pcm_sw_volume.c | 4 |
3 files changed, 31 insertions, 0 deletions
diff --git a/firmware/drivers/audio/eros_qn_codec.c b/firmware/drivers/audio/eros_qn_codec.c index 21347f5fca..fdf21d2f9d 100644 --- a/firmware/drivers/audio/eros_qn_codec.c +++ b/firmware/drivers/audio/eros_qn_codec.c | |||
@@ -26,10 +26,14 @@ | |||
26 | #include "audiohw.h" | 26 | #include "audiohw.h" |
27 | #include "settings.h" | 27 | #include "settings.h" |
28 | #include "pcm_sw_volume.h" | 28 | #include "pcm_sw_volume.h" |
29 | #include "gpio-x1000.h" | ||
29 | 30 | ||
30 | static long int vol_l_hw = 0; | 31 | static long int vol_l_hw = 0; |
31 | static long int vol_r_hw = 0; | 32 | static long int vol_r_hw = 0; |
32 | 33 | ||
34 | /* internal: mute the headphone amp. 0 - unmuted, 1 - muted */ | ||
35 | void audiohw_mute_hp(int mute); | ||
36 | |||
33 | void pcm5102_set_outputs(void) | 37 | void pcm5102_set_outputs(void) |
34 | { | 38 | { |
35 | audiohw_set_volume(vol_l_hw, vol_r_hw); | 39 | audiohw_set_volume(vol_l_hw, vol_r_hw); |
@@ -53,13 +57,33 @@ void audiohw_set_volume(int vol_l, int vol_r) | |||
53 | if (lineout_inserted() && !headphones_inserted()) | 57 | if (lineout_inserted() && !headphones_inserted()) |
54 | { | 58 | { |
55 | l = r = global_settings.volume_limit * 10; | 59 | l = r = global_settings.volume_limit * 10; |
60 | |||
61 | /* mute the headphone amp if not plugged in */ | ||
62 | audiohw_mute_hp(1); | ||
56 | } | 63 | } |
57 | else | 64 | else |
58 | { | 65 | { |
66 | /* unmute the headphone amp when plugged in */ | ||
67 | audiohw_mute_hp(0); | ||
59 | l = vol_l; | 68 | l = vol_l; |
60 | r = vol_r; | 69 | r = vol_r; |
61 | } | 70 | } |
62 | #endif | 71 | #endif |
63 | 72 | ||
73 | l = l <= PCM5102A_VOLUME_MIN ? PCM_MUTE_LEVEL : l; | ||
74 | r = r <= PCM5102A_VOLUME_MIN ? PCM_MUTE_LEVEL : r; | ||
75 | |||
64 | pcm_set_master_volume(l, r); | 76 | pcm_set_master_volume(l, r); |
65 | } | 77 | } |
78 | |||
79 | void audiohw_mute_hp(int mute) | ||
80 | { | ||
81 | if (mute == 0) | ||
82 | { | ||
83 | gpio_set_level(GPIO_MAX97220_SHDN, 1); | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | gpio_set_level(GPIO_MAX97220_SHDN, 0); | ||
88 | } | ||
89 | } | ||
diff --git a/firmware/export/eros_qn_codec.h b/firmware/export/eros_qn_codec.h index 15c745c04b..9c900186a8 100644 --- a/firmware/export/eros_qn_codec.h +++ b/firmware/export/eros_qn_codec.h | |||
@@ -26,6 +26,9 @@ | |||
26 | #define PCM5102A_VOLUME_MIN -740 | 26 | #define PCM5102A_VOLUME_MIN -740 |
27 | #define PCM5102A_VOLUME_MAX 0 | 27 | #define PCM5102A_VOLUME_MAX 0 |
28 | 28 | ||
29 | /* a small DC offset appears to prevent play/pause clicking */ | ||
30 | #define PCM_DC_OFFSET_VALUE -1 | ||
31 | |||
29 | AUDIOHW_SETTING(VOLUME, "dB", 0, 1, PCM5102A_VOLUME_MIN/10, PCM5102A_VOLUME_MAX/10, 0) | 32 | AUDIOHW_SETTING(VOLUME, "dB", 0, 1, PCM5102A_VOLUME_MIN/10, PCM5102A_VOLUME_MAX/10, 0) |
30 | 33 | ||
31 | /* this just calls audiohw_set_volume() with the last (locally) known volume, | 34 | /* this just calls audiohw_set_volume() with the last (locally) known volume, |
diff --git a/firmware/pcm_sw_volume.c b/firmware/pcm_sw_volume.c index 7322269f44..3593c684af 100644 --- a/firmware/pcm_sw_volume.c +++ b/firmware/pcm_sw_volume.c | |||
@@ -54,7 +54,11 @@ static typeof (memcpy) *pcm_scaling_fn = NULL; | |||
54 | /* Scale sample by PCM factor */ | 54 | /* Scale sample by PCM factor */ |
55 | static inline int32_t pcm_scale_sample(PCM_F_T f, int32_t s) | 55 | static inline int32_t pcm_scale_sample(PCM_F_T f, int32_t s) |
56 | { | 56 | { |
57 | #if defined(PCM_DC_OFFSET_VALUE) | ||
58 | return (f * s + PCM_DC_OFFSET_VALUE) >> PCM_SW_VOLUME_FRACBITS; | ||
59 | #else | ||
57 | return (f * s) >> PCM_SW_VOLUME_FRACBITS; | 60 | return (f * s) >> PCM_SW_VOLUME_FRACBITS; |
61 | #endif | ||
58 | } | 62 | } |
59 | 63 | ||
60 | /* Both UNITY, use direct copy */ | 64 | /* Both UNITY, use direct copy */ |