os/mm/mmlibs/mmfw/Codecs/Src/Gsm610CodecCommon/gsm610fr.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Polymorphic DLL implementation of GSM 6.10 full rate (FR) speech coder
sl@0
    15
// and decoder    objects.
sl@0
    16
// This codec is based on ANSI C simulation codes. For this implementation
sl@0
    17
// (polymorphic DLL) the original ANSI C codes have been modified slightly:
sl@0
    18
// - The original .c files were renamed to .cpp files.
sl@0
    19
// - All global varibles (codec's state) are now encoder's or decoder's
sl@0
    20
// private member variables.
sl@0
    21
// - Because codec's state is in the codec object, an extra variable -
sl@0
    22
// a pointer codec object - have been added to some original routines.
sl@0
    23
// - Global tables are now const C++ tables in tables.h header file.
sl@0
    24
// - VAD and DTX modules have been removed from the original routines.
sl@0
    25
// - Due to error in GNU tool chain all array indexes of type [i-1] in
sl@0
    26
// rpeltp.cpp have been removed and changed to [j] type.
sl@0
    27
// - multr, L_add, L_mac from basicop.cpp inlined
sl@0
    28
// INCLUDES
sl@0
    29
// 
sl@0
    30
//
sl@0
    31
sl@0
    32
#include "gsm610fr.h"
sl@0
    33
#include "codec.h"
sl@0
    34
#include <e32uid.h>
sl@0
    35
sl@0
    36
sl@0
    37
//  LOCAL FUNCTIONS
sl@0
    38
//===================================================================
sl@0
    39
/*
sl@0
    40
-----------------------------------------------------------------------------
sl@0
    41
sl@0
    42
    GSM610FR_Encoder
sl@0
    43
sl@0
    44
    ConstructL
sl@0
    45
sl@0
    46
    This function implements the second phase construction of GSM610FR_Encoder
sl@0
    47
    class. Function binds the encoder to given input and output streams and
sl@0
    48
    resets encoder.
sl@0
    49
sl@0
    50
    Parameters:     RReadStream aInStrm     Handle to input stream (16 bit
sl@0
    51
                                            PCM speech data)
sl@0
    52
                    RWriteStream aOutStrm   Handle to output stream (encoded
sl@0
    53
                                            speech data)
sl@0
    54
sl@0
    55
    Return Values:  none
sl@0
    56
sl@0
    57
-----------------------------------------------------------------------------
sl@0
    58
*/
sl@0
    59
EXPORT_C void CGSM610FR_Encoder::ConstructL()
sl@0
    60
    {
sl@0
    61
    ::reset_encoder(this);
sl@0
    62
    iOddFrame = TRUE;
sl@0
    63
    }
sl@0
    64
sl@0
    65
sl@0
    66
/*
sl@0
    67
-----------------------------------------------------------------------------
sl@0
    68
sl@0
    69
    GSM610FR_Encoder
sl@0
    70
sl@0
    71
    ~GSM610FR_Encoder
sl@0
    72
sl@0
    73
    Empty encoder destructor.
sl@0
    74
sl@0
    75
    Parameters:     none
sl@0
    76
    
sl@0
    77
    Return Values:  none
sl@0
    78
sl@0
    79
-----------------------------------------------------------------------------
sl@0
    80
*/
sl@0
    81
EXPORT_C CGSM610FR_Encoder::~CGSM610FR_Encoder()
sl@0
    82
    {
sl@0
    83
    }
sl@0
    84
sl@0
    85
sl@0
    86
/*
sl@0
    87
-----------------------------------------------------------------------------
sl@0
    88
sl@0
    89
    GSM610FR_Encoder
sl@0
    90
sl@0
    91
    StartL
sl@0
    92
sl@0
    93
    Start encoder object. Initialize codec status.
sl@0
    94
sl@0
    95
    Parameters:     none
sl@0
    96
    
sl@0
    97
    Return Values:  none
sl@0
    98
sl@0
    99
-----------------------------------------------------------------------------
sl@0
   100
*/
sl@0
   101
EXPORT_C void CGSM610FR_Encoder::StartL()
sl@0
   102
    {
sl@0
   103
    ::reset_encoder(this);
sl@0
   104
    iOddFrame = TRUE;
sl@0
   105
    }
sl@0
   106
sl@0
   107
sl@0
   108
