videoeditorengine/mp3aacManipLib/AACGain/src/coupling.cpp
branchRCL_3
changeset 3 e0b5df5c0969
parent 0 951a5db380a0
child 5 4c409de21d23
equal deleted inserted replaced
0:951a5db380a0 3:e0b5df5c0969
     1 /*
       
     2 * Copyright (c) 2010 Ixonos Plc.
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Ixonos Plc
       
    14 *
       
    15 * Description:
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**************************************************************************
       
    21   coupling.cpp - Coupling channel implementations (parsing only!).
       
    22  
       
    23   Author(s): Juha Ojanpera
       
    24   Copyright (c) 2000-2004 by Nokia Research Center, Speech and Audio Systems.
       
    25   *************************************************************************/
       
    26 
       
    27 /*-- System Headers. --*/
       
    28 #include <math.h>
       
    29 
       
    30 /*-- Project Headers. --*/
       
    31 #include "tool2.h"
       
    32 #include "defines.h"
       
    33 
       
    34 int16
       
    35 GetCCE(CAACAudDec *aac, TBitStream *bs, CMC_Info *mip, CCInfo **ccInfo)
       
    36 {
       
    37   TCh_Info cip;
       
    38   CToolInfo *tool;
       
    39   CWindowInfo *ccWin;
       
    40   int16 i, j, tag, cidx, ch, nele, nch;
       
    41   int16 shared[2 * ((LEN_NCC << 3) + 1)], global_gain;
       
    42 
       
    43   ZERO_MEMORY(&cip, sizeof(TCh_Info));
       
    44 
       
    45   /*-- Get (dummy) channel index for this coupling channel. --*/
       
    46   cidx = mip->dummyCCh;
       
    47 
       
    48   tool = ccInfo[cidx]->tool;
       
    49   ccWin = ccInfo[cidx]->winInfo;
       
    50 
       
    51   tag = (int16) BsGetBits(bs, LEN_TAG);
       
    52   mip->cc_ind[cidx] = (int16) BsGetBits(bs, LEN_IND_SW_CCE);
       
    53 
       
    54   /*-- Coupled (target) elements. --*/
       
    55   ZERO_MEMORY(shared, sizeof(shared));
       
    56   nele = (int16) BsGetBits(bs, LEN_NCC);
       
    57   for(i = 0, nch = 0; i < nele + 1; i++)
       
    58   {
       
    59     int16 cpe;
       
    60     
       
    61     cpe = (int16) BsGetBits(bs, LEN_IS_CPE);
       
    62     tag = (int16) BsGetBits(bs, LEN_TAG);
       
    63     ch = CCChIndex(mip, cpe, tag);
       
    64 
       
    65     if(!cpe)
       
    66       shared[nch++] = 0;
       
    67     else
       
    68     {
       
    69       int16 cc_l = (int16) BsGetBits(bs, LEN_CC_LR);
       
    70       int16 cc_r = (int16) BsGetBits(bs, LEN_CC_LR);
       
    71       j = (int16) ((cc_l << 1) | cc_r);
       
    72 
       
    73       switch(j)
       
    74       {
       
    75         /*-- Shared gain list. --*/
       
    76         case 0:
       
    77           shared[nch] = 1;
       
    78           shared[nch + 1] = 1;
       
    79           nch += 2;
       
    80           break;
       
    81  
       
    82         /*-- Left channel gain list. --*/
       
    83         case 1:
       
    84           shared[nch] = 0;
       
    85           nch += 1;
       
    86           break;
       
    87 
       
    88         /*-- Right channel gain list. --*/
       
    89         case 2:
       
    90           shared[nch] = 0;
       
    91           nch += 1;
       
    92           break;
       
    93 
       
    94         /*-- Two gain lists. --*/
       
    95         case 3:
       
    96           shared[nch] = 0;
       
    97           shared[nch + 1] = 0;
       
    98           nch += 2;
       
    99           break;
       
   100       
       
   101         default:
       
   102           shared[nch] = 0;
       
   103           shared[nch + 1] = 0;
       
   104           break;
       
   105       }
       
   106     }
       
   107   }
       
   108   
       
   109   int16 cc_dom = (int16) BsGetBits(bs, LEN_CC_DOM);
       
   110   int16 cc_gain_ele_sign = (int16) BsGetBits(bs, LEN_CC_SGN);
       
   111   int16 scl_idx = (int16) BsGetBits(bs, LEN_CCH_GES);
       
   112 
       
   113   /*-- Global gain. --*/
       
   114   global_gain = (int16) BsGetBits(bs, LEN_SCL_PCM);
       
   115 
       
   116   /*-- Side information. --*/
       
   117   if(!GetICSInfo(bs, ccWin, tool->ltp, NULL))
       
   118     return (-1);
       
   119   
       
   120   cip.info = mip->sfbInfo->winmap[ccWin->wnd];
       
   121   
       
   122   /*-- Channel parameters. --*/
       
   123   if (cip.sf_huf == 0) return (-1);
       
   124   if(!GetICS(bs, &cip, ccWin->group, ccWin->max_sfb, ccWin->cb_map, 
       
   125              tool->quant, global_gain, ccWin->sfac))
       
   126     return (-1);
       
   127   
       
   128   /*-- Coupling for first target channel(s) is already at correct scale. --*/
       
   129   ch = shared[0] ? (int16) 2 : (int16) 1;
       
   130 
       
   131   /*-- Bitstreams for target channel scale factors. --*/
       
   132   for( ; ch < nch; ch++)
       
   133   {
       
   134     /*-- If needed, get common gain elment present. --*/
       
   135     int16 cgep = (mip->cc_ind[cidx]) ? (int16) 1 : (int16) BsGetBits(bs, LEN_CCH_CGP);
       
   136 
       
   137     if(cgep) 
       
   138       int16 fac = (int16) (GetHcb(aac->sf_huf, bs) - MIDFAC);
       
   139     
       
   140     /*-- Must be dependently switched CCE. --*/
       
   141     else
       
   142       if(!huf_sfac(bs, &cip, ccWin->group, ccWin->cb_map, 0, ccWin->sfac, ccWin->max_sfb))
       
   143         return (-1);
       
   144   }
       
   145 
       
   146   return (TRUE);
       
   147 }