mpegaudiodec_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 "dsputil_altivec.h"
23 #include "libavutil/attributes.h"
24 #include "libavutil/internal.h"
27 
28 #define MACS(rt, ra, rb) rt+=(ra)*(rb)
29 #define MLSS(rt, ra, rb) rt-=(ra)*(rb)
30 
31 #define SUM8(op, sum, w, p) \
32 { \
33  op(sum, (w)[0 * 64], (p)[0 * 64]); \
34  op(sum, (w)[1 * 64], (p)[1 * 64]); \
35  op(sum, (w)[2 * 64], (p)[2 * 64]); \
36  op(sum, (w)[3 * 64], (p)[3 * 64]); \
37  op(sum, (w)[4 * 64], (p)[4 * 64]); \
38  op(sum, (w)[5 * 64], (p)[5 * 64]); \
39  op(sum, (w)[6 * 64], (p)[6 * 64]); \
40  op(sum, (w)[7 * 64], (p)[7 * 64]); \
41 }
42 
43 static void apply_window(const float *buf, const float *win1,
44  const float *win2, float *sum1, float *sum2, int len)
45 {
46  const vector float *win1a = (const vector float *) win1;
47  const vector float *win2a = (const vector float *) win2;
48  const vector float *bufa = (const vector float *) buf;
49  vector float *sum1a = (vector float *) sum1;
50  vector float *sum2a = (vector float *) sum2;
51  vector float av_uninit(v0), av_uninit(v4);
52  vector float v1, v2, v3;
53 
54  len = len >> 2;
55 
56 #define MULT(a, b) \
57  { \
58  v1 = vec_ld(a, win1a); \
59  v2 = vec_ld(b, win2a); \
60  v3 = vec_ld(a, bufa); \
61  v0 = vec_madd(v3, v1, v0); \
62  v4 = vec_madd(v2, v3, v4); \
63  }
64 
65  while (len--) {
66  v0 = vec_xor(v0, v0);
67  v4 = vec_xor(v4, v4);
68 
69  MULT( 0, 0);
70  MULT( 256, 64);
71  MULT( 512, 128);
72  MULT( 768, 192);
73  MULT(1024, 256);
74  MULT(1280, 320);
75  MULT(1536, 384);
76  MULT(1792, 448);
77 
78  vec_st(v0, 0, sum1a);
79  vec_st(v4, 0, sum2a);
80  sum1a++;
81  sum2a++;
82  win1a++;
83  win2a++;
84  bufa++;
85  }
86 }
87 
88 static void apply_window_mp3(float *in, float *win, int *unused, float *out,
89  int incr)
90 {
91  LOCAL_ALIGNED_16(float, suma, [17]);
92  LOCAL_ALIGNED_16(float, sumb, [17]);
93  LOCAL_ALIGNED_16(float, sumc, [17]);
94  LOCAL_ALIGNED_16(float, sumd, [17]);
95 
96  float sum;
97  int j;
98  float *out2 = out + 32 * incr;
99 
100  /* copy to avoid wrap */
101  memcpy(in + 512, in, 32 * sizeof(*in));
102 
103  apply_window(in + 16, win , win + 512, suma, sumc, 16);
104  apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
105 
106  SUM8(MLSS, suma[0], win + 32, in + 48);
107 
108  sumc[ 0] = 0;
109  sumb[16] = 0;
110  sumd[16] = 0;
111 
112  out[0 ] = suma[ 0];
113  out += incr;
114  out2 -= incr;
115  for(j=1;j<16;j++) {
116  *out = suma[ j] - sumd[16-j];
117  *out2 = -sumb[16-j] - sumc[ j];
118  out += incr;
119  out2 -= incr;
120  }
121 
122  sum = 0;
123  SUM8(MLSS, sum, win + 16 + 32, in + 32);
124  *out = sum;
125 }
126 
128 {
130 }
const char * s
Definition: avisynth_c.h:668
static void apply_window_mp3(float *in, float *win, int *unused, float *out, int incr)
#define MLSS(rt, ra, rb)
#define MULT(a, b)
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
#define SUM8(op, sum, w, p)
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:78
static void apply_window(const float *buf, const float *win1, const float *win2, float *sum1, float *sum2, int len)
common internal API header
av_cold void ff_mpadsp_init_altivec(MPADSPContext *s)
void * buf
Definition: avisynth_c.h:594
Contains misc utility macros and inline functions.
#define v0
Definition: regdef.h:26
void(* apply_window_float)(float *synth_buf, float *window, int *dither_state, float *samples, int incr)
Definition: mpegaudiodsp.h:26
int len
#define av_uninit(x)
Definition: attributes.h:137
#define LOCAL_ALIGNED_16(t, v,...)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out