/*
sl@0
   109
-----------------------------------------------------------------------------
sl@0
   110
sl@0
   111
    GSM610FR_Encoder
sl@0
   112
sl@0
   113
    ExecuteL
sl@0
   114
sl@0
   115
    Execute encoder object. Read one speech frame from the input stream,
sl@0
   116
    RPELTP encode it and write the encoded frame to output stream.
sl@0
   117
sl@0
   118
    Parameters:     none
sl@0
   119
    
sl@0
   120
    Return Values:  none
sl@0
   121
sl@0
   122
    Leave Handling:
sl@0
   123
    
sl@0
   124
    If the length of data available in the input stream is less than
sl@0
   125
    FRAMESIZE then the function leaves with KErrEof.
sl@0
   126
sl@0
   127
-----------------------------------------------------------------------------
sl@0
   128
*/
sl@0
   129
EXPORT_C void CGSM610FR_Encoder::ExecuteL(TUint8* aInBuf, TUint8* aOutBuf)
sl@0
   130
{
sl@0
   131
	TInt16* inBufPtr  = (TInt16*) aInBuf;
sl@0
   132
sl@0
   133
sl@0
   134
	for (TInt frame = 0; frame < 2; frame++)
sl@0
   135
	{
sl@0
   136
	    ::RPELTP_encoder(this, inBufPtr, &iCodeBuf);
sl@0
   137
sl@0
   138
		if ( iOddFrame )
sl@0
   139
		{
sl@0
   140
			PackFrame0 (&iCodeBuf, (TInt8*) aOutBuf);
sl@0
   141
		}
sl@0
   142
		else
sl@0
   143
		{
sl@0
   144
			PackFrame1 (&iCodeBuf, (TInt8*) aOutBuf);
sl@0
   145
		}
sl@0
   146
sl@0
   147
		iOddFrame = !iOddFrame;
sl@0
   148
		inBufPtr += FRAMESIZE;
sl@0
   149
	}
sl@0
   150
sl@0
   151
}
sl@0
   152
/*
sl@0
   153
-----------------------------------------------------------------------------
sl@0
   154
sl@0
   155
    GSM610FR_Encoder
sl@0
   156
sl@0
   157
    StopL
sl@0
   158
sl@0
   159
    Stop encoder object. Flush out last frames, if necessary.
sl@0
   160
sl@0
   161
    Parameters:     none
sl@0
   162
    
sl@0
   163
    Return Values:  none
sl@0
   164
sl@0
   165
-----------------------------------------------------------------------------
sl@0
   166
*/
sl@0
   167
EXPORT_C void CGSM610FR_Encoder::StopL()
sl@0
   168
    {
sl@0
   169
    }
sl@0
   170
sl@0
   171
sl@0
   172
/*
sl@0
   173
-----------------------------------------------------------------------------
sl@0
   174
sl@0
   175
    GSM610FR_Encoder
sl@0
   176
sl@0
   177
    PackFrame0
sl@0
   178
sl@0
   179
    Pack the codewords of the even frame into pack buffer.
sl@0
   180
sl@0
   181
    Packing as in MS gsm610 encoder.
sl@0
   182
sl@0
   183
    Parameters:     struct codes* aCodeBuf    Code words for one speech frame.
sl@0
   184
    
sl@0
   185
    Return Values:  none
sl@0
   186
sl@0
   187
sl@0
   188
-----------------------------------------------------------------------------
sl@0
   189
*/
sl@0
   190
