164 lines
9.7 KiB
HTML
Executable File
164 lines
9.7 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: src/requant.c 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 Page</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div>
|
|
<div class="nav">
|
|
<a class="el" href="dir_000002.html">src</a></div>
|
|
<h1>requant.c</h1><a href="requant_8c.html">Go to the documentation of this file.</a><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
|
|
00038
|
|
00039 <span class="preprocessor">#include "<a class="code" href="musepack_8h.html">musepack/musepack.h</a>"</span>
|
|
00040 <span class="preprocessor">#include "musepack/internal.h"</span>
|
|
00041
|
|
00042 <span class="comment">/* C O N S T A N T S */</span>
|
|
00043 <span class="comment">// bits per sample for chosen quantizer</span>
|
|
00044 <span class="keyword">const</span> mpc_uint32_t Res_bit [18] = {
|
|
00045 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
|
00046 };
|
|
00047
|
|
00048 <span class="comment">// coefficients for requantization</span>
|
|
00049 <span class="comment">// 65536/step bzw. 65536/(2*D+1)</span>
|
|
00050
|
|
00051 <span class="preprocessor">#define _(X) MAKE_MPC_SAMPLE_EX(X,14)</span>
|
|
00052 <span class="preprocessor"></span>
|
|
00053 <span class="keyword">const</span> MPC_SAMPLE_FORMAT __Cc [1 + 18] = {
|
|
00054 _(111.285962475327f), <span class="comment">// 32768/2/255*sqrt(3)</span>
|
|
00055 _(65536.000000000000f), _(21845.333333333332f), _(13107.200000000001f), _(9362.285714285713f),
|
|
00056 _(7281.777777777777f), _(4369.066666666666f), _(2114.064516129032f), _(1040.253968253968f),
|
|
00057 _(516.031496062992f), _(257.003921568627f), _(128.250489236790f), _(64.062561094819f),
|
|
00058 _(32.015632633121f), _(16.003907203907f), _(8.000976681723f), _(4.000244155527f),
|
|
00059 _(2.000061037018f), _(1.000015259021f)
|
|
00060 };
|
|
00061
|
|
00062 <span class="preprocessor">#undef _</span>
|
|
00063 <span class="preprocessor"></span>
|
|
00064 <span class="comment">// offset for requantization</span>
|
|
00065 <span class="comment">// 2*D+1 = steps of quantizer</span>
|
|
00066 <span class="keyword">const</span> mpc_int32_t __Dc [1 + 18] = {
|
|
00067 2,
|
|
00068 0, 1, 2, 3, 4, 7, 15, 31, 63,
|
|
00069 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767
|
|
00070 };
|
|
00071
|
|
00072 <span class="preprocessor">#ifdef MPC_FIXED_POINT</span>
|
|
00073 <span class="preprocessor"></span><span class="keyword">static</span> mpc_uint32_t find_shift(<span class="keywordtype">double</span> fval)
|
|
00074 {
|
|
00075 mpc_int64_t val = (mpc_int64_t)fval;
|
|
00076 <span class="keywordflow">if</span> (val<0) val = -val;
|
|
00077 mpc_uint32_t ptr = 0;
|
|
00078 while(val) {val>>=1;ptr++;}
|
|
00079
|
|
00080 <span class="keywordflow">return</span> ptr > 31 ? 0 : 31 - ptr;
|
|
00081 }
|
|
00082 <span class="preprocessor">#endif</span>
|
|
00083 <span class="preprocessor"></span>
|
|
00084 <span class="comment">/* F U N C T I O N S */</span>
|
|
00085
|
|
00086 <span class="preprocessor">#define SET_SCF(N,X) d->SCF[N] = MAKE_MPC_SAMPLE_EX(X,SCF_shift[N] = (unsigned char)find_shift(X));</span>
|
|
00087 <span class="preprocessor"></span>
|
|
00088 <span class="keywordtype">void</span>
|
|
<a name="l00089"></a><a class="code" href="requant_8c.html#a5">00089</a> <a class="code" href="musepack_8h.html#a15">mpc_decoder_scale_output</a>(mpc_decoder *d, <span class="keywordtype">double</span> factor)
|
|
00090 {
|
|
00091 mpc_int32_t n;
|
|
00092 <span class="keywordtype">double</span> f1;
|
|
00093 <span class="keywordtype">double</span> f2;
|
|
00094 <span class="preprocessor">#ifndef MPC_FIXED_POINT</span>
|
|
00095 <span class="preprocessor"></span> factor *= 1.0 / (double)(1<<(MPC_FIXED_POINT_SHIFT-1));
|
|
00096 <span class="preprocessor">#else</span>
|
|
00097 <span class="preprocessor"></span> factor *= 1.0 / (double)(1<<(16 - MPC_FIXED_POINT_SHIFT));
|
|
00098 <span class="preprocessor">#endif</span>
|
|
00099 <span class="preprocessor"></span> f1 = f2 = factor;
|
|
00100
|
|
00101 <span class="comment">// handles +1.58...-98.41 dB, where's scf[n] / scf[n-1] = 1.20050805774840750476</span>
|
|
00102
|
|
00103 SET_SCF(1,factor);
|
|
00104
|
|
00105 f1 *= 0.83298066476582673961;
|
|
00106 f2 *= 1/0.83298066476582673961;
|
|
00107
|
|
00108 <span class="keywordflow">for</span> ( n = 1; n <= 128; n++ ) {
|
|
00109 SET_SCF((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)(1+n),f1);
|
|
00110 SET_SCF((<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>)(1-n),f2);
|
|
00111 f1 *= 0.83298066476582673961;
|
|
00112 f2 *= 1/0.83298066476582673961;
|
|
00113 }
|
|
00114 }
|
|
00115
|
|
00116 <span class="keyword">static</span> <span class="keywordtype">void</span>
|
|
00117 mpc_decoder_quantisierungsmodes(mpc_decoder *d) <span class="comment">// conversion: index -> quantizer (bitstream reading)</span>
|
|
00118 { <span class="comment">// conversion: quantizer -> index (bitstream writing)</span>
|
|
00119 mpc_int32_t Band = 0;
|
|
00120 mpc_int32_t i;
|
|
00121
|
|
00122 <span class="keywordflow">do</span> {
|
|
00123 d->Q_bit [Band] = 4;
|
|
00124 <span class="keywordflow">for</span> ( i = 0; i < 16-1; i++ )
|
|
00125 d->Q_res [Band] [i] = i;
|
|
00126 d->Q_res [Band][i] = 17;
|
|
00127 Band++;
|
|
00128 } while ( Band < 11 );
|
|
00129
|
|
00130 do {
|
|
00131 d->Q_bit [Band] = 3;
|
|
00132 <span class="keywordflow">for</span> ( i = 0; i < 8-1; i++ )
|
|
00133 d->Q_res [Band] [i] = i;
|
|
00134 d->Q_res [Band] [i] = 17;
|
|
00135 Band++;
|
|
00136 } while ( Band < 23 );
|
|
00137
|
|
00138 do {
|
|
00139 d->Q_bit [Band] = 2;
|
|
00140 <span class="keywordflow">for</span> ( i = 0; i < 4-1; i++ )
|
|
00141 d->Q_res [Band] [i] = i;
|
|
00142 d->Q_res [Band] [i] = 17;
|
|
00143 Band++;
|
|
00144 } while ( Band < 32 );
|
|
00145 }
|
|
00146
|
|
00147 <span class="keywordtype">void</span>
|
|
00148 mpc_decoder_initialisiere_quantisierungstabellen(mpc_decoder *d, <span class="keywordtype">double</span> scale_factor)
|
|
00149 {
|
|
00150 mpc_decoder_quantisierungsmodes(d);
|
|
00151 <a class="code" href="musepack_8h.html#a15">mpc_decoder_scale_output</a>(d, scale_factor);
|
|
00152 }
|
|
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sat Jan 22 09:34:07 2005 for libmusepack by
|
|
<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>
|