misc/libtremor/misc.h
author nemo
Fri, 02 Sep 2011 13:02:34 -0400
changeset 5741 a406d8a5000d
parent 5170 f7e49eff3708
permissions -rw-r--r--
lighten a bit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5170
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     1
/********************************************************************
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     2
 *                                                                  *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     3
 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE.   *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     4
 *                                                                  *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     5
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     6
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     7
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     8
 *                                                                  *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
     9
 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002    *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    10
 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/                  *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    11
 *                                                                  *
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    12
 ********************************************************************
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    13
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    14
 function: miscellaneous math and prototypes
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    15
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    16
 ********************************************************************/
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    17
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    18
#ifndef _V_RANDOM_H_
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    19
#define _V_RANDOM_H_
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    20
#include "ivorbiscodec.h"
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    21
#include "os.h"
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    22
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    23
#include "asm_arm.h"
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    24
#include <stdlib.h> /* for abs() */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    25
  
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    26
#ifndef _V_WIDE_MATH
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    27
#define _V_WIDE_MATH
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    28
  
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    29
#ifndef  _LOW_ACCURACY_
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    30
/* 64 bit multiply */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    31
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    32
#if !(defined WIN32 && defined WINCE)
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    33
#include <sys/types.h>
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    34
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    35
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    36
#if BYTE_ORDER==LITTLE_ENDIAN
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    37
union magic {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    38
  struct {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    39
    ogg_int32_t lo;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    40
    ogg_int32_t hi;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    41
  } halves;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    42
  ogg_int64_t whole;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    43
};
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    44
#endif 
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    45
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    46
#if BYTE_ORDER==BIG_ENDIAN
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    47
union magic {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    48
  struct {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    49
    ogg_int32_t hi;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    50
    ogg_int32_t lo;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    51
  } halves;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    52
  ogg_int64_t whole;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    53
};
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    54
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    55
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    56
STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    57
  union magic magic;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    58
  magic.whole = (ogg_int64_t)x * y;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    59
  return magic.halves.hi;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    60
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    61
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    62
STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    63
  return MULT32(x,y)<<1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    64
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    65
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    66
STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    67
  union magic magic;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    68
  magic.whole  = (ogg_int64_t)x * y;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    69
  return ((ogg_uint32_t)(magic.halves.lo)>>15) | ((magic.halves.hi)<<17);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    70
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    71
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    72
#else
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    73
/* 32 bit multiply, more portable but less accurate */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    74
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    75
/*
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    76
 * Note: Precision is biased towards the first argument therefore ordering
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    77
 * is important.  Shift values were chosen for the best sound quality after
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    78
 * many listening tests.
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    79
 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    80
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    81
/*
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    82
 * For MULT32 and MULT31: The second argument is always a lookup table
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    83
 * value already preshifted from 31 to 8 bits.  We therefore take the 
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    84
 * opportunity to save on text space and use unsigned char for those
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    85
 * tables in this case.
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    86
 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    87
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    88
STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    89
  return (x >> 9) * y;  /* y preshifted >>23 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    90
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    91
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    92
STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    93
  return (x >> 8) * y;  /* y preshifted >>23 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    94
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    95
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    96
STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    97
  return (x >> 6) * y;  /* y preshifted >>9 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    98
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
    99
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   100
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   101
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   102
/*
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   103
 * This should be used as a memory barrier, forcing all cached values in
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   104
 * registers to wr writen back to memory.  Might or might not be beneficial
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   105
 * depending on the architecture and compiler.
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   106
 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   107
#define MB()
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   108
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   109
/*
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   110
 * The XPROD functions are meant to optimize the cross products found all
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   111
 * over the place in mdct.c by forcing memory operation ordering to avoid
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   112
 * unnecessary register reloads as soon as memory is being written to.
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   113
 * However this is only beneficial on CPUs with a sane number of general
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   114
 * purpose registers which exclude the Intel x86.  On Intel, better let the
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   115
 * compiler actually reload registers directly from original memory by using
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   116
 * macros.
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   117
 */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   118
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   119
#ifdef __i386__
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   120
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   121
#define XPROD32(_a, _b, _t, _v, _x, _y)		\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   122
  { *(_x)=MULT32(_a,_t)+MULT32(_b,_v);		\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   123
    *(_y)=MULT32(_b,_t)-MULT32(_a,_v); }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   124
