~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/ac3enc_fixed.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#define CONFIG_FFT_FLOAT 0
30
30
#undef CONFIG_AC3ENC_FLOAT
31
31
#include "ac3enc.h"
 
32
#include "eac3enc.h"
32
33
 
33
34
#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED
34
35
#include "ac3enc_opts_template.c"
35
 
static AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
36
 
                                ac3fixed_options, LIBAVUTIL_VERSION_INT };
 
36
static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name,
 
37
                                      ac3fixed_options, LIBAVUTIL_VERSION_INT };
37
38
 
38
39
#include "ac3enc_template.c"
39
40
 
40
41
 
41
42
/**
42
43
 * Finalize MDCT and free allocated memory.
 
44
 *
 
45
 * @param s  AC-3 encoder private context
43
46
 */
44
 
av_cold void AC3_NAME(mdct_end)(AC3MDCTContext *mdct)
 
47
av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s)
45
48
{
46
 
    ff_mdct_end(&mdct->fft);
 
49
    ff_mdct_end(&s->mdct);
47
50
}
48
51
 
49
52
 
50
53
/**
51
54
 * Initialize MDCT tables.
52
 
 * @param nbits log2(MDCT size)
 
55
 *
 
56
 * @param s  AC-3 encoder private context
 
57
 * @return   0 on success, negative error code on failure
53
58
 */
54
 
av_cold int AC3_NAME(mdct_init)(AVCodecContext *avctx, AC3MDCTContext *mdct,
55
 
                                int nbits)
 
59
av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s)
56
60
{
57
 
    int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0);
58
 
    mdct->window = ff_ac3_window;
 
61
    int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0);
 
62
    s->mdct_window = ff_ac3_window;
59
63
    return ret;
60
64
}
61
65
 
62
66
 
63
 
/**
 
67
/*
64
68
 * Apply KBD window to input samples prior to MDCT.
65
69
 */
66
 
void AC3_NAME(apply_window)(DSPContext *dsp, int16_t *output,
67
 
                            const int16_t *input, const int16_t *window,
68
 
                            unsigned int len)
 
70
static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input,
 
71
                         const int16_t *window, unsigned int len)
69
72
{
70
73
    dsp->apply_window_int16(output, input, window, len);
71
74
}
72
75
 
73
76
 
74
 
/**
75
 
 * Calculate the log2() of the maximum absolute value in an array.
76
 
 * @param tab input array
77
 
 * @param n   number of values in the array
78
 
 * @return    log2(max(abs(tab[])))
79
 
 */
80
 
static int log2_tab(AC3EncodeContext *s, int16_t *src, int len)
81
 
{
82
 
    int v = s->ac3dsp.ac3_max_msb_abs_int16(src, len);
83
 
    return av_log2(v);
84
 
}
85
 
 
86
 
 
87
 
/**
 
77
/*
88
78
 * Normalize the input samples to use the maximum available precision.
89
79
 * This assumes signed 16-bit input samples.
90
 
 *
91
 
 * @return exponent shift
92
80
 */
93
 
int AC3_NAME(normalize_samples)(AC3EncodeContext *s)
 
81
static int normalize_samples(AC3EncodeContext *s)
94
82
{
95
 
    int v = 14 - log2_tab(s, s->windowed_samples, AC3_WINDOW_SIZE);
 
83
    int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE);
 
84
    v = 14 - av_log2(v);
96
85
    if (v > 0)
97
86
        s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v);
98
87
    /* +6 to right-shift from 31-bit to 25-bit */
100
89
}
101
90
 
102
91
 
103
 
/**
 
92
/*
104
93
 * Scale MDCT coefficients to 25-bit signed fixed-point.
105
94
 */
106
 
void AC3_NAME(scale_coefficients)(AC3EncodeContext *s)
 
95
static void scale_coefficients(AC3EncodeContext *s)
107
96
{
108
97
    int blk, ch;
109
98
 
110
 
    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
 
99
    for (blk = 0; blk < s->num_blocks; blk++) {
111
100
        AC3Block *block = &s->blocks[blk];
112
101
        for (ch = 1; ch <= s->channels; ch++) {
113
102
            s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS,
117
106
}
118
107
 
119
108
 
 
109
/*
 
110
 * Clip MDCT coefficients to allowable range.
 
111
 */
 
112
static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len)
 
113
{
 
114
    dsp->vector_clip_int32(coef, coef, COEF_MIN, COEF_MAX, len);
 
115
}
 
116
 
 
117
 
 
118
/*
 
119
 * Calculate a single coupling coordinate.
 
120
 */
 
121
static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl)
 
122
{
 
123
    if (energy_cpl <= COEF_MAX) {
 
124
        return 1048576;
 
125
    } else {
 
126
        uint64_t coord   = energy_ch / (energy_cpl >> 24);
 
127
        uint32_t coord32 = FFMIN(coord, 1073741824);
 
128
        coord32          = ff_sqrt(coord32) << 9;
 
129
        return FFMIN(coord32, COEF_MAX);
 
130
    }
 
131
}
 
132
 
 
133
 
120
134
static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx)
121
135
{
122
136
    AC3EncodeContext *s = avctx->priv_data;
126
140
 
127
141
 
128
142
AVCodec ff_ac3_fixed_encoder = {
129
 
    "ac3_fixed",
130
 
    AVMEDIA_TYPE_AUDIO,
131
 
    CODEC_ID_AC3,
132
 
    sizeof(AC3EncodeContext),
133
 
    ac3_fixed_encode_init,
134
 
    ff_ac3_encode_frame,
135
 
    ff_ac3_encode_close,
136
 
    NULL,
 
143
    .name           = "ac3_fixed",
 
144
    .type           = AVMEDIA_TYPE_AUDIO,
 
145
    .id             = CODEC_ID_AC3,
 
146
    .priv_data_size = sizeof(AC3EncodeContext),
 
147
    .init           = ac3_fixed_encode_init,
 
148
    .encode         = ff_ac3_fixed_encode_frame,
 
149
    .close          = ff_ac3_encode_close,
137
150
    .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE},
138
151
    .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
139
152
    .priv_class = &ac3enc_class,