FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ac3dec_fixed.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012
3  * MIPS Technologies, Inc., California.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the MIPS Technologies, Inc., nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE MIPS TECHNOLOGIES, INC. ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE MIPS TECHNOLOGIES, INC. BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * Author: Stanislav Ocovaj (socovaj@mips.com)
30  *
31  * AC3 fixed-point decoder for MIPS platforms
32  *
33  * This file is part of FFmpeg.
34  *
35  * FFmpeg is free software; you can redistribute it and/or
36  * modify it under the terms of the GNU Lesser General Public
37  * License as published by the Free Software Foundation; either
38  * version 2.1 of the License, or (at your option) any later version.
39  *
40  * FFmpeg is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
43  * Lesser General Public License for more details.
44  *
45  * You should have received a copy of the GNU Lesser General Public
46  * License along with FFmpeg; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
48  */
49 
50 #define FFT_FLOAT 0
51 #define USE_FIXED 1
52 #define FFT_FIXED_32 1
53 #include "ac3dec.h"
54 
55 
56 static const int end_freq_inv_tab[8] =
57 {
58  50529027, 44278013, 39403370, 32292987, 27356480, 23729101, 20951060, 18755316
59 };
60 
61 static void scale_coefs (
62  int32_t *dst,
63  const int32_t *src,
64  int dynrng,
65  int len)
66 {
67  int i, shift, round;
68  int16_t mul;
69  int temp, temp1, temp2, temp3, temp4, temp5, temp6, temp7;
70 
71  mul = (dynrng & 0x1f) + 0x20;
72  shift = 4 - ((dynrng << 23) >> 28);
73  if (shift > 0 ) {
74  round = 1 << (shift-1);
75  for (i=0; i<len; i+=8) {
76 
77  temp = src[i] * mul;
78  temp1 = src[i+1] * mul;
79  temp = temp + round;
80  temp2 = src[i+2] * mul;
81 
82  temp1 = temp1 + round;
83  dst[i] = temp >> shift;
84  temp3 = src[i+3] * mul;
85  temp2 = temp2 + round;
86 
87  dst[i+1] = temp1 >> shift;
88  temp4 = src[i + 4] * mul;
89  temp3 = temp3 + round;
90  dst[i+2] = temp2 >> shift;
91 
92  temp5 = src[i+5] * mul;
93  temp4 = temp4 + round;
94  dst[i+3] = temp3 >> shift;
95  temp6 = src[i+6] * mul;
96 
97  dst[i+4] = temp4 >> shift;
98  temp5 = temp5 + round;
99  temp7 = src[i+7] * mul;
100  temp6 = temp6 + round;
101 
102  dst[i+5] = temp5 >> shift;
103  temp7 = temp7 + round;
104  dst[i+6] = temp6 >> shift;
105  dst[i+7] = temp7 >> shift;
106 
107  }
108  } else {
109  shift = -shift;
110  for (i=0; i<len; i+=8) {
111 
112  temp = src[i] * mul;
113  temp1 = src[i+1] * mul;
114  temp2 = src[i+2] * mul;
115 
116  dst[i] = temp << shift;
117  temp3 = src[i+3] * mul;
118 
119  dst[i+1] = temp1 << shift;
120  temp4 = src[i + 4] * mul;
121  dst[i+2] = temp2 << shift;
122 
123  temp5 = src[i+5] * mul;
124  dst[i+3] = temp3 << shift;
125  temp6 = src[i+6] * mul;
126 
127  dst[i+4] = temp4 << shift;
128  temp7 = src[i+7] * mul;
129 
130  dst[i+5] = temp5 << shift;
131  dst[i+6] = temp6 << shift;
132  dst[i+7] = temp7 << shift;
133 
134  }
135  }
136 }
137 
138 /**
139  * Downmix samples from original signal to stereo or mono (this is for 16-bit samples
140  * and fixed point decoder - original (for 32-bit samples) is in ac3dsp.c).
141  */
142 static void ac3_downmix_c_fixed16(int16_t **samples, int16_t (*matrix)[2],
143  int out_ch, int in_ch, int len)
144 {
145  int i, j;
146  int v0, v1;
147  if (out_ch == 2) {
148  for (i = 0; i < len; i++) {
149  v0 = v1 = 0;
150  for (j = 0; j < in_ch; j++) {
151  v0 += samples[j][i] * matrix[j][0];
152  v1 += samples[j][i] * matrix[j][1];
153  }
154  samples[0][i] = (v0+2048)>>12;
155  samples[1][i] = (v1+2048)>>12;
156  }
157  } else if (out_ch == 1) {
158  for (i = 0; i < len; i++) {
159  v0 = 0;
160  for (j = 0; j < in_ch; j++)
161  v0 += samples[j][i] * matrix[j][0];
162  samples[0][i] = (v0+2048)>>12;
163  }
164  }
165 }
166 
167 #include "eac3dec.c"
168 #include "ac3dec.c"
169 
170 static const AVOption options[] = {
171  { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR },
172  { "heavy_compr", "heavy dynamic range compression enabled", OFFSET(heavy_compression), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, PAR },
173  { NULL},
174 };
175 
176 static const AVClass ac3_decoder_class = {
177  .class_name = "Fixed-Point AC-3 Decoder",
178  .item_name = av_default_item_name,
179  .option = options,
180  .version = LIBAVUTIL_VERSION_INT,
181 };
182 
184  .name = "ac3_fixed",
185  .type = AVMEDIA_TYPE_AUDIO,
186  .id = AV_CODEC_ID_AC3,
187  .priv_data_size = sizeof (AC3DecodeContext),
189  .close = ac3_decode_end,
191  .capabilities = CODEC_CAP_DR1,
192  .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
193  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
195  .priv_class = &ac3_decoder_class,
196 };
static const AVClass ac3_decoder_class
Definition: ac3dec_fixed.c:176
#define NULL
Definition: coverity.c:32
static int shift(int a, int b)
Definition: sonic.c:82
AVOption.
Definition: opt.h:255
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
static void ac3_downmix_c_fixed16(int16_t **samples, int16_t(*matrix)[2], int out_ch, int in_ch, int len)
Downmix samples from original signal to stereo or mono (this is for 16-bit samples and fixed point de...
Definition: ac3dec_fixed.c:142
else temp
Definition: vf_mcdeint.c:257
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
GLfloat v0
Definition: opengl_enc.c:107
AVCodec.
Definition: avcodec.h:3181
static void scale_coefs(int32_t *dst, const int32_t *src, int dynrng, int len)
Definition: ac3dec_fixed.c:61
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
static av_cold int ac3_decode_end(AVCodecContext *avctx)
Uninitialize the AC-3 decoder.
Definition: ac3dec.c:1631
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:789
Common code between the AC-3 and E-AC-3 decoders.
av_default_item_name
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
const char * name
Name of the codec implementation.
Definition: avcodec.h:3188
static av_always_inline av_const double round(double x)
Definition: libm.h:162
static int ac3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Decode a single AC-3 frame.
Definition: ac3dec.c:1405
AVCodec ff_ac3_fixed_decoder
Definition: ac3dec_fixed.c:183
int32_t
AVS_Value src
Definition: avisynth_c.h:482
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
static const AVOption options[]
Definition: ac3dec_fixed.c:170
static const int end_freq_inv_tab[8]
Definition: ac3dec_fixed.c:56
Describe the class of an AVClass context structure.
Definition: log.h:67
Definition: af_afade.c:45
#define OFFSET(x)
Definition: ffmpeg_opt.c:2874
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:522
int len
signed 16 bits, planar
Definition: samplefmt.h:68
static av_cold int ac3_decode_init(AVCodecContext *avctx)
AVCodec initialization.
Definition: ac3dec.c:181