os/mm/devsound/devsoundrefplugin/src/codec/sbcencoder/SBCFrameParameters.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2004-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
//
sl@0
    15
sl@0
    16
#ifndef __SBCFRAMEPARAMETERS_H__
sl@0
    17
#define __SBCFRAMEPARAMETERS_H__
sl@0
    18
sl@0
    19
/**
sl@0
    20
This class contains 6 SBC frame parameters: sampling frequency, block length, 
sl@0
    21
channel mode, allocation mode, subbands and bitpool. It can validate all the 
sl@0
    22
parameters, calculate frame length and bit rate.
sl@0
    23
@internalComponent
sl@0
    24
*/
sl@0
    25
class TSBCFrameParameters
sl@0
    26
	{
sl@0
    27
public:
sl@0
    28
	/**
sl@0
    29
	This enum list all the possible sampling frequency settings
sl@0
    30
	*/
sl@0
    31
	enum TSamplingFrequency
sl@0
    32
		{
sl@0
    33
		/**
sl@0
    34
		sampling frequency is 16000 Hz
sl@0
    35
		*/
sl@0
    36
		E16000Hz = 0,
sl@0
    37
		/**
sl@0
    38
		sampling frequency is 32000 Hz
sl@0
    39
		*/
sl@0
    40
		E32000Hz,
sl@0
    41
		/**
sl@0
    42
		sampling frequency is 44100 Hz
sl@0
    43
		*/
sl@0
    44
		E44100Hz,
sl@0
    45
		/**
sl@0
    46
		sampling frequency is 48000 Hz
sl@0
    47
		*/
sl@0
    48
		E48000Hz
sl@0
    49
		};
sl@0
    50
sl@0
    51
	/**
sl@0
    52
	This enum list all the possible block length settings
sl@0
    53
	*/
sl@0
    54
	enum TBlockLength
sl@0
    55
		{
sl@0
    56
		/**
sl@0
    57
		block length is 4, one frame contains 4 blocks of audio samples
sl@0
    58
		*/
sl@0
    59
		E4Blocks = 0,
sl@0
    60
		/**
sl@0
    61
		block length is 8, one frame contains 8 blocks of audio samples
sl@0
    62
		*/
sl@0
    63
		E8Blocks,
sl@0
    64
		/**
sl@0
    65
		block length is 12, one frame contains 12 blocks of audio samples
sl@0
    66
		*/
sl@0
    67
		E12Blocks,
sl@0
    68
		/**
sl@0
    69
		block length is 16, one frame contains 16 blocks of audio samples
sl@0
    70
		*/
sl@0
    71
		E16Blocks
sl@0
    72
		};
sl@0
    73
sl@0
    74
	/**
sl@0
    75
	This enum list all the possible channel mode settings
sl@0
    76
	*/
sl@0
    77
	enum TChannelMode
sl@0
    78
		{
sl@0
    79
		/**
sl@0
    80
		channel mode is Mono, in this mode,
sl@0
    81
		only one channel contains audio samples.
sl@0
    82
		*/
sl@0
    83
		EMono = 0,
sl@0
    84
		/**
sl@0
    85
		channel mode is Dual Channel, in this mode,
sl@0
    86
		it contains two seperate mono audio samples.
sl@0
    87
		*/
sl@0
    88
		EDualChannel,
sl@0
    89
		/**
sl@0
    90
		channel mode is Stereo, in this mode,
sl@0
    91
		it contains stereo audio samples.
sl@0
    92
		*/
sl@0
    93
		EStereo,
sl@0
    94
		/**
sl@0
    95
		channel mode is Joint Stereo, in this mode,
sl@0
    96
		the left channel stores half of sum of both channels, 
sl@0
    97
		the right channel stores half of difference of both channels. 
sl@0
    98
		*/
sl@0
    99
		EJointStereo
sl@0
   100
		};
sl@0
   101
sl@0
   102
	/**
sl@0
   103
	This enum list all the possible allocation method settings
sl@0
   104
	*/
sl@0
   105
	enum TAllocationMethod
sl@0
   106
		{
sl@0
   107
		/**
sl@0
   108
		allocation method is Loudness, in this mode, 
sl@0
   109
		the bit allocation calculation uses Table offset4 or offset8 as well as scale factors
sl@0
   110
		*/
sl@0
   111
		ELoudness = 0,
sl@0
   112
		/**
sl@0
   113
		allocation method is SNR, in this mode,
sl@0
   114
		bit allocation only uses scale factors
sl@0
   115
		*/
sl@0
   116
		ESNR
sl@0
   117
		};
sl@0
   118
sl@0
   119
	/**
sl@0
   120
	This enum list all the possible subbands settings
sl@0
   121
	*/
sl@0
   122
	enum TSubbands
sl@0
   123
		{
sl@0
   124
		/**
sl@0
   125
		subbands is 4, each channel contains 4 subbands in each block, 
sl@0
   126
		each subband contains one sample
sl@0
   127
		*/
sl@0
   128
		E4Subbands = 0,
sl@0
   129
		/**
sl@0
   130
		subbands is 8, each channel contains 8 subbands in each block, 
sl@0
   131
		each subband contains one sample
sl@0
   132
		*/
sl@0
   133
		E8Subbands
sl@0
   134
		};
sl@0
   135
		
sl@0
   136
public:
sl@0
   137
	inline TSBCFrameParameters();
sl@0
   138
	
sl@0
   139
	inline void Reset();
sl@0
   140
sl@0
   141
	inline TUint8 	SamplingFrequencyEnum() const;
sl@0
   142
	inline TUint	SamplingFrequencyHz() const;
sl@0
   143
	inline void		SetSamplingFrequency(TSamplingFrequency aSamplingFrequency);
sl@0
   144
	
sl@0
   145
	inline TUint8	BlockLength() const;
sl@0
   146
	inline void		SetBlockLength(TBlockLength aBlockLength);
sl@0
   147
	
sl@0
   148
	inline TUint8 	ChannelMode() const;
sl@0
   149
	inline TUint8	Channels() const;
sl@0
   150
	inline void 	SetChannelMode(TChannelMode aChannelMode);
sl@0
   151
	
sl@0
   152
	inline TUint8 	AllocationMethod() const;
sl@0
   153
	inline void 	SetAllocationMethod(TAllocationMethod aAllocationMethod);
sl@0
   154
	
sl@0
   155
	inline TUint8	SubbandsEnum() const;
sl@0
   156
	inline TUint8	Subbands() const;
sl@0
   157
	inline void 	SetSubbands(TSubbands aSubbands);
sl@0
   158
	
sl@0
   159
	inline TUint8	Bitpool() const;
sl@0
   160
	inline void		SetBitpool(TUint8 aBitpool);
sl@0
   161
	
sl@0
   162
	inline TUint8	Parameters() const;
sl@0
   163
	inline TInt 	Validate() const;
sl@0
   164
sl@0
   165
	inline TUint 	CalcFrameLength() const;
sl@0
   166
	inline TUint 	CalcBitRate(TUint aFrameLength) const;
sl@0
   167
sl@0
   168
private:
sl@0
   169
	TUint8 	iParameters;
sl@0
   170
	TUint8 	iBitpool;
sl@0
   171
	};
