Home | History | Annotate | Download | only in encoder
      1 /******************************************************************************
      2  *
      3  * Copyright (C) 2018 The Android Open Source Project
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at:
      8  *
      9  * http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  *****************************************************************************
     18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
     19 */
     20 /*!
     21 ******************************************************************************
     22 * \file squrt_interp.c
     23 *
     24 * \brief
     25 *    This file contain square root interpolate function
     26 *
     27 * \date
     28 *
     29 * \author
     30 *    ittiam
     31 *
     32 ******************************************************************************
     33 */
     34 /*****************************************************************************/
     35 /* File Includes                                                             */
     36 /*****************************************************************************/
     37 /* System include files */
     38 #include <stdio.h>
     39 #include <stdlib.h>
     40 
     41 /* User include files */
     42 #include "ia_type_def.h"
     43 #include "defs.h"
     44 /* #include "constants.h" */
     45 #include "ia_basic_ops32.h"
     46 /* #include "ia_basic_ops16.h" */
     47 #include "ia_basic_ops40.h"
     48 #include "sqrt_interp.h"
     49 /* #include "ia_enhaacplus_enc_basicops.h" */
     50 #include "common_rom.h"
     51 
     52 WORD32 sqrtFix_interpolate(WORD32 num, WORD *q, const WORD32 *sqrt_tab)
     53 {
     54     WORD32 index, answer, temp, delta, step_size;
     55     WORD q_temp = *q;
     56     WORD k;
     57 
     58     if(num == 0)
     59         return 0;
     60 
     61     k = norm32(num);
     62     temp = shr32(shl32(num, k), 21);
     63     q_temp += k;
     64     index = temp & 0x1FF; /* Leave leading 1 */
     65     {
     66         delta = shl32((shl32(num, k) - shl32(temp, 21)), 10);
     67         step_size = sub32(sqrt_tab[index + 1], sqrt_tab[index]);
     68         step_size = mult32_shl_sat(step_size, delta); /* Q:Q_SQRT_TAB + 21 + 10 - 31 */
     69         answer = add32(sqrt_tab[index], step_size);
     70     }
     71     if(q_temp & 1)
     72     {
     73         q_temp -= 1;
     74         answer = mult32_shl_sat(answer, INV_SQRT_2_Q31);
     75     }
     76 
     77     q_temp = q_temp >> 1;
     78     q_temp += (Q_SQRT_TAB);
     79     *q = q_temp;
     80 
     81     answer >>= 1;
     82     *q -= 1;
     83 
     84     return answer;
     85 }
     86 
     87 WORD32 sqrtFix(WORD32 num, WORD *q, const WORD32 *sqrt_tab)
     88 {
     89     WORD32 index, answer, temp;
     90     WORD k;
     91     WORD q_temp = *q;
     92 
     93     if(num == 0)
     94         return 0;
     95 
     96     k = norm32(num);
     97     temp = shr32(shl32(num, k), 21);
     98     q_temp += k;
     99     index = temp & 0x1FF; /* Leave leading 1 */
    100     answer = sqrt_tab[index];
    101     if(q_temp & 1)
    102     {
    103         q_temp -= 1;
    104         answer = mult32x16in32_shl(answer, INV_SQRT_2_Q15);
    105     }
    106     q_temp = q_temp >> 1;
    107     q_temp += Q_SQRT_TAB;
    108     *q = q_temp;
    109     return answer;
    110 }
    111 
    112 #ifdef ITT_C6678
    113 #pragma CODE_SECTION(sqrtFix_interpolate, "itt_varq_l1pram");
    114 #pragma CODE_SECTION(sqrtFix, "itt_varq_l1pram");
    115 #endif
    116