author | Xeli |
Sun, 28 Oct 2012 15:15:39 +0100 | |
branch | hedgeroid |
changeset 7859 | 519d5bc91dd3 |
parent 7849 | a12155461b34 |
permissions | -rw-r--r-- |
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 |
* * |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
9 |
* THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 * |
5170
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" |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
21 |
#include "os.h" |
5170
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" |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
24 |
#include <stdlib.h> /* for abs() */ |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
32 |
#if !(defined WIN32 && defined WINCE) |
5170
f7e49eff3708
add libTremor sources (integer-only libvorbis implementation) to repo and ios project
koda
parents:
diff
changeset
|
33 |
#include <sys/types.h> |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
34 |
#endif |
5170
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 |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
47 |
/*union magic { |
5170
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; |
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
53 |
};*/ |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
56 |
STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
62 |
STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
66 |
STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
88 |
STIN ogg_int32_t MULT32(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
92 |
STIN ogg_int32_t MULT31(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
96 |
STIN ogg_int32_t MULT31_SHIFT15(ogg_int32_t x, ogg_int32_t y) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
133 |
STIN void XPROD32(ogg_int32_t a, ogg_int32_t b, |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
141 |
STIN void XPROD31(ogg_int32_t a, ogg_int32_t b, |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
149 |
STIN void XNPROD31(ogg_int32_t a, ogg_int32_t b, |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
164 |
STIN ogg_int32_t CLIP_TO_15(ogg_int32_t x) { |
5170
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 |
|
7849
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
173 |
STIN ogg_int32_t VFLOAT_MULT(ogg_int32_t a,ogg_int32_t ap, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
174 |
ogg_int32_t b,ogg_int32_t bp, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
175 |
ogg_int32_t *p){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
176 |
if(a && b){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
177 |
#ifndef _LOW_ACCURACY_ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
178 |
*p=ap+bp+32; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
179 |
return MULT32(a,b); |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
180 |
#else |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
181 |
*p=ap+bp+31; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
182 |
return (a>>15)*(b>>16); |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
183 |
#endif |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
184 |
}else |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
185 |
return 0; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
186 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
187 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
188 |
int _ilog(unsigned int); |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
189 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
190 |
STIN ogg_int32_t VFLOAT_MULTI(ogg_int32_t a,ogg_int32_t ap, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
191 |
ogg_int32_t i, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
192 |
ogg_int32_t *p){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
193 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
194 |
int ip=_ilog(abs(i))-31; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
195 |
return VFLOAT_MULT(a,ap,i<<-ip,ip,p); |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
196 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
197 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
198 |
STIN ogg_int32_t VFLOAT_ADD(ogg_int32_t a,ogg_int32_t ap, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
199 |
ogg_int32_t b,ogg_int32_t bp, |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
200 |
ogg_int32_t *p){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
201 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
202 |
if(!a){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
203 |
*p=bp; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
204 |
return b; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
205 |
}else if(!b){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
206 |
*p=ap; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
207 |
return a; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
208 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
209 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
210 |
/* yes, this can leak a bit. */ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
211 |
if(ap>bp){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
212 |
int shift=ap-bp+1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
213 |
*p=ap+1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
214 |
a>>=1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
215 |
if(shift<32){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
216 |
b=(b+(1<<(shift-1)))>>shift; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
217 |
}else{ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
218 |
b=0; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
219 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
220 |
}else{ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
221 |
int shift=bp-ap+1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
222 |
*p=bp+1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
223 |
b>>=1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
224 |
if(shift<32){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
225 |
a=(a+(1<<(shift-1)))>>shift; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
226 |
}else{ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
227 |
a=0; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
228 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
229 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
230 |
|
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
231 |
a+=b; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
232 |
if((a&0xc0000000)==0xc0000000 || |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
233 |
(a&0xc0000000)==0){ |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
234 |
a<<=1; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
235 |
(*p)--; |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
236 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
237 |
return(a); |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
238 |
} |
a12155461b34
revert r767d3c4153a1 this tremor implementation is buggy
koda
parents:
7697
diff
changeset
|
239 |
|
5170
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 |