summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/erosqlinux_codec.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2021-04-08 23:58:49 -0400
committerSolomon Peachy <pizza@shaftnet.org>2021-04-08 23:58:49 -0400
commit1e2a9a651c26b7526530428b248132e02624bb84 (patch)
tree190d6e83db300c43481c62b94d2ff7d4cc59db08 /firmware/drivers/audio/erosqlinux_codec.c
parente86d90905be290ff24a774e9687eca3236953490 (diff)
downloadrockbox-1e2a9a651c26b7526530428b248132e02624bb84.tar.gz
rockbox-1e2a9a651c26b7526530428b248132e02624bb84.zip
erosq: Switch to 32-bit PCM output, and do volume scaling in driver
Should improve audio output quality, especially at lower volumes. Change-Id: I31c38f05fe4b554b092511f0fe7aaad9f346f6c5
Diffstat (limited to 'firmware/drivers/audio/erosqlinux_codec.c')
-rw-r--r--firmware/drivers/audio/erosqlinux_codec.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c
index b1c5aa0c4f..58104a61e6 100644
--- a/firmware/drivers/audio/erosqlinux_codec.c
+++ b/firmware/drivers/audio/erosqlinux_codec.c
@@ -169,6 +169,10 @@ void audiohw_set_frequency(int fsel)
169 (void)fsel; 169 (void)fsel;
170} 170}
171 171
172/* min/max for pcm volume */
173const int min_pcm = -430;
174const int max_pcm = 0;
175
172void audiohw_set_volume(int vol_l, int vol_r) 176void audiohw_set_volume(int vol_l, int vol_r)
173{ 177{
174 logf("hw vol %d %d", vol_l, vol_r); 178 logf("hw vol %d %d", vol_l, vol_r);
@@ -179,7 +183,7 @@ void audiohw_set_volume(int vol_l, int vol_r)
179 vol_r_hw = vol_r; 183 vol_r_hw = vol_r;
180 184
181 if (lineout_inserted()) { 185 if (lineout_inserted()) {
182 /* On the EROS Q/K hardware, line out is _very_ hot 186 /* On the EROS Q/K hardware, full scale line out is _very_ hot
183 at ~5.8Vpp. As the hardware provides no way to reduce 187 at ~5.8Vpp. As the hardware provides no way to reduce
184 output gain, we have to back off on the PCM signal 188 output gain, we have to back off on the PCM signal
185 to avoid blowing out the signal. 189 to avoid blowing out the signal.
@@ -190,10 +194,9 @@ void audiohw_set_volume(int vol_l, int vol_r)
190 r = vol_r_hw; 194 r = vol_r_hw;
191 } 195 }
192 196
193 /* SW volume for <= 1.0 gain, HW at unity, < -740 == MUTE */ 197 int sw_volume_l = l <= min_pcm ? min_pcm : MIN(l, max_pcm);
194 int sw_volume_l = l <= -740 ? PCM_MUTE_LEVEL : MIN(l, 0); 198 int sw_volume_r = r <= min_pcm ? min_pcm : MIN(r, max_pcm);
195 int sw_volume_r = r <= -740 ? PCM_MUTE_LEVEL : MIN(r, 0); 199 pcm_set_mixer_volume(sw_volume_l / 10, sw_volume_r / 10);
196 pcm_set_master_volume(sw_volume_l, sw_volume_r);
197} 200}
198 201
199void audiohw_set_lineout_volume(int vol_l, int vol_r) 202void audiohw_set_lineout_volume(int vol_l, int vol_r)
@@ -212,7 +215,7 @@ void audiohw_set_lineout_volume(int vol_l, int vol_r)
212 r = vol_r_hw; 215 r = vol_r_hw;
213 } 216 }
214 217
215 int sw_volume_l = l <= -740 ? PCM_MUTE_LEVEL : MIN(l, 0); 218 int sw_volume_l = l <= min_pcm ? min_pcm : MIN(l, max_pcm);
216 int sw_volume_r = r <= -740 ? PCM_MUTE_LEVEL : MIN(r, 0); 219 int sw_volume_r = r <= min_pcm ? min_pcm : MIN(r, max_pcm);
217 pcm_set_master_volume(sw_volume_l, sw_volume_r); 220 pcm_set_mixer_volume(sw_volume_l / 10, sw_volume_r / 10);
218} 221}