sl@0
   172
sl@0
   173
/**
sl@0
   174
The minimum SBC bitpool value is 2 
sl@0
   175
*/	
sl@0
   176
const TUint8 KSBCMinBitpoolValue = 2;
sl@0
   177
/**
sl@0
   178
The maximum SBC bitpool value is 250 
sl@0
   179
*/	
sl@0
   180
const TUint8 KSBCMaxBitpoolValue = 250;
sl@0
   181
sl@0
   182
/**
sl@0
   183
The sampling frequency bits mask is 0b11, 2 bits
sl@0
   184
*/	
sl@0
   185
const TUint8 KSBCSampFreqBitsMask  = 0x3;
sl@0
   186
/**
sl@0
   187
The bit offset of sampling frequency field in TSBCFrameParameters::iParameters is 6
sl@0
   188
*/
sl@0
   189
const TUint8 KSBCSampFreqBitOffset = 6;
sl@0
   190
sl@0
   191
/**
sl@0
   192
The block length bits mask is 0b11, 2 bits
sl@0
   193
*/	
sl@0
   194
const TUint8 KSBCBlckLengBitsMask  = 0x3;
sl@0
   195
/**
sl@0
   196
The bit offset of block length field in TSBCFrameParameters::iParameters is 4
sl@0
   197
*/
sl@0
   198
