1/* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13 * express or implied.
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
17 */
18/*
19
20 Pathname: ./src/esc_iquant_scaling.c
21 Funtions:  esc_iquant_scaling
22
23------------------------------------------------------------------------------
24 REVISION HISTORY
25
26 Description:  Modified from esc_iquant_fxp.c code
27
28 Description:  Eliminated unused variables to avoid warnings, changed header
29
30 Who:                                   Date:
31 Description:
32
33------------------------------------------------------------------------------
34 INPUT AND OUTPUT DEFINITIONS
35
36 Inputs:
37    quantSpec[] = array of quantized compressed spectral coefficients, of
38                  data type Int and length sfbWidth.
39
40    sfbWidth    = number of array elements in quantSpec and the output array
41                  coef, data type Int.
42
43    coef[]      = output array of uncompressed coefficients, stored in a
44                  variable Q format, depending on the maximum value found
45                  for the group, array of Int32, length sfbWdith to be
46                  overwritten.
47
48    QFormat     = the output Q format for the array coef[].
49
50
51    scale       = scaling factor after separating power of 2 factor out from
52                  0.25*(sfb_scale - 100), i.e., 0.25*sfb_scale.
53
54    maxInput    = maximum absolute value of quantSpec.
55
56 Local Stores/Buffers/Pointers Needed: None.
57
58 Global Stores/Buffers/Pointers Needed:
59    inverseQuantTable = lookup table of const integer values to the one third
60                power stored in Q27 format, in file iquant_table.c, const
61                array of UInt32, of size 1025.
62
63 Outputs: None
64
65 Pointers and Buffers Modified:
66    coef[] contents are overwritten with the uncompressed values from
67    quantSpec[]
68
69
70
71
72 Local Stores Modified: None.
73
74 Global Stores Modified: None.
75
76------------------------------------------------------------------------------
77 FUNCTION DESCRIPTION
78
79 This function performs the inverse quantization of the spectral coeficients
80 read from huffman decoding. It takes each input array value to the four
81 thirds power, then scales it according to the scaling factor input argument
82 ,and stores the result in the output array in a variable Q format
83 depending upon the maximum input value found.
84
85------------------------------------------------------------------------------
86 REQUIREMENTS
87
88 This function shall not have static or global variables.
89
90------------------------------------------------------------------------------
91 REFERENCES
92
93 (1) ISO/IEC 13818-7:1997 Titled "Information technology - Generic coding
94   of moving pictures and associated audio information - Part 7: Advanced
95   Audio Coding (AAC)", Section 10.3, "Decoding process", page 43.
96
97 (2) MPEG-2 NBC Audio Decoder
98   "This software module was originally developed by AT&T, Dolby
99   Laboratories, Fraunhofer Gesellschaft IIS in the course of development
100   of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
101   3. This software module is an implementation of a part of one or more
102   MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
103   Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
104   standards free license to this software module or modifications thereof
105   for use in hardware or software products claiming conformance to the
106   MPEG-2 NBC/MPEG-4 Audio  standards. Those intending to use this software
107   module in hardware or software products are advised that this use may
108   infringe existing patents. The original developer of this software
109   module and his/her company, the subsequent editors and their companies,
110   and ISO/IEC have no liability for use of this software module or
111   modifications thereof in an implementation. Copyright is not released
112   for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
113   developer retains full right to use the code for his/her own purpose,
114   assign or donate the code to a third party and to inhibit third party
115   from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
116   This copyright notice must be included in all copies or derivative
117   works."
118   Copyright(c)1996.
119
120------------------------------------------------------------------------------
121 PSEUDO-CODE
122
123    maxInput = 0;
124
125    FOR (i = sfbWidth - 1; i >= 0; i--)
126        x = quantSpec[i];
127
128        IF ( x >= 0)
129            absX = x;
130        ELSE
131            absX = -x;
132        ENDIF
133
134        coef[i] = absX;
135
136        IF (absX > maxInput)
137            maxInput = absX;
138        ENDIF
139    ENDFOR
140
141    IF (maxInput == 0)
142        *pQFormat = QTABLE;
143    ELSE
144        temp = inverseQuantTable[(maxInput >> ORDER) + 1];
145
146        temp += ((1 << (QTABLE))-1);
147
148        temp >>= (QTABLE-1);
149
150        temp *= maxInput;
151
152        binaryDigits = 0;
153        WHILE( temp != 0)
154            temp >>= 1;
155            binaryDigits++;
156        WEND
157
158        IF (binaryDigits < (SIGNED32BITS - QTABLE))
159            binaryDigits = SIGNED32BITS - QTABLE;
160        ENDIF
161
162        *pQFormat = SIGNED32BITS - binaryDigits;
163        shift = QTABLE - *pQFormat;
164
165        IF (maxInput < TABLESIZE)
166            FOR (i = sfbWidth - 1; i >= 0; i--)
167                x = quantSpec[i];
168
169                absX = coef[i];
170
171                tmp_coef = x * (inverseQuantTable[absX] >> shift);
172
173                b_low  = (tmp_coef & 0xFFFF);
174                b_high = (tmp_coef >> 16);
175
176                mult_low  = ( (UInt32) b_low * scale );
177                mult_high = ( (Int32) b_high * scale );
178
179                mult_low >>= 16;
180
181                coef[i]  = (Int32) (mult_high + mult_low);
182
183            ENDFOR
184        ELSE
185            FOR (i = sfbWidth; i >= 0 ; i--)
186                x    = quantSpec[i];
187                absX = coef[i];
188
189                IF (absX < TABLESIZE)
190                    tmp_coef = x * (inverseQuantTable[absX] >> shift);
191                ELSE
192                    index = absX >> ORDER;
193                    w1 = inverseQuantTable[index];
194
195                    approxOneThird = (w1 * FACTOR) >> shift;
196
197
198                    x1 = index * SPACING;
199                    w2 = inverseQuantTable[index+1];
200
201                    deltaOneThird = (w2 - w1) * (absX - x1);
202
203                    deltaOneThird >>= (shift + ORDER - 1);
204
205                    tmp_coef = x * (approxOneThird + deltaOneThird);
206
207                ENDIF
208
209                b_low  = (mult_high & 0xFFFF);
210                b_high = (mult_high >> 16);
211
212                mult_low  = ( (UInt32) b_low * scale );
213                mult_high = ( (Int32) b_high * scale );
214
215                mult_low >>= 16;
216
217                coef[i]  = (Int32) (mult_high + mult_low);
218
219            ENDFOR
220        ENDIF
221    ENDIF
222
223    RETURN
224
225
226------------------------------------------------------------------------------
227 RESOURCES USED
228   When the code is written for a specific target processor the
229     the resources used should be documented below.
230
231 STACK USAGE: [stack count for this module] + [variable to represent
232          stack usage for each subroutine called]
233
234     where: [stack usage variable] = stack usage for [subroutine
235         name] (see [filename].ext)
236
237 DATA MEMORY USED: x words
238
239 PROGRAM MEMORY USED: x words
240
241 CLOCK CYCLES: [cycle count equation for this module] + [variable
242           used to represent cycle count for each subroutine
243           called]
244
245     where: [cycle count variable] = cycle count for [subroutine
246        name] (see [filename].ext)
247
248------------------------------------------------------------------------------
249*/
250
251/*----------------------------------------------------------------------------
252; INCLUDES
253----------------------------------------------------------------------------*/
254#include "pv_audio_type_defs.h"
255#include "iquant_table.h"
256#include "esc_iquant_scaling.h"
257#include "aac_mem_funcs.h"         /* For pv_memset                         */
258
259#include "fxp_mul32.h"
260
261/*----------------------------------------------------------------------------
262; MACROS
263; Define module specific macros here
264----------------------------------------------------------------------------*/
265
266/*----------------------------------------------------------------------------
267; DEFINES
268; Include all pre-processor statements here. Include conditional
269; compile variables also.
270----------------------------------------------------------------------------*/
271/*
272 * Read further on what order is.
273 * Note: If ORDER is not a multiple of 3, FACTOR is not an integer.
274 * Note: Portions of this function assume ORDER is 3, and so does the table
275 *       in iquant_table.c
276 */
277#define ORDER        (3)
278/*
279 * For input values > TABLESIZE, multiply by FACTOR to get x ^ (1/3)
280 * FACTOR = 2 ^ (ORDER/3)
281 */
282#define FACTOR       (2)
283
284/*
285 * This is one more than the range of expected inputs.
286 */
287#define INPUTRANGE   (8192)
288
289/*
290 * SPACING is 2 ^ ORDER, and is the spacing between points when in the
291 * interpolation range.
292 */
293#define SPACING      (1<<ORDER)
294
295/*
296 * The actual table size is one more than TABLESIZE, to allow for
297 * interpolation for numbers near 8191
298 */
299#define TABLESIZE    (INPUTRANGE/SPACING)
300
301/*
302 * Format the table is stored in.
303 */
304#define QTABLE       (27)
305
306/*
307 * Number of bits for data in a signed 32 bit integer.
308 */
309#define SIGNED32BITS  (31)
310
311/*
312 * Round up value for intermediate values obtained from the table
313 */
314#define ROUND_UP (( ((UInt32) 1) << (QTABLE) )-1)
315
316#define     MASK_LOW16  0xffff
317#define     UPPER16     16
318
319/*----------------------------------------------------------------------------
320; LOCAL FUNCTION DEFINITIONS
321; Function Prototype declaration
322----------------------------------------------------------------------------*/
323
324/*----------------------------------------------------------------------------
325; LOCAL VARIABLE DEFINITIONS
326; Variable declaration - defined here and used outside this module
327----------------------------------------------------------------------------*/
328
329/*----------------------------------------------------------------------------
330; EXTERNAL FUNCTION REFERENCES
331; Declare functions defined elsewhere and referenced in this module
332----------------------------------------------------------------------------*/
333
334/*----------------------------------------------------------------------------
335; EXTERNAL VARIABLES REFERENCES
336; Declare variables used in this module but defined elsewhere
337----------------------------------------------------------------------------*/
338
339/*
340 * Processing in this function is performed in these steps:
341 *
342 * 1) Find the overall Q format for the entire group of inputs. This consists
343 *    of:
344 *    a) Finding the maximum input
345 *    b) estimate the maximum output
346 *    c) Using the table, get max ^ (4/3), taking into account the table is
347 *       in q format.
348 * 2) For each array element, see if the value is directly inside the table.
349 *    a) If yes, just multiply by table value by itself, then shift as
350 *       appropriate.
351 *    b) If no, get an approximation (described below) for x ^ (1/3) by linearly
352 *       interpolating using lower values in the table, then multiply by a
353 *       correction factor, then multiply by x (see below).
354 *
355 * It more accurate to interpolate x ^ (1/3) then x ^ (4/3), so that is stored
356 * in the lookup table. For values not in the table, interpolation is used:
357 *
358 *  We want y = x ^ (4/3) = x * (x ^ (1/3))
359 *
360 *  Let     x = w * (2 ^ m)  where m is a constant, = ORDER
361 *
362 *  then     x ^ (1/3) = w ^ (1/3) * (2 ^ (m/3))
363 *
364 *  w is most likely not an integer, so an interpolation with floor(w) and
365 *  ceil(w) can be performed to approximate w ^ (1/3) by getting values out of
366 *  the table. Then to get x ^ (1/3), multiply by FACTOR. If m = 0, 3, 6,
367 *  then FACTOR is a simple power of 2, so a shift can do the job.
368 *
369 *  The actual code employs some more tricks to speed things up, and because
370 *  the table is stored in Q format.
371 *
372 *  Rather than saving the sign of each input, the unsigned value of
373 *  abs(x) ^ (1/3) is multiplied by the signed input value.
374 */
375
376
377
378#if ( defined(_ARM) || defined(_ARM_V4))
379
380/*
381 *  Absolute value for 16 bit-numbers
382 */
383__inline Int32 abs2(Int32 x)
384{
385    Int32 z;
386    /*
387        z = x - (x<0);
388        x = z ^ sign(z)
389     */
390    __asm
391    {
392        sub  z, x, x, lsr #31
393        eor  x, z, z, asr #31
394    }
395    return (x);
396}
397
398
399#define pv_abs(x)   abs2(x)
400
401
402#elif (defined(PV_ARM_GCC_V5)||defined(PV_ARM_GCC_V4))
403
404/*
405 *  Absolute value for 16 bit-numbers
406 */
407__inline Int32 abs2(Int32 x)
408{
409    register Int32 z;
410    register Int32 y;
411    register Int32 ra = x;
412    asm volatile(
413        "sub  %0, %2, %2, lsr #31\n\t"
414        "eor  %1, %0, %0, asr #31"
415    : "=&r*i"(z),
416        "=&r*i"(y)
417                : "r"(ra));
418
419    return (y);
420}
421
422#define pv_abs(x)   abs2(x)
423
424
425#else
426
427#define pv_abs(x)   ((x) > 0)? (x) : (-x)
428
429#endif
430
431
432
433
434
435void esc_iquant_scaling(
436    const Int16     quantSpec[],
437    Int32         coef[],
438    const Int     sfbWidth,
439    Int const      QFormat,
440    UInt16        scale,
441    Int           maxInput)
442{
443    Int    i;
444    Int    x;
445    Int    y;
446    Int    index;
447    Int    shift;
448    UInt   absX;
449    UInt32 w1, w2;
450    UInt32 deltaOneThird;
451    UInt32 x1;
452    UInt32 approxOneThird;
453    Int32   mult_high;
454
455
456#if ( defined(_ARM) || defined(_ARM_V4))
457
458    {
459        Int32   *temp;
460        Int32   R12, R11, R10, R9;
461
462        deltaOneThird = sizeof(Int32) * sfbWidth;
463        temp = coef;
464
465        // from standard library call for __rt_memset
466        __asm
467        {
468            MOV     R12, #0x0
469            MOV     R11, #0x0
470            MOV     R10, #0x0
471            MOV     R9, #0x0
472            SUBS    deltaOneThird, deltaOneThird, #0x20
473loop:
474            STMCSIA temp!, {R12, R11, R10, R9}
475            STMCSIA temp!, {R12, R11, R10, R9}
476            SUBCSS  deltaOneThird, deltaOneThird, #0x20
477            BCS     loop
478
479            MOVS    deltaOneThird, deltaOneThird, LSL #28
480            STMCSIA temp!, {R12, R11, R10, R9}
481            STMMIIA temp!, {R12, R11}
482        }
483    }
484
485#else
486    pv_memset(coef, 0, sizeof(Int32) * sfbWidth);
487#endif
488
489    if (maxInput > 0)
490    {
491
492        shift = QTABLE - QFormat;
493
494        if (scale != 0)
495        {
496            if (maxInput < TABLESIZE)
497            {
498
499                for (i = sfbWidth - 1; i >= 0; i -= 4)
500                {
501                    x = quantSpec[i];
502                    y = quantSpec[i-1];
503                    if (x)
504                    {
505                        absX = pv_abs(x);
506                        mult_high = (x * (inverseQuantTable[absX] >> shift));
507                        coef[i] = fxp_mul32_by_16(mult_high, scale) << 1;
508                    }
509
510                    if (y)
511                    {
512                        absX = pv_abs(y);
513                        mult_high = y * (inverseQuantTable[absX] >> shift);
514                        coef[i-1] = fxp_mul32_by_16(mult_high, scale) << 1;
515                    }
516
517                    x = quantSpec[i-2];
518                    y = quantSpec[i-3];
519                    if (x)
520                    {
521                        absX = pv_abs(x);
522                        mult_high = x * (inverseQuantTable[absX] >> shift);
523                        coef[i-2] = fxp_mul32_by_16(mult_high, scale) << 1;
524                    }
525
526                    if (y)
527                    {
528                        absX = pv_abs(y);
529                        mult_high = y * (inverseQuantTable[absX] >> shift);
530                        coef[i-3] = fxp_mul32_by_16(mult_high, scale) << 1;
531                    }
532                } /* end for (i = sfbWidth - 1; i >= 0; i--) */
533
534            } /* end if (maxInput < TABLESIZE)*/
535
536            else /* maxInput >= TABLESIZE) */
537            {
538                for (i = sfbWidth - 1; i >= 0; i -= 4)
539                {
540                    x    = quantSpec[i];
541                    if (x)
542                    {
543                        absX = pv_abs(x);
544                        if (absX < TABLESIZE)
545                        {
546                            mult_high = x * (inverseQuantTable[absX] >> shift);
547                            coef[i] = fxp_mul32_by_16(mult_high, scale) << 1;
548
549                        }
550                        else
551                        {
552                            index = absX >> ORDER;
553                            w1 = inverseQuantTable[index];
554                            w2 = inverseQuantTable[index+1];
555                            approxOneThird = (w1 * FACTOR) >> shift;
556                            x1 = index << ORDER;
557                            deltaOneThird = (w2 - w1) * (absX - x1);
558                            deltaOneThird >>= (shift + 2);
559                            mult_high = x * (approxOneThird + deltaOneThird);
560                            coef[i] = fxp_mul32_by_16(mult_high, scale) << 1;
561
562                        }
563                    } /* if(x) */
564
565
566                    x    = quantSpec[i-1];
567                    if (x)
568                    {
569                        absX = pv_abs(x);
570                        if (absX < TABLESIZE)
571                        {
572                            mult_high = (x * (inverseQuantTable[absX] >> shift));
573                            coef[i-1] = fxp_mul32_by_16(mult_high, scale) << 1;
574
575                        }
576                        else
577                        {
578                            index = absX >> ORDER;
579                            w1 = inverseQuantTable[index];
580                            w2 = inverseQuantTable[index+1];
581                            approxOneThird = (w1 * FACTOR) >> shift;
582                            x1 = index << ORDER;
583                            deltaOneThird = (w2 - w1) * (absX - x1);
584                            deltaOneThird >>= (shift + 2);
585                            mult_high = x * (approxOneThird + deltaOneThird);
586                            coef[i-1] = fxp_mul32_by_16(mult_high, scale) << 1;
587                        }
588                    } /* if(x) */
589
590                    x    = quantSpec[i-2];
591                    if (x)
592                    {
593                        absX = pv_abs(x);
594                        if (absX < TABLESIZE)
595                        {
596                            mult_high = x * (inverseQuantTable[absX] >> shift);
597                            coef[i-2] = fxp_mul32_by_16(mult_high, scale) << 1;
598                        }
599                        else
600                        {
601                            index = absX >> ORDER;
602                            w1 = inverseQuantTable[index];
603                            w2 = inverseQuantTable[index+1];
604                            approxOneThird = (w1 * FACTOR) >> shift;
605                            x1 = index << ORDER;
606                            deltaOneThird = (w2 - w1) * (absX - x1);
607                            deltaOneThird >>= (shift + 2);
608                            mult_high = x * (approxOneThird + deltaOneThird);
609                            coef[i-2] = fxp_mul32_by_16(mult_high, scale) << 1;
610                        }
611                    } /* if(x) */
612
613                    x    = quantSpec[i-3];
614                    if (x)
615                    {
616                        absX = pv_abs(x);
617                        if (absX < TABLESIZE)
618                        {
619                            mult_high = x * (inverseQuantTable[absX] >> shift);
620                            coef[i-3] = fxp_mul32_by_16(mult_high, scale) << 1;
621
622                        }
623                        else
624                        {
625                            index = absX >> ORDER;
626                            w1 = inverseQuantTable[index];
627                            w2 = inverseQuantTable[index+1];
628                            approxOneThird = (w1 * FACTOR) >> shift;
629                            x1 = index << ORDER;
630                            deltaOneThird = (w2 - w1) * (absX - x1);
631                            deltaOneThird >>= (shift + 2);
632                            mult_high = x * (approxOneThird + deltaOneThird);
633                            coef[i-3] = fxp_mul32_by_16(mult_high, scale) << 1;
634
635                        }
636                    } /* if(x) */
637
638                }  /* end for (i = sfbWidth - 1; i >= 0; i--) */
639            } /* end else for if (maxInput < TABLESIZE)*/
640        }
641        else /* scale == 0 */
642        {
643            if (maxInput < TABLESIZE)
644            {
645                for (i = sfbWidth - 1; i >= 0; i -= 4)
646                {
647                    x = quantSpec[i];
648                    y = quantSpec[i-1];
649                    if (x)
650                    {
651                        absX = pv_abs(x);
652                        mult_high = x * (inverseQuantTable[absX] >> shift);
653                        coef[i] = mult_high >> 1;
654                    }
655
656                    if (y)
657                    {
658                        absX = pv_abs(y);
659                        mult_high = y * (inverseQuantTable[absX] >> shift);
660                        coef[i-1] = mult_high >> 1;
661                    }
662
663                    x = quantSpec[i-2];
664                    y = quantSpec[i-3];
665                    if (x)
666                    {
667                        absX = pv_abs(x);
668                        mult_high = x * (inverseQuantTable[absX] >> shift);
669                        coef[i-2] = mult_high >> 1;
670                    }
671
672                    if (y)
673                    {
674                        absX = pv_abs(y);
675                        mult_high = y * (inverseQuantTable[absX] >> shift);
676                        coef[i-3] = mult_high >> 1;
677                    }
678                }
679
680            } /* end if (maxInput < TABLESIZE)*/
681
682            else /* maxInput >= TABLESIZE) */
683            {
684                for (i = sfbWidth - 1; i >= 0; i -= 4)
685                {
686                    x    = quantSpec[i];
687                    if (x)
688                    {
689                        absX = pv_abs(x);
690                        if (absX < TABLESIZE)
691                        {
692                            mult_high = x * (inverseQuantTable[absX] >> shift);
693                            coef[i] = (mult_high >> 1);
694                        } /* end if (absX < TABLESIZE) */
695                        else
696                        {
697                            index = absX >> ORDER;
698                            w1 = inverseQuantTable[index];
699                            w2 = inverseQuantTable[index+1];
700                            approxOneThird = (w1 * FACTOR) >> shift;
701                            x1 = index << ORDER;
702                            deltaOneThird = (w2 - w1) * (absX - x1);
703                            deltaOneThird >>= (shift + 2);
704                            mult_high = x * (approxOneThird + deltaOneThird);
705                            coef[i] = (mult_high >> 1);
706                        }
707                    } /* if(x) */
708
709                    x    = quantSpec[i-1];
710                    if (x)
711                    {
712                        absX = pv_abs(x);
713                        if (absX < TABLESIZE)
714                        {
715                            mult_high = x * (inverseQuantTable[absX] >> shift);
716                            coef[i-1] = (mult_high >> 1);
717                        } /* end if (absX < TABLESIZE) */
718                        else
719                        {
720                            index = absX >> ORDER;
721                            w1 = inverseQuantTable[index];
722                            w2 = inverseQuantTable[index+1];
723                            approxOneThird = (w1 * FACTOR) >> shift;
724                            x1 = index << ORDER;
725                            deltaOneThird = (w2 - w1) * (absX - x1);
726                            deltaOneThird >>= (shift + 2);
727                            mult_high = x * (approxOneThird + deltaOneThird);
728                            coef[i-1] = (mult_high >> 1);
729                        }
730                    } /* if(x) */
731
732                    x    = quantSpec[i-2];
733                    if (x)
734                    {
735                        absX = pv_abs(x);
736                        if (absX < TABLESIZE)
737                        {
738                            mult_high = x * (inverseQuantTable[absX] >> shift);
739                            coef[i-2] = (mult_high >> 1);
740                        } /* end if (absX < TABLESIZE) */
741                        else
742                        {
743                            index = absX >> ORDER;
744                            w1 = inverseQuantTable[index];
745                            w2 = inverseQuantTable[index+1];
746                            approxOneThird = (w1 * FACTOR) >> shift;
747                            x1 = index << ORDER;
748                            deltaOneThird = (w2 - w1) * (absX - x1);
749                            deltaOneThird >>= (shift + 2);
750                            mult_high = x * (approxOneThird + deltaOneThird);
751                            coef[i-2] = (mult_high >> 1);
752                        }
753                    } /* if(x) */
754
755                    x    = quantSpec[i-3];
756                    if (x)
757                    {
758                        absX = pv_abs(x);
759                        if (absX < TABLESIZE)
760                        {
761                            mult_high = x * (inverseQuantTable[absX] >> shift);
762                            coef[i-3] = (mult_high >> 1);
763                        } /* end if (absX < TABLESIZE) */
764                        else
765                        {
766                            index = absX >> ORDER;
767                            w1 = inverseQuantTable[index];
768                            w2 = inverseQuantTable[index+1];
769                            approxOneThird = (w1 * FACTOR) >> shift;
770                            x1 = index << ORDER;
771                            deltaOneThird = (w2 - w1) * (absX - x1);
772                            deltaOneThird >>= (shift + 2);
773                            mult_high = x * (approxOneThird + deltaOneThird);
774                            coef[i-3] = (mult_high >> 1);
775                        }
776
777                    } /* if(x) */
778
779                }  /* end for (i = sfbWidth - 1; i >= 0; i--) */
780
781            } /* end else for if (maxInput < TABLESIZE)*/
782
783        } /* end else for if(scale!=0) */
784
785    }  /* end else for if(maxInput == 0) */
786
787} /* end esc_iquant_fxp */
788
789
790