Revision e0b33d47

View differences:

doc/encoders.texi
353 353

  
354 354
@end table
355 355

  
356
@subheading Other AC-3 Encoding Options
357

  
358
@table @option
359

  
360
@item -stereo_rematrixing @var{boolean}
361
Stereo Rematrixing. Enables/Disables use of rematrixing for stereo input. This
362
is an optional AC-3 feature that increases quality by selectively encoding
363
the left/right channels as mid/side. This option is enabled by default, and it
364
is highly recommended that it be left as enabled except for testing purposes.
365

  
366
@end table
367

  
356 368
@c man end ENCODERS
libavcodec/ac3enc.c
52 52
/** Maximum number of exponent groups. +1 for separate DC exponent. */
53 53
#define AC3_MAX_EXP_GROUPS 85
54 54

  
55
/* stereo rematrixing algorithms */
56
#define AC3_REMATRIXING_IS_STATIC 0x1
57
#define AC3_REMATRIXING_SUMS    0
58
#define AC3_REMATRIXING_NONE    1
59
#define AC3_REMATRIXING_ALWAYS  3
60

  
61 55
#if CONFIG_AC3ENC_FLOAT
62 56
#define MAC_COEF(d,a,b) ((d)+=(a)*(b))
63 57
typedef float SampleType;
......
103 97

  
104 98
    /* other encoding options */
105 99
    int allow_per_frame_metadata;
100
    int stereo_rematrixing;
106 101
} AC3EncOptions;
107 102

  
108 103
/**
......
170 165
    int bandwidth_code[AC3_MAX_CHANNELS];   ///< bandwidth code (0 to 60)               (chbwcod)
171 166
    int nb_coefs[AC3_MAX_CHANNELS];
172 167

  
173
    int rematrixing;                        ///< determines how rematrixing strategy is calculated
168
    int rematrixing_enabled;                ///< stereo rematrixing enabled
174 169
    int num_rematrixing_bands;              ///< number of rematrixing bands
175 170

  
176 171
    /* bitrate allocation control */
......
269 264
{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), FF_OPT_TYPE_INT, -1, -1, 1, AC3ENC_PARAM, "ad_conv_type"},
270 265
    {"standard", "Standard (default)", 0, FF_OPT_TYPE_CONST, 0, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
271 266
    {"hdcd",     "HDCD",               0, FF_OPT_TYPE_CONST, 1, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"},
267
/* Other Encoding Options */
268
{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), FF_OPT_TYPE_INT, 1, 0, 1, AC3ENC_PARAM},
272 269
{NULL}
273 270
};
274 271

  
......
431 428

  
432 429

  
433 430
/**
434
 * Initialize stereo rematrixing.
435
 * If the strategy does not change for each frame, set the rematrixing flags.
436
 */
437
static void rematrixing_init(AC3EncodeContext *s)
438
{
439
    if (s->channel_mode == AC3_CHMODE_STEREO)
440
        s->rematrixing = AC3_REMATRIXING_SUMS;
441
    else
442
        s->rematrixing = AC3_REMATRIXING_NONE;
443
    /* NOTE: AC3_REMATRIXING_ALWAYS might be used in
444
             the future in conjunction with channel coupling. */
445

  
446
    if (s->rematrixing & AC3_REMATRIXING_IS_STATIC) {
447
        int flag = (s->rematrixing == AC3_REMATRIXING_ALWAYS);
448
        s->blocks[0].new_rematrixing_strategy = 1;
449
        memset(s->blocks[0].rematrixing_flags, flag,
450
               sizeof(s->blocks[0].rematrixing_flags));
451
    }
452
}
453

  
454

  
455
/**
456 431
 * Determine rematrixing flags for each block and band.
457 432
 */
458 433
static void compute_rematrixing_strategy(AC3EncodeContext *s)
......
461 436
    int blk, bnd, i;
462 437
    AC3Block *block, *block0;
463 438

  
464
    s->num_rematrixing_bands = 4;
465

  
466
    if (s->rematrixing & AC3_REMATRIXING_IS_STATIC)
439
    if (s->channel_mode != AC3_CHMODE_STEREO)
467 440
        return;
468 441

  
442
    s->num_rematrixing_bands = 4;
443

  
469 444
    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
470 445

  
471 446
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
472 447
        block = &s->blocks[blk];
473 448
        block->new_rematrixing_strategy = !blk;
449
        if (!s->rematrixing_enabled)
450
            continue;
474 451
        for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) {
475 452
            /* calculate calculate sum of squared coeffs for one band in one block */
476 453
            int start = ff_ac3_rematrix_band_tab[bnd];
......
514 491
    int start, end;
515 492
    uint8_t *flags;
516 493

  
517
    if (s->rematrixing == AC3_REMATRIXING_NONE)
494
    if (!s->rematrixing_enabled)
518 495
        return;
519 496

  
520 497
    nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]);
......
2088 2065
    if (ret)
2089 2066
        return ret;
2090 2067

  
2068
    s->rematrixing_enabled = s->options.stereo_rematrixing &&
2069
                             (s->channel_mode == AC3_CHMODE_STEREO);
2070

  
2091 2071
    return 0;
2092 2072
}
2093 2073

  
......
2246 2226

  
2247 2227
    set_bandwidth(s);
2248 2228

  
2249
    rematrixing_init(s);
2250

  
2251 2229
    exponent_init(s);
2252 2230

  
2253 2231
    bit_alloc_init(s);

Also available in: Unified diff