~ubuntu-branches/ubuntu/precise/mplayer2/precise-proposed

« back to all changes in this revision

Viewing changes to ffmpeg-mt/libavcodec/aaccoder.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-21 09:21:39 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110421092139-7a21foqroxvir3wr
Tags: 2.0-54-gd33877a-1
* New upstream version
* Bug fix: "internal MP3 decoder miscompiles with gcc 4.6", thanks to
  Norbert Preining (Closes: #623279). Fixed by no longer using internal
  mp3lib copy.
* drop build host specific optimizations

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * AAC coefficients encoder
3
3
 * Copyright (C) 2008-2009 Konstantin Shishkov
4
4
 *
5
 
 * This file is part of FFmpeg.
 
5
 * This file is part of Libav.
6
6
 *
7
 
 * FFmpeg is free software; you can redistribute it and/or
 
7
 * Libav is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
9
9
 * License as published by the Free Software Foundation; either
10
10
 * version 2.1 of the License, or (at your option) any later version.
11
11
 *
12
 
 * FFmpeg is distributed in the hope that it will be useful,
 
12
 * Libav is distributed in the hope that it will be useful,
13
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
15
 * Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with FFmpeg; if not, write to the Free Software
 
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
110
110
    const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512];
111
111
    const float  Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512];
112
112
    const float CLIPPED_ESCAPE = 165140.0f*IQ;
113
 
    int i, j, k;
 
113
    int i, j;
114
114
    float cost = 0;
115
115
    const int dim = BT_PAIR ? 2 : 4;
116
116
    int resbits = 0;
146
146
            curidx *= range;
147
147
            curidx += quants[j] + off;
148
148
        }
149
 
            curbits =  ff_aac_spectral_bits[cb-1][curidx];
150
 
            vec     = &ff_aac_codebook_vectors[cb-1][curidx*dim];
151
 
            if (BT_UNSIGNED) {
152
 
                for (k = 0; k < dim; k++) {
153
 
                    float t = fabsf(in[i+k]);
154
 
                    float di;
155
 
                    if (BT_ESC && vec[k] == 64.0f) { //FIXME: slow
156
 
                        if (t >= CLIPPED_ESCAPE) {
157
 
                            di = t - CLIPPED_ESCAPE;
158
 
                            curbits += 21;
159
 
                        } else {
160
 
                            int c = av_clip(quant(t, Q), 0, 8191);
161
 
                            di = t - c*cbrtf(c)*IQ;
162
 
                            curbits += av_log2(c)*2 - 4 + 1;
163
 
                        }
 
149
        curbits =  ff_aac_spectral_bits[cb-1][curidx];
 
150
        vec     = &ff_aac_codebook_vectors[cb-1][curidx*dim];
 
151
        if (BT_UNSIGNED) {
 
152
            for (j = 0; j < dim; j++) {
 
153
                float t = fabsf(in[i+j]);
 
154
                float di;
 
155
                if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow
 
156
                    if (t >= CLIPPED_ESCAPE) {
 
157
                        di = t - CLIPPED_ESCAPE;
 
158
                        curbits += 21;
164
159
                    } else {
165
 
                        di = t - vec[k]*IQ;
 
160
                        int c = av_clip(quant(t, Q), 0, 8191);
 
161
                        di = t - c*cbrtf(c)*IQ;
 
162
                        curbits += av_log2(c)*2 - 4 + 1;
166
163
                    }
167
 
                    if (vec[k] != 0.0f)
168
 
                        curbits++;
169
 
                    rd += di*di;
170
 
                }
171
 
            } else {
172
 
                for (k = 0; k < dim; k++) {
173
 
                    float di = in[i+k] - vec[k]*IQ;
174
 
                    rd += di*di;
175
 
                }
176
 
            }
 
164
                } else {
 
165
                    di = t - vec[j]*IQ;
 
166
                }
 
167
                if (vec[j] != 0.0f)
 
168
                    curbits++;
 
169
                rd += di*di;
 
170
            }
 
171
        } else {
 
172
            for (j = 0; j < dim; j++) {
 
173
                float di = in[i+j] - vec[j]*IQ;
 
174
                rd += di*di;
 
175
            }
 
176
        }
177
177
        cost    += rd * lambda + curbits;
178
178
        resbits += curbits;
179
179
        if (cost >= uplim)
575
575
        int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512);
576
576
        q1 = qnrg + 30;
577
577
        q0 = qnrg - 30;
578
 
    //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
 
578
        //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1);
579
579
        if (q0 < q0low) {
580
580
            q1 += q0low - q0;
581
581
            q0  = q0low;
723
723
            sce->zeroes[w*16+g] = !nz;
724
724
            if (nz)
725
725
                minthr = FFMIN(minthr, uplim);
726
 
            allz = FFMAX(allz, nz);
 
726
            allz |= nz;
727
727
        }
728
728
    }
729
729
    for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) {
817
817
                int prevsc = sce->sf_idx[w*16+g];
818
818
                if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) {
819
819
                    if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1))
820
 
                    sce->sf_idx[w*16+g]--;
 
820
                        sce->sf_idx[w*16+g]--;
821
821
                    else //Try to make sure there is some energy in every band
822
822
                        sce->sf_idx[w*16+g]-=2;
823
823
                }
1057
1057
                    for (i = 0; i < sce0->ics.swb_sizes[g]; i++) {
1058
1058
                        M[i] = (sce0->coeffs[start+w2*128+i]
1059
1059
                              + sce1->coeffs[start+w2*128+i]) * 0.5;
1060
 
                        S[i] =  sce0->coeffs[start+w2*128+i]
 
1060
                        S[i] =  M[i]
1061
1061
                              - sce1->coeffs[start+w2*128+i];
1062
1062
                    }
1063
1063
                    abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]);