void CGSM610FR_Encoder::PackFrame0(struct codes* aCodeBuf, TInt8* pbuf)
sl@0
   191
    {
sl@0
   192
    TInt16* LAR = aCodeBuf->LARc;
sl@0
   193
    
sl@0
   194
    // pack the LARc[0..7] into the first 4.5 bytes
sl@0
   195
    *pbuf++ = (TUint8)(((LAR[0]     ) & 0x3F) | ((LAR[1] << 6) & 0xC0));
sl@0
   196
    *pbuf++ = (TUint8)(((LAR[1] >> 2) & 0x0F) | ((LAR[2] << 4) & 0xF0));
sl@0
   197
    *pbuf++ = (TUint8)(((LAR[2] >> 4) & 0x01) | ((LAR[3] << 1) & 0x3E) | ((LAR[4] << 6) & 0xC0));
sl@0
   198
    *pbuf++ = (TUint8)(((LAR[4] >> 2) & 0x03) | ((LAR[5] << 2) & 0x3C) | ((LAR[6] << 6) & 0xC0));
sl@0
   199
    *pbuf   = (TUint8)(((LAR[6] >> 2) & 0x01) | ((LAR[7] << 1) & 0x0E));
sl@0
   200
    
sl@0
   201
    // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
sl@0
   202
    for(TInt i = 0; i < 4; i++)
sl@0
   203
        {
sl@0
   204
        struct sfcodes& c = aCodeBuf->sfc[i];
sl@0
   205
        *pbuf++ |= ((c.Nc << 4) & 0xF0);
sl@0
   206
        *pbuf++ = (TUint8)(((c.Nc >> 4) & 0x07) | ((c.bc << 3) & 0x18) | ((c.Mc << 5) & 0x60) | ((c.xmaxc << 7) & 0x80));
sl@0
   207
        *pbuf++ = (TUint8)(((c.xmaxc >> 1) & 0x1F) | ((c.xMc[0] << 5) & 0xE0));
sl@0
   208
        *pbuf++ = (TUint8)((c.xMc[1] & 0x07) | ((c.xMc[2] << 3) & 0x38) | ((c.xMc[3] << 6) & 0xC0));
sl@0
   209
        *pbuf++ = (TUint8)(((c.xMc[3] >> 2) & 0x01) | ((c.xMc[4] << 1) & 0x0E) | ((c.xMc[5] << 4) & 0x70) | ((c.xMc[6] << 7) & 0x80));
sl@0
   210
        *pbuf++ = (TUint8)(((c.xMc[6] >> 1) & 0x03) | ((c.xMc[7] << 2) & 0x1C) | ((c.xMc[8] << 5) & 0xE0));
sl@0
   211
        *pbuf++ = (TUint8)((c.xMc[9] & 0x07) | ((c.xMc[10] << 3) & 0x38) | ((c.xMc[11] << 6) & 0xC0));
sl@0
   212
        *pbuf   = (TUint8)(((c.xMc[11] >> 2) & 0x01) | ((c.xMc[12] << 1) & 0x0E));
sl@0
   213
        }
sl@0
   214
    }
sl@0
   215
sl@0
   216
sl@0
   217
/*
sl@0
   218
-----------------------------------------------------------------------------
sl@0
   219
sl@0
   220
    GSM610FR_Encoder
sl@0
   221
sl@0
   222
    PackFrame1
sl@0
   223
sl@0
   224
    Pack the codewords of the odd frame into pack buffer.
sl@0
   225
sl@0
   226
    Packing as in MS gsm610 encoder.
sl@0
   227
sl@0
   228
    Parameters:     struct codes* aCodeBuf    Code words for one speech frame.
sl@0
   229
    
sl@0
   230
    Return Values:  none
sl@0
   231
sl@0
   232
sl@0
   233
-----------------------------------------------------------------------------
sl@0
   234
*/
sl@0
   235
