summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/pcm_sw_volume.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/firmware/pcm_sw_volume.c b/firmware/pcm_sw_volume.c
index bcd498fe46..473e63c7cb 100644
--- a/firmware/pcm_sw_volume.c
+++ b/firmware/pcm_sw_volume.c
@@ -40,9 +40,9 @@ static int pcm_dbl_buf_num = 0;
40static size_t frame_size; 40static size_t frame_size;
41static unsigned int frame_count, frame_err, frame_frac; 41static unsigned int frame_count, frame_err, frame_frac;
42 42
43static int32_t vol_factor_l = 0, vol_factor_r = 0;
43#ifdef AUDIOHW_HAVE_PRESCALER 44#ifdef AUDIOHW_HAVE_PRESCALER
44static int32_t prescale_factor = PCM_FACTOR_UNITY; 45static int32_t prescale_factor = PCM_FACTOR_UNITY;
45static int32_t vol_factor_l = 0, vol_factor_r = 0;
46#endif /* AUDIOHW_HAVE_PRESCALER */ 46#endif /* AUDIOHW_HAVE_PRESCALER */
47 47
48/* pcm scaling factors */ 48/* pcm scaling factors */
@@ -223,25 +223,30 @@ static int32_t pcm_centibels_to_factor(int volume)
223 return 0; /* mute */ 223 return 0; /* mute */
224 224
225 /* Centibels -> fixedpoint */ 225 /* Centibels -> fixedpoint */
226 return fp_factor(PCM_FACTOR_UNITY*volume / 10, PCM_FACTOR_BITS); 226 return fp_factor(fp_div(volume, 10, PCM_FACTOR_BITS), PCM_FACTOR_BITS);
227} 227}
228 228
229#ifdef AUDIOHW_HAVE_PRESCALER
230/* Produce final pcm scale factor */ 229/* Produce final pcm scale factor */
231static void pcm_sync_prescaler(void) 230static void pcm_sync_prescaler(void)
232{ 231{
233 int32_t factor_l = fp_mul(prescale_factor, vol_factor_l, PCM_FACTOR_BITS); 232 int32_t factor_l = vol_factor_l;
234 int32_t factor_r = fp_mul(prescale_factor, vol_factor_r, PCM_FACTOR_BITS); 233 int32_t factor_r = vol_factor_r;
234#ifdef AUDIOHW_HAVE_PRESCALER
235 factor_l = fp_mul(prescale_factor, factor_l, PCM_FACTOR_BITS);
236 factor_r = fp_mul(prescale_factor, factor_r, PCM_FACTOR_BITS);
237#endif
235 pcm_factor_l = PCM_FACTOR_CLIP(factor_l); 238 pcm_factor_l = PCM_FACTOR_CLIP(factor_l);
236 pcm_factor_r = PCM_FACTOR_CLIP(factor_r); 239 pcm_factor_r = PCM_FACTOR_CLIP(factor_r);
237} 240}
238 241
242#ifdef AUDIOHW_HAVE_PRESCALER
239/* Set the prescaler value for all PCM playback */ 243/* Set the prescaler value for all PCM playback */
240void pcm_set_prescaler(int prescale) 244void pcm_set_prescaler(int prescale)
241{ 245{
242 prescale_factor = pcm_centibels_to_factor(-prescale); 246 prescale_factor = pcm_centibels_to_factor(-prescale);
243 pcm_sync_prescaler(); 247 pcm_sync_prescaler();
244} 248}
249#endif /* AUDIOHW_HAVE_PRESCALER */
245 250
246/* Set the per-channel volume cut/gain for all PCM playback */ 251/* Set the per-channel volume cut/gain for all PCM playback */
247void pcm_set_master_volume(int vol_l, int vol_r) 252void pcm_set_master_volume(int vol_l, int vol_r)
@@ -250,15 +255,3 @@ void pcm_set_master_volume(int vol_l, int vol_r)
250 vol_factor_r = pcm_centibels_to_factor(vol_r); 255 vol_factor_r = pcm_centibels_to_factor(vol_r);
251 pcm_sync_prescaler(); 256 pcm_sync_prescaler();
252} 257}
253
254#else /* ndef AUDIOHW_HAVE_PRESCALER */
255
256/* Set the per-channel volume cut/gain for all PCM playback */
257void pcm_set_master_volume(int vol_l, int vol_r)
258{
259 int32_t factor_l = pcm_centibels_to_factor(vol_l);
260 int32_t factor_r = pcm_centibels_to_factor(vol_r);
261 pcm_factor_l = PCM_FACTOR_CLIP(factor_l);
262 pcm_factor_r = PCM_FACTOR_CLIP(factor_r);
263}
264#endif /* AUDIOHW_HAVE_PRESCALER */