Skip to content
Permalink
Browse files

Merge branch 'develop'

  • Loading branch information
mringwal committed Dec 4, 2019
2 parents 56027ab + 43d70f1 commit f07720a033c9fcfa856511634253b9889fa94cd8
Showing 353 changed files with 11,335 additions and 4,791 deletions.
@@ -67,9 +67,10 @@ Declarations of codec functions, data types, and macros.


#define SBC_HEADER_LEN 4

#define SBC_MAX_FRAME_LEN (SBC_HEADER_LEN + \
((SBC_MAX_BANDS * SBC_MAX_CHANNELS / 2) + \
(SBC_MAX_BANDS + SBC_MAX_BLOCKS * SBC_MAX_BITPOOL + 7)/8))
((SBC_MAX_BANDS + (SBC_MAX_BLOCKS * SBC_MAX_BITPOOL) + 7)/8)))
#define SBC_MAX_SAMPLES_PER_FRAME (SBC_MAX_BANDS * SBC_MAX_BLOCKS)

#define SBC_MAX_SCALEFACTOR_BYTES ((4*(SBC_MAX_CHANNELS * SBC_MAX_BANDS) + 7)/8)
@@ -35,11 +35,11 @@ PRIVATE OI_STATUS OI_CODEC_SBC_Alloc(OI_CODEC_SBC_COMMON_CONTEXT *common,
size_t subdataSize;
OI_BYTE *codecData = (OI_BYTE*)codecDataAligned;

if (maxChannels < 1 || maxChannels > 2) {
if ((maxChannels < 1) || (maxChannels > 2)) {
return OI_STATUS_INVALID_PARAMETERS;
}

if (pcmStride < 1 || pcmStride > maxChannels) {
if ((pcmStride < 1) || (pcmStride > maxChannels)) {
return OI_STATUS_INVALID_PARAMETERS;
}

@@ -147,7 +147,7 @@ OI_UINT16 OI_CODEC_SBC_CalculateBitpool(OI_CODEC_SBC_FRAME_INFO *frame,
nrof_blocks *= 2;
}
}
bits = 8 * (frameLen - SBC_HEADER_LEN) - hdr;
bits = (8 * (frameLen - SBC_HEADER_LEN)) - hdr;
return DIVIDE(bits, nrof_blocks);
}

@@ -68,7 +68,7 @@ PRIVATE OI_UINT16 internal_CalculateFramelen(OI_CODEC_SBC_FRAME_INFO *frame)
if (frame->mode == SBC_DUAL_CHANNEL) { result += nbits; }
if (frame->mode == SBC_MONO) { result += 4*nrof_subbands; } else { result += 8*nrof_subbands; }
}
return SBC_HEADER_LEN + (result + 7) / 8;
return SBC_HEADER_LEN + ((result + 7) / 8);
}


@@ -83,7 +83,7 @@ PRIVATE OI_UINT32 internal_CalculateBitrate(OI_CODEC_SBC_FRAME_INFO *frame)

