From 6cecbf38c110bd3fb83ed06523d5045fa1481139 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 22 Dec 2011 07:33:15 +0100 Subject: 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. --- libaf/af_volume.c | 9 ++++----- 1 file 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> 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; -- cgit v1.2.3