void CGSM610FR_Encoder::PackFrame1(struct codes* aCodeBuf, TInt8* pbuf)
sl@0
   236
    {
sl@0
   237
    TInt16* LAR = aCodeBuf->LARc;
sl@0
   238
    
sl@0
   239
	pbuf += (PACKSIZE / 2);
sl@0
   240
	TInt8 pbufZero = pbuf[0];
sl@0
   241
sl@0
   242
    // pack the LARc[0..7] into the first 4.5 bytes, starting with the msb of the first byte
sl@0
   243
    *pbuf++ = (TUint8) (pbufZero | ((LAR[0] << 4) & 0xF0));
sl@0
   244
    *pbuf++ = (TUint8)(((LAR[0] >> 4) & 0x03) | ((LAR[1] << 2) & 0xFC));
sl@0
   245
    *pbuf++ = (TUint8)(((LAR[2]     ) & 0x1F) | ((LAR[3] << 5) & 0xE0));
sl@0
   246
    *pbuf++ = (TUint8)(((LAR[3] >> 3) & 0x03) | ((LAR[4] << 2) & 0x3C) | ((LAR[5] << 6) & 0xC0));
sl@0
   247
    *pbuf++ = (TUint8)(((LAR[5] >> 2) & 0x03) | ((LAR[6] << 2) & 0x1C) | ((LAR[7] << 5) & 0xE0));
sl@0
   248
    
sl@0
   249
    // pack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
sl@0
   250
    for(TInt i = 0; i < 4; i++)
sl@0
   251
        {
sl@0
   252
        struct sfcodes& c = aCodeBuf->sfc[i];
sl@0
   253
        *pbuf++ = (TUint8)((c.Nc & 0x7F) | ((c.bc << 7) & 0x80));
sl@0
   254
        *pbuf++ = (TUint8)(((c.bc >> 1) & 0x01) | ((c.Mc << 1) & 0x06) | ((c.xmaxc << 3) & 0xF8));
sl@0
   255
        *pbuf++ = (TUint8)(((c.xmaxc >> 5) & 0x01) | ((c.xMc[0] << 1) & 0x0E) | ((c.xMc[1] << 4) & 0x70) | ((c.xMc[2] << 7) & 0x80));
sl@0
   256
        *pbuf++ = (TUint8)(((c.xMc[2] >> 1) & 0x03) | ((c.xMc[3] << 2) & 0x1C) | ((c.xMc[4] << 5) & 0xE0));
sl@0
   257
        *pbuf++ = (TUint8)(((c.xMc[5]) & 0x07) | ((c.xMc[6] << 3) & 0x38) | ((c.xMc[7] << 6) & 0xC0));
sl@0
   258
        *pbuf++ = (TUint8)(((c.xMc[7] >> 2) & 0x01) | ((c.xMc[8] << 1) & 0x0E) | ((c.xMc[9] << 4) & 0x70) | ((c.xMc[10] << 7) & 0x80));
sl@0
   259
        *pbuf++ = (TUint8)(((c.xMc[10] >> 1) & 0x03) | ((c.xMc[11] << 2) & 0x1C) | ((c.xMc[12] << 5) & 0xE0));
sl@0
   260
        }
sl@0
   261
    }
sl@0
   262
sl@0
   263
/*
sl@0
   264
-----------------------------------------------------------------------------
sl@0
   265
sl@0
   266
    GSM610FR_Decoder
sl@0
   267
sl@0
   268
    ConstructL
sl@0
   269
sl@0
   270
    This function implements the second phase construction of GSM610FR_Decoder
sl@0
   271
    class. Function binds the decoder to given input and output streams and
sl@0
   272
    resets decoder.
sl@0
   273
sl@0
   274
    Parameters:     RReadStream aInStrm     Handle to input stream (encoded
sl@0
   275
                                            speech data)
sl@0
   276
                                            
sl@0
   277
                    RWriteStream aOutStrm   Handle to output stream (16 bit
sl@0
   278
                                            PCM speech data)
sl@0
   279
sl@0
   280
    Return Values:  none
sl@0
   281
sl@0
   282
-----------------------------------------------------------------------------
sl@0
   283
*/
sl@0
   284
EXPORT_C void CGSM610FR_Decoder::ConstructL()
sl@0
   285
    {
sl@0
   286
    ::reset_decoder(this);
sl@0
   287
    iOddFrame = TRUE;
sl@0
   288
    }
sl@0
   289
sl@0
   290
sl@0
   291
/*
sl@0
   292
-----------------------------------------------------------------------------
sl@0
   293
sl@0
   294
    GSM610FR_Decoder
sl@0
   295
sl@0
   296
    ~GSM610FR_Decoder
sl@0
   297
sl@0
   298
    Empty decoder destructor.
sl@0
   299
sl@0
   300
    Parameters:     none
sl@0
   301
    
sl@0
   302
    Return Values:  none
sl@0
   303
sl@0
   304
-----------------------------------------------------------------------------
sl@0
   305
*/
sl@0
   306
EXPORT_C CGSM610FR_Decoder::~CGSM610FR_Decoder()
sl@0
   307
    {
sl@0
   308
    }
sl@0
   309
sl@0
   310
sl@0
   311
/*
sl@0
   312
-----------------------------------------------------------------------------
sl@0
   313
sl@0
   314
    GSM610FR_Decoder
sl@0
   315
sl@0
   316
    StartL
sl@0
   317
sl@0
   318
    Start decoder object. Initialize codec status.
sl@0
   319
sl@0
   320
    Parameters:     none
sl@0
   321
    
sl@0
   322
    Return Values:  none
sl@0
   323
sl@0
   324
-----------------------------------------------------------------------------
sl@0
   325
*/
sl@0
   326
