mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
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
This commit is contained in:
parent
4f2c0c1ed2
commit
21b62bd893
1 changed files with 10 additions and 17 deletions
|
@ -40,9 +40,9 @@ static int pcm_dbl_buf_num = 0;
|
||||||
static size_t frame_size;
|
static size_t frame_size;
|
||||||
static unsigned int frame_count, frame_err, frame_frac;
|
static unsigned int frame_count, frame_err, frame_frac;
|
||||||
|
|
||||||
|
static int32_t vol_factor_l = 0, vol_factor_r = 0;
|
||||||
#ifdef AUDIOHW_HAVE_PRESCALER
|
#ifdef AUDIOHW_HAVE_PRESCALER
|
||||||
static int32_t prescale_factor = PCM_FACTOR_UNITY;
|
static int32_t prescale_factor = PCM_FACTOR_UNITY;
|
||||||
static int32_t vol_factor_l = 0, vol_factor_r = 0;
|
|
||||||
#endif /* AUDIOHW_HAVE_PRESCALER */
|
#endif /* AUDIOHW_HAVE_PRESCALER */
|
||||||
|
|
||||||
/* pcm scaling factors */
|
/* pcm scaling factors */
|
||||||
|
@ -223,25 +223,30 @@ static int32_t pcm_centibels_to_factor(int volume)
|
||||||
return 0; /* mute */
|
return 0; /* mute */
|
||||||
|
|
||||||
/* Centibels -> fixedpoint */
|
/* 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 */
|
/* Produce final pcm scale factor */
|
||||||
static void pcm_sync_prescaler(void)
|
static void pcm_sync_prescaler(void)
|
||||||
{
|
{
|
||||||
int32_t factor_l = fp_mul(prescale_factor, vol_factor_l, PCM_FACTOR_BITS);
|
int32_t factor_l = vol_factor_l;
|
||||||
int32_t factor_r = fp_mul(prescale_factor, vol_factor_r, PCM_FACTOR_BITS);
|
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_l = PCM_FACTOR_CLIP(factor_l);
|
||||||
pcm_factor_r = PCM_FACTOR_CLIP(factor_r);
|
pcm_factor_r = PCM_FACTOR_CLIP(factor_r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef AUDIOHW_HAVE_PRESCALER
|
||||||
/* Set the prescaler value for all PCM playback */
|
/* Set the prescaler value for all PCM playback */
|
||||||
void pcm_set_prescaler(int prescale)
|
void pcm_set_prescaler(int prescale)
|
||||||
{
|
{
|
||||||
prescale_factor = pcm_centibels_to_factor(-prescale);
|
prescale_factor = pcm_centibels_to_factor(-prescale);
|
||||||
pcm_sync_prescaler();
|
pcm_sync_prescaler();
|
||||||
}
|
}
|
||||||
|
#endif /* AUDIOHW_HAVE_PRESCALER */
|
||||||
|
|
||||||
/* Set the per-channel volume cut/gain for all PCM playback */
|
/* Set the per-channel volume cut/gain for all PCM playback */
|
||||||
void pcm_set_master_volume(int vol_l, int vol_r)
|
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);
|
vol_factor_r = pcm_centibels_to_factor(vol_r);
|
||||||
pcm_sync_prescaler();
|
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 */
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue