comparison mpegaudiodec.c @ 2491:c559ea6e395c libavcodec

optimize antialias switch to integer antialias code as default as its faster now
author michael
date Wed, 02 Feb 2005 01:37:33 +0000
parents c2c642ad6ef4
children 7a79cb42eddb
comparison
equal deleted inserted replaced
2490:c2c642ad6ef4 2491:c559ea6e395c
222 } 222 }
223 223
224 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */ 224 /* compute value^(4/3) * 2^(exponent/4). It normalized to FRAC_BITS */
225 static inline int l3_unscale(int value, int exponent) 225 static inline int l3_unscale(int value, int exponent)
226 { 226 {
227
228 unsigned int m; 227 unsigned int m;
229 int e; 228 int e;
230 229
231 e = table_4_3_exp [4*value + (exponent&3)]; 230 e = table_4_3_exp [4*value + (exponent&3)];
232 m = table_4_3_value[4*value + (exponent&3)]; 231 m = table_4_3_value[4*value + (exponent&3)];
321 avctx->sample_fmt= SAMPLE_FMT_S32; 320 avctx->sample_fmt= SAMPLE_FMT_S32;
322 #else 321 #else
323 avctx->sample_fmt= SAMPLE_FMT_S16; 322 avctx->sample_fmt= SAMPLE_FMT_S16;
324 #endif 323 #endif
325 324
326 if(avctx->antialias_algo == FF_AA_INT) 325 if(avctx->antialias_algo != FF_AA_FLOAT)
327 s->compute_antialias= compute_antialias_integer; 326 s->compute_antialias= compute_antialias_integer;
328 else 327 else
329 s->compute_antialias= compute_antialias_float; 328 s->compute_antialias= compute_antialias_float;
330 329
331 if (!init && !avctx->parse_only) { 330 if (!init && !avctx->parse_only) {
448 for(i=0;i<8;i++) { 447 for(i=0;i<8;i++) {
449 float ci, cs, ca; 448 float ci, cs, ca;
450 ci = ci_table[i]; 449 ci = ci_table[i];
451 cs = 1.0 / sqrt(1.0 + ci * ci); 450 cs = 1.0 / sqrt(1.0 + ci * ci);
452 ca = cs * ci; 451 ca = cs * ci;
453 csa_table[i][0] = FIX(cs); 452 csa_table[i][0] = FIXHR(cs/4);
454 csa_table[i][1] = FIX(ca); 453 csa_table[i][1] = FIXHR(ca/4);
455 csa_table[i][2] = FIX(ca) + FIX(cs); 454 csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4);
456 csa_table[i][3] = FIX(ca) - FIX(cs); 455 csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4);
457 csa_table_float[i][0] = cs; 456 csa_table_float[i][0] = cs;
458 csa_table_float[i][1] = ca; 457 csa_table_float[i][1] = ca;
459 csa_table_float[i][2] = ca + cs; 458 csa_table_float[i][2] = ca + cs;
460 csa_table_float[i][3] = ca - cs; 459 csa_table_float[i][3] = ca - cs;
461 // printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca)); 460 // printf("%d %d %d %d\n", FIX(cs), FIX(cs-1), FIX(ca), FIX(cs)-FIX(ca));
1909 } 1908 }
1910 1909
1911 static void compute_antialias_integer(MPADecodeContext *s, 1910 static void compute_antialias_integer(MPADecodeContext *s,
1912 GranuleDef *g) 1911 GranuleDef *g)
1913 { 1912 {
1914 int32_t *ptr, *p0, *p1, *csa; 1913 int32_t *ptr, *csa;
1915 int n, i, j; 1914 int n, i;
1916 1915
1917 /* we antialias only "long" bands */ 1916 /* we antialias only "long" bands */
1918 if (g->block_type == 2) { 1917 if (g->block_type == 2) {
1919 if (!g->switch_point) 1918 if (!g->switch_point)
1920 return; 1919 return;
1924 n = SBLIMIT - 1; 1923 n = SBLIMIT - 1;
1925 } 1924 }
1926 1925
1927 ptr = g->sb_hybrid + 18; 1926 ptr = g->sb_hybrid + 18;
1928 for(i = n;i > 0;i--) { 1927 for(i = n;i > 0;i--) {
1929 p0 = ptr - 1; 1928 int tmp0, tmp1, tmp2;
1930 p1 = ptr; 1929 csa = &csa_table[0][0];
1931 csa = &csa_table[0][0]; 1930 #define INT_AA(j) \
1932 for(j=0;j<4;j++) { 1931 tmp0 = 4*(ptr[-1-j]);\
1933 int tmp0 = *p0; 1932 tmp1 = 4*(ptr[ j]);\
1934 int tmp1 = *p1; 1933 tmp2= MULH(tmp0 + tmp1, csa[0+4*j]);\
1935 #if 0 1934 ptr[-1-j] = tmp2 - MULH(tmp1, csa[2+4*j]);\
1936 *p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1])); 1935 ptr[ j] = tmp2 + MULH(tmp0, csa[3+4*j]);
1937 *p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0])); 1936
1938 #else 1937 INT_AA(0)
1939 int64_t tmp2= MUL64(tmp0 + tmp1, csa[0]); 1938 INT_AA(1)
1940 *p0 = FRAC_RND(tmp2 - MUL64(tmp1, csa[2])); 1939 INT_AA(2)
1941 *p1 = FRAC_RND(tmp2 + MUL64(tmp0, csa[3])); 1940 INT_AA(3)
1942 #endif 1941 INT_AA(4)
1943 p0--; p1++; 1942 INT_AA(5)
1944 csa += 4; 1943 INT_AA(6)
1945 tmp0 = *p0; 1944 INT_AA(7)
1946 tmp1 = *p1; 1945
1947 #if 0
1948 *p0 = FRAC_RND(MUL64(tmp0, csa[0]) - MUL64(tmp1, csa[1]));
1949 *p1 = FRAC_RND(MUL64(tmp0, csa[1]) + MUL64(tmp1, csa[0]));
1950 #else
1951 tmp2= MUL64(tmp0 + tmp1, csa[0]);
1952 *p0 = FRAC_RND(tmp2 - MUL64(tmp1, csa[2]));
1953 *p1 = FRAC_RND(tmp2 + MUL64(tmp0, csa[3]));
1954 #endif
1955 p0--; p1++;
1956 csa += 4;
1957 }
1958 ptr += 18; 1946 ptr += 18;
1959 } 1947 }
1960 } 1948 }
1961 1949
1962 static void compute_antialias_float(MPADecodeContext *s, 1950 static void compute_antialias_float(MPADecodeContext *s,
1963 GranuleDef *g) 1951 GranuleDef *g)
1964 { 1952 {
1965 int32_t *ptr, *p0, *p1; 1953 int32_t *ptr;
1966 int n, i, j; 1954 int n, i;
1967 1955
1968 /* we antialias only "long" bands */ 1956 /* we antialias only "long" bands */
1969 if (g->block_type == 2) { 1957 if (g->block_type == 2) {
1970 if (!g->switch_point) 1958 if (!g->switch_point)
1971 return; 1959 return;
1975 n = SBLIMIT - 1; 1963 n = SBLIMIT - 1;
1976 } 1964 }
1977 1965
1978 ptr = g->sb_hybrid + 18; 1966 ptr = g->sb_hybrid + 18;
1979 for(i = n;i > 0;i--) { 1967 for(i = n;i > 0;i--) {
1968 float tmp0, tmp1;
1980 float *csa = &csa_table_float[0][0]; 1969 float *csa = &csa_table_float[0][0];
1981 p0 = ptr - 1; 1970 #define FLOAT_AA(j)\
1982 p1 = ptr; 1971 tmp0= ptr[-1-j];\
1983 for(j=0;j<4;j++) { 1972 tmp1= ptr[ j];\
1984 float tmp0 = *p0; 1973 ptr[-1-j] = lrintf(tmp0 * csa[0+4*j] - tmp1 * csa[1+4*j]);\
1985 float tmp1 = *p1; 1974 ptr[ j] = lrintf(tmp0 * csa[1+4*j] + tmp1 * csa[0+4*j]);
1986 #if 1 1975
1987 *p0 = lrintf(tmp0 * csa[0] - tmp1 * csa[1]); 1976 FLOAT_AA(0)
1988 *p1 = lrintf(tmp0 * csa[1] + tmp1 * csa[0]); 1977 FLOAT_AA(1)
1989 #else 1978 FLOAT_AA(2)
1990 float tmp2= (tmp0 + tmp1) * csa[0]; 1979 FLOAT_AA(3)
1991 *p0 = lrintf(tmp2 - tmp1 * csa[2]); 1980 FLOAT_AA(4)
1992 *p1 = lrintf(tmp2 + tmp0 * csa[3]); 1981 FLOAT_AA(5)
1993 #endif 1982 FLOAT_AA(6)
1994 p0--; p1++; 1983 FLOAT_AA(7)
1995 csa += 4; 1984
1996 tmp0 = *p0;
1997 tmp1 = *p1;
1998 #if 1
1999 *p0 = lrintf(tmp0 * csa[0] - tmp1 * csa[1]);
2000 *p1 = lrintf(tmp0 * csa[1] + tmp1 * csa[0]);
2001 #else
2002 tmp2= (tmp0 + tmp1) * csa[0];
2003 *p0 = lrintf(tmp2 - tmp1 * csa[2]);
2004 *p1 = lrintf(tmp2 + tmp0 * csa[3]);
2005 #endif
2006 p0--; p1++;
2007 csa += 4;
2008 }
2009 ptr += 18; 1985 ptr += 18;
2010 } 1986 }
2011 } 1987 }
2012 1988
2013 static void compute_imdct(MPADecodeContext *s, 1989 static void compute_imdct(MPADecodeContext *s,