EXPORT_C void CGSM610FR_Decoder::StartL()
sl@0
   327
    {
sl@0
   328
    ::reset_decoder(this);
sl@0
   329
    iOddFrame = TRUE;
sl@0
   330
    }
sl@0
   331
sl@0
   332
sl@0
   333
/*
sl@0
   334
-----------------------------------------------------------------------------
sl@0
   335
sl@0
   336
    GSM610FR_Decoder
sl@0
   337
sl@0
   338
    ExecuteL
sl@0
   339
sl@0
   340
    Execute decoder object. Read one encoded speech frame from the input
sl@0
   341
    stream RPELTP decode it and write the decoded frame to output stream.
sl@0
   342
sl@0
   343
    Parameters:     none
sl@0
   344
    
sl@0
   345
    Return Values:  none
sl@0
   346
sl@0
   347
    Leave Handling:
sl@0
   348
    
sl@0
   349
    If the length of data available in the input stream is less than size
sl@0
   350
    of one encoded speech frame then the function leaves with KErrEof.
sl@0
   351
sl@0
   352
-----------------------------------------------------------------------------
sl@0
   353
*/
sl@0
   354
EXPORT_C void CGSM610FR_Decoder::ExecuteL(TUint8* aInBuf, TUint8* aOutBuf)
sl@0
   355
{
sl@0
   356
sl@0
   357
	TInt16* outBufPtr = (TInt16*) aOutBuf;
sl@0
   358
sl@0
   359
sl@0
   360
	// Process both odd and even frames
sl@0
   361
sl@0
   362
	for (TInt frame = 0; frame < 2; frame++)
sl@0
   363
	{
sl@0
   364
		if ( iOddFrame )
sl@0
   365
		{
sl@0
   366
			UnpackFrame0(&iCodeBuf, (TInt8*) aInBuf);
sl@0
   367
        }
sl@0
   368
	   else
sl@0
   369
        {
sl@0
   370
			UnpackFrame1(&iCodeBuf, (TInt8*) aInBuf);
sl@0
   371
		}
sl@0
   372
sl@0
   373
sl@0
   374
		::RPELTP_decoder(this, &iCodeBuf, outBufPtr);
sl@0
   375
sl@0
   376
		iOddFrame = !iOddFrame;
sl@0
   377
		outBufPtr += FRAMESIZE;
sl@0
   378
sl@0
   379
	}
sl@0
   380
sl@0
   381
}
sl@0
   382
sl@0
   383
/*
sl@0
   384
-----------------------------------------------------------------------------
sl@0
   385
sl@0
   386
    GSM610FR_Decoder
sl@0
   387
sl@0
   388
    StopL
sl@0
   389
sl@0
   390
    Stop decoder object. Flush out last frames, if necessary.
sl@0
   391
sl@0
   392
    Parameters:     none
sl@0
   393
    
sl@0
   394
    Return Values:  none
sl@0
   395
sl@0
   396
-----------------------------------------------------------------------------
sl@0
   397
*/
sl@0
   398
EXPORT_C void CGSM610FR_Decoder::StopL()
sl@0
   399
    {
sl@0
   400
    }
sl@0
   401
sl@0
   402
sl@0
   403
/*
sl@0
   404
-----------------------------------------------------------------------------
sl@0
   405
sl@0
   406
    GSM610FR_Decoder
sl@0
   407
sl@0
   408
    UnpackFrame0
sl@0
   409
sl@0
   410
    Unpack the codewords of the even frame from pack buffer.
sl@0
   411
sl@0
   412
    Packing as in MS gsm610 encoder.
sl@0
   413
sl@0
   414
    Parameters:     struct codes* aCodeBuf    Code words for one speech frame
sl@0
   415
                                              are unpacked into this structure.
sl@0
   416
    
sl@0
   417
    Return Values:  none
sl@0
   418
sl@0
   419
sl@0
   420
-----------------------------------------------------------------------------
sl@0
   421
*/
sl@0
   422
void CGSM610FR_Decoder::UnpackFrame0(struct codes* aCodeBuf,  TInt8* pbuf)
sl@0
   423
    {
sl@0
   424
    TInt16* LAR = aCodeBuf->LARc;
sl@0
   425
sl@0
   426
    // unpack the LAR[0..7] from the first 4.5 bytes
sl@0
   427
    LAR[0] = (TInt16)((pbuf[0] & 0x3F));
sl@0
   428
    LAR[1] = (TInt16)(((pbuf[0] & 0xC0) >> 6) | ((pbuf[1] & 0x0F) << 2));
sl@0
   429
    LAR[2] = (TInt16)(((pbuf[1] & 0xF0) >> 4) | ((pbuf[2] & 0x01) << 4));
sl@0
   430
    LAR[3] = (TInt16)(((pbuf[2] & 0x3E) >> 1));
sl@0
   431
    LAR[4] = (TInt16)(((pbuf[2] & 0xC0) >> 6) | ((pbuf[3] & 0x03) << 2));
sl@0
   432
    LAR[5] = (TInt16)(((pbuf[3] & 0x3C) >> 2));
sl@0
   433
    LAR[6] = (TInt16)(((pbuf[3] & 0xC0) >> 6) | ((pbuf[4] & 0x01) << 2));
sl@0
   434
    LAR[7] = (TInt16)(((pbuf[4] & 0x0E) >> 1));
sl@0
   435
sl@0
   436
    // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
sl@0
   437
    for(TInt i = 0; i < 4; i++)
sl@0
   438
        {
sl@0
   439
        struct sfcodes& c = aCodeBuf->sfc[i];
sl@0
   440
#define sfb(x) (pbuf[4+i*7+x])
sl@0
   441
        c.Nc = (TInt16)(((sfb(0) & 0xF0) >> 4) | ((sfb(1) & 0x07) << 4));
sl@0
   442
        c.bc = (TInt16)(((sfb(1) & 0x18) >> 3));
sl@0
   443
        c.Mc = (TInt16)(((sfb(1) & 0x60) >> 5));
sl@0
   444
        c.xmaxc = (TInt16)(((sfb(1) & 0x80) >> 7) | ((sfb(2) & 0x1F) << 1));
sl@0
   445
        c.xMc[0] = (TInt16)(((sfb(2) & 0xE0) >> 5));
sl@0
   446
        c.xMc[1] = (TInt16)((sfb(3) & 0x07));
sl@0
   447
        c.xMc[2] = (TInt16)(((sfb(3) & 0x3C) >> 3));
sl@0
   448
        c.xMc[3] = (TInt16)(((sfb(3) & 0xC0) >> 6) | ((sfb(4) & 0x01) << 2));
sl@0
   449
        c.xMc[4] = (TInt16)(((sfb(4) & 0x0E) >> 1));
sl@0
   450
        c.xMc[5] = (TInt16)(((sfb(4) & 0x70) >> 4));
sl@0
   451
        c.xMc[6] = (TInt16)(((sfb(4) & 0x80) >> 7) | ((sfb(5) & 0x03) << 1));
sl@0
   452
        c.xMc[7] = (TInt16)(((sfb(5) & 0x1C) >> 2));
sl@0
   453
        c.xMc[8] = (TInt16)(((sfb(5) & 0xE0) >> 5));
sl@0
   454
        c.xMc[9] = (TInt16)((sfb(6) & 0x07));
sl@0
   455
        c.xMc[10] = (TInt16)(((sfb(6) & 0x38) >> 3));
sl@0
   456
        c.xMc[11] = (TInt16)(((sfb(6) & 0xC0) >> 6) | ((sfb(7) & 0x01) << 2));
sl@0
   457
        c.xMc[12] = (TInt16)(((sfb(7) & 0x0E) >> 1));
sl@0
   458
#undef sfb
sl@0
   459
        }
sl@0
   460
    }
sl@0
   461
sl@0
   462
sl@0
   463
/*
sl@0
   464
-----------------------------------------------------------------------------
sl@0
   465
sl@0
   466
    GSM610FR_Decoder
sl@0
   467
sl@0
   468
    UnpackFrame1
sl@0
   469
sl@0
   470
    Unpack the codewords of the odd frame from pack buffer.
sl@0
   471
sl@0
   472
    Packing as in MS gsm610 encoder.
sl@0
   473
sl@0
   474
    Parameters:     struct codes* aCodeBuf    Code words for one speech frame
sl@0
   475
                                              are unpacked into this structure.
sl@0
   476
    
sl@0
   477
    Return Values:  none
sl@0
   478
sl@0
   479
sl@0
   480
-----------------------------------------------------------------------------
sl@0
   481
*/
sl@0
   482