#define XPROD31(_a, _b, _t, _v, _x, _y)		\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   125
  { *(_x)=MULT31(_a,_t)+MULT31(_b,_v);		\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   126
    *(_y)=MULT31(_b,_t)-MULT31(_a,_v); }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   127
#define XNPROD31(_a, _b, _t, _v, _x, _y)	\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   128
  { *(_x)=MULT31(_a,_t)-MULT31(_b,_v);		\
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   129
    *(_y)=MULT31(_b,_t)+MULT31(_a,_v); }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   130
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   131
#else
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   132
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   133
STIN void XPROD32(ogg_int32_t  a, ogg_int32_t  b,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   134
			   ogg_int32_t  t, ogg_int32_t  v,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   135
			   ogg_int32_t *x, ogg_int32_t *y)
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   136
{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   137
  *x = MULT32(a, t) + MULT32(b, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   138
  *y = MULT32(b, t) - MULT32(a, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   139
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   140
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   141
STIN void XPROD31(ogg_int32_t  a, ogg_int32_t  b,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   142
			   ogg_int32_t  t, ogg_int32_t  v,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   143
			   ogg_int32_t *x, ogg_int32_t *y)
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   144
{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   145
  *x = MULT31(a, t) + MULT31(b, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   146
  *y = MULT31(b, t) - MULT31(a, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   147
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   148
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   149
STIN void XNPROD31(ogg_int32_t  a, ogg_int32_t  b,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   150
			    ogg_int32_t  t, ogg_int32_t  v,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   151
			    ogg_int32_t *x, ogg_int32_t *y)
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   152
{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   153
  *x = MULT31(a, t) - MULT31(b, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   154
  *y = MULT31(b, t) + MULT31(a, v);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   155
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   156
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   157
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   158
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   159
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   160
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   161
#ifndef _V_CLIP_MATH
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   162
#define _V_CLIP_MATH
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   163
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   164
STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) {
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   165
  int ret=x;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   166
  ret-= ((x<=32767)-1)&(x-32767);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   167
  ret-= ((x>=-32768)-1)&(x+32768);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   168
  return(ret);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   169
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   170
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   171
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   172
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   173
STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   174
				      ogg_int32_t b,ogg_int32_t bp,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   175
				      ogg_int32_t *p){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   176
  if(a && b){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   177
#ifndef _LOW_ACCURACY_
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   178
    *p=ap+bp+32;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   179
    return MULT32(a,b);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   180
#else
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   181
    *p=ap+bp+31;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   182
    return (a>>15)*(b>>16); 
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   183
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   184
  }else
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   185
    return 0;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   186
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   187
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   188
int _ilog(unsigned int);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   189
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   190
STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   191
				      ogg_int32_t i,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   192
				      ogg_int32_t *p){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   193
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   194
  int ip=_ilog(abs(i))-31;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   195
  return VFLOAT_MULT(a,ap,i<<-ip,ip,p);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   196
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   197
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   198
STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   199
				      ogg_int32_t b,ogg_int32_t bp,
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   200
				      ogg_int32_t *p){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   201
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   202
  if(!a){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   203
    *p=bp;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   204
    return b;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   205
  }else if(!b){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   206
    *p=ap;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   207
    return a;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   208
  }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   209
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   210
  /* yes, this can leak a bit. */
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   211
  if(ap>bp){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   212
    int shift=ap-bp+1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   213
    *p=ap+1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   214
    a>>=1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   215
    if(shift<32){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   216
      b=(b+(1<<(shift-1)))>>shift;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   217
    }else{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   218
      b=0;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   219
    }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   220
  }else{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   221
    int shift=bp-ap+1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   222
    *p=bp+1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   223
    b>>=1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   224
    if(shift<32){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   225
      a=(a+(1<<(shift-1)))>>shift;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   226
    }else{
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   227
      a=0;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   228
    }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   229
  }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   230
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   231
  a+=b;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   232
  if((a&0xc0000000)==0xc0000000 || 
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   233
     (a&0xc0000000)==0){
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   234
    a<<=1;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   235
    (*p)--;
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   236
  }
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   237
  return(a);
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   238
}
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   239
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   240
#endif
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   241
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   242
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   243
f7e49eff3708 add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff changeset
   244