const TUint8 KSBCBlckLengBitOffset = 4;
sl@0
   199
sl@0
   200
/**
sl@0
   201
The block length bits mask is 0b11, 2 bits
sl@0
   202
*/	
sl@0
   203
const TUint8 KSBCChnlModeBitsMask  = 0x3;
sl@0
   204
/**
sl@0
   205
The bit offset of block length field in TSBCFrameParameters::iParameters is 2
sl@0
   206
*/
sl@0
   207
const TUint8 KSBCChnlModeBitOffset = 2;
sl@0
   208
sl@0
   209
/**
sl@0
   210
The block length bits mask is 0b01, 1 bit
sl@0
   211
*/	
sl@0
   212
const TUint8 KSBCAllcMthdBitsMask  = 0x1;
sl@0
   213
/**
sl@0
   214
The bit offset of block length field in TSBCFrameParameters::iParameters is 1
sl@0
   215
*/
sl@0
   216
const TUint8 KSBCAllcMthdBitOffset = 1;
sl@0
   217
sl@0
   218
/**
sl@0
   219
The block length bits mask is 0b01, 1 bit
sl@0
   220
*/	
sl@0
   221
const TUint8 KSBCSubbandsBitsMask  = 0x1;
sl@0
   222
/**
sl@0
   223
The bit offset of block length field in TSBCFrameParameters::iParameters is 0
sl@0
   224
*/
sl@0
   225
const TUint8 KSBCSubbandsBitOffset = 0;
sl@0
   226
sl@0
   227
/**
sl@0
   228
Constructor
sl@0
   229
@internalComponent
sl@0
   230
*/
sl@0
   231
inline TSBCFrameParameters::TSBCFrameParameters() : iParameters(0), iBitpool(0)
sl@0
   232
	{
sl@0
   233
	}
sl@0
   234
	
sl@0
   235
/**
sl@0
   236
This function reset all the parameters
sl@0
   237
@internalComponent
sl@0
   238
*/
sl@0
   239
inline void TSBCFrameParameters::Reset()
sl@0
   240
	{
sl@0
   241
	iParameters = 0;
sl@0
   242
	iBitpool = 0;
sl@0
   243
	}
sl@0
   244
	
sl@0
   245
/**
sl@0
   246
This function gets the sampling frequency enum value
sl@0
   247
@internalComponent
sl@0
   248
@return enum value of sampling frequency
sl@0
   249
*/
sl@0
   250
inline TUint8 TSBCFrameParameters::SamplingFrequencyEnum() const
sl@0
   251
	{
sl@0
   252
	return static_cast<TUint8>( (iParameters >> KSBCSampFreqBitOffset) & KSBCSampFreqBitsMask);
sl@0
   253
	}
sl@0
   254
	
sl@0
   255
/**
sl@0
   256
This function gets the sampling frequency value in Hz
sl@0
   257
@internalComponent
sl@0
   258
@return samplinng frequency value in Hz
sl@0
   259
*/
sl@0
   260
