Browse code

af_pan: remove dual double/int storage of gain.

libswresample takes care of that now.

Nicolas George authored on 2012/02/21 05:25:12
Showing 1 changed files
... ...
@@ -37,11 +37,7 @@
37 37
 
38 38
 typedef struct PanContext {
39 39
     int64_t out_channel_layout;
40
-    union {
41
-        double d[MAX_CHANNELS][MAX_CHANNELS];
42
-        // i is 1:7:8 fixed-point, i.e. in [-128*256; +128*256[
43
-        int    i[MAX_CHANNELS][MAX_CHANNELS];
44
-    } gain;
40
+    double gain[MAX_CHANNELS][MAX_CHANNELS];
45 41
     int64_t need_renorm;
46 42
     int need_renumber;
47 43
     int nb_input_channels;
... ...
@@ -171,7 +167,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque)
171 171
                        "Can not mix named and numbered channels\n");
172 172
                 return AVERROR(EINVAL);
173 173
             }
174
-            pan->gain.d[out_ch_id][in_ch_id] = gain;
174
+            pan->gain[out_ch_id][in_ch_id] = gain;
175 175
             if (!*arg)
176 176
                 break;
177 177
             if (*arg != '+') {
... ...
@@ -196,7 +192,7 @@ static int are_gains_pure(const PanContext *pan)
196 196
         int nb_gain = 0;
197 197
 
198 198
         for (j = 0; j < MAX_CHANNELS; j++) {
199
-            double gain = pan->gain.d[i][j];
199
+            double gain = pan->gain[i][j];
200 200
 
201 201
             /* channel mapping is effective only if 0% or 100% of a channel is
202 202
              * selected... */
... ...
@@ -247,7 +243,7 @@ static int config_props(AVFilterLink *link)
247 247
         for (i = j = 0; i < MAX_CHANNELS; i++) {
248 248
             if ((link->channel_layout >> i) & 1) {
249 249
                 for (k = 0; k < pan->nb_output_channels; k++)
250
-                    pan->gain.d[k][j] = pan->gain.d[k][i];
250
+                    pan->gain[k][j] = pan->gain[k][i];
251 251
                 j++;
252 252
             }
253 253
         }
... ...
@@ -278,7 +274,7 @@ static int config_props(AVFilterLink *link)
278 278
         for (i = 0; i < pan->nb_output_channels; i++) {
279 279
             int ch_id = -1;
280 280
             for (j = 0; j < pan->nb_input_channels; j++) {
281
-                if (pan->gain.d[i][j]) {
281
+                if (pan->gain[i][j]) {
282 282
                     ch_id = j;
283 283
                     break;
284 284
                 }
... ...
@@ -296,7 +292,7 @@ static int config_props(AVFilterLink *link)
296 296
                 continue;
297 297
             t = 0;
298 298
             for (j = 0; j < pan->nb_input_channels; j++)
299
-                t += pan->gain.d[i][j];
299
+                t += pan->gain[i][j];
300 300
             if (t > -1E-5 && t < 1E-5) {
301 301
                 // t is almost 0 but not exactly, this is probably a mistake
302 302
                 if (t)
... ...
@@ -305,12 +301,11 @@ static int config_props(AVFilterLink *link)
305 305
                 continue;
306 306
             }
307 307
             for (j = 0; j < pan->nb_input_channels; j++)
308
-                pan->gain.d[i][j] /= t;
308
+                pan->gain[i][j] /= t;
309 309
         }
310 310
         av_opt_set_int(pan->swr, "icl", link->channel_layout, 0);
311 311
         av_opt_set_int(pan->swr, "ocl", pan->out_channel_layout, 0);
312
-        swr_set_matrix(pan->swr, pan->gain.d[0],
313
-                       pan->gain.d[1] - pan->gain.d[0]);
312
+        swr_set_matrix(pan->swr, pan->gain[0], pan->gain[1] - pan->gain[0]);
314 313
     }
315 314
 
316 315
     r = swr_init(pan->swr);
... ...
@@ -322,7 +317,7 @@ static int config_props(AVFilterLink *link)
322 322
         cur = buf;
323 323
         for (j = 0; j < pan->nb_input_channels; j++) {
324 324
             r = snprintf(cur, buf + sizeof(buf) - cur, "%s%.3g i%d",
325
-                         j ? " + " : "", pan->gain.d[i][j], j);
325
+                         j ? " + " : "", pan->gain[i][j], j);
326 326
             cur += FFMIN(buf + sizeof(buf) - cur, r);
327 327
         }
328 328
         av_log(ctx, AV_LOG_INFO, "o%d = %s\n", i, buf);
... ...
@@ -338,15 +333,6 @@ static int config_props(AVFilterLink *link)
338 338
         av_log(ctx, AV_LOG_INFO, "\n");
339 339
         return 0;
340 340
     }
341
-    // convert to integer
342
-    for (i = 0; i < pan->nb_output_channels; i++) {
343
-        for (j = 0; j < pan->nb_input_channels; j++) {
344
-            if (pan->gain.d[i][j] < -128 || pan->gain.d[i][j] > 128)
345
-                av_log(ctx, AV_LOG_WARNING,
346
-                    "Gain #%d->#%d too large, clamped\n", j, i);
347
-            pan->gain.i[i][j] = av_clipf(pan->gain.d[i][j], -128, 128) * 256.0;
348
-        }
349
-    }
350 341
     return 0;
351 342
 }
352 343