INLINE OI_UINT16 OI_SBC_CalculateFrameAndHeaderlen(OI_CODEC_SBC_FRAME_INFO *frame, OI_UINT *headerLen_)
{
OI_UINT headerLen = SBC_HEADER_LEN + frame->nrof_subbands * frame->nrof_channels/2;
OI_UINT headerLen = SBC_HEADER_LEN + (frame->nrof_subbands * frame->nrof_channels/2);

if (frame->mode == SBC_JOINT_STEREO) { headerLen++; }

@@ -266,7 +266,7 @@ OI_INT adjustToFitBitpool(const OI_UINT bitpool,
adjust4 |= (adjust4 << 8);
adjust4 |= (adjust4 << 16);

for (i = (subbands / 4 - 1); i >= 0; --i) {
for (i = ((subbands / 4) - 1); i >= 0; --i) {
OI_UINT32 mask;
OI_UINT32 n = bitneeds[i] + adjust4;
mask = 0x7F7F7F7F + ((n & 0x40404040) >> 6);
@@ -177,7 +177,7 @@ PRIVATE void OI_SBC_ReadScalefactors(OI_CODEC_SBC_COMMON_CONTEXT *common,
OI_INT8 *scale_factor = common->scale_factor;
OI_UINT f;

if (common->frameInfo.nrof_subbands == 8 || common->frameInfo.mode != SBC_JOINT_STEREO) {
if ((common->frameInfo.nrof_subbands == 8) || (common->frameInfo.mode != SBC_JOINT_STEREO)) {
if (common->frameInfo.mode == SBC_JOINT_STEREO) {
common->frameInfo.join = *b++;
} else {
@@ -121,12 +121,12 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
/*
* Based on the header data, make sure that there is enough room to write the output samples.
*/
if (*pcmBytes < (sizeof(OI_INT16) * frameSamples * context->common.pcmStride) && !allowPartial) {
if ((*pcmBytes < (sizeof(OI_INT16) * frameSamples * context->common.pcmStride)) && !allowPartial) {
/* If we're not allowing partial decodes, we need room for the entire
* codec frame */
TRACE(("-OI_CODEC_SBC_Decode: OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA"));
return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA;
} else if (*pcmBytes < sizeof (OI_INT16) * context->common.frameInfo.nrof_subbands * context->common.pcmStride) {
} else if (*pcmBytes < (sizeof (OI_INT16) * context->common.frameInfo.nrof_subbands * context->common.pcmStride)) {
/* Even if we're allowing partials, we can still only decode on a frame
* boundary */
return OI_CODEC_SBC_NOT_ENOUGH_AUDIO_DATA;
@@ -174,10 +174,10 @@ static OI_STATUS DecodeBody(OI_CODEC_SBC_DECODER_CONTEXT *context,
/*
* When decoding mono into a stride-2 array, copy pcm data to second channel
*/
if (context->common.frameInfo.nrof_channels == 1 && context->common.pcmStride == 2) {
if ((context->common.frameInfo.nrof_channels == 1) && (context->common.pcmStride == 2)) {
OI_UINT i;
for (i = 0; i < frameSamples; ++i) {
pcmData[2*i+1] = pcmData[2*i];
pcmData[(2*i)+1] = pcmData[2*i];
}
}

@@ -226,7 +226,7 @@ PRIVATE OI_STATUS internal_DecodeRaw(OI_CODEC_SBC_DECODER_CONTEXT *context,
* tones.
*/
status = DecodeBody(context, *frameData, pcmData, pcmBytes, TRUE);
if (OI_SUCCESS(status) || status == OI_CODEC_SBC_PARTIAL_DECODE) {
if (OI_SUCCESS(status) || (status == OI_CODEC_SBC_PARTIAL_DECODE)) {
*frameData += bodyLen;
*frameBytes -= bodyLen;
}
@@ -303,7 +303,7 @@ OI_STATUS OI_CODEC_SBC_DecodeFrame(OI_CODEC_SBC_DECODER_CONTEXT *context,
return OI_STATUS_INVALID_PARAMETERS;
}

if (context->common.pcmStride < 1 || context->common.pcmStride > 2) {
if ((context->common.pcmStride < 1) || (context->common.pcmStride > 2)) {
ERROR(("PCM stride not set correctly during reset"));
return OI_STATUS_INVALID_PARAMETERS;
}
@@ -443,7 +443,7 @@ OI_UINT8 OI_CODEC_SBC_FrameCount(OI_BYTE *frameData,
}

frameCount++;
frameLen = SBC_HEADER_LEN + (frameLen + 7) / 8;
frameLen = SBC_HEADER_LEN + ((frameLen + 7) / 8);
if (frameBytes > frameLen){
frameBytes -= frameLen;
frameData += frameLen;
@@ -205,7 +205,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT

OI_UINT count = (frame->nrof_subbands * frame->nrof_channels / 2u) + 4;

if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 8) {
if ((frame->mode == SBC_JOINT_STEREO) && (frame->nrof_subbands == 8)) {
count++;
}

@@ -215,7 +215,7 @@ PRIVATE OI_UINT8 OI_SBC_CalculateChecksum(OI_CODEC_SBC_FRAME_INFO *frame, OI_BYT
}
}

if (frame->mode == SBC_JOINT_STEREO && frame->nrof_subbands == 4) {
if ((frame->mode == SBC_JOINT_STEREO) && (frame->nrof_subbands == 4)) {
crc = crc_iterate_top4(crc, data[i]);
}

@@ -69,11 +69,11 @@ INLINE OI_INT32 default_mul_32s_32s_hi(OI_INT32 u, OI_INT32 v)
u0 = u & 0xFFFF; u1 = u >> 16;
v0 = v & 0xFFFF; v1 = v >> 16;
t = u0*v0;
t = u1*v0 + ((OI_UINT32)t >> 16);
t = (u1*v0) + ((OI_UINT32)t >> 16);
w1 = t & 0xFFFF;
w2 = t >> 16;
w1 = u0*v1 + w1;
return u1*v1 + w2 + (w1 >> 16);
w1 = (u0*v1) + w1;
return (u1*v1) + w2 + (w1 >> 16);
}

#define MUL_32S_32S_HI(_x, _y) default_mul_32s_32s_hi(_x, _y)
@@ -262,9 +262,9 @@ PRIVATE void OI_SBC_SynthFrame_80(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT1
OI_UINT blk;
OI_UINT ch;
OI_UINT nrof_channels = context->common.frameInfo.nrof_channels;
OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1;
OI_UINT pcmStrideShift = (context->common.pcmStride == 1) ? 0 : 1;
OI_UINT offset = context->common.filterBufferOffset;
OI_INT32 *s = context->common.subdata + 8 * nrof_channels * blkstart;
OI_INT32 *s = context->common.subdata + (8 * nrof_channels * blkstart);
OI_UINT blkstop = blkstart + blkcount;

for (blk = blkstart; blk < blkstop; blk++) {
@@ -294,9 +294,9 @@ PRIVATE void OI_SBC_SynthFrame_4SB(OI_CODEC_SBC_DECODER_CONTEXT *context, OI_INT
OI_UINT blk;
OI_UINT ch;
OI_UINT nrof_channels = context->common.frameInfo.nrof_channels;
OI_UINT pcmStrideShift = context->common.pcmStride == 1 ? 0 : 1;
OI_UINT pcmStrideShift = (context->common.pcmStride == 1) ? 0 : 1;
OI_UINT offset = context->common.filterBufferOffset;
OI_INT32 *s = context->common.subdata + 8 * nrof_channels * blkstart;
OI_INT32 *s = context->common.subdata + (8 * nrof_channels * blkstart);
OI_UINT blkstop = blkstart + blkcount;

for (blk = blkstart; blk < blkstop; blk++) {
@@ -963,7 +963,7 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
ChOffset=s32Ch*Offset2+Offset;
ChOffset=(s32Ch*Offset2)+Offset;

WINDOW_PARTIAL_4

@@ -1066,7 +1066,7 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
}
for (s32Ch=0;s32Ch<s32NumOfChannels;s32Ch++)
{
ChOffset=s32Ch*Offset2+Offset;
ChOffset=(s32Ch*Offset2)+Offset;

WINDOW_PARTIAL_8

@@ -61,18 +61,18 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)

for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
{
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*SBC_MAX_NUM_OF_SUBBANDS;
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*SBC_MAX_NUM_OF_SUBBANDS);

/* bitneed values are derived from scale factor */
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
{
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
ps16GenBufPtr = ps16BitNeed + s32Ch * s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + (s32Ch * s32NumOfSubBands);
}
else
{
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
if(s32NumOfSubBands == 4)
{
ps16GenTabPtr = (SINT16 *)
@@ -85,12 +85,12 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
}
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb] == 0)
if(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb] == 0)
*(ps16GenBufPtr) = -5;
else
{
s32Loudness =
(SINT32)(pstrCodecParams->as16ScaleFactor[s32Ch*s32NumOfSubBands+s32Sb]
(SINT32)(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb]
- *ps16GenTabPtr);
if(s32Loudness > 0)
*(ps16GenBufPtr) = (SINT16)(s32Loudness >>1);
@@ -105,15 +105,15 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)

/* max bitneed index is searched*/
s32MaxBitNeed = 0;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if( *(ps16GenBufPtr) > s32MaxBitNeed)
s32MaxBitNeed = *(ps16GenBufPtr);

ps16GenBufPtr++;
}
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
/*iterative process to find hwo many bitslices fit into the bitpool*/
s32BitSlice = s32MaxBitNeed + 1;
s32BitCount = pstrCodecParams->s16BitPool;
@@ -126,7 +126,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)

for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && (*ps16GenBufPtr-s32BitSlice) >= 1))
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && ((*ps16GenBufPtr-s32BitSlice) >= 1)))
{
if((*ps16GenBufPtr-s32BitSlice) == 1)
s32SliceCount+=2;
@@ -136,8 +136,8 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr++;

}/*end of for*/
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
}while(s32BitCount-s32SliceCount>0);
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
}while((s32BitCount-s32SliceCount)>0);

if(s32BitCount == 0)
{
@@ -146,11 +146,11 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
}

/*Bits are distributed until the last bitslice is reached*/
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
{
if(*(ps16GenBufPtr) < s32BitSlice+2)
if(*(ps16GenBufPtr) < (s32BitSlice+2))
*(ps16GenArrPtr) = 0;
else
*(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ?
@@ -159,8 +159,8 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenBufPtr++;
ps16GenArrPtr++;
}
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
ps16GenBufPtr = ps16BitNeed + s32Ch*s32NumOfSubBands;
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
/*the remaining bits are allocated starting at subband 0*/
s32Sb=0;
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
@@ -170,7 +170,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
(*(ps16GenArrPtr))++;
s32BitCount--;
}
else if( (*(ps16GenBufPtr) == s32BitSlice+1) &&
else if( (*(ps16GenBufPtr) == (s32BitSlice+1)) &&
(s32BitCount > 1) )
{
*(ps16GenArrPtr) = 2;
@@ -180,7 +180,7 @@ void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
ps16GenArrPtr++;
ps16GenBufPtr++;
}
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Ch*s32NumOfSubBands;
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);


s32Sb=0;
@@ -113,20 +113,20 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
s32SliceCount = 0;
ps16GenBufPtr = ps16BitNeed;

for (s32Sb = 0; s32Sb < 2*s32NumOfSubBands; s32Sb++)
for (s32Sb = 0; s32Sb < (2*s32NumOfSubBands); s32Sb++)
{
if ( (*ps16GenBufPtr >= s32BitSlice + 1) && (*ps16GenBufPtr < s32BitSlice + 16) )
if ( (*ps16GenBufPtr >= (s32BitSlice + 1)) && (*ps16GenBufPtr < (s32BitSlice + 16)) )
{
if (*(ps16GenBufPtr) == s32BitSlice+1)
if (*(ps16GenBufPtr) == (s32BitSlice+1))
s32SliceCount += 2;
else
s32SliceCount++;
}
ps16GenBufPtr++;
}
} while (s32BitCount-s32SliceCount>0);
} while ((s32BitCount-s32SliceCount)>0);

if (s32BitCount-s32SliceCount == 0)
if ((s32BitCount-s32SliceCount) == 0)
{
s32BitCount -= s32SliceCount;
s32BitSlice --;
@@ -139,7 +139,7 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
{
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
{
if (*ps16GenBufPtr < s32BitSlice+2)
if (*ps16GenBufPtr < (s32BitSlice+2))
*ps16GenArrPtr = 0;
else
*ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ?
@@ -162,7 +162,7 @@ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
(*(ps16GenArrPtr))++;
s32BitCount--;
}
else if ((*ps16GenBufPtr == s32BitSlice+1) && (s32BitCount > 1))
else if ((*ps16GenBufPtr == (s32BitSlice+1)) && (s32BitCount > 1))
{
*(ps16GenArrPtr) = 2;
s32BitCount -= 2;

0 comments on commit f07720a

Please sign in to comment.
You can’t perform that action at this time.