diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2013-04-23 21:33:55 -0400 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2013-04-23 21:33:55 -0400 |
commit | 21b62bd893b3be5e56b49d58f5cac7d9fb1300be (patch) | |
tree | 88b9c419216dbe1103a9ed449e48f194d2f6fc9e /firmware/pcm_sw_volume.c | |
parent | 4f2c0c1ed2c869f79e6cd6df3e346cdb0adce0fd (diff) |
Make pcm_sw_volume.c a bit less verbose by merging volume code.
pcm_set_master_volume had two implementations, one for a prescaler
and one without one but the differences can be made minimal enough
to combine them.
Change-Id: I889e60b50b9f046c093853cb1685058796fe9067
Diffstat (limited to 'firmware/pcm_sw_volume.c')
-rw-r--r-- | firmware/pcm_sw_volume.c | 27 |
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; static size_t frame_size; static unsigned int frame_count, frame_err, frame_frac; +static int32_t vol_factor_l = 0, vol_factor_r = 0; #ifdef AUDIOHW_HAVE_PRESCALER static int32_t prescale_factor = PCM_FACTOR_UNITY; -static int32_t vol_factor_l = 0, vol_factor_r = 0; #endif /* AUDIOHW_HAVE_PRESCALER */ /* pcm scaling factors */ @@ -223,25 +223,30 @@ static int32_t pcm_centibels_to_factor(int volume) return 0; /* mute */ /* Centibels -> fixedpoint */ - return fp_factor(PCM_FACTOR_UNITY*volume / 10, PCM_FACTOR_BITS); + return fp_factor(fp_div(volume, 10, PCM_FACTOR_BITS), PCM_FACTOR_BITS); } -#ifdef AUDIOHW_HAVE_PRESCALER /* Produce final pcm scale factor */ static void pcm_sync_prescaler(void) { - int32_t factor_l = fp_mul(prescale_factor, vol_factor_l, PCM_FACTOR_BITS); - int32_t factor_r = fp_mul(prescale_factor, vol_factor_r, PCM_FACTOR_BITS); + int32_t factor_l = vol_factor_l; + int32_t factor_r = vol_factor_r; +#ifdef AUDIOHW_HAVE_PRESCALER + factor_l = fp_mul(prescale_factor, factor_l, PCM_FACTOR_BITS); + factor_r = fp_mul(prescale_factor, factor_r, PCM_FACTOR_BITS); +#endif pcm_factor_l = PCM_FACTOR_CLIP(factor_l); pcm_factor_r = PCM_FACTOR_CLIP(factor_r); } +#ifdef AUDIOHW_HAVE_PRESCALER /* Set the prescaler value for all PCM playback */ void pcm_set_prescaler(int prescale) { prescale_factor = pcm_centibels_to_factor(-prescale); pcm_sync_prescaler(); } +#endif /* AUDIOHW_HAVE_PRESCALER */ /* Set the per-channel volume cut/gain for all PCM playback */ void 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) vol_factor_r = pcm_centibels_to_factor(vol_r); pcm_sync_prescaler(); } - -#else /* ndef AUDIOHW_HAVE_PRESCALER */ - -/* Set the per-channel volume cut/gain for all PCM playback */ -void pcm_set_master_volume(int vol_l, int vol_r) -{ - int32_t factor_l = pcm_centibels_to_factor(vol_l); - int32_t factor_r = pcm_centibels_to_factor(vol_r); - pcm_factor_l = PCM_FACTOR_CLIP(factor_l); - pcm_factor_r = PCM_FACTOR_CLIP(factor_r); -} -#endif /* AUDIOHW_HAVE_PRESCALER */ |