# HG changeset patch # User reimar # Date 1383074653 0 # Node ID abdc52a1ab2cd523ca158d1129de19b3dee06f52 # Parent eb406ab18f4a12aea4c923493c9b727cfd568099 af_volume: Avoid pointlessly calculating the maximum volume. Only calculate it when it will be used, and do not calculate it per-channel. diff -r eb406ab18f4a -r abdc52a1ab2c libaf/af_volume.c --- a/libaf/af_volume.c Sun Oct 27 18:06:52 2013 +0000 +++ b/libaf/af_volume.c Tue Oct 29 19:24:13 2013 +0000 @@ -43,7 +43,7 @@ // Data for specific instances of this filter typedef struct af_volume_s { - float max[AF_NCH]; // Max Power level [dB] + float max; // Max Power level [dB] float level[AF_NCH]; // Gain level for each channel int soft; // Enable/disable soft clipping int fast; // Use fix-point volume control @@ -93,18 +93,14 @@ return af_from_dB(AF_NCH,(float*)arg,s->level,20.0,-200.0,60.0); case AF_CONTROL_VOLUME_LEVEL | AF_CONTROL_GET: return af_to_dB(AF_NCH,s->level,(float*)arg,20.0); - case AF_CONTROL_PRE_DESTROY:{ - float m = 0.0; - int i; + case AF_CONTROL_PRE_DESTROY: if(!s->fast){ - for(i=0;imax[i]); + float m = s->max; af_to_dB(1, &m, &m, 10.0); mp_msg(MSGT_AFILTER, MSGL_INFO, "[volume] The maximum volume was %0.2fdB \n", m); } return AF_OK; } - } return AF_UNKNOWN; } @@ -140,14 +136,13 @@ 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 (i = 0; !s->fast && i < len; i++) + // Check maximum power value + s->max = FFMAX(s->max, a[i] * a[i]); for(ch = 0; ch < nch ; ch++){ // Volume control (fader) for(i=ch;i s->max[ch]) - s->max[ch] = pow; // Set volume x *= s->level[ch]; /* Soft clipping, the sound of a dream, thanks to Jon Wattes