Blame mpglib/decode_i386.c

Packit 47f805
/*
Packit 47f805
 * decode_i396.c: Mpeg Layer-1,2,3 audio decoder
Packit 47f805
 *
Packit 47f805
 * Copyright (C) 1999-2010 The L.A.M.E. project
Packit 47f805
 *
Packit 47f805
 * Initially written by Michael Hipp, see also AUTHORS and README.
Packit 47f805
 *  
Packit 47f805
 * This library is free software; you can redistribute it and/or
Packit 47f805
 * modify it under the terms of the GNU Library General Public
Packit 47f805
 * License as published by the Free Software Foundation; either
Packit 47f805
 * version 2 of the License, or (at your option) any later version.
Packit 47f805
 *
Packit 47f805
 * This library is distributed in the hope that it will be useful,
Packit 47f805
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 47f805
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Packit 47f805
 * Library General Public License for more details.
Packit 47f805
 *
Packit 47f805
 * You should have received a copy of the GNU Library General Public
Packit 47f805
 * License along with this library; if not, write to the
Packit 47f805
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 47f805
 * Boston, MA 02111-1307, USA.
Packit 47f805
 *
Packit 47f805
 *
Packit 47f805
 * Slighlty optimized for machines without autoincrement/decrement.
Packit 47f805
 * The performance is highly compiler dependend. Maybe
Packit 47f805
 * the decode.c version for 'normal' processor may be faster
Packit 47f805
 * even for Intel processors.
Packit 47f805
 */
Packit 47f805
Packit 47f805
/* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
Packit 47f805
Packit 47f805
#ifdef HAVE_CONFIG_H
Packit 47f805
#include <config.h>
Packit 47f805
#endif
Packit 47f805
Packit 47f805
#ifdef STDC_HEADERS
Packit 47f805
# include <stdlib.h>
Packit 47f805
# include <string.h>
Packit 47f805
#else
Packit 47f805
# ifndef HAVE_STRCHR
Packit 47f805
#  define strchr index
Packit 47f805
#  define strrchr rindex
Packit 47f805
# endif
Packit 47f805
char   *strchr(), *strrchr();
Packit 47f805
# ifndef HAVE_MEMCPY
Packit 47f805
#  define memcpy(d, s, n) bcopy ((s), (d), (n))
Packit 47f805
#  define memmove(d, s, n) bcopy ((s), (d), (n))
Packit 47f805
# endif
Packit 47f805
#endif
Packit 47f805
Packit 47f805
#if defined(__riscos__) && defined(FPA10)
Packit 47f805
#include "ymath.h"
Packit 47f805
#else
Packit 47f805
#include <math.h>
Packit 47f805
#endif
Packit 47f805
Packit 47f805
#include "decode_i386.h"
Packit 47f805
#include "dct64_i386.h"
Packit 47f805
#include "tabinit.h"
Packit 47f805
Packit 47f805
#ifdef WITH_DMALLOC
Packit 47f805
#include <dmalloc.h>
Packit 47f805
#endif
Packit 47f805
Packit 47f805
Packit 47f805
 /* old WRITE_SAMPLE_CLIPPED */
Packit 47f805
#define WRITE_SAMPLE_CLIPPED(TYPE,samples,sum,clip) \
Packit 47f805
  if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
Packit 47f805
  else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