inline TUint TSBCFrameParameters::SamplingFrequencyHz() const
sl@0
   261
	{
sl@0
   262
	switch (SamplingFrequencyEnum() )
sl@0
   263
		{
sl@0
   264
		case E16000Hz:
sl@0
   265
			return 16000;
sl@0
   266
			
sl@0
   267
		case E32000Hz:
sl@0
   268
			return 32000;
sl@0
   269
			
sl@0
   270
		case E44100Hz:
sl@0
   271
			return 44100;
sl@0
   272
			
sl@0
   273
		case E48000Hz:
sl@0
   274
			return 48000;
sl@0
   275
		}
sl@0
   276
	return 0;
sl@0
   277
	}
sl@0
   278
sl@0
   279
/**
sl@0
   280
This function sets the sampling frequency value
sl@0
   281
@internalComponent
sl@0
   282
@param aSampFreq
sl@0
   283
New sampling frequency enum value to set
sl@0
   284
*/
sl@0
   285
inline void TSBCFrameParameters::SetSamplingFrequency(TSamplingFrequency aSampFreq)
sl@0
   286
	{
sl@0
   287
	// clear sampling frequency bits
sl@0
   288
	iParameters &= ~(KSBCSampFreqBitsMask << KSBCSampFreqBitOffset);
sl@0
   289
	// set new sampling frequency bits
sl@0
   290
	iParameters |= ( (aSampFreq & KSBCSampFreqBitsMask) << KSBCSampFreqBitOffset);
sl@0
   291
	}
sl@0
   292
sl@0
   293
/**
sl@0
   294
This function gets the block length value
sl@0
   295
@internalComponent
sl@0
   296
@return number of blocks in one frame
sl@0
   297
*/
sl@0
   298
inline TUint8 TSBCFrameParameters::BlockLength() const
sl@0
   299
	{
sl@0
   300
	switch ( (iParameters >> KSBCBlckLengBitOffset) & KSBCBlckLengBitsMask)
sl@0
   301
		{
sl@0
   302
		case E4Blocks:
sl@0
   303
			return 4;
sl@0
   304
			
sl@0
   305
		case E8Blocks:
sl@0
   306
			return 8;
sl@0
   307
			
sl@0
   308
		case E12Blocks:
sl@0
   309
			return 12;
sl@0
   310
			
sl@0
   311
		case E16Blocks:
sl@0
   312
			return 16;
sl@0
   313
		}
sl@0
   314
	return 0;
sl@0
   315
	}
sl@0
   316
sl@0
   317
/**
sl@0
   318
This function sets the block length value
sl@0
   319
@internalComponent
sl@0
   320
@param aBlockLen
sl@0
   321
New block length value to set
sl@0
   322
*/
sl@0
   323
inline void TSBCFrameParameters::SetBlockLength(TBlockLength aBlockLen)
sl@0
   324
	{
sl@0
   325
	// clear block length bits
sl@0
   326
	iParameters &= ~(KSBCBlckLengBitsMask << KSBCBlckLengBitOffset);
sl@0
   327
	// set new block length bits
sl@0
   328
	iParameters |= ( (aBlockLen & KSBCBlckLengBitsMask) << KSBCBlckLengBitOffset);
sl@0
   329
	}
sl@0
   330
sl@0
   331
/**
sl@0
   332
This function gets the channel mode enum value
sl@0
   333
@internalComponent
sl@0
   334
@return channel mode enum value
sl@0
   335
*/
sl@0
   336
inline TUint8 TSBCFrameParameters::ChannelMode() const
sl@0
   337
	{
sl@0
   338
	return static_cast<TUint8>( (iParameters >> KSBCChnlModeBitOffset) & KSBCChnlModeBitsMask);
sl@0
   339
	}
sl@0
   340
sl@0
   341
/**
sl@0
   342
This function gets number of channels
sl@0
   343
@internalComponent
sl@0
   344
@return number of channels
sl@0
   345
*/
sl@0
   346
