FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mpegaudiodsp_altivec.c
Go to the documentation of this file.
1 /*
2  * Altivec optimized MP3 decoding functions
3  * Copyright (c) 2010 Vitor Sessak
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
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
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/ppc/cpu.h"
29 
30 #if HAVE_ALTIVEC
31 
32 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
33 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
34 
35 #define SUM8(op, sum, w, p) \
36 { \
37  op(sum, (w)[0 * 64], (p)[0 * 64]); \
38  op(sum, (w)[1 * 64], (p)[1 * 64]); \
39  op(sum, (w)[2 * 64], (p)[2 * 64]); \
40  op(sum, (w)[3 * 64], (p)[3 * 64]); \
41  op(sum, (w)[4 * 64], (p)[4 * 64]); \
42  op(sum, (w)[5 * 64], (p)[5 * 64]); \
43  op(sum, (w)[6 * 64], (p)[6 * 64]); \
44  op(sum, (w)[7 * 64], (p)[7 * 64]); \
45 }
46 
47 static void apply_window(const float *buf, const float *win1,
48  const float *win2, float *sum1, float *sum2, int len)
49 {
50  const vector float *win1a = (const vector float *) win1;
51  const vector float *win2a = (const vector float *) win2;
52  const vector float *bufa = (const vector float *) buf;
53  vector float *sum1a = (vector float *) sum1;
54  vector float *sum2a = (vector float *) sum2;
55  vector float av_uninit(v0), av_uninit(v4);
56  vector float v1, v2, v3;
57 
58  len = len >> 2;
59 
60 #define MULT(a, b) \
61  { \
62  v1 = vec_ld(a, win1a); \
63  v2 = vec_ld(b, win2a); \
64  v3 = vec_ld(a, bufa); \
65  v0 = vec_madd(v3, v1, v0); \
66  v4 = vec_madd(v2, v3, v4); \
67  }
68 
69  while (len--) {
70  v0 = vec_xor(v0, v0);
71  v4 = vec_xor(v4, v4);
72 
73  MULT( 0, 0);
74  MULT( 256, 64);
75  MULT( 512, 128);
76  MULT( 768, 192);
77  MULT(1024, 256);
78  MULT(1280, 320);
79  MULT(1536, 384);
80  MULT(1792, 448);
81 
82  vec_st(v0, 0, sum1a);
83  vec_st(v4, 0, sum2a);
84  sum1a++;
85  sum2a++;
86  win1a++;
87  win2a++;
88  bufa++;
89  }
90 }
91 
92 static void apply_window_mp3(float *in, float *win, int *unused, float *out,
93  int incr)
94 {
95  LOCAL_ALIGNED_16(float, suma, [17]);
96  LOCAL_ALIGNED_16(float, sumb, [17]);
97  LOCAL_ALIGNED_16(float, sumc, [17]);
98  LOCAL_ALIGNED_16(float, sumd, [17]);
99 
100  float sum;
101  int j;
102  float *out2 = out + 32 * incr;
103 
104  /* copy to avoid wrap */
105  memcpy(in + 512, in, 32 * sizeof(*in));
106 
107  apply_window(in + 16, win , win + 512, suma, sumc, 16);
108  apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
109 
110  SUM8(MLSS, suma[0], win + 32, in + 48);
111 
112  sumc[ 0] = 0;
113  sumb[16] = 0;
114  sumd[16] = 0;
115 
116  out[0 ] = suma[ 0];
117  out += incr;
118  out2 -= incr;
119  for(j=1;j<16;j++) {
120  *out = suma[ j] - sumd[16-j];
121  *out2 = -sumb[16-j] - sumc[ j];
122  out += incr;
123  out2 -= incr;
124  }
125 
126  sum = 0;
127  SUM8(MLSS, sum, win + 16 + 32, in + 32);
128  *out = sum;
129 }
130 
131 #endif /* HAVE_ALTIVEC */
132 
134 {
135 #if HAVE_ALTIVEC
137  return;
138 
139  s->apply_window_float = apply_window_mp3;
140 #endif /* HAVE_ALTIVEC */
141 }
const char * s
Definition: avisynth_c.h:768
GLfloat v0
Definition: opengl_enc.c:107
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:82
#define SUM8(op, sum, w, p)
#define PPC_ALTIVEC(flags)
Definition: cpu.h:26
#define MULT(c, x, n)
Definition: xvididct.c:145
common internal API header
static void(*const apply_window[4])(AVFloatDSPContext *fdsp, SingleChannelElement *sce, const float *audio)
Definition: aacenc.c:144
#define MLSS(rt, ra, rb)
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
void * buf
Definition: avisynth_c.h:690
void(* apply_window_float)(float *synth_buf, float *window, int *dither_state, float *samples, int incr)
Definition: mpegaudiodsp.h:26
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
Contains misc utility macros and inline functions.
av_cold void ff_mpadsp_init_ppc(MPADSPContext *s)
int len
#define av_uninit(x)
Definition: attributes.h:149
FILE * out
Definition: movenc.c:54
#define LOCAL_ALIGNED_16(t, v,...)
Definition: internal.h:121