Ignore:
Timestamp:
10/12/06 18:08:02 (18 years ago)
Author:
r2d
Message:
  • modified quantization to use standard functions
  • can now compile with -03
File:
1 edited

Legend:

Unmodified
Added
Removed
  • mppenc/branches/r2d/libmpcenc/quant.c

    r65 r73  
    161161    float  tmp ;
    162162    float  tmp2;
    163     float  tmp3;
    164163
    165164    // Summation of the absolute power and the quadratic error
    166165    for ( k = 0; k < 36; k++ ) {
    167166        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    168         // q = ftol(in), correct rounding
    169         tmp  = tmp2 * fac + 0xFF8000;
    170         tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
    171         tmp  = tmp3 - tmp2;
     167                tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    172168
    173169        Fehler += tmp * tmp;
     
    191187    float  tmp ;
    192188    float  tmp2;
    193     float  tmp3;
    194189
    195190    // Summation of the absolute power and the quadratic error
     
    198193    for ( ; k < 12; k++ ) {
    199194        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    200         // q = ftol(in), correct rounding
    201         tmp  = tmp2 * fac + 0xFF8000;
    202         tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
    203         tmp  = tmp3 - tmp2;
     195                tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    204196
    205197        Fehler += tmp * tmp;
     
    211203    for ( ; k < 24; k++ ) {
    212204        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    213         // q = ftol(in), correct rounding
    214         tmp  = tmp2 * fac + 0xFF8000;
    215         tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
    216         tmp  = tmp3 - tmp2;
     205                tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    217206
    218207        Fehler += tmp * tmp;
     
    225214    for ( ; k < 36; k++ ) {
    226215        tmp2    = input[k] * NoiseInjectionCompensation1D [res];
    227         // q = ftol(in), correct rounding
    228         tmp  = tmp2 * fac + 0xFF8000;
    229         tmp3 = (*(int*) & tmp - 0x4B7F8000) * invfac;
    230         tmp  = tmp3 - tmp2;
     216                tmp  = __builtin_nearbyintf(tmp2 * fac) * invfac - tmp2;
    231217
    232218        Fehler += tmp * tmp;
     
    250236    float  mult    = A [res] * NoiseInjectionCompensation1D [res];
    251237    float  invmult = C [res];
    252     float  tmp;
    253238    int    quant;
    254239    float  signal;
    255240
    256241        for ( n = 0; n < 36 - maxNsOrder; n++, input++, qu_output++ ) {
    257         // q = ftol(in), correct rounding
    258         tmp   = *input * mult + 0xFF8000;
    259         quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
     242                quant = (unsigned int)(__builtin_lrintf(*input * mult) + offset);
    260243
    261244        // limitation to 0...2D
     
    268251
    269252    for ( ; n < 36; n++, input++, qu_output++ ) {
    270         // q = ftol(in), correct rounding
    271253        signal = *input * mult;
    272         tmp   =  signal + 0xFF8000;
    273         quant = (unsigned int)(*(int*) & tmp - 0x4B7F8000 + offset);
     254                quant = (unsigned int)(__builtin_lrintf(signal) + offset);
    274255
    275256        // calculate the current error and save it for error refeeding
     
    293274
    294275    float  signal;
    295     float  tmp;
    296276    float  mult    = A [res];
    297277    float  invmult = C [res];
     
    304284    for ( n = 0; n < 36; n++, input++, qu_output++ ) {
    305285        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]);
    306 
    307         // quant = ftol(signal), correct rounding
    308         tmp   = signal * mult + 0xFF8000;
    309         quant = *(int*) & tmp - 0x4B7F8000;
     286                quant = __builtin_lrintf(signal * mult);
    310287
    311288        // calculate the current error and save it for error refeeding
Note: See TracChangeset for help on using the changeset viewer.