diff options
author | wm4 <wm4@mplayer2.org> | 2011-12-22 07:33:15 +0100 |
---|---|---|
committer | Uoti Urpala <uau@mplayer2.org> | 2012-01-16 22:40:14 +0200 |
commit | 6cecbf38c110bd3fb83ed06523d5045fa1481139 (patch) | |
tree | fe9622733cca34e95f7011882ffe5bd10b547572 /libaf | |
parent | 5489d0e89a1ed40d585134e7e5161eb92228e349 (diff) |
af_volume: do not change data when volume is 1
When the volume multiplier is 1, the data shouldn't be changed, but the
code actually multiplied each sample with 255/256. Change the factor to
256, and hope there wasn't a good reason for the value 255.
Additionally, don't work on the data if it wouldn't be changed anyway.
This is a micro-optimization.
This doesn't touch the code path for the float format.
Diffstat (limited to 'libaf')
-rw-r--r-- | libaf/af_volume.c | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libaf/af_volume.c b/libaf/af_volume.c index 768f67c5f3..4e6a3b40f6 100644 --- a/libaf/af_volume.c +++ b/libaf/af_volume.c @@ -142,7 +142,6 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data) { af_data_t* c = data; // Current working data af_volume_t* s = (af_volume_t*)af->setup; // Setup for this instance - int ch = 0; // Channel counter register int nch = c->nch; // Number of channels register int i = 0; @@ -150,9 +149,9 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data) if(af->data->format == (AF_FORMAT_S16_NE)){ int16_t* a = (int16_t*)c->audio; // Audio data int len = c->len/2; // Number of samples - for(ch = 0; ch < nch ; ch++){ - if(s->enable[ch]){ - register int vol = (int)(255.0 * s->level[ch]); + for (int ch = 0; ch < nch; ch++) { + int vol = 256.0 * s->level[ch]; + if (s->enable[ch] && vol != 256) { for(i=ch;i<len;i+=nch){ register int x = (a[i] * vol) >> 8; a[i]=clamp(x,SHRT_MIN,SHRT_MAX); @@ -164,7 +163,7 @@ static af_data_t* play(struct af_instance_s* af, af_data_t* data) else if(af->data->format == (AF_FORMAT_FLOAT_NE)){ float* a = (float*)c->audio; // Audio data int len = c->len/4; // Number of samples - for(ch = 0; ch < nch ; ch++){ + for (int ch = 0; ch < nch; ch++) { // Volume control (fader) if(s->enable[ch]){ float t = 1.0 - s->time; |