inline TUint8 TSBCFrameParameters::Channels() const
sl@0
   347
	{
sl@0
   348
	switch (ChannelMode() )
sl@0
   349
		{
sl@0
   350
		case EMono:
sl@0
   351
			return 1;
sl@0
   352
			
sl@0
   353
		case EDualChannel:
sl@0
   354
		case EStereo:
sl@0
   355
		case EJointStereo:
sl@0
   356
			return 2;
sl@0
   357
		}
sl@0
   358
	return 0;
sl@0
   359
	}
sl@0
   360
	
sl@0
   361
/**
sl@0
   362
This function sets the channel mode enum value
sl@0
   363
@internalComponent
sl@0
   364
@param aChnlMode
sl@0
   365
New channel mode enum value to set
sl@0
   366
*/
sl@0
   367
inline void TSBCFrameParameters::SetChannelMode(TChannelMode aChnlMode)
sl@0
   368
	{
sl@0
   369
	// clear channel mode bits
sl@0
   370
	iParameters &= ~(KSBCChnlModeBitsMask << KSBCChnlModeBitOffset);
sl@0
   371
	// set new channel mode bits
sl@0
   372
	iParameters |= ( (aChnlMode & KSBCChnlModeBitsMask) << KSBCChnlModeBitOffset);
sl@0
   373
	}
sl@0
   374
sl@0
   375
/**
sl@0
   376
This function gets the allocation method enum value
sl@0
   377
@internalComponent
sl@0
   378
@return allocation method enum value
sl@0
   379
*/
sl@0
   380
inline TUint8 TSBCFrameParameters::AllocationMethod() const
sl@0
   381
	{
sl@0
   382
	return static_cast<TUint8>( (iParameters >> KSBCAllcMthdBitOffset) & KSBCAllcMthdBitsMask);
sl@0
   383
	}
sl@0
   384
sl@0
   385
/**
sl@0
   386
This function sets the channel mode enum value
sl@0
   387
@internalComponent
sl@0
   388
@param aAllocMethod
sl@0
   389
New channel mode enum value to set
sl@0
   390
*/
sl@0
   391
inline void TSBCFrameParameters::SetAllocationMethod(TAllocationMethod aAllocMethod)
sl@0
   392
	{
sl@0
   393
	// clear allocation method bits
sl@0
   394
	iParameters &= ~(KSBCAllcMthdBitsMask << KSBCAllcMthdBitOffset);
sl@0
   395
	// set new allocation method bits
sl@0
   396
	iParameters |= ( (aAllocMethod & KSBCAllcMthdBitsMask) << KSBCAllcMthdBitOffset);
sl@0
   397
	}		
sl@0
   398
sl@0
   399
/**
sl@0
   400
This function gets the subbands enum value
sl@0
   401
@internalComponent
sl@0
   402
@return subbands enum value
sl@0
   403
*/
sl@0
   404
inline TUint8 TSBCFrameParameters::SubbandsEnum() const
sl@0
   405
	{
sl@0
   406
	return static_cast<TUint8>( (iParameters >> KSBCSubbandsBitOffset) & KSBCSubbandsBitsMask);
sl@0
   407
	}
sl@0
   408
sl@0
   409
/**
sl@0
   410
This function gets the subbands value
sl@0
   411
@internalComponent
sl@0
   412
@return subbands value, i.e 4, 8
sl@0
   413
*/
sl@0
   414
inline TUint8 TSBCFrameParameters::Subbands() const
sl@0
   415
	{
sl@0
   416
	switch (SubbandsEnum() )
sl@0
   417
		{
sl@0
   418
		case E4Subbands:
sl@0
   419
			return 4;
sl@0
   420
			
sl@0
   421
		case E8Subbands:
sl@0
   422
			return 8;
sl@0
   423
		}
sl@0
   424
	return 0;
sl@0
   425
	}
sl@0
   426
	
sl@0
   427
/**
sl@0
   428
This function sets the subbands enum value
sl@0
   429
@internalComponent
sl@0
   430
@param aSubbands
sl@0
   431
New subbands enum value to set
sl@0
   432
*/
sl@0
   433