void CGSM610FR_Decoder::UnpackFrame1(struct codes* aCodeBuf, TInt8* pbuf)
sl@0
   483
{
sl@0
   484
    TInt16* LAR = aCodeBuf->LARc;
sl@0
   485
sl@0
   486
    // unpack the LAR[0..7] from the first 4.5 bytes
sl@0
   487
    LAR[0] = (TInt16)(((pbuf[32] & 0xF0) >> 4) | ((pbuf[33] & 0x03) << 4));
sl@0
   488
    LAR[1] = (TInt16)(((pbuf[33] & 0xFC) >> 2));
sl@0
   489
    LAR[2] = (TInt16)(((pbuf[34] & 0x1F)));
sl@0
   490
    LAR[3] = (TInt16)(((pbuf[34] & 0xE0) >> 5) | ((pbuf[35] & 0x03) << 3));
sl@0
   491
    LAR[4] = (TInt16)(((pbuf[35] & 0x3C) >> 2));
sl@0
   492
    LAR[5] = (TInt16)(((pbuf[35] & 0xC0) >> 6) | ((pbuf[36] & 0x03) << 2));
sl@0
   493
    LAR[6] = (TInt16)(((pbuf[36] & 0x1C) >> 2));
sl@0
   494
    LAR[7] = (TInt16)(((pbuf[36] & 0xE0) >> 5));
sl@0
   495
sl@0
   496
    // unpack Nc, bc, Mc, xmaxc, and xMc for each of the 4 sub-frames
sl@0
   497
    for(TInt i = 0; i < 4; i++)
sl@0
   498
        {
sl@0
   499
        struct sfcodes& c = aCodeBuf->sfc[i];
sl@0
   500
#define sfb(x) (pbuf[37+i*7+x])
sl@0
   501
        c.Nc = (TInt16)(sfb(0) & 0x7F);
sl@0
   502
        c.bc = (TInt16)(((sfb(0) & 0x80) >> 7) | ((sfb(1) & 0x01) << 1));
sl@0
   503
        c.Mc = (TInt16)(((sfb(1) & 0x06) >> 1));
sl@0
   504
        c.xmaxc = (TInt16)(((sfb(1) & 0xF8) >> 3) | ((sfb(2) & 0x01) << 5));
sl@0
   505
        c.xMc[0] = (TInt16)(((sfb(2) & 0x0E) >> 1));
sl@0
   506
        c.xMc[1] = (TInt16)(((sfb(2) & 0x70) >> 4));
sl@0
   507
        c.xMc[2] = (TInt16)(((sfb(2) & 0x80) >> 7) | ((sfb(3) & 0x03) << 1));
sl@0
   508
        c.xMc[3] = (TInt16)(((sfb(3) & 0x1C) >> 2));
sl@0
   509
        c.xMc[4] = (TInt16)(((sfb(3) & 0xE0) >> 5));
sl@0
   510
        c.xMc[5] = (TInt16)(((sfb(4) & 0x07)));
sl@0
   511
        c.xMc[6] = (TInt16)(((sfb(4) & 0x38) >> 3));
sl@0
   512
        c.xMc[7] = (TInt16)(((sfb(4) & 0xC0) >> 6) | ((sfb(5) & 0x01) << 2));
sl@0
   513
        c.xMc[8] = (TInt16)(((sfb(5) & 0x0E) >> 1));
sl@0
   514
        c.xMc[9] = (TInt16)(((sfb(5) & 0x70) >> 4));
sl@0
   515
        c.xMc[10] = (TInt16)(((sfb(5) & 0x80) >> 7) | ((sfb(6) & 0x03) << 1));
sl@0
   516
        c.xMc[11] = (TInt16)(((sfb(6) & 0x1C) >> 2));
sl@0
   517
        c.xMc[12] = (TInt16)(((sfb(6) & 0xE0) >> 5));
sl@0
   518
sl@0
   519
#undef sfb
sl@0
   520
        }
sl@0
   521
    }
sl@0
   522
sl@0
   523
sl@0
   524
//-----------------------------------------------------------------------------
sl@0
   525
//  End of File
sl@0
   526
//-----------------------------------------------------------------------------