summaryrefslogtreecommitdiffstats
path: root/embdrv/sbc/encoder/srce/sbc_encoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'embdrv/sbc/encoder/srce/sbc_encoder.c')
-rw-r--r--embdrv/sbc/encoder/srce/sbc_encoder.c133
1 files changed, 72 insertions, 61 deletions
diff --git a/embdrv/sbc/encoder/srce/sbc_encoder.c b/embdrv/sbc/encoder/srce/sbc_encoder.c
index ce7dbb9..f111ed0 100644
--- a/embdrv/sbc/encoder/srce/sbc_encoder.c
+++ b/embdrv/sbc/encoder/srce/sbc_encoder.c
@@ -1,15 +1,26 @@
/******************************************************************************
-**
-** File Name: $RCSfile: sbc_encoder.c,v $
-**
-** Description: contains code for encoder flow and initalization of encoder
-**
-** Revision : $Id: sbc_encoder.c,v 1.17 2006/04/13 17:24:47 mjougit Exp $
-**
-** Copyright (c) 1999-2002, Widcomm Inc., All Rights Reserved.
-** Widcomm Bluetooth Core. Proprietary and confidential.
-**
-******************************************************************************/
+ *
+ * Copyright (C) 1999-2012 Broadcom Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************************/
+
+/******************************************************************************
+ *
+ * contains code for encoder flow and initalization of encoder
+ *
+ ******************************************************************************/
#include <string.h>
#include "sbc_encoder.h"
@@ -47,7 +58,7 @@ SINT16 EncMaxShiftCounter;
*
* if(index > 0)
* {
- * p = &u8frame[base_index];
+ * p = &u8frame[base_index];
* if((index&1)&&(u16PacketLength > (base_index+index*2)))
* {
* // odd index: swap 2 bytes
@@ -108,7 +119,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
SINT32 s32Sb; /* counter for sub-band*/
UINT32 u32Count, maxBit = 0; /* loop count*/
SINT32 s32MaxValue; /* temp variable to store max value */
-
+
SINT16 *ps16ScfL;
SINT32 *SbBuffer;
SINT32 s32Blk; /* counter for block*/
@@ -122,7 +133,7 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
tSBC_FR_CB *p_cur, *p_last;
UINT32 idx, tmp, tmp2;
register SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
-
+
pstrEncParams->pu8NextPacket = pstrEncParams->pu8Packet;
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
@@ -131,19 +142,19 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->as16PcmBuffer;
#endif
do
- {
+ {
/* SBC ananlysis filter*/
if (s32NumOfSubBands == 4)
SbcAnalysisFilter4(pstrEncParams);
else
SbcAnalysisFilter8(pstrEncParams);
-
+
/* compute the scale factor, and save the max */
ps16ScfL = pstrEncParams->as16ScaleFactor;
s32Ch=pstrEncParams->s16NumOfChannels*s32NumOfSubBands;
pstrEncParams->ps16NextPcmBuffer+=s32Ch*s32NumOfBlocks; /* in case of multible sbc frame to encode update the pcm pointer */
-
+
for (s32Sb=0; s32Sb<s32Ch; s32Sb++)
{
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
@@ -154,16 +165,16 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
s32MaxValue=abs32(*SbBuffer);
SbBuffer+=s32Ch;
}
-
+
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
-
+
for ( ; u32Count < 15; u32Count++)
{
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
break;
}
*ps16ScfL++ = (SINT16)u32Count;
-
+
if (u32Count > maxBit)
maxBit = u32Count;
}
@@ -209,30 +220,30 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
u32CountDiff=u32Count;
if ( (*ps16ScfL + *(ps16ScfL+s32NumOfSubBands)) > (SINT16)(u32CountSum + u32CountDiff) )
{
-
+
if (u32CountSum > maxBit)
maxBit = u32CountSum;
-
+
if (u32CountDiff > maxBit)
maxBit = u32CountDiff;
-
+
*ps16ScfL = (SINT16)u32CountSum;
*(ps16ScfL+s32NumOfSubBands) = (SINT16)u32CountDiff;
-
+
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
pSum = s32LRSum;
pDiff = s32LRDiff;
-
+
for (s32Blk = 0; s32Blk < s32NumOfBlocks; s32Blk++)
{
- *SbBuffer = *pSum;
+ *SbBuffer = *pSum;
*(SbBuffer+s32NumOfSubBands) = *pDiff;
-
- SbBuffer += s32NumOfSubBands<<1;
+
+ SbBuffer += s32NumOfSubBands<<1;
pSum++;
pDiff++;
}
-
+
pstrEncParams->as16Join[s32Sb] = 1;
}
else
@@ -241,18 +252,18 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
}
ps16ScfL++;
}
- pstrEncParams->as16Join[s32Sb] = 0;
+ pstrEncParams->as16Join[s32Sb] = 0;
}
#endif
-
+
pstrEncParams->s16MaxBitNeed = (SINT16)maxBit;
-
+
/* bit allocation */
if ((pstrEncParams->s16ChannelMode == SBC_STEREO) || (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO))
sbc_enc_bit_alloc_ste(pstrEncParams);
else
sbc_enc_bit_alloc_mono(pstrEncParams);
-
+
/* save the beginning of the frame. pu8NextPacket is modified in EncPacking() */
pu8 = pstrEncParams->pu8NextPacket;
/* Quantize the encoded audio */
@@ -270,9 +281,9 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
SBC_PRTC_SCRMB((&pu8[sbc_prtc_cb.base]));
}
while(--(pstrEncParams->u8NumPacketToEncode));
-
+
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
-
+
}
/****************************************************************************
@@ -295,7 +306,7 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
pstrEncParams->s16NumOfChannels = 1;
else
pstrEncParams->s16NumOfChannels = 2;
-
+
/* Bit pool calculation */
if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
s16SamplingFreq = 16000;
@@ -305,31 +316,31 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
s16SamplingFreq = 44100;
else
s16SamplingFreq = 48000;
-
+
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) )
{
- s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
+ s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
- -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
+ -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
pstrEncParams->s16NumOfChannels)
- + ( (pstrEncParams->s16ChannelMode - 2) *
+ + ( (pstrEncParams->s16ChannelMode - 2) *
pstrEncParams->s16NumOfSubBands ) )
/ pstrEncParams->s16NumOfBlocks) );
-
+
s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
pstrEncParams->s16NumOfChannels)/8
- + ( ((pstrEncParams->s16ChannelMode - 2) *
- pstrEncParams->s16NumOfSubBands)
+ + ( ((pstrEncParams->s16ChannelMode - 2) *
+ pstrEncParams->s16NumOfSubBands)
+ (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
-
- s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
- / (pstrEncParams->s16NumOfSubBands *
+
+ s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
+ / (pstrEncParams->s16NumOfSubBands *
pstrEncParams->s16NumOfBlocks * 1000);
-
+
if (s16BitRate > pstrEncParams->u16BitRate)
s16Bitpool--;
-
+
if(pstrEncParams->s16NumOfSubBands == 8)
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
else
@@ -337,34 +348,34 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
}
else
{
- s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
+ s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
pstrEncParams->u16BitRate * 1000)
/ (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
- -( ( (32 / pstrEncParams->s16NumOfChannels) +
+ -( ( (32 / pstrEncParams->s16NumOfChannels) +
(4 * pstrEncParams->s16NumOfSubBands) )
/ pstrEncParams->s16NumOfBlocks ) );
-
- pstrEncParams->s16BitPool = (s16Bitpool >
+
+ pstrEncParams->s16BitPool = (s16Bitpool >
(16 * pstrEncParams->s16NumOfSubBands))
? (16*pstrEncParams->s16NumOfSubBands) : s16Bitpool;
}
-
+
if (pstrEncParams->s16BitPool < 0)
pstrEncParams->s16BitPool = 0;
/* sampling freq */
- HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6);
-
+ HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6);
+
/* number of blocks*/
HeaderParams |= (((pstrEncParams->s16NumOfBlocks -4) & 12) << 2);
-
+
/* channel mode: mono, dual...*/
- HeaderParams |= ((pstrEncParams->s16ChannelMode & 3)<< 2);
-
+ HeaderParams |= ((pstrEncParams->s16ChannelMode & 3)<< 2);
+
/* Loudness or SNR */
HeaderParams |= ((pstrEncParams->s16AllocationMethod & 1)<< 1);
HeaderParams |= ((pstrEncParams->s16NumOfSubBands >> 3) & 1); /*4 or 8*/
pstrEncParams->FrameHeader=HeaderParams;
-
+
if (pstrEncParams->s16NumOfSubBands==4)
{
if (pstrEncParams->s16NumOfChannels==1)
@@ -379,8 +390,8 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
else
EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-8*10*2)>>4)<<3;
}
-
- APPL_TRACE_EVENT2("SBC_Encoder_Init : bitrate %d, bitpool %d",
+
+ APPL_TRACE_EVENT2("SBC_Encoder_Init : bitrate %d, bitpool %d",
pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
SbcAnalysisInit();