inline void TSBCFrameParameters::SetSubbands(TSubbands aSubbands)
sl@0
   434
	{
sl@0
   435
	// clear subbands bits
sl@0
   436
	iParameters &= ~(KSBCSubbandsBitsMask << KSBCSubbandsBitOffset);
sl@0
   437
	// set new subbands bits
sl@0
   438
	iParameters |= ( (aSubbands & KSBCSubbandsBitsMask) << KSBCSubbandsBitOffset);
sl@0
   439
	}		
sl@0
   440
sl@0
   441
/**
sl@0
   442
This function gets the bitpool value
sl@0
   443
@internalComponent
sl@0
   444
@return bitpool value
sl@0
   445
*/
sl@0
   446
inline TUint8 TSBCFrameParameters::Bitpool() const
sl@0
   447
	{
sl@0
   448
	return iBitpool;
sl@0
   449
	}
sl@0
   450
sl@0
   451
/**
sl@0
   452
This function sets the bitpool enum value
sl@0
   453
@internalComponent
sl@0
   454
@param aSubbands
sl@0
   455
New bitpool enum value to set
sl@0
   456
*/
sl@0
   457
inline void TSBCFrameParameters::SetBitpool(TUint8 aBitpool)
sl@0
   458
	{
sl@0
   459
	iBitpool = aBitpool;
sl@0
   460
	}
sl@0
   461
sl@0
   462
/**
sl@0
   463
This function gets the 5 parameters (except bitpool) byte value
sl@0
   464
@internalComponent
sl@0
   465
@return 5 parameters byte value
sl@0
   466
*/
sl@0
   467
inline TUint8 TSBCFrameParameters::Parameters() const
sl@0
   468
	{
sl@0
   469
	return iParameters;
sl@0
   470
	}
sl@0
   471
	
sl@0
   472
/**
sl@0
   473
This function checks the bitpool value according to:
sl@0
   474
1. bitpool >= 2 and bitpool <= 250
sl@0
   475
2. bitpool <= 16 * subbands for Mono and Dual Channel,
sl@0
   476
   bitpool <= 32 * subbands for Stereo and Joint Stereo 
sl@0
   477
3. results in bit_rate <= 320 kbps for Mono
sl@0
   478
   results in bit_rate <= 512 kpbs for two-channel modes
sl@0
   479
@internalComponent
sl@0
   480
@return -1 if invalid; 0 if valid
sl@0
   481
*/
sl@0
   482
inline TInt TSBCFrameParameters::Validate() const
sl@0
   483
	{
sl@0
   484
	if (iBitpool < KSBCMinBitpoolValue || iBitpool > KSBCMaxBitpoolValue)
sl@0
   485
		{
sl@0
   486
		return -1;
sl@0
   487
		}
sl@0
   488
		
sl@0
   489
	const TUint16 numSubbands = Subbands(); // use 16 bits to avoid overflow
sl@0
   490
	const TUint8 channelMode = ChannelMode();
sl@0
   491
	
sl@0
   492
	if (channelMode == EMono || channelMode == EDualChannel)
sl@0
   493
		{
sl@0
   494
		// bitpool <= 16 * subbands, for Mono and Dual_Channel modes
sl@0
   495
		if (iBitpool > (numSubbands << 4) )
sl@0
   496
			{
sl@0
   497
			return -1;
sl@0
   498
			}
sl@0
   499
		}
sl@0
   500
	else
sl@0
   501
		{
sl@0
   502
		// bitpool <= 32 * subbands, for Stereo and Joint_Stereo modes
sl@0
   503
		if (iBitpool > (numSubbands << 5) )
sl@0
   504
			{
sl@0
   505
			return -1;
sl@0
   506
			}
sl@0
   507
		}
sl@0
   508
	
sl@0
   509
	if (channelMode == EMono)
sl@0
   510
		{
sl@0
   511
		// bit rate <= 320kbps for Mono mode
sl@0
   512
		if (CalcBitRate(CalcFrameLength() ) > 320)
sl@0
   513
			{
sl@0
   514
			return -1;
sl@0
   515
			}
sl@0
   516
		}
sl@0
   517
	else
sl@0
   518
		{
sl@0
   519
		// bit rate <= 512kpbs for two-channels modes
sl@0
   520
		if (CalcBitRate(CalcFrameLength() ) > 512)
sl@0
   521
			{
sl@0
   522
			return -1;
sl@0
   523
			}
sl@0
   524
		}
sl@0
   525
	
sl@0
   526
	return 0;
sl@0
   527
	}
