comparison mpegaudiodec.c @ 11885:0e777af9160a libavcodec

Factorize the mpegaudio windowing code in a function and call it by a function pointer. Should allow for ASM optimizations.
author vitor
date Sat, 19 Jun 2010 09:56:05 +0000
parents f21bbfe942d4
children b9f69606a094
comparison
equal deleted inserted replaced
11884:d62a89be5458 11885:0e777af9160a
67 #include "mpegaudiodata.h" 67 #include "mpegaudiodata.h"
68 #include "mpegaudiodectab.h" 68 #include "mpegaudiodectab.h"
69 69
70 static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g); 70 static void compute_antialias_integer(MPADecodeContext *s, GranuleDef *g);
71 static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g); 71 static void compute_antialias_float(MPADecodeContext *s, GranuleDef *g);
72 static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
73 int *dither_state, OUT_INT *samples, int incr);
72 74
73 /* vlc structure for decoding layer 3 huffman tables */ 75 /* vlc structure for decoding layer 3 huffman tables */
74 static VLC huff_vlc[16]; 76 static VLC huff_vlc[16];
75 static VLC_TYPE huff_vlc_tables[ 77 static VLC_TYPE huff_vlc_tables[
76 0+128+128+128+130+128+154+166+ 78 0+128+128+128+130+128+154+166+
303 MPADecodeContext *s = avctx->priv_data; 305 MPADecodeContext *s = avctx->priv_data;
304 static int init=0; 306 static int init=0;
305 int i, j, k; 307 int i, j, k;
306 308
307 s->avctx = avctx; 309 s->avctx = avctx;
310 s->apply_window_mp3 = apply_window_mp3_c;
308 311
309 avctx->sample_fmt= OUT_FMT; 312 avctx->sample_fmt= OUT_FMT;
310 s->error_recognition= avctx->error_recognition; 313 s->error_recognition= avctx->error_recognition;
311 314
312 if (!init && !avctx->parse_only) { 315 if (!init && !avctx->parse_only) {
834 if (i != 0) 837 if (i != 0)
835 window[512 - i] = v; 838 window[512 - i] = v;
836 } 839 }
837 } 840 }
838 841
839 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output: 842 static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window,
840 32 samples. */ 843 int *dither_state, OUT_INT *samples, int incr)
841 /* XXX: optimize by avoiding ring buffer usage */ 844 {
842 void RENAME(ff_mpa_synth_filter)(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
843 MPA_INT *window, int *dither_state,
844 OUT_INT *samples, int incr,
845 INTFLOAT sb_samples[SBLIMIT])
846 {
847 register MPA_INT *synth_buf;
848 register const MPA_INT *w, *w2, *p; 845 register const MPA_INT *w, *w2, *p;
849 int j, offset; 846 int j;
850 OUT_INT *samples2; 847 OUT_INT *samples2;
851 #if CONFIG_FLOAT 848 #if CONFIG_FLOAT
852 float sum, sum2; 849 float sum, sum2;
853 #elif FRAC_BITS <= 15 850 #elif FRAC_BITS <= 15
854 int32_t tmp[32];
855 int sum, sum2; 851 int sum, sum2;
856 #else 852 #else
857 int64_t sum, sum2; 853 int64_t sum, sum2;
858 #endif
859
860 offset = *synth_buf_offset;
861 synth_buf = synth_buf_ptr + offset;
862
863 #if FRAC_BITS <= 15 && !CONFIG_FLOAT
864 dct32(tmp, sb_samples);
865 for(j=0;j<32;j++) {
866 /* NOTE: can cause a loss in precision if very high amplitude
867 sound */
868 synth_buf[j] = av_clip_int16(tmp[j]);
869 }
870 #else
871 dct32(synth_buf, sb_samples);
872 #endif 854 #endif
873 855
874 /* copy to avoid wrap */ 856 /* copy to avoid wrap */
875 memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); 857 memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf));
876 858
907 889
908 p = synth_buf + 32; 890 p = synth_buf + 32;
909 SUM8(MLSS, sum, w + 32, p); 891 SUM8(MLSS, sum, w + 32, p);
910 *samples = round_sample(&sum); 892 *samples = round_sample(&sum);
911 *dither_state= sum; 893 *dither_state= sum;
894 }
895
896
897 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
898 32 samples. */
899 /* XXX: optimize by avoiding ring buffer usage */
900 #if CONFIG_FLOAT
901 void ff_mpa_synth_filter_float(MPADecodeContext *s, float *synth_buf_ptr,
902 int *synth_buf_offset,
903 float *window, int *dither_state,
904 float *samples, int incr,
905 float sb_samples[SBLIMIT])
906 {
907 float *synth_buf;
908 int offset;
909
910 offset = *synth_buf_offset;
911 synth_buf = synth_buf_ptr + offset;
912
913 dct32(synth_buf, sb_samples);
914 s->apply_window_mp3(synth_buf, window, dither_state, samples, incr);
912 915
913 offset = (offset - 32) & 511; 916 offset = (offset - 32) & 511;
914 *synth_buf_offset = offset; 917 *synth_buf_offset = offset;
915 } 918 }
919 #else
920 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
921 MPA_INT *window, int *dither_state,
922 OUT_INT *samples, int incr,
923 INTFLOAT sb_samples[SBLIMIT])
924 {
925 register MPA_INT *synth_buf;
926 int offset;
927 #if FRAC_BITS <= 15
928 int32_t tmp[32];
929 #endif
930
931 offset = *synth_buf_offset;
932 synth_buf = synth_buf_ptr + offset;
933
934 #if FRAC_BITS <= 15 && !CONFIG_FLOAT
935 dct32(tmp, sb_samples);
936 for(j=0;j<32;j++) {
937 /* NOTE: can cause a loss in precision if very high amplitude
938 sound */
939 synth_buf[j] = av_clip_int16(tmp[j]);
940 }
941 #else
942 dct32(synth_buf, sb_samples);
943 #endif
944
945 apply_window_mp3_c(synth_buf, window, dither_state, samples, incr);
946
947 offset = (offset - 32) & 511;
948 *synth_buf_offset = offset;
949 }
950 #endif
916 951
917 #define C3 FIXHR(0.86602540378443864676/2) 952 #define C3 FIXHR(0.86602540378443864676/2)
918 953
919 /* 0.5 / cos(pi*(2*i+1)/36) */ 954 /* 0.5 / cos(pi*(2*i+1)/36) */
920 static const INTFLOAT icos36[9] = { 955 static const INTFLOAT icos36[9] = {
2225 2260
2226 /* apply the synthesis filter */ 2261 /* apply the synthesis filter */
2227 for(ch=0;ch<s->nb_channels;ch++) { 2262 for(ch=0;ch<s->nb_channels;ch++) {
2228 samples_ptr = samples + ch; 2263 samples_ptr = samples + ch;
2229 for(i=0;i<nb_frames;i++) { 2264 for(i=0;i<nb_frames;i++) {
2230 RENAME(ff_mpa_synth_filter)(s->synth_buf[ch], &(s->synth_buf_offset[ch]), 2265 RENAME(ff_mpa_synth_filter)(
2266 #if CONFIG_FLOAT
2267 s,
2268 #endif
2269 s->synth_buf[ch], &(s->synth_buf_offset[ch]),
2231 RENAME(ff_mpa_synth_window), &s->dither_state, 2270 RENAME(ff_mpa_synth_window), &s->dither_state,
2232 samples_ptr, s->nb_channels, 2271 samples_ptr, s->nb_channels,
2233 s->sb_samples[ch][i]); 2272 s->sb_samples[ch][i]);
2234 samples_ptr += 32 * s->nb_channels; 2273 samples_ptr += 32 * s->nb_channels;
2235 } 2274 }