📄 mpegaudsynth.c
字号:
/* * MPEG Audio decoder * Copyright (c) 2001, 2002 Fabrice Bellard. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * *//** * @file mpegaudiodec.c * MPEG Audio decoder. * from FFMPEG_VERSION "0.4.8" */ //#define DEBUG#include <stdio.h>#include <string.h>#include "mpegaudiodec.h"#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)#if (OUT_SHIFT == 24) #define MULSH MULS24#elif (FRAC_BITS > 15) #define MULSH(a,b) ((int)(((int64_t)(a) * (int64_t)(b)) >> (OUT_SHIFT)))#endif#if (FRAC_BITS > 15) #define saturate16(sum) ((sum > 32767) ? 32767 : ((sum < -32768) ? -32768 : sum)) #define SUM8(sum, op, w, p) \ { \ sum op MULSH((w)[0 * 64], p[0 * 64]);\ sum op MULSH((w)[1 * 64], p[1 * 64]);\ sum op MULSH((w)[2 * 64], p[2 * 64]);\ sum op MULSH((w)[3 * 64], p[3 * 64]);\ sum op MULSH((w)[4 * 64], p[4 * 64]);\ sum op MULSH((w)[5 * 64], p[5 * 64]);\ sum op MULSH((w)[6 * 64], p[6 * 64]);\ sum op MULSH((w)[7 * 64], p[7 * 64]);\ } #define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \ { \ int tmp;\ tmp = p[0 * 64];\ sum1 op1 MULSH((w1)[0 * 64], tmp);\ sum2 op2 MULSH((w2)[0 * 64], tmp);\ tmp = p[1 * 64];\ sum1 op1 MULSH((w1)[1 * 64], tmp);\ sum2 op2 MULSH((w2)[1 * 64], tmp);\ tmp = p[2 * 64];\ sum1 op1 MULSH((w1)[2 * 64], tmp);\ sum2 op2 MULSH((w2)[2 * 64], tmp);\ tmp = p[3 * 64];\ sum1 op1 MULSH((w1)[3 * 64], tmp);\ sum2 op2 MULSH((w2)[3 * 64], tmp);\ tmp = p[4 * 64];\ sum1 op1 MULSH((w1)[4 * 64], tmp);\ sum2 op2 MULSH((w2)[4 * 64], tmp);\ tmp = p[5 * 64];\ sum1 op1 MULSH((w1)[5 * 64], tmp);\ sum2 op2 MULSH((w2)[5 * 64], tmp);\ tmp = p[6 * 64];\ sum1 op1 MULSH((w1)[6 * 64], tmp);\ sum2 op2 MULSH((w2)[6 * 64], tmp);\ tmp = p[7 * 64];\ sum1 op1 MULSH((w1)[7 * 64], tmp);\ sum2 op2 MULSH((w2)[7 * 64], tmp);\ }#endif/* 32 sub band synthesis filter. Input: 32 sub band samples, Output: 32 samples. *//* XXX: optimize by avoiding ring buffer usage */#ifndef USE_CE_ASM_FUNCTIONvoid synth_filter(int *synth_buf, int *offset, int16_t *samples, int incr, int *tmp){ const register MPA_INT *ww, *w2, *pp; int j; int16_t *samples2; int sum, sum2; memcpy(synth_buf, tmp, 32 * sizeof(MPA_INT)); /* copy to avoid wrap */ memcpy(synth_buf + 512, synth_buf, 32 * sizeof(MPA_INT)); samples2 = samples + 31 * incr; ww = window; w2 = window + 31; #ifdef USE_INT_MULTC SUM16(sum, ww, ww + 32, pp); *samples = saturate16(sum); samples += incr; ww++; #else sum = 0; pp = synth_buf + 16; SUM8(sum, +=, ww, pp); pp = synth_buf + 48; SUM8(sum, -=, ww + 32, pp); *samples = saturate16(sum); samples += incr; ww++; #endif /* we calculate two samples at the same time to avoid one memory access per two samples */ for (j = 1; j < 16; j++) { #ifdef USE_INT_MULTC SUM16A(ww + 32); SUM16B(w2 + 32); #else sum= 0; sum2 = 0; pp = synth_buf + 16 + j; SUM8P2(sum, +=, sum2, -=, ww, w2, pp); pp = synth_buf + 48 - j; SUM8P2(sum, -=, sum2, -=, ww + 32, w2 + 32, pp); #endif *samples = saturate16(sum); samples += incr; *samples2 = saturate16(sum2); samples2 -= incr; ww++; w2--; } #ifdef USE_INT_MULTC SUM8M(ww + 32); #else pp = synth_buf + 32; sum = 0; SUM8(sum, -=, ww + 32, pp); #endif *samples = saturate16(sum); *offset = (*offset - 32) & 511;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -