FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
aacpsdsp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 #include "libavutil/attributes.h"
23 #include "aacpsdsp.h"
24 
25 static void ps_add_squares_c(float *dst, const float (*src)[2], int n)
26 {
27  int i;
28  for (i = 0; i < n; i++)
29  dst[i] += src[i][0] * src[i][0] + src[i][1] * src[i][1];
30 }
31 
32 static void ps_mul_pair_single_c(float (*dst)[2], float (*src0)[2], float *src1,
33  int n)
34 {
35  int i;
36  for (i = 0; i < n; i++) {
37  dst[i][0] = src0[i][0] * src1[i];
38  dst[i][1] = src0[i][1] * src1[i];
39  }
40 }
41 
42 static void ps_hybrid_analysis_c(float (*out)[2], float (*in)[2],
43  const float (*filter)[8][2],
44  int stride, int n)
45 {
46  int i, j;
47 
48  for (i = 0; i < n; i++) {
49  float sum_re = filter[i][6][0] * in[6][0];
50  float sum_im = filter[i][6][0] * in[6][1];
51 
52  for (j = 0; j < 6; j++) {
53  float in0_re = in[j][0];
54  float in0_im = in[j][1];
55  float in1_re = in[12-j][0];
56  float in1_im = in[12-j][1];
57  sum_re += filter[i][j][0] * (in0_re + in1_re) -
58  filter[i][j][1] * (in0_im - in1_im);
59  sum_im += filter[i][j][0] * (in0_im + in1_im) +
60  filter[i][j][1] * (in0_re - in1_re);
61  }
62  out[i * stride][0] = sum_re;
63  out[i * stride][1] = sum_im;
64  }
65 }
66 
67 static void ps_hybrid_analysis_ileave_c(float (*out)[32][2], float L[2][38][64],
68  int i, int len)
69 {
70  int j;
71 
72  for (; i < 64; i++) {
73  for (j = 0; j < len; j++) {
74  out[i][j][0] = L[0][j][i];
75  out[i][j][1] = L[1][j][i];
76  }
77  }
78 }
79 
80 static void ps_hybrid_synthesis_deint_c(float out[2][38][64],
81  float (*in)[32][2],
82  int i, int len)
83 {
84  int n;
85 
86  for (; i < 64; i++) {
87  for (n = 0; n < len; n++) {
88  out[0][n][i] = in[i][n][0];
89  out[1][n][i] = in[i][n][1];
90  }
91  }
92 }
93 
94 static void ps_decorrelate_c(float (*out)[2], float (*delay)[2],
95  float (*ap_delay)[PS_QMF_TIME_SLOTS + PS_MAX_AP_DELAY][2],
96  const float phi_fract[2], const float (*Q_fract)[2],
97  const float *transient_gain,
98  float g_decay_slope,
99  int len)
100 {
101  static const float a[] = { 0.65143905753106f,
102  0.56471812200776f,
103  0.48954165955695f };
104  float ag[PS_AP_LINKS];
105  int m, n;
106 
107  for (m = 0; m < PS_AP_LINKS; m++)
108  ag[m] = a[m] * g_decay_slope;
109 
110  for (n = 0; n < len; n++) {
111  float in_re = delay[n][0] * phi_fract[0] - delay[n][1] * phi_fract[1];
112  float in_im = delay[n][0] * phi_fract[1] + delay[n][1] * phi_fract[0];
113  for (m = 0; m < PS_AP_LINKS; m++) {
114  float a_re = ag[m] * in_re;
115  float a_im = ag[m] * in_im;
116  float link_delay_re = ap_delay[m][n+2-m][0];
117  float link_delay_im = ap_delay[m][n+2-m][1];
118  float fractional_delay_re = Q_fract[m][0];
119  float fractional_delay_im = Q_fract[m][1];
120  float apd_re = in_re;
121  float apd_im = in_im;
122  in_re = link_delay_re * fractional_delay_re -
123  link_delay_im * fractional_delay_im - a_re;
124  in_im = link_delay_re * fractional_delay_im +
125  link_delay_im * fractional_delay_re - a_im;
126  ap_delay[m][n+5][0] = apd_re + ag[m] * in_re;
127  ap_delay[m][n+5][1] = apd_im + ag[m] * in_im;
128  }
129  out[n][0] = transient_gain[n] * in_re;
130  out[n][1] = transient_gain[n] * in_im;
131  }
132 }
133 
134 static void ps_stereo_interpolate_c(float (*l)[2], float (*r)[2],
135  float h[2][4], float h_step[2][4],
136  int len)
137 {
138  float h0 = h[0][0];
139  float h1 = h[0][1];
140  float h2 = h[0][2];
141  float h3 = h[0][3];
142  float hs0 = h_step[0][0];
143  float hs1 = h_step[0][1];
144  float hs2 = h_step[0][2];
145  float hs3 = h_step[0][3];
146  int n;
147 
148  for (n = 0; n < len; n++) {
149  //l is s, r is d
150  float l_re = l[n][0];
151  float l_im = l[n][1];
152  float r_re = r[n][0];
153  float r_im = r[n][1];
154  h0 += hs0;
155  h1 += hs1;
156  h2 += hs2;
157  h3 += hs3;
158  l[n][0] = h0 * l_re + h2 * r_re;
159  l[n][1] = h0 * l_im + h2 * r_im;
160  r[n][0] = h1 * l_re + h3 * r_re;
161  r[n][1] = h1 * l_im + h3 * r_im;
162  }
163 }
164 
165 static void ps_stereo_interpolate_ipdopd_c(float (*l)[2], float (*r)[2],
166  float h[2][4], float h_step[2][4],
167  int len)
168 {
169  float h00 = h[0][0], h10 = h[1][0];
170  float h01 = h[0][1], h11 = h[1][1];
171  float h02 = h[0][2], h12 = h[1][2];
172  float h03 = h[0][3], h13 = h[1][3];
173  float hs00 = h_step[0][0], hs10 = h_step[1][0];
174  float hs01 = h_step[0][1], hs11 = h_step[1][1];
175  float hs02 = h_step[0][2], hs12 = h_step[1][2];
176  float hs03 = h_step[0][3], hs13 = h_step[1][3];
177  int n;
178 
179  for (n = 0; n < len; n++) {
180  //l is s, r is d
181  float l_re = l[n][0];
182  float l_im = l[n][1];
183  float r_re = r[n][0];
184  float r_im = r[n][1];
185  h00 += hs00;
186  h01 += hs01;
187  h02 += hs02;
188  h03 += hs03;
189  h10 += hs10;
190  h11 += hs11;
191  h12 += hs12;
192  h13 += hs13;
193 
194  l[n][0] = h00 * l_re + h02 * r_re - h10 * l_im - h12 * r_im;
195  l[n][1] = h00 * l_im + h02 * r_im + h10 * l_re + h12 * r_re;
196  r[n][0] = h01 * l_re + h03 * r_re - h11 * l_im - h13 * r_im;
197  r[n][1] = h01 * l_im + h03 * r_im + h11 * l_re + h13 * r_re;
198  }
199 }
200 
202 {
211 
212  if (ARCH_ARM)
214  if (ARCH_MIPS)
216 }
static void ps_decorrelate_c(float(*out)[2], float(*delay)[2], float(*ap_delay)[PS_QMF_TIME_SLOTS+PS_MAX_AP_DELAY][2], const float phi_fract[2], const float(*Q_fract)[2], const float *transient_gain, float g_decay_slope, int len)
Definition: aacpsdsp.c:94
const char * s
Definition: avisynth_c.h:631
static void ps_stereo_interpolate_c(float(*l)[2], float(*r)[2], float h[2][4], float h_step[2][4], int len)
Definition: aacpsdsp.c:134
void ff_psdsp_init_arm(PSDSPContext *s)
av_cold void ff_psdsp_init(PSDSPContext *s)
Definition: aacpsdsp.c:201
void(* decorrelate)(float(*out)[2], float(*delay)[2], float(*ap_delay)[PS_QMF_TIME_SLOTS+PS_MAX_AP_DELAY][2], const float phi_fract[2], const float(*Q_fract)[2], const float *transient_gain, float g_decay_slope, int len)
Definition: aacpsdsp.h:39
void(* hybrid_analysis_ileave)(float(*out)[32][2], float L[2][38][64], int i, int len)
Definition: aacpsdsp.h:35
static void ps_hybrid_synthesis_deint_c(float out[2][38][64], float(*in)[32][2], int i, int len)
Definition: aacpsdsp.c:80
void(* mul_pair_single)(float(*dst)[2], float(*src0)[2], float *src1, int n)
Definition: aacpsdsp.h:30
Macro definitions for various function/variable attributes.
static void ps_mul_pair_single_c(float(*dst)[2], float(*src0)[2], float *src1, int n)
Definition: aacpsdsp.c:32
void(* stereo_interpolate[2])(float(*l)[2], float(*r)[2], float h[2][4], float h_step[2][4], int len)
Definition: aacpsdsp.h:45
#define av_cold
Definition: attributes.h:74
#define PS_MAX_AP_DELAY
Definition: aacps.h:39
static float phi_fract[2][50][2]
unsigned m
Definition: audioconvert.c:187
void(* hybrid_synthesis_deint)(float out[2][38][64], float(*in)[32][2], int i, int len)
Definition: aacpsdsp.h:37
const char * r
Definition: vf_curves.c:107
void(* hybrid_analysis)(float(*out)[2], float(*in)[2], const float(*filter)[8][2], int stride, int n)
Definition: aacpsdsp.h:32
static void ps_stereo_interpolate_ipdopd_c(float(*l)[2], float(*r)[2], float h[2][4], float h_step[2][4], int len)
Definition: aacpsdsp.c:165
static void ps_add_squares_c(float *dst, const float(*src)[2], int n)
Definition: aacpsdsp.c:25
int n
Definition: avisynth_c.h:547
#define L(x)
Definition: vp56_arith.h:36
static void ps_hybrid_analysis_c(float(*out)[2], float(*in)[2], const float(*filter)[8][2], int stride, int n)
Definition: aacpsdsp.c:42
#define src1
Definition: h264pred.c:138
AVS_Value src
Definition: avisynth_c.h:482
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define src0
Definition: h264pred.c:137
void ff_psdsp_init_mips(PSDSPContext *s)
#define PS_AP_LINKS
Definition: aacps.h:38
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
static void filter(MpegAudioContext *s, int ch, const short *samples, int incr)
#define PS_QMF_TIME_SLOTS
Definition: aacps.h:36
int len
void(* add_squares)(float *dst, const float(*src)[2], int n)
Definition: aacpsdsp.h:29
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define stride
static void ps_hybrid_analysis_ileave_c(float(*out)[32][2], float L[2][38][64], int i, int len)
Definition: aacpsdsp.c:67