gps/GPSResources/tcpmp 0.73/mpc/libmusepack/docs/html/math_8h-source.html

157 lines
9.6 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>libmusepack: include/musepack/math.h Source File</title>
<link href="custom.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">include</a>&nbsp;/&nbsp;<a class="el" href="dir_000001.html">musepack</a></div>
<h1>math.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment"> Copyright (c) 2005, The Musepack Development Team</span>
00003 <span class="comment"> All rights reserved.</span>
00004 <span class="comment"></span>
00005 <span class="comment"> Redistribution and use in source and binary forms, with or without</span>
00006 <span class="comment"> modification, are permitted provided that the following conditions are</span>
00007 <span class="comment"> met:</span>
00008 <span class="comment"></span>
00009 <span class="comment"> * Redistributions of source code must retain the above copyright</span>
00010 <span class="comment"> notice, this list of conditions and the following disclaimer.</span>
00011 <span class="comment"></span>
00012 <span class="comment"> * Redistributions in binary form must reproduce the above</span>
00013 <span class="comment"> copyright notice, this list of conditions and the following</span>
00014 <span class="comment"> disclaimer in the documentation and/or other materials provided</span>
00015 <span class="comment"> with the distribution.</span>
00016 <span class="comment"></span>
00017 <span class="comment"> * Neither the name of the The Musepack Development Team nor the</span>
00018 <span class="comment"> names of its contributors may be used to endorse or promote</span>
00019 <span class="comment"> products derived from this software without specific prior</span>
00020 <span class="comment"> written permission.</span>
00021 <span class="comment"></span>
00022 <span class="comment"> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
00023 <span class="comment"> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
00024 <span class="comment"> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
00025 <span class="comment"> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT</span>
00026 <span class="comment"> OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
00027 <span class="comment"> SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT</span>
00028 <span class="comment"> LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</span>
00029 <span class="comment"> DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</span>
00030 <span class="comment"> THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</span>
00031 <span class="comment"> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE</span>
00032 <span class="comment"> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
00033 <span class="comment">*/</span>
00034
00037
00038 <span class="preprocessor">#ifndef _musepack_math_h_</span>
00039 <span class="preprocessor"></span><span class="preprocessor">#define _musepack_math_h_</span>
00040 <span class="preprocessor"></span>
00041 <span class="comment">//#define MPC_FIXED_POINT</span>
00042
00043 <span class="preprocessor">#define MPC_FIXED_POINT_SHIFT 16</span>
00044 <span class="preprocessor"></span>
00045 <span class="preprocessor">#ifdef MPC_FIXED_POINT</span>
00046 <span class="preprocessor"></span>
00047
00048 <span class="preprocessor">#ifdef _WIN32_WCE</span>
00049 <span class="preprocessor"></span>
00050 <span class="preprocessor">#include &lt;cmnintrin.h&gt;</span>
00051
00052 <span class="preprocessor">#define MPC_HAVE_MULHIGH</span>
00053 <span class="preprocessor"></span>
00054 <span class="preprocessor">#endif</span>
00055 <span class="preprocessor"></span>
00056
00057 <span class="preprocessor">#define MPC_FIXED_POINT_SCALE_SHIFT (MPC_FIXED_POINT_SHIFT + MPC_FIXED_POINT_FRACTPART)</span>
00058 <span class="preprocessor"></span><span class="preprocessor">#define MPC_FIXED_POINT_SCALE (1 &lt;&lt; (MPC_FIXED_POINT_SCALE_SHIFT - 1))</span>
00059 <span class="preprocessor"></span>
00060
00061 <span class="comment">//in fixedpoint mode, results in decode output buffer are in -MPC_FIXED_POINT_SCALE ... MPC_FIXED_POINT_SCALE range</span>
00062
00063 <span class="preprocessor">#define MPC_FIXED_POINT_FRACTPART 14</span>
00064 <span class="preprocessor"></span><span class="keyword">typedef</span> mpc_int32_t MPC_SAMPLE_FORMAT;
00065
00066 <span class="keyword">typedef</span> mpc_int64_t MPC_SAMPLE_FORMAT_MULTIPLY;
00067
00068 <span class="preprocessor">#define MAKE_MPC_SAMPLE(X) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)&lt;&lt;MPC_FIXED_POINT_FRACTPART))</span>
00069 <span class="preprocessor"></span><span class="preprocessor">#define MAKE_MPC_SAMPLE_EX(X,Y) (MPC_SAMPLE_FORMAT)((double)(X) * (double)(((mpc_int64_t)1)&lt;&lt;(Y)))</span>
00070 <span class="preprocessor"></span>
00071 <span class="preprocessor">#define MPC_MULTIPLY_NOTRUNCATE(X,Y) \</span>
00072 <span class="preprocessor"> (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) &gt;&gt; MPC_FIXED_POINT_FRACTPART)</span>
00073 <span class="preprocessor"></span>
00074 <span class="preprocessor">#define MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z) \</span>
00075 <span class="preprocessor"> (((MPC_SAMPLE_FORMAT_MULTIPLY)(X) * (MPC_SAMPLE_FORMAT_MULTIPLY)(Y)) &gt;&gt; (Z))</span>
00076 <span class="preprocessor"></span>
00077 <span class="preprocessor">#ifdef _DEBUG</span>
00078 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> MPC_SAMPLE_FORMAT MPC_MULTIPLY(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2)
00079 {
00080 MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_NOTRUNCATE(item1,item2);
00081 assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
00082 <span class="keywordflow">return</span> (MPC_SAMPLE_FORMAT)temp;
00083 }
00084
00085 static inline MPC_SAMPLE_FORMAT MPC_MULTIPLY_EX(MPC_SAMPLE_FORMAT item1,MPC_SAMPLE_FORMAT item2,<span class="keywordtype">unsigned</span> shift)
00086 {
00087 MPC_SAMPLE_FORMAT_MULTIPLY temp = MPC_MULTIPLY_EX_NOTRUNCATE(item1,item2,shift);
00088 assert(temp == (MPC_SAMPLE_FORMAT_MULTIPLY)(MPC_SAMPLE_FORMAT)temp);
00089 <span class="keywordflow">return</span> (MPC_SAMPLE_FORMAT)temp;
00090 }
00091
00092 #else
00093
00094 #define MPC_MULTIPLY(X,Y) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_NOTRUNCATE(X,Y))
00095 #define MPC_MULTIPLY_EX(X,Y,Z) ((MPC_SAMPLE_FORMAT)MPC_MULTIPLY_EX_NOTRUNCATE(X,Y,Z))
00096
00097 #endif
00098
00099 #ifdef MPC_HAVE_MULHIGH
00100 #define MPC_MULTIPLY_FRACT(X,Y) _MulHigh(X,Y)
00101 #else
00102 #define MPC_MULTIPLY_FRACT(X,Y) MPC_MULTIPLY_EX(X,Y,32)
00103 #endif
00104
00105 #define MPC_MAKE_FRACT_CONST(X) (MPC_SAMPLE_FORMAT)((X) * (<span class="keywordtype">double</span>)(((mpc_int64_t)1)&lt;&lt;32) )
00106 #define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
00107 #define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) ( MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1&lt;&lt;(Z)) )) &lt;&lt; (Z) )
00108 #define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y / (1&lt;&lt;(Z)) ))
00109
00110 #define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
00111 #define MPC_SCALE_CONST(X,Y,Z) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z))
00112 #define MPC_SCALE_CONST_SHL(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)-(S))
00113 #define MPC_SCALE_CONST_SHR(X,Y,Z,S) MPC_MULTIPLY_EX(X,MAKE_MPC_SAMPLE_EX(Y,Z),(Z)+(S))
00114 #define MPC_SHR(X,Y) ((X)&gt;&gt;(Y))
00115 #define MPC_SHL(X,Y) ((X)&lt;&lt;(Y))
00116
00117 #else
00118
00119 <span class="comment">//in floating-point mode, decoded samples are in -1...1 range</span>
00120
00121 typedef <span class="keywordtype">float</span> MPC_SAMPLE_FORMAT;
00122
00123 #define MAKE_MPC_SAMPLE(X) ((MPC_SAMPLE_FORMAT)(X))
00124 #define MAKE_MPC_SAMPLE_EX(X,Y) ((MPC_SAMPLE_FORMAT)(X))
00125
00126 #define MPC_MULTIPLY_FRACT(X,Y) ((X)*(Y))
00127 #define MPC_MAKE_FRACT_CONST(X) (X)
00128 #define MPC_MULTIPLY_FRACT_CONST(X,Y) MPC_MULTPLY_FRACT(X,MPC_MAKE_FRACT_CONST(Y))
00129 #define MPC_MULTIPLY_FRACT_CONST_SHR(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
00130 #define MPC_MULTIPLY_FRACT_CONST_FIX(X,Y,Z) MPC_MULTIPLY_FRACT(X,MPC_MAKE_FRACT_CONST( Y ))
00131
00132 #define MPC_MULTIPLY_FLOAT_INT(X,Y) ((X)*(Y))
00133 #define MPC_MULTIPLY(X,Y) ((X)*(Y))
00134 #define MPC_MULTIPLY_EX(X,Y,Z) ((X)*(Y))
00135 #define MPC_SCALE_CONST(X,Y,Z) ((X)*(Y))
00136 #define MPC_SCALE_CONST_SHL(X,Y,Z,S) ((X)*(Y))
00137 #define MPC_SCALE_CONST_SHR(X,Y,Z,S) ((X)*(Y))
00138 #define MPC_SHR(X,Y) (X)
00139 #define MPC_SHL(X,Y) (X)
00140
00141 #endif
00142
00143 #endif <span class="comment">// _musepack_math_h_</span>
00144
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sat Jan 22 09:34:06 2005 for libmusepack by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>