Changeset 156


Ignore:
Timestamp:
12/09/06 22:45:39 (18 years ago)
Author:
r2d
Message:
  • removed slow builtin_ functions
Location:
libmpc/branches/r2d
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libmpc/branches/r2d/include/mpc/mpcmath.h

    r137 r156  
    1717 */
    1818
     19#include <mpc/mpc_types.h>
    1920
    2021#ifndef M_PI
     
    5859#define ATAN2F(x,y)  ATAN2 (x,y)
    5960#define IFLOORF(x)   IFLOOR (x)
     61
     62typedef union mpc_floatint
     63{
     64        float   f;
     65        mpc_int32_t n;
     66} mpc_floatint;
     67
     68static mpc_inline mpc_int32_t mpc_lrintf(float fVal)
     69{
     70        mpc_floatint tmp;
     71        tmp.f = fVal  + 0x00FF8000;
     72        return tmp.n - 0x4B7F8000;
     73}
     74
     75static mpc_inline float mpc_nearbyintf(float fVal)
     76{
     77        return (float) mpc_lrintf(fVal);
     78}
     79
  • libmpc/branches/r2d/libmpc.kdevelop

    r150 r156  
    33  <general>
    44    <author>Nicolas Botti</author>
    5     <email/>
     5    <email></email>
    66    <version>0.1</version>
    77    <projectmanagement>KDevAutoProject</projectmanagement>
     
    1414    <projectdirectory>.</projectdirectory>
    1515    <absoluteprojectpath>false</absoluteprojectpath>
    16     <description/>
     16    <description></description>
    1717  </general>
    1818  <kdevautoproject>
    1919    <general>
    20       <activetarget>libmpcdec/libmpcdec.la</activetarget>
     20      <activetarget>mppenc/mppenc</activetarget>
    2121      <useconfiguration>debug</useconfiguration>
    2222    </general>
    2323    <run>
    24       <mainprogram>/usr/bin/xmms</mainprogram>
     24      <mainprogram>mppenc/mppenc</mainprogram>
    2525      <terminal>true</terminal>
    26       <directoryradio>custom</directoryradio>
     26      <directoryradio>executable</directoryradio>
    2727      <runarguments>
    2828        <mppenc/>
    2929      </runarguments>
    3030      <customdirectory>/</customdirectory>
    31       <programargs/>
     31      <programargs></programargs>
    3232      <autocompile>true</autocompile>
    3333      <envvars/>
     
    3939        <cxxcompiler>kdevgppoptions</cxxcompiler>
    4040        <f77compiler>kdevg77options</f77compiler>
    41         <cflags>-O3 -fomit-frame-pointer -pipe -Wall -ffast-math</cflags>
     41        <cflags>-O3 -fomit-frame-pointer -pipe -Wall</cflags>
    4242        <envvars/>
    43         <configargs/>
    44         <topsourcedir/>
     43        <configargs></configargs>
     44        <topsourcedir></topsourcedir>
    4545        <cppflags>-DMPP_ENCODER=1 -DTRUE=1 -DFALSE=0</cppflags>
    46         <ldflags/>
    47         <ccompilerbinary/>
    48         <cxxcompilerbinary/>
    49         <f77compilerbinary/>
    50         <cxxflags/>
    51         <f77flags/>
     46        <ldflags></ldflags>
     47        <ccompilerbinary></ccompilerbinary>
     48        <cxxcompilerbinary></cxxcompilerbinary>
     49        <f77compilerbinary></f77compilerbinary>
     50        <cxxflags></cxxflags>
     51        <f77flags></f77flags>
    5252      </optimized>
    5353      <debug>
     
    7777      <numberofjobs>1</numberofjobs>
    7878      <dontact>false</dontact>
    79       <makebin/>
     79      <makebin></makebin>
    8080      <prio>0</prio>
    8181    </make>
     
    139139      <group pattern="*.h" name="Header files" />
    140140      <group pattern="*.c" name="Source files" />
    141       <hidenonprojectfiles>false</hidenonprojectfiles>
    142       <hidenonlocation>false</hidenonlocation>
    143141    </groups>
    144142    <tree>
     
    184182    </codecompletion>
    185183    <creategettersetter>
    186       <prefixGet/>
     184      <prefixGet></prefixGet>
    187185      <prefixSet>set</prefixSet>
    188186      <prefixVariable>m_,_</prefixVariable>
     
    200198  <kdevdebugger>
    201199    <general>
    202       <programargs>~/08\ -\ Jimmy\ Jimmy.mpc</programargs>
    203       <gdbpath/>
     200      <programargs>--overwrite /home/nico/08\ -\ Jimmy\ Jimmy.wav</programargs>
     201      <gdbpath></gdbpath>
    204202      <dbgshell>libtool</dbgshell>
    205       <configGdbScript/>
    206       <runShellScript/>
    207       <runGdbScript/>
     203      <configGdbScript></configGdbScript>
     204      <runShellScript></runShellScript>
     205      <runGdbScript></runGdbScript>
    208206      <breakonloadinglibs>true</breakonloadinglibs>
    209207      <separatetty>false</separatetty>
  • libmpc/branches/r2d/libmpcenc/quant.c

    r142 r156  
    2222#include "libmpcenc.h"
    2323#include <mpc/minimax.h>
     24#include <mpc/mpcmath.h>
    2425
    2526/* V A R I A B L E S */
     
    158159{
    159160    int    k;
    160     float  fac    = A [res];
    161     float  invfac = C [res];
    162     float  Signal = 1.e-30f;
    163     float  Fehler = 1.e-30f;
    164     float  tmp ;
    165     float  tmp2;
     161    const float  fac    = A [res];
     162        const float  invfac = C [res];
     163    float  signal = 1.e-30f;
     164    float  error = 1.e-30f;
     165    float  sig, err;
    166166
    167167    // Summation of the absolute power and the quadratic error
    168168    for ( k = 0; k < 36; k++ ) {
    169         tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    170                 tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    171 
    172         Fehler += tmp * tmp;
    173         Signal += tmp2 * tmp2;
     169        err = input[k] * NoiseInjectionCompensation1D [res];
     170                sig = mpc_nearbyintf(err * fac) * invfac - err;
     171
     172        error += sig * sig;
     173        signal += err * err;
    174174    }
    175175
    176176    // Utilization of SNRcomp only if SNR > 1 !!!
    177     return Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
     177    return signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
    178178}
    179179
     
    185185    float  fac    = A [res];
    186186    float  invfac = C [res];
    187     float  Signal;
    188     float  Fehler;
    189     float  ret ;
    190     float  tmp ;
    191     float  tmp2;
     187        float  signal, error, ret, sig, err;
    192188
    193189    // Summation of the absolute power and the quadratic error
    194     k = 0;
    195     Signal = Fehler = 1.e-30f;
     190        k = 0;
     191        signal = error = 1.e-30f;
    196192    for ( ; k < 12; k++ ) {
    197         tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    198                 tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    199 
    200         Fehler += tmp * tmp;
    201         Signal += tmp2 * tmp2;
    202     }
    203     tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
    204     ret = tmp;
    205     Signal = Fehler = 1.e-30f;
     193        err = input[k] * NoiseInjectionCompensation1D [res];
     194                sig = mpc_nearbyintf(err * fac) * invfac - err;
     195
     196        error += sig * sig;
     197        signal += err * err;
     198    }
     199    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
     200    ret = sig;
     201    signal = error = 1.e-30f;
    206202    for ( ; k < 24; k++ ) {
    207         tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    208                 tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    209 
    210         Fehler += tmp * tmp;
    211         Signal += tmp2 * tmp2;
    212     }
    213     tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
    214     if ( tmp > ret ) ret = tmp;
    215     //ret += tmp;
    216     Signal = Fehler = 1.e-30f;
     203        err = input[k] * NoiseInjectionCompensation1D [res];
     204                sig = mpc_nearbyintf(err * fac) * invfac - err;
     205
     206        error += sig * sig;
     207        signal += err * err;
     208    }
     209    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
     210        ret = maxf(ret, sig);
     211
     212    signal = error = 1.e-30f;
    217213    for ( ; k < 36; k++ ) {
    218         tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    219                 tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    220 
    221         Fehler += tmp * tmp;
    222         Signal += tmp2 * tmp2;
    223     }
    224     tmp = Signal > Fehler  ?  Fehler / (SNRcomp * Signal)  :  Fehler / Signal;
    225     if ( tmp > ret ) ret = tmp;
    226     //ret += tmp;
    227     //ret *= 0.33333333333f;
     214        err = input[k] * NoiseInjectionCompensation1D [res];
     215                sig = mpc_nearbyintf(err * fac) * invfac - err;
     216
     217        error += sig * sig;
     218        signal += err * err;
     219    }
     220    sig = signal > error  ?  error / (SNRcomp * signal)  :  error / signal;
     221        ret = maxf(ret, sig);
    228222
    229223    return ret;
     
    235229QuantizeSubband ( unsigned int* qu_output, const float* input, const int res, float* errors, const int maxNsOrder )
    236230{
    237     int    n;
     231        int    n, quant;
    238232    int    offset  = D [res];
    239233    float  mult    = A [res] * NoiseInjectionCompensation1D [res];
    240234    float  invmult = C [res];
    241     int    quant;
    242235    float  signal;
    243236
    244         for ( n = 0; n < 36 - maxNsOrder; n++, input++, qu_output++ ) {
    245                 quant = (unsigned int)(__builtin_lrintf(*input * mult) + offset);
     237        for ( n = 0; n < 36 - maxNsOrder; n++) {
     238                quant = (unsigned int)(mpc_lrintf(input[n] * mult) + offset);
    246239
    247240        // limitation to 0...2D
    248         if ((unsigned int)quant > (unsigned int)2*offset ) {
    249             quant = mini ( quant, 2*offset );
    250             quant = maxi ( quant,        0 );
     241        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
     242            quant = mini ( quant, offset * 2 );
     243            quant = maxi ( quant, 0 );
    251244        }
    252         *qu_output = quant;
    253     }
    254 
    255     for ( ; n < 36; n++, input++, qu_output++ ) {
    256         signal = *input * mult;
    257                 quant = (unsigned int)(__builtin_lrintf(signal) + offset);
     245        qu_output[n] = quant;
     246    }
     247
     248    for ( ; n < 36; n++) {
     249        signal = input[n] * mult;
     250                quant = (unsigned int)(mpc_lrintf(signal) + offset);
    258251
    259252        // calculate the current error and save it for error refeeding
     
    261254
    262255        // limitation to 0...2D
    263         if ((unsigned int)quant > (unsigned int)2*offset ) {
    264             quant = mini ( quant, 2*offset );
    265             quant = maxi ( quant,        0 );
     256        if ((unsigned int)quant > (unsigned int)offset * 2 ) {
     257            quant = mini ( quant, offset * 2 );
     258            quant = maxi ( quant, 0 );
    266259        }
    267         *qu_output = quant;
     260        qu_output[n] = quant;
    268261    }
    269262}
     
    274267QuantizeSubbandWithNoiseShaping ( unsigned int* qu_output, const float* input, const int res, float* errors, const float* FIR )
    275268{
    276 #define E(x) *((int*)errors+(x))
    277 
    278269    float  signal;
    279270    float  mult    = A [res];
    280271    float  invmult = C [res];
    281272    int    offset  = D [res];
    282     int    n;
    283     int    quant;
    284 
    285     E(0) = E(1) = E(2) = E(3) = E(4) = E(5) = 0;       // arghh, it produces pops on each frame boundary!
    286 
    287     for ( n = 0; n < 36; n++, input++, qu_output++ ) {
    288         signal = *input * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
    289                 quant = __builtin_lrintf(signal * mult);
     273    int    n, quant;
     274
     275        memset(errors, 0, 6 * sizeof *errors);       // arghh, it produces pops on each frame boundary!
     276
     277    for ( n = 0; n < 36; n++) {
     278        signal = input[n] * NoiseInjectionCompensation1D [res] - (FIR[5]*errors[n+0] + FIR[4]*errors[n+1] + FIR[3]*errors[n+2] + FIR[2]*errors[n+3] + FIR[1]*errors[n+4] + FIR[0]*errors[n+5]);
     279                quant = mpc_lrintf(signal * mult);
    290280
    291281        // calculate the current error and save it for error refeeding
     
    296286        quant = maxf ( quant, -offset );
    297287
    298         *qu_output = (unsigned int)(quant + offset);
     288        qu_output[n] = (unsigned int)(quant + offset);
    299289    }
    300290}
Note: See TracChangeset for help on using the changeset viewer.