sl@0
   528
sl@0
   529
/**
sl@0
   530
This function calculates the frame length value according to:
sl@0
   531
1. for MONO or DUAL_CHANNEL
sl@0
   532
   frame_len = 4 + (4 * subbands * channels) / 8 + ceil(blocks * channels * bitpool / 8)
sl@0
   533
2. for STEREO
sl@0
   534
   frame_len = 4 + (4 * subbands * channels) / 8 + ceil(blocks * bitpool / 8)
sl@0
   535
3. for JOINT_STEREO
sl@0
   536
   frame_len = 4 + (4 * subbands * channels) / 8 + ceil((subbands + blocks * bitpool) / 8)
sl@0
   537
ceil(), taking the upper integer value
sl@0
   538
@internalComponent
sl@0
   539
@return frame length value
sl@0
   540
*/
sl@0
   541
inline TUint TSBCFrameParameters::CalcFrameLength() const
sl@0
   542
	{
sl@0
   543
	TUint temp = 0;
sl@0
   544
	switch (ChannelMode() )
sl@0
   545
		{
sl@0
   546
		case EMono:
sl@0
   547
			temp = BlockLength() * Bitpool(); // blocks * bitpool
sl@0
   548
			break;
sl@0
   549
			
sl@0
   550
		case EDualChannel:
sl@0
   551
			temp = (BlockLength() * Bitpool() ) << 1; // blocks * bitpool * 2
sl@0
   552
			break;
sl@0
   553
			
sl@0
   554
		case EStereo:
sl@0
   555
			temp = BlockLength() * Bitpool(); // blocks * bitpool
sl@0
   556
			break;
sl@0
   557
			
sl@0
   558
		case EJointStereo:
sl@0
   559
			temp = Subbands() + BlockLength() * Bitpool(); // subbands + blocks * bitpool
sl@0
   560
			break;
sl@0
   561
			
sl@0
   562
		default:
sl@0
   563
			User::Panic(_L("Invalid channel mode"), KErrNotSupported);
sl@0
   564
			break;
sl@0
   565
		}
sl@0
   566
		
sl@0
   567
	TUint frameLen = 4 + ( (Subbands() * Channels() ) >> 1) + (temp >> 3);
sl@0
   568
	if (temp & 0x7)
sl@0
   569
		{
sl@0
   570
		frameLen++;
sl@0
   571
		}
sl@0
   572
		
sl@0
   573
	return frameLen;
sl@0
   574
	}
sl@0
   575
sl@0
   576
/**
sl@0
   577
This function calculates the bit rate value according to:
sl@0
   578
	bit_rate = 8 * frame_len * sampling_freq / subbands / blocks
sl@0
   579
@internalComponent
sl@0
   580
@return bit rate value in kHz
sl@0
   581
*/
sl@0
   582
inline TUint TSBCFrameParameters::CalcBitRate(TUint aFrameLen) const
sl@0
   583
	{
sl@0
   584
	return (aFrameLen << 3) * SamplingFrequencyHz() / (Subbands() * BlockLength() * 1000);
sl@0
   585
	}
sl@0
   586
sl@0
   587
#endif // __SBCFRAMEPARAMETERS_H__
sl@0
   588