Packit 47f805
  else { *(samples) = (TYPE)((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
Packit 47f805
Packit 47f805
#define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
Packit 47f805
  *samples = (TYPE)sum;
Packit 47f805
Packit 47f805
  /* *INDENT-OFF* */
Packit 47f805
Packit 47f805
 /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
Packit 47f805
#define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1)                    \
Packit 47f805
  TYPE samples_tmp[64];                                                \
Packit 47f805
  TYPE *tmp1 = samples_tmp;                                            \
Packit 47f805
  int i,ret;                                                           \
Packit 47f805
  int pnt1 = 0;                                                        \
Packit 47f805
                                                                       \
Packit 47f805
  ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
Packit 47f805
  out += *pnt;                                                         \
Packit 47f805
                                                                       \
Packit 47f805
  for(i=0;i<32;i++) {                                                  \
Packit 47f805
    *( (TYPE *) out) = *tmp1;                                          \
Packit 47f805
    out += sizeof(TYPE);                                               \
Packit 47f805
    tmp1 += 2;                                                         \
Packit 47f805
  }                                                                    \
Packit 47f805
  *pnt += 32*sizeof(TYPE);                                             \
Packit 47f805
                                                                       \
Packit 47f805
  return ret; 
Packit 47f805
Packit 47f805
  /* *INDENT-ON* */
Packit 47f805
Packit 47f805
Packit 47f805
int
Packit 47f805
synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
Packit 47f805
{
Packit 47f805
    SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
Packit 47f805
} int
Packit 47f805
synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
Packit 47f805
{
Packit 47f805
    SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
Packit 47f805
}
Packit 47f805
Packit 47f805
    /* *INDENT-OFF* */
Packit 47f805
/* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
Packit 47f805
#define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE)         \
Packit 47f805
  static const int step = 2;                             \
Packit 47f805
  int bo;                                                \
Packit 47f805
  TYPE *samples = (TYPE *) (out + *pnt);                 \
Packit 47f805
                                                         \
Packit 47f805
  real *b0,(*buf)[0x110];                                \
Packit 47f805
  int clip = 0;                                          \
Packit 47f805
  int bo1;                                               \
Packit 47f805
                                                         \
Packit 47f805
  bo = mp->synth_bo;                                     \
Packit 47f805
                                                         \
Packit 47f805
  if(!channel) {                                         \
Packit 47f805
    bo--;                                                \
Packit 47f805
    bo &= 0xf;                                           \
Packit 47f805
    buf = mp->synth_buffs[0];                            \
Packit 47f805
  }                                                      \
Packit 47f805
  else {                                                 \
Packit 47f805
    samples++;                                           \
Packit 47f805
    buf = mp->synth_buffs[1];                            \
Packit 47f805
  }                                                      \
Packit 47f805
                                                         \
Packit 47f805
  if(bo & 0x1) {                                         \
Packit 47f805
    b0 = buf[0];                                         \
Packit 47f805
    bo1 = bo;                                            \
Packit 47f805
    dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);        \
Packit 47f805
  }                                                      \
Packit 47f805
  else {                                                 \
Packit 47f805
    b0 = buf[1];                                         \
Packit 47f805
    bo1 = bo+1;                                          \
Packit 47f805
    dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);                \
Packit 47f805
  }                                                      \
Packit 47f805
                                                         \
Packit 47f805
  mp->synth_bo = bo;                                     \
Packit 47f805
                                                         \
Packit 47f805
  {                                                      \
Packit 47f805
    int j;                                               \
Packit 47f805
    real *window = decwin + 16 - bo1;                    \
Packit 47f805
                                                         \
Packit 47f805
    for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
Packit 47f805
    {                                                    \
Packit 47f805
      real sum;                                          \
Packit 47f805
      sum  = window[0x0] * b0[0x0];                      \
Packit 47f805
      sum -= window[0x1] * b0[0x1];                      \
Packit 47f805
      sum += window[0x2] * b0[0x2];                      \
Packit 47f805
      sum -= window[0x3] * b0[0x3];                      \
Packit 47f805
      sum += window[0x4] * b0[0x4];                      \
Packit 47f805
      sum -= window[0x5] * b0[0x5];                      \
Packit 47f805
      sum += window[0x6] * b0[0x6];                      \
Packit 47f805
      sum -= window[0x7] * b0[0x7];                      \
Packit 47f805
      sum += window[0x8] * b0[0x8];                      \
Packit 47f805
      sum -= window[0x9] * b0[0x9];                      \
Packit 47f805
      sum += window[0xA] * b0[0xA];                      \
Packit 47f805
      sum -= window[0xB] * b0[0xB];                      \
Packit 47f805
      sum += window[0xC] * b0[0xC];                      \
Packit 47f805
      sum -= window[0xD] * b0[0xD];                      \
Packit 47f805
      sum += window[0xE] * b0[0xE];                      \
Packit 47f805
      sum -= window[0xF] * b0[0xF];                      \
Packit 47f805
                                                         \
Packit 47f805
      WRITE_SAMPLE (TYPE,samples,sum,clip);              \
Packit 47f805
    }                                                    \
Packit 47f805
                                                         \
Packit 47f805
    {                                                    \
Packit 47f805
      real sum;                                          \
Packit 47f805
      sum  = window[0x0] * b0[0x0];                      \
Packit 47f805
      sum += window[0x2] * b0[0x2];                      \
Packit 47f805
      sum += window[0x4] * b0[0x4];                      \
Packit 47f805
      sum += window[0x6] * b0[0x6];                      \
Packit 47f805
      sum += window[0x8] * b0[0x8];                      \
Packit 47f805
      sum += window[0xA] * b0[0xA];                      \
Packit 47f805
      sum += window[0xC] * b0[0xC];                      \
Packit 47f805
      sum += window[0xE] * b0[0xE];                      \
Packit 47f805
      WRITE_SAMPLE (TYPE,samples,sum,clip);              \
Packit 47f805
      b0-=0x10,window-=0x20,samples+=step;               \
Packit 47f805
    }                                                    \
Packit 47f805
    window += bo1<<1;                                    \
Packit 47f805
                                                         \
Packit 47f805
    for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
Packit 47f805
    {                                                    \
Packit 47f805
      real sum;                                          \
Packit 47f805
      sum = -window[-0x1] * b0[0x0];                     \
Packit 47f805
      sum -= window[-0x2] * b0[0x1];                     \
Packit 47f805
      sum -= window[-0x3] * b0[0x2];                     \
Packit 47f805
      sum -= window[-0x4] * b0[0x3];                     \
Packit 47f805
      sum -= window[-0x5] * b0[0x4];                     \
Packit 47f805
      sum -= window[-0x6] * b0[0x5];                     \
Packit 47f805
      sum -= window[-0x7] * b0[0x6];                     \
Packit 47f805
      sum -= window[-0x8] * b0[0x7];                     \
Packit 47f805
      sum -= window[-0x9] * b0[0x8];                     \
Packit 47f805
      sum -= window[-0xA] * b0[0x9];                     \
Packit 47f805
      sum -= window[-0xB] * b0[0xA];                     \
Packit 47f805
      sum -= window[-0xC] * b0[0xB];                     \
Packit 47f805
      sum -= window[-0xD] * b0[0xC];                     \
Packit 47f805
      sum -= window[-0xE] * b0[0xD];                     \
Packit 47f805
      sum -= window[-0xF] * b0[0xE];                     \
Packit 47f805
      sum -= window[-0x0] * b0[0xF];                     \
Packit 47f805
                                                         \
Packit 47f805
      WRITE_SAMPLE (TYPE,samples,sum,clip);              \
Packit 47f805
    }                                                    \
Packit 47f805
  }                                                      \
Packit 47f805
  *pnt += 64*sizeof(TYPE);                               \
Packit 47f805
                                                         \
Packit 47f805
  return clip;                                           
Packit 47f805
    /* *INDENT-ON* */
Packit 47f805
Packit 47f805
Packit 47f805
int
Packit 47f805
synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
Packit 47f805
{
Packit 47f805
    SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
Packit 47f805
} int
Packit 47f805
synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
Packit 47f805
{
Packit 47f805
    SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)
Packit 47f805
}