⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icdct.c

📁 DSP c64优化 ACT spraa14 mp3优化实例 与其优化应用报告配套
💻 C
字号:
/*____________________________________________________________________________
        
        FreeAmp - The Free MP3 Player

        MP3 Decoder originally Copyright (C) 1995-1997 Xing Technology
        Corp.  http://www.xingtech.com

        Portions Copyright (C) 1998 EMusic.com

        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.

        This program 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 General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
        
        $Id: icdct.c,v 1.2 2000/09/15 20:44:01 eric Exp $
____________________________________________________________________________*/

/****  icdct.c  ***************************************************


MPEG audio decoder, dct
portable C    integer dct

mod 1/8/97 warnings

******************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include "itype.h"

#define forward_bf idx_forward_bf

/*-------------------------------------------------------------------*/
static DCTCOEF coef32[32];        /* 32 pt dct coefs */

/*------------------------------------------------------------*/
DCTCOEF *i_dct_coef_addr()
{
   return coef32;
}

/*------------------------------------------------------------*/
static void idx_forward_bf(int m, int n, INT32 x[], INT32 f[restrict], DCTCOEF coef[])
{
   int i, j, n2;
   int p, q, p0, k;

   p0 = 0;
   n2 = n >> 1;
   for (i = 0; i < m; i++, p0 += n)
   {
      k = 0;
      p = p0;
      q = p + n - 1;
      for (j = 0; j < n2; j++, p++, q--, k++)
      {
         f[p] = x[p] + x[q];
         f[n2 + p] = ((x[p] - x[q]) * coef[k]) >> DCTBITS;
      }
   }
}

/*------------------------------------------------------------*/
static void forward_bfm(int m, INT32 x[], INT32 f[])
{
   int i;
   int p;

/*--- special case last fwd stage ----*/
   for (p = 0, i = 0; i < m; i++, p += 2)
   {
      f[p] = x[p] + x[p + 1];
      f[p + 1] = ((x[p] - x[p + 1]) * coef32[30]) >> DCTBITS;
   }
}

/*------------------------------------------------------------*/
static void back_bf(int m, int n, INT32 x[], INT32 f[restrict])
{
   int i, j, n2, n21;
   int p, q, p0;

   p0 = 0;
   n2 = n >> 1;
   n21 = n2 - 1;
   for (i = 0; i < m; i++, p0 += n)
   {
      p = p0;
      q = p0;
      for (j = 0; j < n2; j++, p += 2, q++)
         f[p] = x[q];
      p = p0 + 1;
      for (j = 0; j < n21; j++, p += 2, q++)
         f[p] = x[q] + x[q + 1];
      f[p] = x[q];
   }
}

/*------------------------------------------------------------*/
static void back_bf0(int n, INT32 x[], WININT f[restrict])
{
   int p, q;

   n--;

   for (p = 0, q = 0; p < n; p += 2, q++)
      f[p] = x[q];   
   for (p = 1; q < n; p += 2, q++)
      f[p] = x[q] + x[q + 1];
   f[p] = x[q];

}

/*------------------------------------------------------------*/
void i_dct32(SAMPLEINT x[], WININT c[])
{
   INT32 a[32];                        /* ping pong buffers */
   INT32 b[32];
   int p, q;
   
   ALIGNED_ARRAY(x);

/* special first stage */
   for (p = 0, q = 31; p < 16; p++, q--)
   {
      a[p] = (INT32) x[p] + x[q];
      a[16 + p] = (coef32[p] * ((INT32) x[p] - x[q])) >> DCTBITS;
   }

   forward_bf(2, 16, a, b, coef32 + 16);
   forward_bf(4, 8, b, a, coef32 + 16 + 8);
   forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
   forward_bfm(16, b, a);
   back_bf(8, 4, a, b);
   back_bf(4, 8, b, a);
   back_bf(2, 16, a, b);
   back_bf0(32, b, c);
}

