comparison mpegaudiodec.c @ 2468:1addaf6facbb libavcodec

exported ff_mpa_synth_filter for upcoming qdm2 decoder
author alex
date Fri, 28 Jan 2005 19:54:10 +0000
parents d9cf90e66883
children 021dc26e760f
comparison
equal deleted inserted replaced
2467:0b3697268285 2468:1addaf6facbb
178 FIXR(1.18920711500272106671), 178 FIXR(1.18920711500272106671),
179 FIXR(1.41421356237309504880), 179 FIXR(1.41421356237309504880),
180 FIXR(1.68179283050742908605), 180 FIXR(1.68179283050742908605),
181 }; 181 };
182 182
183 void ff_mpa_synth_init(MPA_INT *window);
183 static MPA_INT window[512] __attribute__((aligned(16))); 184 static MPA_INT window[512] __attribute__((aligned(16)));
184 185
185 /* layer 1 unscaling */ 186 /* layer 1 unscaling */
186 /* n = number of bits of the mantissa minus 1 */ 187 /* n = number of bits of the mantissa minus 1 */
187 static inline int l1_unscale(int n, int mant, int scale_factor) 188 static inline int l1_unscale(int n, int mant, int scale_factor)
348 scale_factor_mult[i][0], 349 scale_factor_mult[i][0],
349 scale_factor_mult[i][1], 350 scale_factor_mult[i][1],
350 scale_factor_mult[i][2]); 351 scale_factor_mult[i][2]);
351 } 352 }
352 353
353 /* window */ 354 ff_mpa_synth_init(window);
354 /* max = 18760, max sum over all 16 coefs : 44736 */
355 for(i=0;i<257;i++) {
356 int v;
357 v = mpa_enwindow[i];
358 #if WFRAC_BITS < 16
359 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
360 #endif
361 window[i] = v;
362 if ((i & 63) != 0)
363 v = -v;
364 if (i != 0)
365 window[512 - i] = v;
366 }
367 355
368 /* huffman decode tables */ 356 /* huffman decode tables */
369 huff_code_table[0] = NULL; 357 huff_code_table[0] = NULL;
370 for(i=1;i<16;i++) { 358 for(i=1;i<16;i++) {
371 const HuffTable *h = &mpa_huff_tables[i]; 359 const HuffTable *h = &mpa_huff_tables[i];
848 tmp = p[7 * 64];\ 836 tmp = p[7 * 64];\
849 sum1 op1 MULS((w1)[7 * 64], tmp);\ 837 sum1 op1 MULS((w1)[7 * 64], tmp);\
850 sum2 op2 MULS((w2)[7 * 64], tmp);\ 838 sum2 op2 MULS((w2)[7 * 64], tmp);\
851 } 839 }
852 840
841 void ff_mpa_synth_init(MPA_INT *window)
842 {
843 int i;
844
845 /* max = 18760, max sum over all 16 coefs : 44736 */
846 for(i=0;i<257;i++) {
847 int v;
848 v = mpa_enwindow[i];
849 #if WFRAC_BITS < 16
850 v = (v + (1 << (16 - WFRAC_BITS - 1))) >> (16 - WFRAC_BITS);
851 #endif
852 window[i] = v;
853 if ((i & 63) != 0)
854 v = -v;
855 if (i != 0)
856 window[512 - i] = v;
857 }
858 }
853 859
854 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output: 860 /* 32 sub band synthesis filter. Input: 32 sub band samples, Output:
855 32 samples. */ 861 32 samples. */
856 /* XXX: optimize by avoiding ring buffer usage */ 862 /* XXX: optimize by avoiding ring buffer usage */
857 static void synth_filter(MPADecodeContext *s1, 863 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
858 int ch, int16_t *samples, int incr, 864 MPA_INT *window,
865 int16_t *samples, int incr,
859 int32_t sb_samples[SBLIMIT]) 866 int32_t sb_samples[SBLIMIT])
860 { 867 {
861 int32_t tmp[32]; 868 int32_t tmp[32];
862 register MPA_INT *synth_buf; 869 register MPA_INT *synth_buf;
863 register const MPA_INT *w, *w2, *p; 870 register const MPA_INT *w, *w2, *p;
866 #if FRAC_BITS <= 15 873 #if FRAC_BITS <= 15
867 int sum, sum2; 874 int sum, sum2;
868 #else 875 #else
869 int64_t sum, sum2; 876 int64_t sum, sum2;
870 #endif 877 #endif
871 878
872 dct32(tmp, sb_samples); 879 dct32(tmp, sb_samples);
873 880
874 offset = s1->synth_buf_offset[ch]; 881 offset = *synth_buf_offset;
875 synth_buf = s1->synth_buf[ch] + offset; 882 synth_buf = synth_buf_ptr + offset;
876 883
877 for(j=0;j<32;j++) { 884 for(j=0;j<32;j++) {
878 v = tmp[j]; 885 v = tmp[j];
879 #if FRAC_BITS <= 15 886 #if FRAC_BITS <= 15
880 /* NOTE: can cause a loss in precision if very high amplitude 887 /* NOTE: can cause a loss in precision if very high amplitude
924 sum = 0; 931 sum = 0;
925 SUM8(sum, -=, w + 32, p); 932 SUM8(sum, -=, w + 32, p);
926 *samples = round_sample(sum); 933 *samples = round_sample(sum);
927 934
928 offset = (offset - 32) & 511; 935 offset = (offset - 32) & 511;
929 s1->synth_buf_offset[ch] = offset; 936 *synth_buf_offset = offset;
930 } 937 }
931 938
932 /* cos(pi*i/24) */ 939 /* cos(pi*i/24) */
933 #define C1 FIXR(0.99144486137381041114) 940 #define C1 FIXR(0.99144486137381041114)
934 #define C3 FIXR(0.92387953251128675612) 941 #define C3 FIXR(0.92387953251128675612)
2503 #endif 2510 #endif
2504 /* apply the synthesis filter */ 2511 /* apply the synthesis filter */
2505 for(ch=0;ch<s->nb_channels;ch++) { 2512 for(ch=0;ch<s->nb_channels;ch++) {
2506 samples_ptr = samples + ch; 2513 samples_ptr = samples + ch;
2507 for(i=0;i<nb_frames;i++) { 2514 for(i=0;i<nb_frames;i++) {
2508 synth_filter(s, ch, samples_ptr, s->nb_channels, 2515 ff_mpa_synth_filter(s->synth_buf[ch], &(s->synth_buf_offset[ch]),
2516 window,
2517 samples_ptr, s->nb_channels,
2509 s->sb_samples[ch][i]); 2518 s->sb_samples[ch][i]);
2510 samples_ptr += 32 * s->nb_channels; 2519 samples_ptr += 32 * s->nb_channels;
2511 } 2520 }
2512 } 2521 }
2513 #ifdef DEBUG 2522 #ifdef DEBUG