1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/Codecs/Src/Gsm610CodecCommon/codec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,262 @@
1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "rpeltp.h"
1.20 +#include "codec.h"
1.21 +#include "gsm610fr.h"
1.22 +
1.23 +/*
1.24 +** LPC analysis part of the RPE-LTP-coder
1.25 +**
1.26 +** Input:
1.27 +** sop[0..159]
1.28 +** unprocessed sample frame
1.29 +** Output:
1.30 +** d[0..159]
1.31 +** residual
1.32 +** LARc[0..7]
1.33 +** coded reflection coefficients
1.34 +** *SP_flag:
1.35 +** decision of tx DTX (boolean)
1.36 +** *VAD_flag:
1.37 +** decision of VAD (boolean)
1.38 +**
1.39 +** Return value:
1.40 +** None
1.41 +*/
1.42 +void LPC_analysis(CGSM610FR_Encoder* aEncoder, int2 ibuf[], struct codes *ecodes)
1.43 +{
1.44 +
1.45 + int4 L_ACF[9];
1.46 + int2 LAR[8]; /* used for r[], LAR[], LARpp */
1.47 + int2 rp[8]; /* used for LARp[], rp[] */
1.48 +// int2 scalauto; /* returned from autoc to be used by vad */
1.49 +
1.50 +
1.51 + prepr( aEncoder, ibuf, ibuf ); /* sof <- so */
1.52 + preemp( aEncoder, ibuf, ibuf ); /* s <- sof */
1.53 +// scalauto = autoc( L_ACF, ibuf ); /* L_ACF <- , s <- s */
1.54 + autoc( L_ACF, ibuf ); /* L_ACF <- , s <- s */
1.55 +
1.56 + /*
1.57 + ** VAD decision could be computed here when L_ACF and scalauto are available.
1.58 + ** In current version vad is executed after LAR computation
1.59 + */
1.60 +
1.61 + schur( LAR, L_ACF ); /* r <- L_ACF */
1.62 +
1.63 + larcomp( LAR, LAR ); /* LAR <- r */
1.64 +
1.65 + codlar( ecodes->LARc, LAR ); /* LARc <- LAR */
1.66 + declar( LAR, ecodes->LARc ); /* LARpp <- LARc */
1.67 +
1.68 + cparc1( rp, aEncoder->LARpp_prev, LAR ); /* LARp <- LARpp_prev, LARpp */
1.69 + crp( rp, rp ); /* rp <- LARp */
1.70 + invfil( aEncoder, ibuf, ibuf, rp, 0, 12 ); /* d <- s */
1.71 +
1.72 + cparc2( rp, aEncoder->LARpp_prev, LAR ); /* LARp <- LARpp_prev, LARpp */
1.73 + crp( rp, rp ); /* rp <- LARp */
1.74 + invfil( aEncoder, ibuf, ibuf, rp, 13, 26 ); /* d <- s */
1.75 +
1.76 + cparc3( rp, aEncoder->LARpp_prev, LAR ); /* LARp <- LARpp_prev, LARpp */
1.77 + crp( rp, rp ); /* rp <- LARp */
1.78 + invfil( aEncoder, ibuf, ibuf, rp, 27, 39 ); /* d <- s*/
1.79 +
1.80 + cparc4( rp, aEncoder->LARpp_prev, LAR ); /* LARp <- LARpp_prev, LARpp */
1.81 + crp( rp, rp ); /* rp <- LARp */
1.82 + invfil( aEncoder, ibuf, ibuf, rp, 40, 159 ); /* d <- s */
1.83 + return;
1.84 +}
1.85 +
1.86 +/*
1.87 +** Encoding of the residual signal of the LPC analysis filter
1.88 +** Input:
1.89 +**
1.90 +** d[k_start..k_start+39]
1.91 +** LPC residual (output of LPC analysis filter)
1.92 +**
1.93 +** Output:
1.94 +**
1.95 +** bc, Nc
1.96 +** encoded LTP parameters (gain and lag)
1.97 +** xmaxc
1.98 +** block maximum of the encoded subframe.
1.99 +** xMc[0..12]
1.100 +** coded normalized RPE pulses
1.101 +**
1.102 +** return xmax for SID computation
1.103 +*/
1.104 +int2 residual_encoder( CGSM610FR_Encoder* aEncoder, int sf_nro, int2 d[], struct sfcodes *sfc )
1.105 +{
1.106 + int k_start;
1.107 + int2 xmax; /* return value */
1.108 +
1.109 + /* Note: d[] is used also for for x[] and e[] */
1.110 +
1.111 + int2 xM[13]; /* used for xM[], xMp[] */
1.112 + /* xM[] is required simultaneously with xMc because LTP
1.113 + * also decodes xMc
1.114 + */
1.115 + int2 dpp[40]; /* required simultaneously with ep[] that is
1.116 + * stored into d[]
1.117 + */
1.118 + int2 Exp;
1.119 + int2 mant;
1.120 +
1.121 + k_start = sf_nro * 40;
1.122 +
1.123 + ltpcomp( aEncoder, &(sfc->Nc), &(sfc->bc), d, k_start );
1.124 + ltpfil( aEncoder, &d[k_start], dpp, d, sfc->bc, sfc->Nc, k_start ); /* e, dpp <- d */
1.125 + weight( &d[k_start], &d[k_start] ); /* x <- e */
1.126 + sfc->Mc = gridsel( xM, &d[k_start] ); /* xM <- x */
1.127 +
1.128 + /*
1.129 + ** quatize residual and store unquantized xmax for SID
1.130 + ** computation
1.131 + */
1.132 + xmax = apcm( &(sfc->xmaxc), xM, sfc->xMc, &Exp, &mant);
1.133 + /* EXP, mant computed int APCM */
1.134 +
1.135 + iapcm( xM, sfc->xMc, Exp, mant ); /* xMp <- xMc */
1.136 + gridpos( &d[k_start], xM, sfc->Mc ); /* ep <- xMc,Mc */
1.137 + ltpupd( aEncoder, dpp, &d[k_start] ); /* dp <- dpp, x */
1.138 +
1.139 + return( xmax );
1.140 +}
1.141 +
1.142 +
1.143 +/*
1.144 +** Decoding of the coded LPC-residual
1.145 +**
1.146 +** Input:
1.147 +** xmaxcr
1.148 +** coded block maxmimum
1.149 +** xMcr[0..12]
1.150 +** coded normalized RPE pulses
1.151 +**
1.152 +** Output:
1.153 +** drp[k_start..k_start+39]
1.154 +** decoded LPC residual (input signal for LPC-synthesis filter)
1.155 +*/
1.156 +void residual_decoder(CGSM610FR_Decoder* aDecoder, int sf_nro, struct sfcodes *sfc, int2 wt[])
1.157 +{
1.158 + int k_start;
1.159 +
1.160 + int2 EXP;
1.161 + int2 mant;
1.162 + int2 xMrp[13];
1.163 + int2 erp[40];
1.164 +
1.165 + k_start = sf_nro * 40;
1.166 +
1.167 + /* in decoder EXP ja mant must be computed from xmaxcr */
1.168 + expman( &EXP, &mant, sfc->xmaxc ); /* EXP, mant <- xmaxc */
1.169 + iapcm( xMrp, sfc->xMc, EXP, mant ); /* xMrp <- xMc */
1.170 + gridpos( erp, xMrp, sfc->Mc ); /* erp <- xMc,Mc */
1.171 +
1.172 + ltpsyn( aDecoder, erp, &wt[k_start], sfc->bc, sfc->Nc );
1.173 +}
1.174 +
1.175 +/*
1.176 +** LPC synthesis part of the RPE-LTP-coder
1.177 +**
1.178 +** Input:
1.179 +** LARcr[0..7]
1.180 +** coded reflection coefficients
1.181 +** wt[0..159]
1.182 +** decoded residual
1.183 +**
1.184 +** Output:
1.185 +** srop[0..159]
1.186 +** decoded speech
1.187 +*/
1.188 +void LPC_synthesis(CGSM610FR_Decoder* aDecoder, struct codes *dcodes, int2 wt[], int2 obuf[])
1.189 +{
1.190 + int2 LARr[8]; /* used for LARr[], LARpp */
1.191 + int2 rrp[8]; /* used for LARp[], rrp[] */
1.192 +
1.193 + declar(LARr, dcodes->LARc); /* LARrpp <- LARc */
1.194 +
1.195 + cparc1( rrp, aDecoder->LARrpp_prev, LARr ); /* LARp <- LARrpp_prev, LARr */
1.196 + crp( rrp, rrp ); /* rrp <- LARp */
1.197 + synfil( aDecoder, obuf, wt, rrp, 0, 12 ); /* sr <- wt */
1.198 +
1.199 + cparc2( rrp, aDecoder->LARrpp_prev, LARr ); /* LARp <- LARrpp_prev, LARr */
1.200 + crp( rrp, rrp ); /* rrp <- LARp */
1.201 + synfil( aDecoder, obuf, wt, rrp, 13, 26 ); /* sr <- wt */
1.202 +
1.203 + cparc3( rrp, aDecoder->LARrpp_prev, LARr ); /* LARp <- LARrpp_prev, LARr */
1.204 + crp( rrp, rrp ); /* rrp <- LARp */
1.205 + synfil( aDecoder, obuf, wt, rrp, 27, 39 ); /* sr <- wt */
1.206 +
1.207 + cparc4( rrp, aDecoder->LARrpp_prev, LARr ); /* LARp <- LARrpp_prev, LARr */
1.208 + crp( rrp, rrp ); /* rrp <- LARp */
1.209 + synfil( aDecoder, obuf, wt, rrp, 40, 159 ); /* sr <- wt */
1.210 + postpr( aDecoder, obuf, obuf );
1.211 + /* combines deemphasis, upscaling and truncation */
1.212 +
1.213 +}
1.214 +
1.215 +
1.216 +/*
1.217 +** RPE-LTP Encoder
1.218 +**
1.219 +** void RPELTP_encoder(CGSM610FR_Encoder* aEncoder, int2 ibuf[], struct codes *ecodes)
1.220 +**
1.221 +** Input:
1.222 +** ibuf[0..159]
1.223 +** Original speech to be coded
1.224 +**
1.225 +** Output:
1.226 +** ecodes
1.227 +** encoded speech stored as codewords
1.228 +*/
1.229 +void RPELTP_encoder(CGSM610FR_Encoder* aEncoder, int2 ibuf[], struct codes *ecodes)
1.230 +{
1.231 + int i;
1.232 +// int2 xmax[4]; /* collect unquantized xmax data for dtx */
1.233 +
1.234 + LPC_analysis( aEncoder, ibuf, ecodes );
1.235 + for (i = 0; i < 4; i++)
1.236 +// xmax[i] = residual_encoder( aEncoder, i, ibuf, &(ecodes->sfc[i]) );
1.237 + residual_encoder( aEncoder, i, ibuf, &(ecodes->sfc[i]) );
1.238 +}
1.239 +
1.240 +
1.241 +/*
1.242 +** RPE-LTP Decoder
1.243 +**
1.244 +** void RPELTP_decoder(struct codes *dcodes, int2 obuf[])
1.245 +** Input:
1.246 +** dcodes
1.247 +** encoded speech stored as codewords to be decoded
1.248 +**
1.249 +** Output:
1.250 +** obuf[0..159]
1.251 +** Decoded speech
1.252 +*/
1.253 +void RPELTP_decoder(CGSM610FR_Decoder* aDecoder, struct codes *dcodes, int2 obuf[])
1.254 +{
1.255 + int i;
1.256 +
1.257 + dcodes->LARc[0] &= 0x7fff; /* VAD flag in sequences */
1.258 + dcodes->LARc[1] &= 0x7fff; /* SP flag in sequences */
1.259 +
1.260 + for (i = 0; i < 4; i++)
1.261 + residual_decoder(aDecoder, i, &(dcodes->sfc[i]), obuf); /* -> wt */
1.262 +
1.263 + LPC_synthesis(aDecoder, dcodes, obuf, obuf); /* wt -> srop */
1.264 +}
1.265 +