/*------------------------------------------------------------*/
void i_dct32_dual(SAMPLEINT x[], WININT c[])
{
   INT32 a[32];                        /* ping pong buffers */
   INT32 b[32];
   int p, pp, qq;

/* special first stage for dual chan (interleaved x) */
   pp = 0;
   qq = 2 * 31;
   for (p = 0; p < 16; p++, pp += 2, qq -= 2)
   {
      a[p] = (INT32) x[pp] + x[qq];
      a[16 + p] = (coef32[p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
   }
   forward_bf(2, 16, a, b, coef32 + 16);
   forward_bf(4, 8, b, a, coef32 + 16 + 8);
   forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
   forward_bfm(16, b, a);
   back_bf(8, 4, a, b);
   back_bf(4, 8, b, a);
   back_bf(2, 16, a, b);
   back_bf0(32, b, c);
}

/*---------------convert dual to mono------------------------------*/
void i_dct32_dual_mono(SAMPLEINT x[], WININT c[])
{
   INT32 a[32];                        /* ping pong buffers */
   INT32 b[32];
   INT32 t1, t2;
   int p, pp, qq;

/* special first stage  */
   pp = 0;
   qq = 2 * 31;
   for (p = 0; p < 16; p++, pp += 2, qq -= 2)
   {
      t1 = ((INT32) x[pp] + x[pp + 1]);
      t2 = ((INT32) x[qq] + x[qq + 1]);
      a[p] = (t1 + t2) >> 1;
      a[16 + p] = coef32[p] * (t1 - t2) >> (DCTBITS + 1);
   }
   forward_bf(2, 16, a, b, coef32 + 16);
   forward_bf(4, 8, b, a, coef32 + 16 + 8);
   forward_bf(8, 4, a, b, coef32 + 16 + 8 + 4);
   forward_bfm(16, b, a);
   back_bf(8, 4, a, b);
   back_bf(4, 8, b, a);
   back_bf(2, 16, a, b);
   back_bf0(32, b, c);
}

/*---------------- 16 pt dct -------------------------------*/
void i_dct16(SAMPLEINT x[], WININT c[])
{
   INT32 a[16];                        /* ping pong buffers */
   INT32 b[16];
   int p, q;

/* special first stage (drop highest sb) */
   a[0] = x[0];
   a[8] = (a[0] * coef32[16]) >> DCTBITS;
   for (p = 1, q = 14; p < 8; p++, q--)
   {
      a[p] = (INT32) x[p] + x[q];
      a[8 + p] = (((INT32) x[p] - x[q]) * coef32[16 + p]) >> DCTBITS;
   }
   forward_bf(2, 8, a, b, coef32 + 16 + 8);
   forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(8, a, b);
   back_bf(4, 4, b, a);
   back_bf(2, 8, a, b);
   back_bf0(16, b, c);
}

/*---------------- 16 pt dct dual chan---------------------*/
void i_dct16_dual(SAMPLEINT x[], WININT c[])
{
   int p, pp, qq;
   INT32 a[16];                        /* ping pong buffers */
   INT32 b[16];

/* special first stage for interleaved input */
   a[0] = x[0];
   a[8] = (coef32[16] * a[0]) >> DCTBITS;
   pp = 2;
   qq = 2 * 14;
   for (p = 1; p < 8; p++, pp += 2, qq -= 2)
   {
      a[p] = (INT32) x[pp] + x[qq];
      a[8 + p] = (coef32[16 + p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
   }
   forward_bf(2, 8, a, b, coef32 + 16 + 8);
   forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(8, a, b);
   back_bf(4, 4, b, a);
   back_bf(2, 8, a, b);
   back_bf0(16, b, c);
}

/*---------------- 16 pt dct dual to mono-------------------*/
void i_dct16_dual_mono(SAMPLEINT x[], WININT c[])
{
   INT32 a[16];                        /* ping pong buffers */
   INT32 b[16];
   INT32 t1, t2;
   int p, pp, qq;

/* special first stage  */
   a[0] = ((INT32) x[0] + x[1]) >> 1;
   a[8] = (coef32[16] * a[0]) >> DCTBITS;
   pp = 2;
   qq = 2 * 14;
   for (p = 1; p < 8; p++, pp += 2, qq -= 2)
   {
      t1 = (INT32) x[pp] + x[pp + 1];
      t2 = (INT32) x[qq] + x[qq + 1];
      a[p] = (t1 + t2) >> 1;
      a[8 + p] = (coef32[16 + p] * (t1 - t2)) >> (DCTBITS + 1);
   }
   forward_bf(2, 8, a, b, coef32 + 16 + 8);
   forward_bf(4, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(8, a, b);
   back_bf(4, 4, b, a);
   back_bf(2, 8, a, b);
   back_bf0(16, b, c);
}

/*---------------- 8 pt dct -------------------------------*/
void i_dct8(SAMPLEINT x[], WININT c[])
{
   int p, q;
   INT32 a[8];                        /* ping pong buffers */
   INT32 b[8];

   ALIGNED_ARRAY(x);
   
/* special first stage  */

   for (p = 0, q = 7; p < 4; p++, q--)
   {
      b[p] = (INT32) x[p] + x[q];
      b[4 + p] = (coef32[16 + 8 + p] * ((INT32) x[p] - x[q])) >> DCTBITS;
   }

   forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(4, a, b);
   back_bf(2, 4, b, a);
   back_bf0(8, a, c);
}

/*---------------- 8 pt dct dual chan---------------------*/
void i_dct8_dual(SAMPLEINT x[], WININT c[])
{
   int p, pp, qq;
   INT32 a[8];                        /* ping pong buffers */
   INT32 b[8];

/* special first stage for interleaved input */
   for (p = 0, pp = 0, qq = 14; p < 4; p++, pp += 2, qq -= 2)
   {
      b[p] = (INT32) x[pp] + x[qq];
      b[4 + p] = (coef32[16 + 8 + p] * ((INT32) x[pp] - x[qq])) >> DCTBITS;
   }
   forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(4, a, b);
   back_bf(2, 4, b, a);
   back_bf0(8, a, c);
}

/*---------------- 8 pt dct dual to mono---------------------*/
void i_dct8_dual_mono(SAMPLEINT x[], WININT c[])
{
   int p, pp, qq;
   INT32 a[8];                        /* ping pong buffers */
   INT32 b[8];
   INT32 t1, t2;

/* special first stage  */
   for (p = 0, pp = 0, qq = 14; p < 4; p++, pp += 2, qq -= 2)
   {
      t1 = (INT32) x[pp] + x[pp + 1];
      t2 = (INT32) x[qq] + x[qq + 1];
      b[p] = (t1 + t2) >> 1;
      b[4 + p] = (coef32[16 + 8 + p] * (t1 - t2)) >> (DCTBITS + 1);
   }
   forward_bf(2, 4, b, a, coef32 + 16 + 8 + 4);
   forward_bfm(4, a, b);
   back_bf(2, 4, b, a);
   back_bf0(8, a, c);
}

/* ***********************************************************
* THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
* REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, 
* INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
* FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR 
* COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. 
* TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET 
* POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY 
* INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR 
* YOUR USE OF THE PROGRAM.
*
* IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, 
* CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY 
* THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT 
* OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. 
* EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF 
* REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS 
* OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF 
* USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S 
* AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF 
* YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS 
* (U.S.$500).
*
* Unless otherwise stated, the Program written and copyrighted 
* by Texas Instruments is distributed as "freeware".  You may, 
* only under TI's copyright in the Program, use and modify the 
* Program without any charge or restriction.  You may 
* distribute to third parties, provided that you transfer a 
* copy of this license to the third party and the third party 
* agrees to these terms by its first use of the Program. You 
* must reproduce the copyright notice and any other legend of 
* ownership on each copy or partial copy, of the Program.
*
* You acknowledge and agree that the Program contains 
* copyrighted material, trade secrets and other TI proprietary 
* information and is protected by copyright laws, 
* international copyright treaties, and trade secret laws, as 
* well as other intellectual property laws.  To protect TI's 
* rights in the Program, you agree not to decompile, reverse 
* engineer, disassemble or otherwise translate any object code 
* versions of the Program to a human-readable form.  You agree 
* that in no event will you alter, remove or destroy any 
* copyright notice included in the Program.  TI reserves all 
* rights not specifically granted under this license. Except 
* as specifically provided herein, nothing in this agreement 
* shall be construed as conferring by implication, estoppel, 
* or otherwise, upon you, any license or other right under any 
* TI patents, copyrights or trade secrets.
*
* You may not use the Program in non-TI devices.
* ********************************************************* */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -