V1.0
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
# sbc encoder
|
||||
SBC_ENCODER += \
|
||||
sbc_analysis.c \
|
||||
sbc_dct.c \
|
||||
sbc_dct_coeffs.c \
|
||||
sbc_enc_bit_alloc_mono.c \
|
||||
sbc_enc_bit_alloc_ste.c \
|
||||
sbc_enc_coeffs.c \
|
||||
sbc_encoder.c \
|
||||
sbc_packing.c \
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Definitions for the fast DCT.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SBC_DCT_H
|
||||
#define SBC_DCT_H
|
||||
|
||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1, s32OutLow) \
|
||||
{ \
|
||||
__asm \
|
||||
{ \
|
||||
MUL s32OutLow,(SINT32)s16In2, (s32In1>>15) \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#if (SBC_DSP_OPT==TRUE)
|
||||
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow = SBC_Multiply_32_16_Simplified((SINT32)s16In2,s32In1);
|
||||
#else
|
||||
#if (SBC_IPAQ_OPT==TRUE)
|
||||
/*#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow=(SINT32)((SINT32)(s16In2)*(SINT32)(s32In1>>15)); */
|
||||
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) s32OutLow=(SINT32)(((SINT64)s16In2*(SINT64)s32In1)>>15);
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \
|
||||
{ \
|
||||
s64Temp = ((SINT64) s32In2) * ((SINT64) s32In1)>>31; \
|
||||
s32OutLow = (SINT32) s64Temp; \
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
#define SBC_MULT_32_16_SIMPLIFIED(s16In2, s32In1 , s32OutLow) \
|
||||
{ \
|
||||
s32In1Temp = s32In1; \
|
||||
s32In2Temp = (SINT32)s16In2; \
|
||||
\
|
||||
/* Multiply one +ve and the other -ve number */ \
|
||||
if (s32In1Temp < 0) \
|
||||
{ \
|
||||
s32In1Temp ^= 0xFFFFFFFF; \
|
||||
s32In1Temp++; \
|
||||
s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \
|
||||
s32OutLow += (( s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \
|
||||
s32OutLow ^= 0xFFFFFFFF; \
|
||||
s32OutLow++; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
s32OutLow = (s32In2Temp * (s32In1Temp >> 16)); \
|
||||
s32OutLow += (( s32In2Temp * (s32In1Temp & 0xFFFF)) >> 16); \
|
||||
} \
|
||||
s32OutLow <<= 1; \
|
||||
}
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
#define SBC_MULT_64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
||||
{\
|
||||
s32OutLow=(SINT32)(((SINT64)s32In1*(SINT64)s32In2)& 0x00000000FFFFFFFF);\
|
||||
s32OutHi=(SINT32)(((SINT64)s32In1*(SINT64)s32In2)>>32);\
|
||||
}
|
||||
#define SBC_MULT_32_32(s32In2, s32In1, s32OutLow) \
|
||||
{ \
|
||||
s32HiTemp = 0; \
|
||||
SBC_MULT_64(s32In2,s32In1 , s32OutLow, s32HiTemp); \
|
||||
s32OutLow = (((s32OutLow>>15)&0x1FFFF) | (s32HiTemp << 17)); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Function declarations.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SBC_FUNCDECLARE_H
|
||||
#define SBC_FUNCDECLARE_H
|
||||
|
||||
/*#include "sbc_encoder.h"*/
|
||||
/* Global data */
|
||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
|
||||
extern const SINT16 gas32CoeffFor4SBs[];
|
||||
extern const SINT16 gas32CoeffFor8SBs[];
|
||||
#else
|
||||
extern const SINT32 gas32CoeffFor4SBs[];
|
||||
extern const SINT32 gas32CoeffFor8SBs[];
|
||||
#endif
|
||||
|
||||
/* Global functions*/
|
||||
|
||||
extern void sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *CodecParams);
|
||||
extern void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *CodecParams);
|
||||
|
||||
extern void SbcAnalysisInit (SBC_ENC_PARAMS *CodecParams);
|
||||
|
||||
extern void SbcAnalysisFilter4(SBC_ENC_PARAMS *strEncParams);
|
||||
extern void SbcAnalysisFilter8(SBC_ENC_PARAMS *strEncParams);
|
||||
|
||||
extern void SBC_FastIDCT8 (SINT32 *pInVect, SINT32 *pOutVect);
|
||||
extern void SBC_FastIDCT4 (SINT32 *x0, SINT32 *pOutVect);
|
||||
|
||||
extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
|
||||
extern void EncQuantizer(SBC_ENC_PARAMS *);
|
||||
#if (SBC_DSP_OPT==TRUE)
|
||||
SINT32 SBC_Multiply_32_16_Simplified(SINT32 s32In2Temp,SINT32 s32In1Temp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains constants and structures used by Encoder.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SBC_ENCODER_H
|
||||
#define SBC_ENCODER_H
|
||||
|
||||
#define ENCODER_VERSION "0025"
|
||||
|
||||
#ifdef BUILDCFG
|
||||
#include "bt_target.h"
|
||||
#endif
|
||||
|
||||
/*DEFINES*/
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE (!FALSE)
|
||||
#endif
|
||||
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
#define SBC_NO_PCM_CPY_OPTION TRUE
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
|
||||
|
||||
#define SBC_MAX_NUM_OF_SUBBANDS 8
|
||||
#define SBC_MAX_NUM_OF_CHANNELS 2
|
||||
#define SBC_MAX_NUM_OF_BLOCKS 16
|
||||
|
||||
#define SBC_LOUDNESS 0
|
||||
#define SBC_SNR 1
|
||||
|
||||
#define SUB_BANDS_8 8
|
||||
#define SUB_BANDS_4 4
|
||||
|
||||
#define SBC_sf16000 0
|
||||
#define SBC_sf32000 1
|
||||
#define SBC_sf44100 2
|
||||
#define SBC_sf48000 3
|
||||
|
||||
#define SBC_MONO 0
|
||||
#define SBC_DUAL 1
|
||||
#define SBC_STEREO 2
|
||||
#define SBC_JOINT_STEREO 3
|
||||
|
||||
#define SBC_BLOCK_0 4
|
||||
#define SBC_BLOCK_1 8
|
||||
#define SBC_BLOCK_2 12
|
||||
#define SBC_BLOCK_3 16
|
||||
|
||||
#define SBC_NULL 0
|
||||
|
||||
#ifndef SBC_MAX_NUM_FRAME
|
||||
#define SBC_MAX_NUM_FRAME 1
|
||||
#endif
|
||||
|
||||
#ifndef SBC_DSP_OPT
|
||||
#define SBC_DSP_OPT FALSE
|
||||
#endif
|
||||
|
||||
/* Set SBC_USE_ARM_PRAGMA to TRUE to use "#pragma arm section zidata" */
|
||||
#ifndef SBC_USE_ARM_PRAGMA
|
||||
#define SBC_USE_ARM_PRAGMA FALSE
|
||||
#endif
|
||||
|
||||
/* Set SBC_ARM_ASM_OPT to TRUE in case the target is an ARM */
|
||||
/* this will replace all the 32 and 64 bit mult by in line assembly code */
|
||||
#ifndef SBC_ARM_ASM_OPT
|
||||
#define SBC_ARM_ASM_OPT FALSE
|
||||
#endif
|
||||
|
||||
/* green hill compiler option -> Used to distinguish the syntax for inline assembly code*/
|
||||
#ifndef SBC_GHS_COMPILER
|
||||
#define SBC_GHS_COMPILER FALSE
|
||||
#endif
|
||||
|
||||
/* ARM compiler option -> Used to distinguish the syntax for inline assembly code */
|
||||
#ifndef SBC_ARM_COMPILER
|
||||
#define SBC_ARM_COMPILER TRUE
|
||||
#endif
|
||||
|
||||
/* Set SBC_IPAQ_OPT to TRUE in case the target is an ARM */
|
||||
/* 32 and 64 bit mult will be performed using SINT64 ( usualy __int64 ) cast that usualy give optimal performance if supported */
|
||||
#ifndef SBC_IPAQ_OPT
|
||||
#define SBC_IPAQ_OPT TRUE
|
||||
#endif
|
||||
|
||||
/* Debug only: set SBC_IS_64_MULT_IN_WINDOW_ACCU to TRUE to use 64 bit multiplication in the windowing */
|
||||
/* -> not recomended, more MIPS for the same restitution. */
|
||||
#ifndef SBC_IS_64_MULT_IN_WINDOW_ACCU
|
||||
#define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE
|
||||
#endif /*SBC_IS_64_MULT_IN_WINDOW_ACCU */
|
||||
|
||||
/* Set SBC_IS_64_MULT_IN_IDCT to TRUE to use 64 bits multiplication in the DCT of Matrixing */
|
||||
/* -> more MIPS required for a better audio quality. comparasion with the SIG utilities shows a division by 10 of the RMS */
|
||||
/* CAUTION: It only apply in the if SBC_FAST_DCT is set to TRUE */
|
||||
#ifndef SBC_IS_64_MULT_IN_IDCT
|
||||
#define SBC_IS_64_MULT_IN_IDCT FALSE
|
||||
#endif /*SBC_IS_64_MULT_IN_IDCT */
|
||||
|
||||
/* set SBC_IS_64_MULT_IN_QUANTIZER to TRUE to use 64 bits multiplication in the quantizer */
|
||||
/* setting this flag to FALSE add whistling noise at 5.5 and 11 KHz usualy not perceptible by human's hears. */
|
||||
#ifndef SBC_IS_64_MULT_IN_QUANTIZER
|
||||
#define SBC_IS_64_MULT_IN_QUANTIZER TRUE
|
||||
#endif /*SBC_IS_64_MULT_IN_IDCT */
|
||||
|
||||
/* Debug only: set this flag to FALSE to disable fast DCT algorithm */
|
||||
#ifndef SBC_FAST_DCT
|
||||
#define SBC_FAST_DCT TRUE
|
||||
#endif /*SBC_FAST_DCT */
|
||||
|
||||
/* In case we do not use joint stereo mode the flag save some RAM and ROM in case it is set to FALSE */
|
||||
#ifndef SBC_JOINT_STE_INCLUDED
|
||||
#define SBC_JOINT_STE_INCLUDED TRUE
|
||||
#endif
|
||||
|
||||
/* TRUE -> application should provide PCM buffer, FALSE PCM buffer reside in SBC_ENC_PARAMS */
|
||||
#ifndef SBC_NO_PCM_CPY_OPTION
|
||||
#define SBC_NO_PCM_CPY_OPTION FALSE
|
||||
#endif
|
||||
|
||||
#define MINIMUM_ENC_VX_BUFFER_SIZE (8*10*2)
|
||||
#ifndef ENC_VX_BUFFER_SIZE
|
||||
#define ENC_VX_BUFFER_SIZE (MINIMUM_ENC_VX_BUFFER_SIZE + 64)
|
||||
/*#define ENC_VX_BUFFER_SIZE MINIMUM_ENC_VX_BUFFER_SIZE + 1024*/
|
||||
#endif
|
||||
|
||||
#ifndef SBC_FOR_EMBEDDED_LINUX
|
||||
#define SBC_FOR_EMBEDDED_LINUX FALSE
|
||||
#endif
|
||||
|
||||
/*constants used for index calculation*/
|
||||
#define SBC_BLK (SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS)
|
||||
|
||||
#include "sbc_types.h"
|
||||
|
||||
typedef struct SBC_ENC_PARAMS_TAG
|
||||
{
|
||||
SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
|
||||
SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
|
||||
SINT16 s16NumOfSubBands; /* 4 or 8 */
|
||||
SINT16 s16NumOfChannels;
|
||||
SINT16 s16NumOfBlocks; /* SBC: 4, 8, 12 or 16; mSBC: 15*/
|
||||
SINT16 s16AllocationMethod; /* loudness or SNR*/
|
||||
SINT16 s16BitPool; /* 16*numOfSb for mono & dual;
|
||||
32*numOfSb for stereo & joint stereo */
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
// UINT16 u16BitRate;
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
UINT8 u8NumPacketToEncode; /* number of sbc frame to encode. Default is 1 */
|
||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||
SINT16 as16Join[SBC_MAX_NUM_OF_SUBBANDS]; /*1 if JS, 0 otherwise*/
|
||||
#endif
|
||||
|
||||
SINT16 s16MaxBitNeed;
|
||||
SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
|
||||
|
||||
SINT16 *ps16NextPcmBuffer;
|
||||
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
|
||||
SINT16 *ps16PcmBuffer;
|
||||
#else
|
||||
SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
|
||||
#endif
|
||||
|
||||
SINT16 s16ScartchMemForBitAlloc[16];
|
||||
|
||||
SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
|
||||
|
||||
SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
|
||||
|
||||
UINT8 *pu8Packet;
|
||||
UINT8 *pu8NextPacket;
|
||||
UINT16 FrameHeader;
|
||||
UINT16 u16PacketLength;
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
UINT8 mSBCEnabled;
|
||||
// from sbc_analysis
|
||||
SINT32 s32DCTY[16];// = {0};
|
||||
SINT32 s32X[ENC_VX_BUFFER_SIZE/2];
|
||||
SINT16 *s16X;//=(SINT16*) s32X; /* s16X must be 32 bits aligned cf SHIFTUP_X8_2*/
|
||||
SINT16 ShiftCounter;
|
||||
// from sbc_encoder
|
||||
SINT16 EncMaxShiftCounter;
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
}SBC_ENC_PARAMS;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
SBC_API extern void SBC_Encoder(SBC_ENC_PARAMS *strEncParams);
|
||||
SBC_API extern void SBC_Encoder_Init(SBC_ENC_PARAMS *strEncParams);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* Data type declarations.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SBC_TYPES_H
|
||||
#define SBC_TYPES_H
|
||||
|
||||
#ifdef BUILDCFG
|
||||
#include "bt_target.h"
|
||||
#endif
|
||||
|
||||
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
#if 0
|
||||
// #include "data_types.h"
|
||||
|
||||
typedef short SINT16;
|
||||
typedef long SINT32;
|
||||
|
||||
#if (SBC_IPAQ_OPT == TRUE)
|
||||
|
||||
#if (SBC_FOR_EMBEDDED_LINUX == TRUE)
|
||||
typedef long long SINT64;
|
||||
#else
|
||||
typedef __int64 SINT64;
|
||||
#endif
|
||||
|
||||
#elif (SBC_IS_64_MULT_IN_WINDOW_ACCU == TRUE) || (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
|
||||
#if (SBC_FOR_EMBEDDED_LINUX == TRUE)
|
||||
typedef long long SINT64;
|
||||
#else
|
||||
typedef __int64 SINT64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#else
|
||||
|
||||
#include <stdint.h>
|
||||
typedef int8_t SINT8;
|
||||
typedef int16_t SINT16;
|
||||
typedef int32_t SINT32;
|
||||
typedef int64_t SINT64;
|
||||
typedef uint8_t UINT8;
|
||||
typedef uint16_t UINT16;
|
||||
typedef uint32_t UINT32;
|
||||
typedef uint64_t UINT64;
|
||||
|
||||
#endif
|
||||
/* BK4BTSTACK_CHANGE STOP */
|
||||
|
||||
#define SBC_API
|
||||
#define abs32(x) ( (x >= 0) ? x : (-x) )
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
//#include "msbc_encoder_port.h"
|
||||
#include "sbc_encoder.h"
|
||||
#include "xc60xx.h"
|
||||
|
||||
#define mSBC_SYNCWORD 0xad
|
||||
#define SBC_MAX_CHANNELS 2
|
||||
|
||||
struct msbc_encoder_state {
|
||||
SBC_ENC_PARAMS *context;
|
||||
int num_data_bytes;
|
||||
uint8_t sbc_packet[512];
|
||||
};
|
||||
|
||||
|
||||
__attribute__((section("ram_user"))) static struct msbc_encoder_state encoder_state = {0};
|
||||
static uint8_t msbc_encode_inited = 0;
|
||||
|
||||
int msbc_encoder_init(void)
|
||||
{
|
||||
static SBC_ENC_PARAMS msbc_context = {
|
||||
.s16NumOfBlocks = 15,
|
||||
.s16NumOfSubBands = 8,
|
||||
.s16AllocationMethod = SBC_LOUDNESS,
|
||||
.s16BitPool = 26,
|
||||
.s16ChannelMode = SBC_MONO,
|
||||
.s16NumOfChannels = 1,
|
||||
.mSBCEnabled = 1,
|
||||
.s16SamplingFreq = SBC_sf16000,
|
||||
};
|
||||
// int status = 0;
|
||||
|
||||
encoder_state.context = &msbc_context;
|
||||
encoder_state.context->pu8Packet = encoder_state.sbc_packet;
|
||||
|
||||
SBC_Encoder_Init(encoder_state.context);
|
||||
msbc_encode_inited = 1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int msbc_encoder_num_audio_frames(void)
|
||||
{
|
||||
SBC_ENC_PARAMS * context = encoder_state.context;
|
||||
return context->s16NumOfSubBands * context->s16NumOfBlocks;
|
||||
}
|
||||
|
||||
uint8_t * msbc_encoder_sbc_buffer(void)
|
||||
{
|
||||
SBC_ENC_PARAMS * context = encoder_state.context;
|
||||
return context->pu8Packet;
|
||||
}
|
||||
|
||||
uint16_t msbc_encoder_sbc_buffer_length(void)
|
||||
{
|
||||
SBC_ENC_PARAMS * context = encoder_state.context;
|
||||
return context->u16PacketLength;
|
||||
}
|
||||
|
||||
void __attribute__((section("ram_sbc_code"))) msbc_encoder_process_data(int16_t * input_buffer)
|
||||
{
|
||||
if (!msbc_encode_inited) {
|
||||
printf("SBC encoder: sbc state is NULL, call btstack_sbc_encoder_init to initialize it\r\n");
|
||||
}
|
||||
SBC_ENC_PARAMS * context = encoder_state.context;
|
||||
context->ps16PcmBuffer = input_buffer;
|
||||
if (context->mSBCEnabled) {
|
||||
context->pu8Packet[0] = 0xad;
|
||||
}
|
||||
SBC_Encoder(context);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef __MSBC_ENCODER_PORT_H_
|
||||
#define __MSBC_ENCODER_PORT_H_
|
||||
|
||||
int msbc_encoder_num_audio_frames(void);
|
||||
uint8_t * msbc_encoder_sbc_buffer(void);
|
||||
uint16_t msbc_encoder_sbc_buffer_length(void);
|
||||
int msbc_encoder_init(void);
|
||||
void msbc_encoder_process_data(int16_t * input_buffer);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,241 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* source file for fast dct operations
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sbc_encoder.h"
|
||||
#include "sbc_enc_func_declare.h"
|
||||
#include "sbc_dct.h"
|
||||
#include "xc60xx.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function SBC_FastIDCT8
|
||||
**
|
||||
** Description implementation of fast DCT algorithm by Feig and Winograd
|
||||
**
|
||||
**
|
||||
** Returns y = dct(pInVect)
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == FALSE)
|
||||
#define SBC_COS_PI_SUR_4 (0x00005a82) /* ((0x8000) * 0.7071) = cos(pi/4) */
|
||||
#define SBC_COS_PI_SUR_8 (0x00007641) /* ((0x8000) * 0.9239) = (cos(pi/8)) */
|
||||
#define SBC_COS_3PI_SUR_8 (0x000030fb) /* ((0x8000) * 0.3827) = (cos(3*pi/8)) */
|
||||
#define SBC_COS_PI_SUR_16 (0x00007d8a) /* ((0x8000) * 0.9808)) = (cos(pi/16)) */
|
||||
#define SBC_COS_3PI_SUR_16 (0x00006a6d) /* ((0x8000) * 0.8315)) = (cos(3*pi/16)) */
|
||||
#define SBC_COS_5PI_SUR_16 (0x0000471c) /* ((0x8000) * 0.5556)) = (cos(5*pi/16)) */
|
||||
#define SBC_COS_7PI_SUR_16 (0x000018f8) /* ((0x8000) * 0.1951)) = (cos(7*pi/16)) */
|
||||
#define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_16_SIMPLIFIED(a,b,c)
|
||||
#else
|
||||
#define SBC_COS_PI_SUR_4 (0x5A827999) /* ((0x80000000) * 0.707106781) = (cos(pi/4) ) */
|
||||
#define SBC_COS_PI_SUR_8 (0x7641AF3C) /* ((0x80000000) * 0.923879533) = (cos(pi/8) ) */
|
||||
#define SBC_COS_3PI_SUR_8 (0x30FBC54D) /* ((0x80000000) * 0.382683432) = (cos(3*pi/8) ) */
|
||||
#define SBC_COS_PI_SUR_16 (0x7D8A5F3F) /* ((0x80000000) * 0.98078528 )) = (cos(pi/16) ) */
|
||||
#define SBC_COS_3PI_SUR_16 (0x6A6D98A4) /* ((0x80000000) * 0.831469612)) = (cos(3*pi/16)) */
|
||||
#define SBC_COS_5PI_SUR_16 (0x471CECE6) /* ((0x80000000) * 0.555570233)) = (cos(5*pi/16)) */
|
||||
#define SBC_COS_7PI_SUR_16 (0x18F8B83C) /* ((0x80000000) * 0.195090322)) = (cos(7*pi/16)) */
|
||||
#define SBC_IDCT_MULT(a,b,c) SBC_MULT_32_32(a,b,c)
|
||||
#endif /* SBC_IS_64_MULT_IN_IDCT */
|
||||
|
||||
#if (SBC_FAST_DCT == FALSE)
|
||||
extern const SINT16 gas16AnalDCTcoeff8[];
|
||||
extern const SINT16 gas16AnalDCTcoeff4[];
|
||||
#endif
|
||||
|
||||
void __attribute__((section("ram_sbc_code"))) SBC_FastIDCT8(SINT32 *pInVect, SINT32 *pOutVect)
|
||||
{
|
||||
#if (SBC_FAST_DCT == TRUE)
|
||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||
#else
|
||||
#if (SBC_IPAQ_OPT==TRUE)
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
SINT64 s64Temp;
|
||||
#endif
|
||||
#else
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
SINT32 s32HiTemp;
|
||||
#else
|
||||
SINT32 s32In2Temp;
|
||||
register SINT32 s32In1Temp;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
register SINT32 x0, x1, x2, x3, x4, x5, x6, x7,temp;
|
||||
SINT32 res_even[4], res_odd[4];
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,pInVect[4], x0);
|
||||
|
||||
x1 = (pInVect[3] + pInVect[5]) >>1;
|
||||
x2 = (pInVect[2] + pInVect[6]) >>1;
|
||||
x3 = (pInVect[1] + pInVect[7]) >>1;
|
||||
x4 = (pInVect[0] + pInVect[8]) >>1;
|
||||
x5 = (pInVect[9] - pInVect[15]) >>1;
|
||||
x6 = (pInVect[10] - pInVect[14])>>1;
|
||||
x7 = (pInVect[11] - pInVect[13])>>1;
|
||||
|
||||
/* 2-point IDCT of x0 and x4 as in (11) */
|
||||
temp = x0 ;
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( x0 + x4 ), x0); /*x0 = ( x0 + x4 ) * cos(1*pi/4) ; */
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, ( temp - x4 ), x4); /*x4 = ( temp - x4 ) * cos(1*pi/4) ; */
|
||||
|
||||
/* rearrangement of x2 and x6 as in (15) */
|
||||
x2 -=x6;
|
||||
x6 <<= 1 ;
|
||||
|
||||
/* 2-point IDCT of x2 and x6 and post-multiplication as in (15) */
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4,x6, x6); /*x6 = x6 * cos(1*pi/4) ; */
|
||||
temp = x2 ;
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_8,( x2 + x6 ), x2); /*x2 = ( x2 + x6 ) * cos(1*pi/8) ; */
|
||||
SBC_IDCT_MULT(SBC_COS_3PI_SUR_8,( temp - x6 ), x6); /*x6 = ( temp - x6 ) * cos(3*pi/8) ;*/
|
||||
|
||||
/* 4-point IDCT of x0,x2,x4 and x6 as in (11) */
|
||||
res_even[ 0 ] = x0 + x2 ;
|
||||
res_even[ 1 ] = x4 + x6 ;
|
||||
res_even[ 2 ] = x4 - x6 ;
|
||||
res_even[ 3 ] = x0 - x2 ;
|
||||
|
||||
|
||||
/* rearrangement of x1,x3,x5,x7 as in (15) */
|
||||
x7 <<= 1 ;
|
||||
x5 = ( x5 <<1 ) - x7 ;
|
||||
x3 = ( x3 <<1 ) - x5 ;
|
||||
x1 -= x3 >>1 ;
|
||||
|
||||
/* two-dimensional IDCT of x1 and x5 */
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x5, x5); /*x5 = x5 * cos(1*pi/4) ; */
|
||||
temp = x1 ;
|
||||
x1 = x1 + x5 ;
|
||||
x5 = temp - x5 ;
|
||||
|
||||
/* rearrangement of x3 and x7 as in (15) */
|
||||
x3 -= x7;
|
||||
x7 <<= 1 ;
|
||||
SBC_IDCT_MULT(SBC_COS_PI_SUR_4, x7, x7); /*x7 = x7 * cos(1*pi/4) ; */
|
||||
|
||||
/* 2-point IDCT of x3 and x7 and post-multiplication as in (15) */
|
||||
temp = x3 ;
|
||||
SBC_IDCT_MULT( SBC_COS_PI_SUR_8,( x3 + x7 ), x3); /*x3 = ( x3 + x7 ) * cos(1*pi/8) ; */
|
||||
SBC_IDCT_MULT( SBC_COS_3PI_SUR_8,( temp - x7 ), x7); /*x7 = ( temp - x7 ) * cos(3*pi/8) ;*/
|
||||
|
||||
/* 4-point IDCT of x1,x3,x5 and x7 and post multiplication by diagonal matrix as in (14) */
|
||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_16), ( x1 + x3 ) , res_odd[0]); /*res_odd[ 0 ] = ( x1 + x3 ) * cos(1*pi/16) ; */
|
||||
SBC_IDCT_MULT((SBC_COS_3PI_SUR_16), ( x5 + x7 ) , res_odd[1]); /*res_odd[ 1 ] = ( x5 + x7 ) * cos(3*pi/16) ; */
|
||||
SBC_IDCT_MULT((SBC_COS_5PI_SUR_16), ( x5 - x7 ) , res_odd[2]); /*res_odd[ 2 ] = ( x5 - x7 ) * cos(5*pi/16) ; */
|
||||
SBC_IDCT_MULT((SBC_COS_7PI_SUR_16), ( x1 - x3 ) , res_odd[3]); /*res_odd[ 3 ] = ( x1 - x3 ) * cos(7*pi/16) ; */
|
||||
|
||||
/* additions and subtractions as in (9) */
|
||||
pOutVect[0] = (res_even[ 0 ] + res_odd[ 0 ]) ;
|
||||
pOutVect[1] = (res_even[ 1 ] + res_odd[ 1 ]) ;
|
||||
pOutVect[2] = (res_even[ 2 ] + res_odd[ 2 ]) ;
|
||||
pOutVect[3] = (res_even[ 3 ] + res_odd[ 3 ]) ;
|
||||
pOutVect[7] = (res_even[ 0 ] - res_odd[ 0 ]) ;
|
||||
pOutVect[6] = (res_even[ 1 ] - res_odd[ 1 ]) ;
|
||||
pOutVect[5] = (res_even[ 2 ] - res_odd[ 2 ]) ;
|
||||
pOutVect[4] = (res_even[ 3 ] - res_odd[ 3 ]) ;
|
||||
#else
|
||||
UINT8 Index, k;
|
||||
SINT32 temp;
|
||||
/*Calculate 4 subband samples by matrixing*/
|
||||
for(Index=0; Index<8; Index++)
|
||||
{
|
||||
temp = 0;
|
||||
for(k=0; k<16; k++)
|
||||
{
|
||||
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 );*/
|
||||
temp += (gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] >> 16));
|
||||
temp += ((gas16AnalDCTcoeff8[(Index*8*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
|
||||
}
|
||||
pOutVect[Index] = temp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function SBC_FastIDCT4
|
||||
**
|
||||
** Description implementation of fast DCT algorithm by Feig and Winograd
|
||||
**
|
||||
**
|
||||
** Returns y = dct(x0)
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
void __attribute__((section("ram_sbc_code"))) SBC_FastIDCT4(SINT32 *pInVect, SINT32 *pOutVect)
|
||||
{
|
||||
#if (SBC_FAST_DCT == TRUE)
|
||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||
#else
|
||||
#if (SBC_IPAQ_OPT==TRUE)
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
SINT64 s64Temp;
|
||||
#endif
|
||||
#else
|
||||
#if (SBC_IS_64_MULT_IN_IDCT == TRUE)
|
||||
SINT32 s32HiTemp;
|
||||
#else
|
||||
UINT16 s32In2Temp;
|
||||
SINT32 s32In1Temp;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
SINT32 temp,x2;
|
||||
SINT32 tmp[8];
|
||||
|
||||
x2=pInVect[2]>>1;
|
||||
temp=(pInVect[0]+pInVect[4]);
|
||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_4>>1), temp , tmp[0]);
|
||||
tmp[1]=x2-tmp[0];
|
||||
tmp[0]+=x2;
|
||||
temp=(pInVect[1]+pInVect[3]);
|
||||
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[3]);
|
||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[2]);
|
||||
temp=(pInVect[5]-pInVect[7]);
|
||||
SBC_IDCT_MULT((SBC_COS_3PI_SUR_8>>1), temp , tmp[5]);
|
||||
SBC_IDCT_MULT((SBC_COS_PI_SUR_8>>1), temp , tmp[4]);
|
||||
tmp[6]=tmp[2]+tmp[5];
|
||||
tmp[7]=tmp[3]-tmp[4];
|
||||
pOutVect[0] = (tmp[0]+tmp[6]);
|
||||
pOutVect[1] = (tmp[1]+tmp[7]);
|
||||
pOutVect[2] = (tmp[1]-tmp[7]);
|
||||
pOutVect[3] = (tmp[0]-tmp[6]);
|
||||
#else
|
||||
UINT8 Index, k;
|
||||
SINT32 temp;
|
||||
/*Calculate 4 subband samples by matrixing*/
|
||||
for(Index=0; Index<4; Index++)
|
||||
{
|
||||
temp = 0;
|
||||
for(k=0; k<8; k++)
|
||||
{
|
||||
/*temp += (SINT32)(((SINT64)M[(Index*strEncParams->numOfSubBands*2)+k] * Y[k]) >> 16 ); */
|
||||
temp += (gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] >> 16));
|
||||
temp += ((gas16AnalDCTcoeff4[(Index*4*2)+k] * (pInVect[k] & 0xFFFF)) >> 16);
|
||||
}
|
||||
pOutVect[Index] = temp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains the coefficient table used for DCT computation in
|
||||
* analysis.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sbc_encoder.h"
|
||||
/*DCT coeff for 4 sub-band case.*/
|
||||
#if (SBC_FAST_DCT == FALSE)
|
||||
const SINT16 gas16AnalDCTcoeff4[] =
|
||||
{
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(0.0000*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.0000*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.3827*32768)
|
||||
};
|
||||
|
||||
/*DCT coeff for 8 sub-band case.*/
|
||||
const SINT16 gas16AnalDCTcoeff8[] =
|
||||
{
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(0.0000*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(0.0000*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(0.0000*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.8315*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(-0.7071*32768),
|
||||
(SINT16)(0.9808*32768),
|
||||
(SINT16)(-0.9239*32768),
|
||||
(SINT16)(0.5556*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(1.0000*32767),
|
||||
(SINT16)(-0.9808*32768),
|
||||
(SINT16)(0.9239*32768),
|
||||
(SINT16)(-0.8315*32768),
|
||||
(SINT16)(0.7071*32768),
|
||||
(SINT16)(-0.5556*32768),
|
||||
(SINT16)(0.3827*32768),
|
||||
(SINT16)(-0.1951*32768),
|
||||
(SINT16)(-0.0000*32768),
|
||||
(SINT16)(0.1951*32768),
|
||||
(SINT16)(-0.3827*32768),
|
||||
(SINT16)(0.5556*32768)
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,200 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains the code for bit allocation algorithm. It calculates
|
||||
* the number of bits required for the encoded stream of data.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/*Includes*/
|
||||
#include "sbc_encoder.h"
|
||||
#include "sbc_enc_func_declare.h"
|
||||
#include "xc60xx.h"
|
||||
|
||||
/*global arrays*/
|
||||
const SINT16 sbc_enc_as16Offset4[4][4] = { {-1, 0, 0, 0}, {-2, 0, 0, 1},
|
||||
{-2, 0, 0, 1}, {-2, 0, 0, 1} };
|
||||
const SINT16 sbc_enc_as16Offset8[4][8] = { {-2, 0, 0, 0, 0, 0, 0, 1},
|
||||
{-3, 0, 0, 0, 0, 0, 1, 2},
|
||||
{-4, 0, 0, 0, 0, 0, 1, 2},
|
||||
{-4, 0, 0, 0, 0, 0, 1, 2} };
|
||||
|
||||
/****************************************************************************
|
||||
* BitAlloc - Calculates the required number of bits for the given scale factor
|
||||
* and the number of subbands.
|
||||
*
|
||||
* RETURNS : N/A
|
||||
*/
|
||||
|
||||
void __attribute__((section("ram_sbc_code"))) sbc_enc_bit_alloc_mono(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
{
|
||||
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
|
||||
SINT32 s32BitCount; /*the used number of bits*/
|
||||
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
|
||||
SINT32 s32BitSlice; /*number of bitslices in bitpool*/
|
||||
SINT32 s32Sb; /*counter for sub-band*/
|
||||
SINT32 s32Ch; /*counter for channel*/
|
||||
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
|
||||
SINT32 s32Loudness; /*used in Loudness calculation*/
|
||||
SINT16 *ps16GenBufPtr;
|
||||
SINT16 *ps16GenArrPtr;
|
||||
SINT16 *ps16GenTabPtr;
|
||||
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
|
||||
|
||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||
|
||||
for (s32Ch = 0; s32Ch < pstrCodecParams->s16NumOfChannels; s32Ch++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
if(s32NumOfSubBands == 4)
|
||||
{
|
||||
ps16GenTabPtr = (SINT16 *)
|
||||
sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
||||
}
|
||||
else
|
||||
{
|
||||
ps16GenTabPtr = (SINT16 *)
|
||||
sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
||||
}
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb] == 0)
|
||||
*(ps16GenBufPtr) = -5;
|
||||
else
|
||||
{
|
||||
s32Loudness =
|
||||
(SINT32)(pstrCodecParams->as16ScaleFactor[(s32Ch*s32NumOfSubBands)+s32Sb]
|
||||
- *ps16GenTabPtr);
|
||||
if(s32Loudness > 0)
|
||||
*(ps16GenBufPtr) = (SINT16)(s32Loudness >>1);
|
||||
else
|
||||
*(ps16GenBufPtr) = (SINT16)s32Loudness;
|
||||
}
|
||||
ps16GenBufPtr++;
|
||||
ps16GenTabPtr++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* max bitneed index is searched*/
|
||||
s32MaxBitNeed = 0;
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if( *(ps16GenBufPtr) > s32MaxBitNeed)
|
||||
s32MaxBitNeed = *(ps16GenBufPtr);
|
||||
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
/*iterative process to find hwo many bitslices fit into the bitpool*/
|
||||
s32BitSlice = s32MaxBitNeed + 1;
|
||||
s32BitCount = pstrCodecParams->s16BitPool;
|
||||
s32SliceCount = 0;
|
||||
do
|
||||
{
|
||||
s32BitSlice --;
|
||||
s32BitCount -= s32SliceCount;
|
||||
s32SliceCount = 0;
|
||||
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if( (((*ps16GenBufPtr-s32BitSlice)< 16) && ((*ps16GenBufPtr-s32BitSlice) >= 1)))
|
||||
{
|
||||
if((*ps16GenBufPtr-s32BitSlice) == 1)
|
||||
s32SliceCount+=2;
|
||||
else
|
||||
s32SliceCount++;
|
||||
}
|
||||
ps16GenBufPtr++;
|
||||
|
||||
}/*end of for*/
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
}while((s32BitCount-s32SliceCount)>0);
|
||||
|
||||
if(s32BitCount == 0)
|
||||
{
|
||||
s32BitCount -= s32SliceCount;
|
||||
s32BitSlice --;
|
||||
}
|
||||
|
||||
/*Bits are distributed until the last bitslice is reached*/
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
|
||||
ps16GenBufPtr = ps16BitNeed + (s32Ch*s32NumOfSubBands);
|
||||
for(s32Sb=0; s32Sb<s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if(*(ps16GenBufPtr) < (s32BitSlice+2))
|
||||
*(ps16GenArrPtr) = 0;
|
||||
else
|
||||
*(ps16GenArrPtr) = ((*(ps16GenBufPtr)-s32BitSlice)<16) ?
|
||||
(SINT16)(*(ps16GenBufPtr)-s32BitSlice) : 16;
|
||||
|
||||
ps16GenBufPtr++;
|
||||
ps16GenArrPtr++;
|
||||
}
|
||||
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) )
|
||||
{
|
||||
if( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
|
||||
{
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
else if( (*(ps16GenBufPtr) == (s32BitSlice+1)) &&
|
||||
(s32BitCount > 1) )
|
||||
{
|
||||
*(ps16GenArrPtr) = 2;
|
||||
s32BitCount -= 2;
|
||||
}
|
||||
s32Sb++;
|
||||
ps16GenArrPtr++;
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+(s32Ch*s32NumOfSubBands);
|
||||
|
||||
|
||||
s32Sb=0;
|
||||
while( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
||||
{
|
||||
if( *(ps16GenArrPtr) < 16)
|
||||
{
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
s32Sb++;
|
||||
ps16GenArrPtr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*End of BitAlloc() function*/
|
||||
@@ -0,0 +1,213 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains the code for bit allocation algorithm. It calculates
|
||||
* the number of bits required for the encoded stream of data.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/*Includes*/
|
||||
#include "sbc_encoder.h"
|
||||
#include "sbc_enc_func_declare.h"
|
||||
#include "xc60xx.h"
|
||||
|
||||
/*global arrays*/
|
||||
extern const SINT16 sbc_enc_as16Offset4[4][4];
|
||||
extern const SINT16 sbc_enc_as16Offset8[4][8];
|
||||
|
||||
/****************************************************************************
|
||||
* BitAlloc - Calculates the required number of bits for the given scale factor
|
||||
* and the number of subbands.
|
||||
*
|
||||
* RETURNS : N/A
|
||||
*/
|
||||
|
||||
/*__attribute__((section("ram_sbc_code")))*/ void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *pstrCodecParams)
|
||||
{
|
||||
/* CAUTIOM -> mips optim for arm 32 require to use SINT32 instead of SINT16 */
|
||||
/* Do not change variable type or name */
|
||||
SINT32 s32MaxBitNeed; /*to store the max bits needed per sb*/
|
||||
SINT32 s32BitCount; /*the used number of bits*/
|
||||
SINT32 s32SliceCount; /*to store hwo many slices can be put in bitpool*/
|
||||
SINT32 s32BitSlice; /*number of bitslices in bitpool*/
|
||||
SINT32 s32Sb; /*counter for sub-band*/
|
||||
SINT32 s32Ch; /*counter for channel*/
|
||||
SINT16 *ps16BitNeed; /*temp memory to store required number of bits*/
|
||||
SINT32 s32Loudness; /*used in Loudness calculation*/
|
||||
SINT16 *ps16GenBufPtr,*pas16ScaleFactor;
|
||||
SINT16 *ps16GenArrPtr;
|
||||
SINT16 *ps16GenTabPtr;
|
||||
SINT32 s32NumOfSubBands = pstrCodecParams->s16NumOfSubBands;
|
||||
SINT32 s32BitPool = pstrCodecParams->s16BitPool;
|
||||
|
||||
/* bitneed values are derived from scale factor */
|
||||
if (pstrCodecParams->s16AllocationMethod == SBC_SNR)
|
||||
{
|
||||
ps16BitNeed = pstrCodecParams->as16ScaleFactor;
|
||||
s32MaxBitNeed = pstrCodecParams->s16MaxBitNeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
ps16BitNeed = pstrCodecParams->s16ScartchMemForBitAlloc;
|
||||
pas16ScaleFactor=pstrCodecParams->as16ScaleFactor;
|
||||
s32MaxBitNeed = 0;
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
for (s32Ch = 0; s32Ch < 2; s32Ch++)
|
||||
{
|
||||
if (s32NumOfSubBands == 4)
|
||||
{
|
||||
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset4[pstrCodecParams->s16SamplingFreq];
|
||||
}
|
||||
else
|
||||
{
|
||||
ps16GenTabPtr = (SINT16 *)sbc_enc_as16Offset8[pstrCodecParams->s16SamplingFreq];
|
||||
}
|
||||
|
||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if (*pas16ScaleFactor == 0)
|
||||
*ps16GenBufPtr = -5;
|
||||
else
|
||||
{
|
||||
s32Loudness = (SINT32)(*pas16ScaleFactor - *ps16GenTabPtr);
|
||||
|
||||
if (s32Loudness > 0)
|
||||
*ps16GenBufPtr = (SINT16)(s32Loudness >> 1);
|
||||
else
|
||||
*ps16GenBufPtr = (SINT16)s32Loudness;
|
||||
}
|
||||
|
||||
if (*ps16GenBufPtr > s32MaxBitNeed)
|
||||
s32MaxBitNeed = *ps16GenBufPtr;
|
||||
pas16ScaleFactor++;
|
||||
ps16GenBufPtr++;
|
||||
ps16GenTabPtr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* iterative process to find out hwo many bitslices fit into the bitpool */
|
||||
s32BitSlice = s32MaxBitNeed + 1;
|
||||
s32BitCount = s32BitPool;
|
||||
s32SliceCount = 0;
|
||||
do
|
||||
{
|
||||
s32BitSlice --;
|
||||
s32BitCount -= s32SliceCount;
|
||||
s32SliceCount = 0;
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
|
||||
for (s32Sb = 0; s32Sb < (2*s32NumOfSubBands); s32Sb++)
|
||||
{
|
||||
if ( (*ps16GenBufPtr >= (s32BitSlice + 1)) && (*ps16GenBufPtr < (s32BitSlice + 16)) )
|
||||
{
|
||||
if (*(ps16GenBufPtr) == (s32BitSlice+1))
|
||||
s32SliceCount += 2;
|
||||
else
|
||||
s32SliceCount++;
|
||||
}
|
||||
ps16GenBufPtr++;
|
||||
}
|
||||
} while ((s32BitCount-s32SliceCount)>0);
|
||||
|
||||
if ((s32BitCount-s32SliceCount) == 0)
|
||||
{
|
||||
s32BitCount -= s32SliceCount;
|
||||
s32BitSlice --;
|
||||
}
|
||||
|
||||
/* Bits are distributed until the last bitslice is reached */
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
||||
for (s32Ch = 0; s32Ch < 2; s32Ch++)
|
||||
{
|
||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
if (*ps16GenBufPtr < (s32BitSlice+2))
|
||||
*ps16GenArrPtr = 0;
|
||||
else
|
||||
*ps16GenArrPtr = ((*(ps16GenBufPtr)-s32BitSlice) < 16) ?
|
||||
(SINT16)(*(ps16GenBufPtr)-s32BitSlice):16;
|
||||
ps16GenBufPtr++;
|
||||
ps16GenArrPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
/* the remaining bits are allocated starting at subband 0 */
|
||||
s32Ch=0;
|
||||
s32Sb=0;
|
||||
ps16GenBufPtr = ps16BitNeed;
|
||||
ps16GenArrPtr -= 2*s32NumOfSubBands;
|
||||
|
||||
while ( (s32BitCount > 0) && (s32Sb < s32NumOfSubBands) )
|
||||
{
|
||||
if ( (*(ps16GenArrPtr) >= 2) && (*(ps16GenArrPtr) < 16) )
|
||||
{
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
else if ((*ps16GenBufPtr == (s32BitSlice+1)) && (s32BitCount > 1))
|
||||
{
|
||||
*(ps16GenArrPtr) = 2;
|
||||
s32BitCount -= 2;
|
||||
}
|
||||
if(s32Ch == 1)
|
||||
{
|
||||
s32Ch = 0;
|
||||
s32Sb++;
|
||||
ps16GenBufPtr = ps16BitNeed+s32Sb;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
s32Ch =1;
|
||||
ps16GenBufPtr = ps16BitNeed+s32NumOfSubBands+s32Sb;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
|
||||
}
|
||||
}
|
||||
|
||||
s32Ch=0;
|
||||
s32Sb=0;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits;
|
||||
|
||||
while ((s32BitCount >0) && (s32Sb < s32NumOfSubBands))
|
||||
{
|
||||
if(*(ps16GenArrPtr) < 16)
|
||||
{
|
||||
(*(ps16GenArrPtr))++;
|
||||
s32BitCount--;
|
||||
}
|
||||
if (s32Ch == 1)
|
||||
{
|
||||
s32Ch = 0;
|
||||
s32Sb++;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32Sb;
|
||||
}
|
||||
else
|
||||
{
|
||||
s32Ch = 1;
|
||||
ps16GenArrPtr = pstrCodecParams->as16Bits+s32NumOfSubBands+s32Sb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*End of BitAlloc() function*/
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains the Windowing coeffs for synthesis filter
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sbc_encoder.h"
|
||||
|
||||
#if (SBC_ARM_ASM_OPT==FALSE && SBC_IPAQ_OPT==FALSE)
|
||||
#if (SBC_IS_64_MULT_IN_WINDOW_ACCU == FALSE)
|
||||
/*Window coeff for 4 sub band case*/
|
||||
const SINT16 gas32CoeffFor4SBs[] =
|
||||
{
|
||||
(SINT16)((SINT32)0x00000000 >> 16), (SINT16)0x00000000,
|
||||
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6,
|
||||
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
||||
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
||||
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
||||
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
||||
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
||||
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
||||
|
||||
(SINT16)((SINT32)0x01659F45 >> 16), (SINT16)0x01659F45,
|
||||
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
||||
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
||||
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
||||
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
||||
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
||||
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
||||
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
||||
|
||||
(SINT16)((SINT32)0x115B1ED2 >> 16), (SINT16)0x115B1ED2,
|
||||
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
||||
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
||||
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
||||
(SINT16)((SINT32)0x25AC1FF2 >> 16), (SINT16)0x25AC1FF2,
|
||||
(SINT16)((SINT32)0x2412F251 >> 16), (SINT16)0x2412F251,
|
||||
(SINT16)((SINT32)0x1F91CA46 >> 16), (SINT16)0x1F91CA46,
|
||||
(SINT16)((SINT32)0x18F55C90 >> 16), (SINT16)0x18F55C90,
|
||||
|
||||
(SINT16)((SINT32)0xEEA4E12E >> 16), (SINT16)0xEEA4E12E,
|
||||
(SINT16)((SINT32)0xF60FAF37 >> 16), (SINT16)0xF60FAF37,
|
||||
(SINT16)((SINT32)0xFC4F91D4 >> 16), (SINT16)0xFC4F91D4,
|
||||
(SINT16)((SINT32)0x00C8F2BC >> 16), (SINT16)0x00C8F2BC,
|
||||
(SINT16)((SINT32)0x034FEE2C >> 16), (SINT16)0x034FEE2C,
|
||||
(SINT16)((SINT32)0x041EEE40 >> 16), (SINT16)0x041EEE40,
|
||||
(SINT16)((SINT32)0x03B23341 >> 16), (SINT16)0x03B23341,
|
||||
(SINT16)((SINT32)0x029DBAA3 >> 16), (SINT16)0x029DBAA3,
|
||||
|
||||
(SINT16)((SINT32)0xFE9A60BB >> 16), (SINT16)0xFE9A60BB,
|
||||
(SINT16)((SINT32)0xFF9BB9D5 >> 16), (SINT16)0xFF9BB9D5,
|
||||
(SINT16)((SINT32)0x003D239B >> 16), (SINT16)0x003D239B,
|
||||
(SINT16)((SINT32)0x007F88E4 >> 16), (SINT16)0x007F88E4,
|
||||
(SINT16)((SINT32)0x007DBCC8 >> 16), (SINT16)0x007DBCC8,
|
||||
(SINT16)((SINT32)0x00599403 >> 16), (SINT16)0x00599403,
|
||||
(SINT16)((SINT32)0x0030E2D3 >> 16), (SINT16)0x0030E2D3,
|
||||
(SINT16)((SINT32)0x001194E6 >> 16), (SINT16)0x001194E6
|
||||
};
|
||||
|
||||
/*Window coeff for 8 sub band case*/
|
||||
const SINT16 gas32CoeffFor8SBs[] =
|
||||
{
|
||||
(SINT16)((SINT32)0x00000000 >>16), (SINT16)0x00000000,
|
||||
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173,
|
||||
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
|
||||
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
|
||||
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
|
||||
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
|
||||
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
|
||||
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
|
||||
|
||||
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 8 */
|
||||
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
|
||||
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
|
||||
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
|
||||
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
|
||||
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
|
||||
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
|
||||
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
|
||||
|
||||
(SINT16)((SINT32)0x00B97348 >>16), (SINT16)0x00B97348, /* 16 */
|
||||
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
|
||||
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
|
||||
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
|
||||
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
|
||||
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
|
||||
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
|
||||
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
|
||||
|
||||
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 24 */
|
||||
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
|
||||
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
|
||||
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
|
||||
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
|
||||
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
|
||||
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
|
||||
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
|
||||
|
||||
(SINT16)((SINT32)0x08B4307A >>16), (SINT16)0x08B4307A, /* 32 */
|
||||
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
|
||||
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
|
||||
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
|
||||
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
|
||||
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
|
||||
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
|
||||
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
|
||||
|
||||
(SINT16)((SINT32)0x12CF6C75 >>16), (SINT16)0x12CF6C75, /* 40 */
|
||||
(SINT16)((SINT32)0x129C226F >>16), (SINT16)0x129C226F,
|
||||
(SINT16)((SINT32)0x120435FA >>16), (SINT16)0x120435FA,
|
||||
(SINT16)((SINT32)0x110ECEF0 >>16), (SINT16)0x110ECEF0,
|
||||
(SINT16)((SINT32)0x0FC721F9 >>16), (SINT16)0x0FC721F9,
|
||||
(SINT16)((SINT32)0x0E3BB16F >>16), (SINT16)0x0E3BB16F,
|
||||
(SINT16)((SINT32)0x0C7D59B6 >>16), (SINT16)0x0C7D59B6,
|
||||
(SINT16)((SINT32)0x0A9F3E9A >>16), (SINT16)0x0A9F3E9A,
|
||||
|
||||
(SINT16)((SINT32)0xF74BCF86 >>16), (SINT16)0xF74BCF86, /* 48 */
|
||||
(SINT16)((SINT32)0xF9312891 >>16), (SINT16)0xF9312891,
|
||||
(SINT16)((SINT32)0xFAFF95FC >>16), (SINT16)0xFAFF95FC,
|
||||
(SINT16)((SINT32)0xFCA86E7E >>16), (SINT16)0xFCA86E7E,
|
||||
(SINT16)((SINT32)0xFE20435D >>16), (SINT16)0xFE20435D,
|
||||
(SINT16)((SINT32)0xFF5EEB73 >>16), (SINT16)0xFF5EEB73,
|
||||
(SINT16)((SINT32)0x005FD0FF >>16), (SINT16)0x005FD0FF,
|
||||
(SINT16)((SINT32)0x01223EBA >>16), (SINT16)0x01223EBA,
|
||||
|
||||
(SINT16)((SINT32)0x01A7ECEF >>16), (SINT16)0x01A7ECEF, /* 56 */
|
||||
(SINT16)((SINT32)0x01F5F424 >>16), (SINT16)0x01F5F424,
|
||||
(SINT16)((SINT32)0x02138653 >>16), (SINT16)0x02138653,
|
||||
(SINT16)((SINT32)0x0209291F >>16), (SINT16)0x0209291F,
|
||||
(SINT16)((SINT32)0x01E0224C >>16), (SINT16)0x01E0224C,
|
||||
(SINT16)((SINT32)0x01A1B38B >>16), (SINT16)0x01A1B38B,
|
||||
(SINT16)((SINT32)0x0156B3CA >>16), (SINT16)0x0156B3CA,
|
||||
(SINT16)((SINT32)0x01071B96 >>16), (SINT16)0x01071B96,
|
||||
|
||||
(SINT16)((SINT32)0xFF468CB8 >>16), (SINT16)0xFF468CB8, /* 64 */
|
||||
(SINT16)((SINT32)0xFF8D6793 >>16), (SINT16)0xFF8D6793,
|
||||
(SINT16)((SINT32)0xFFC9F10E >>16), (SINT16)0xFFC9F10E,
|
||||
(SINT16)((SINT32)0xFFFA2413 >>16), (SINT16)0xFFFA2413,
|
||||
(SINT16)((SINT32)0x001D8FD2 >>16), (SINT16)0x001D8FD2,
|
||||
(SINT16)((SINT32)0x0034F8B6 >>16), (SINT16)0x0034F8B6,
|
||||
(SINT16)((SINT32)0x00415B75 >>16), (SINT16)0x00415B75,
|
||||
(SINT16)((SINT32)0x0044EF48 >>16), (SINT16)0x0044EF48,
|
||||
|
||||
(SINT16)((SINT32)0x0041EC6A >>16), (SINT16)0x0041EC6A, /* 72 */
|
||||
(SINT16)((SINT32)0x003A72E7 >>16), (SINT16)0x003A72E7,
|
||||
(SINT16)((SINT32)0x003060F4 >>16), (SINT16)0x003060F4,
|
||||
(SINT16)((SINT32)0x00255A62 >>16), (SINT16)0x00255A62,
|
||||
(SINT16)((SINT32)0x001AFF89 >>16), (SINT16)0x001AFF89,
|
||||
(SINT16)((SINT32)0x00122C7D >>16), (SINT16)0x00122C7D,
|
||||
(SINT16)((SINT32)0x000B3F71 >>16), (SINT16)0x000B3F71,
|
||||
(SINT16)((SINT32)0x00052173 >>16), (SINT16)0x00052173
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
/*Window coeff for 4 sub band case*/
|
||||
const SINT32 gas32CoeffFor4SBs[] =
|
||||
{
|
||||
(SINT32)0x00000000,
|
||||
(SINT32)0x001194E6,
|
||||
(SINT32)0x0030E2D3,
|
||||
(SINT32)0x00599403,
|
||||
(SINT32)0x007DBCC8,
|
||||
(SINT32)0x007F88E4,
|
||||
(SINT32)0x003D239B,
|
||||
(SINT32)0xFF9BB9D5,
|
||||
|
||||
(SINT32)0x01659F45,
|
||||
(SINT32)0x029DBAA3,
|
||||
(SINT32)0x03B23341,
|
||||
(SINT32)0x041EEE40,
|
||||
(SINT32)0x034FEE2C,
|
||||
(SINT32)0x00C8F2BC,
|
||||
(SINT32)0xFC4F91D4,
|
||||
(SINT32)0xF60FAF37,
|
||||
|
||||
(SINT32)0x115B1ED2,
|
||||
(SINT32)0x18F55C90,
|
||||
(SINT32)0x1F91CA46,
|
||||
(SINT32)0x2412F251,
|
||||
(SINT32)0x25AC1FF2,
|
||||
(SINT32)0x2412F251,
|
||||
(SINT32)0x1F91CA46,
|
||||
(SINT32)0x18F55C90,
|
||||
|
||||
(SINT32)0xEEA4E12E,
|
||||
(SINT32)0xF60FAF37,
|
||||
(SINT32)0xFC4F91D4,
|
||||
(SINT32)0x00C8F2BC,
|
||||
(SINT32)0x034FEE2C,
|
||||
(SINT32)0x041EEE40,
|
||||
(SINT32)0x03B23341,
|
||||
(SINT32)0x029DBAA3,
|
||||
|
||||
(SINT32)0xFE9A60BB,
|
||||
(SINT32)0xFF9BB9D5,
|
||||
(SINT32)0x003D239B,
|
||||
(SINT32)0x007F88E4,
|
||||
(SINT32)0x007DBCC8,
|
||||
(SINT32)0x00599403,
|
||||
(SINT32)0x0030E2D3,
|
||||
(SINT32)0x001194E6
|
||||
};
|
||||
|
||||
/*Window coeff for 8 sub band case*/
|
||||
const SINT32 gas32CoeffFor8SBs[] =
|
||||
{
|
||||
(SINT32)0x00000000,
|
||||
(SINT32)0x00052173,
|
||||
(SINT32)0x000B3F71,
|
||||
(SINT32)0x00122C7D,
|
||||
(SINT32)0x001AFF89,
|
||||
(SINT32)0x00255A62,
|
||||
(SINT32)0x003060F4,
|
||||
(SINT32)0x003A72E7,
|
||||
|
||||
(SINT32)0x0041EC6A, /* 8 */
|
||||
(SINT32)0x0044EF48,
|
||||
(SINT32)0x00415B75,
|
||||
(SINT32)0x0034F8B6,
|
||||
(SINT32)0x001D8FD2,
|
||||
(SINT32)0xFFFA2413,
|
||||
(SINT32)0xFFC9F10E,
|
||||
(SINT32)0xFF8D6793,
|
||||
|
||||
(SINT32)0x00B97348, /* 16 */
|
||||
(SINT32)0x01071B96,
|
||||
(SINT32)0x0156B3CA,
|
||||
(SINT32)0x01A1B38B,
|
||||
(SINT32)0x01E0224C,
|
||||
(SINT32)0x0209291F,
|
||||
(SINT32)0x02138653,
|
||||
(SINT32)0x01F5F424,
|
||||
|
||||
(SINT32)0x01A7ECEF, /* 24 */
|
||||
(SINT32)0x01223EBA,
|
||||
(SINT32)0x005FD0FF,
|
||||
(SINT32)0xFF5EEB73,
|
||||
(SINT32)0xFE20435D,
|
||||
(SINT32)0xFCA86E7E,
|
||||
(SINT32)0xFAFF95FC,
|
||||
(SINT32)0xF9312891,
|
||||
|
||||
(SINT32)0x08B4307A, /* 32 */
|
||||
(SINT32)0x0A9F3E9A,
|
||||
(SINT32)0x0C7D59B6,
|
||||
(SINT32)0x0E3BB16F,
|
||||
(SINT32)0x0FC721F9,
|
||||
(SINT32)0x110ECEF0,
|
||||
(SINT32)0x120435FA,
|
||||
(SINT32)0x129C226F,
|
||||
|
||||
(SINT32)0x12CF6C75, /* 40 */
|
||||
(SINT32)0x129C226F,
|
||||
(SINT32)0x120435FA,
|
||||
(SINT32)0x110ECEF0,
|
||||
(SINT32)0x0FC721F9,
|
||||
(SINT32)0x0E3BB16F,
|
||||
(SINT32)0x0C7D59B6,
|
||||
(SINT32)0x0A9F3E9A,
|
||||
|
||||
(SINT32)0xF74BCF86, /* 48 */
|
||||
(SINT32)0xF9312891,
|
||||
(SINT32)0xFAFF95FC,
|
||||
(SINT32)0xFCA86E7E,
|
||||
(SINT32)0xFE20435D,
|
||||
(SINT32)0xFF5EEB73,
|
||||
(SINT32)0x005FD0FF,
|
||||
(SINT32)0x01223EBA,
|
||||
|
||||
(SINT32)0x01A7ECEF, /* 56 */
|
||||
(SINT32)0x01F5F424,
|
||||
(SINT32)0x02138653,
|
||||
(SINT32)0x0209291F,
|
||||
(SINT32)0x01E0224C,
|
||||
(SINT32)0x01A1B38B,
|
||||
(SINT32)0x0156B3CA,
|
||||
(SINT32)0x01071B96,
|
||||
|
||||
(SINT32)0xFF468CB8, /* 64 */
|
||||
(SINT32)0xFF8D6793,
|
||||
(SINT32)0xFFC9F10E,
|
||||
(SINT32)0xFFFA2413,
|
||||
(SINT32)0x001D8FD2,
|
||||
(SINT32)0x0034F8B6,
|
||||
(SINT32)0x00415B75,
|
||||
(SINT32)0x0044EF48,
|
||||
|
||||
(SINT32)0x0041EC6A, /* 72 */
|
||||
(SINT32)0x003A72E7,
|
||||
(SINT32)0x003060F4,
|
||||
(SINT32)0x00255A62,
|
||||
(SINT32)0x001AFF89,
|
||||
(SINT32)0x00122C7D,
|
||||
(SINT32)0x000B3F71,
|
||||
(SINT32)0x00052173
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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"
|
||||
#include "sbc_enc_func_declare.h"
|
||||
#include "xc60xx.h"
|
||||
|
||||
SINT16 EncMaxShiftCounter;
|
||||
|
||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||
SINT32 s32LRDiff[SBC_MAX_NUM_OF_BLOCKS] = {0};
|
||||
SINT32 s32LRSum[SBC_MAX_NUM_OF_BLOCKS] = {0};
|
||||
#endif
|
||||
|
||||
__attribute__((section("ram_sbc_code"))) void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
|
||||
{
|
||||
SINT32 s32Ch; /* counter for ch*/
|
||||
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*/
|
||||
SINT32 s32NumOfBlocks = pstrEncParams->s16NumOfBlocks;
|
||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||
SINT32 s32MaxValue2;
|
||||
UINT32 u32CountSum,u32CountDiff;
|
||||
SINT32 *pSum, *pDiff;
|
||||
#endif
|
||||
register SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
|
||||
|
||||
pstrEncParams->pu8NextPacket = pstrEncParams->pu8Packet;
|
||||
|
||||
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
|
||||
pstrEncParams->ps16NextPcmBuffer = pstrEncParams->ps16PcmBuffer;
|
||||
#else
|
||||
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;
|
||||
s32MaxValue=0;
|
||||
for (s32Blk=s32NumOfBlocks;s32Blk>0;s32Blk--)
|
||||
{
|
||||
if (s32MaxValue<abs32(*SbBuffer))
|
||||
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;
|
||||
}
|
||||
/* In case of JS processing,check whether to use JS */
|
||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
||||
{
|
||||
/* Calculate sum and differance scale factors for making JS decision */
|
||||
ps16ScfL = pstrEncParams->as16ScaleFactor ;
|
||||
/* calculate the scale factor of Joint stereo max sum and diff */
|
||||
for (s32Sb = 0; s32Sb < (s32NumOfSubBands-1); s32Sb++)
|
||||
{
|
||||
SbBuffer=pstrEncParams->s32SbBuffer+s32Sb;
|
||||
s32MaxValue2=0;
|
||||
s32MaxValue=0;
|
||||
pSum = s32LRSum;
|
||||
pDiff = s32LRDiff;
|
||||
for (s32Blk=0;s32Blk<s32NumOfBlocks;s32Blk++)
|
||||
{
|
||||
*pSum=(*SbBuffer+*(SbBuffer+s32NumOfSubBands))>>1;
|
||||
if (abs32(*pSum)>s32MaxValue)
|
||||
s32MaxValue=abs32(*pSum);
|
||||
pSum++;
|
||||
*pDiff=(*SbBuffer-*(SbBuffer+s32NumOfSubBands))>>1;
|
||||
if (abs32(*pDiff)>s32MaxValue2)
|
||||
s32MaxValue2=abs32(*pDiff);
|
||||
pDiff++;
|
||||
SbBuffer+=s32Ch;
|
||||
}
|
||||
u32Count = (s32MaxValue > 0x800000) ? 9 : 0;
|
||||
for ( ; u32Count < 15; u32Count++)
|
||||
{
|
||||
if (s32MaxValue <= (SINT32)(0x8000 << u32Count))
|
||||
break;
|
||||
}
|
||||
u32CountSum=u32Count;
|
||||
u32Count = (s32MaxValue2 > 0x800000) ? 9 : 0;
|
||||
for ( ; u32Count < 15; u32Count++)
|
||||
{
|
||||
if (s32MaxValue2 <= (SINT32)(0x8000 << u32Count))
|
||||
break;
|
||||
}
|
||||
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+s32NumOfSubBands) = *pDiff;
|
||||
|
||||
SbBuffer += s32NumOfSubBands<<1;
|
||||
pSum++;
|
||||
pDiff++;
|
||||
}
|
||||
|
||||
pstrEncParams->as16Join[s32Sb] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pstrEncParams->as16Join[s32Sb] = 0;
|
||||
}
|
||||
ps16ScfL++;
|
||||
}
|
||||
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 */
|
||||
EncPacking(pstrEncParams);
|
||||
}
|
||||
while(--(pstrEncParams->u8NumPacketToEncode));
|
||||
|
||||
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* InitSbcAnalysisFilt - Initalizes the input data to 0
|
||||
*
|
||||
* RETURNS : N/A
|
||||
*/
|
||||
void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
|
||||
{
|
||||
// UINT16 s16SamplingFreq; /*temp variable to store smpling freq*/
|
||||
SINT16 s16Bitpool; /*to store bit pool value*/
|
||||
// SINT16 s16BitRate; /*to store bitrate*/
|
||||
// SINT16 s16FrameLen; /*to store frame length*/
|
||||
UINT16 HeaderParams;
|
||||
|
||||
pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */
|
||||
|
||||
/* Required number of channels */
|
||||
if (pstrEncParams->s16ChannelMode == SBC_MONO)
|
||||
pstrEncParams->s16NumOfChannels = 1;
|
||||
else
|
||||
pstrEncParams->s16NumOfChannels = 2;
|
||||
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
/* Bit pool calculation */
|
||||
// if (pstrEncParams->s16SamplingFreq == SBC_sf16000)
|
||||
// s16SamplingFreq = 16000;
|
||||
// else if (pstrEncParams->s16SamplingFreq == SBC_sf32000)
|
||||
// s16SamplingFreq = 32000;
|
||||
// else if (pstrEncParams->s16SamplingFreq == SBC_sf44100)
|
||||
// s16SamplingFreq = 44100;
|
||||
// else
|
||||
// s16SamplingFreq = 48000;
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
|
||||
if ( (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
||||
|| (pstrEncParams->s16ChannelMode == SBC_STEREO) )
|
||||
{
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
// s16Bitpool = (SINT16)( (pstrEncParams->u16BitRate *
|
||||
// pstrEncParams->s16NumOfSubBands * 1000 / s16SamplingFreq)
|
||||
// -( (32 + (4 * pstrEncParams->s16NumOfSubBands *
|
||||
// pstrEncParams->s16NumOfChannels)
|
||||
// + ( (pstrEncParams->s16ChannelMode - 2) *
|
||||
// pstrEncParams->s16NumOfSubBands ) )
|
||||
// / pstrEncParams->s16NumOfBlocks) );
|
||||
|
||||
s16Bitpool = pstrEncParams->s16BitPool;
|
||||
|
||||
// s16FrameLen = 4 + (4*pstrEncParams->s16NumOfSubBands*
|
||||
// pstrEncParams->s16NumOfChannels)/8
|
||||
// + ( ((pstrEncParams->s16ChannelMode - 2) *
|
||||
// pstrEncParams->s16NumOfSubBands)
|
||||
// + (pstrEncParams->s16NumOfBlocks * s16Bitpool) ) / 8;
|
||||
// s16BitRate = (8 * s16FrameLen * s16SamplingFreq)
|
||||
// / (pstrEncParams->s16NumOfSubBands *
|
||||
// pstrEncParams->s16NumOfBlocks * 1000);
|
||||
|
||||
// if (s16BitRate > pstrEncParams->u16BitRate)
|
||||
// s16Bitpool--;
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
|
||||
if(pstrEncParams->s16NumOfSubBands == 8)
|
||||
pstrEncParams->s16BitPool = (s16Bitpool > 255) ? 255 : s16Bitpool;
|
||||
else
|
||||
pstrEncParams->s16BitPool = (s16Bitpool > 128) ? 128 : s16Bitpool;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!pstrEncParams->mSBCEnabled){
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
// s16Bitpool = (SINT16)( ((pstrEncParams->s16NumOfSubBands *
|
||||
// pstrEncParams->u16BitRate * 1000)
|
||||
// / (s16SamplingFreq * pstrEncParams->s16NumOfChannels))
|
||||
// -( ( (32 / pstrEncParams->s16NumOfChannels) +
|
||||
// (4 * pstrEncParams->s16NumOfSubBands) )
|
||||
// / pstrEncParams->s16NumOfBlocks ) );
|
||||
s16Bitpool = pstrEncParams->s16BitPool;
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
pstrEncParams->s16BitPool = (s16Bitpool >
|
||||
(16 * pstrEncParams->s16NumOfSubBands))
|
||||
? (16*pstrEncParams->s16NumOfSubBands) : s16Bitpool;
|
||||
}
|
||||
}
|
||||
|
||||
if (pstrEncParams->s16BitPool < 0)
|
||||
pstrEncParams->s16BitPool = 0;
|
||||
/* sampling freq */
|
||||
HeaderParams = ((pstrEncParams->s16SamplingFreq & 3)<< 6);
|
||||
|
||||
/* number of blocks*/
|
||||
HeaderParams |= (((pstrEncParams->s16NumOfBlocks -4) & 12) << 2);
|
||||
|
||||
/* channel mode: mono, dual...*/
|
||||
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)
|
||||
pstrEncParams->EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(4*10))>>2)<<2;
|
||||
else
|
||||
pstrEncParams->EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(4*10*2))>>3)<<2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pstrEncParams->s16NumOfChannels==1)
|
||||
pstrEncParams->EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(8*10))>>3)<<3;
|
||||
else
|
||||
pstrEncParams->EncMaxShiftCounter=((ENC_VX_BUFFER_SIZE-(8*10*2))>>4)<<3;
|
||||
}
|
||||
|
||||
// APPL_TRACE_EVENT("SBC_Encoder_Init : bitrate %d, bitpool %d",
|
||||
// pstrEncParams->u16BitRate, pstrEncParams->s16BitPool);
|
||||
|
||||
SbcAnalysisInit(pstrEncParams);
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* This file contains code for packing the Encoded data into bit streams.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sbc_encoder.h"
|
||||
#include "sbc_enc_func_declare.h"
|
||||
#include <stddef.h>
|
||||
#include "xc60xx.h"
|
||||
|
||||
#if (SBC_ARM_ASM_OPT==TRUE)
|
||||
#define Mult32(s32In1,s32In2,s32OutLow) \
|
||||
{ \
|
||||
__asm \
|
||||
{ \
|
||||
MUL s32OutLow,s32In1,s32In2; \
|
||||
} \
|
||||
}
|
||||
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
||||
{ \
|
||||
__asm \
|
||||
{ \
|
||||
SMULL s32OutLow,s32OutHi,s32In1,s32In2 \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define Mult32(s32In1,s32In2,s32OutLow) s32OutLow=(SINT32)s32In1*(SINT32)s32In2;
|
||||
#define Mult64(s32In1, s32In2, s32OutLow, s32OutHi) \
|
||||
{ \
|
||||
s32OutLow = ((SINT32)(UINT16)s32In1 * (UINT16)s32In2); \
|
||||
s32TempVal2 = (SINT32)((s32In1 >> 16) * (UINT16)s32In2); \
|
||||
s32Carry = ( (((UINT32)(s32OutLow)>>16)&0xFFFF) + \
|
||||
+ (s32TempVal2 & 0xFFFF) ) >> 16; \
|
||||
s32OutLow += (s32TempVal2 << 16); \
|
||||
s32OutHi = (s32TempVal2 >> 16) + s32Carry; \
|
||||
}
|
||||
#endif
|
||||
|
||||
__attribute__((section("ram_sbc_code"))) void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
|
||||
{
|
||||
UINT8 *pu8PacketPtr; /* packet ptr*/
|
||||
UINT8 Temp;
|
||||
SINT32 s32Blk; /* counter for block*/
|
||||
SINT32 s32Ch; /* counter for channel*/
|
||||
SINT32 s32Sb; /* counter for sub-band*/
|
||||
SINT32 s32PresentBit; /* represents bit to be stored*/
|
||||
/*SINT32 s32LoopCountI; loop counter*/
|
||||
SINT32 s32LoopCountJ; /* loop counter*/
|
||||
UINT32 u32QuantizedSbValue,u32QuantizedSbValue0; /* temp variable to store quantized sb val*/
|
||||
SINT32 s32LoopCount; /* loop counter*/
|
||||
UINT8 u8XoredVal; /* to store XORed value in CRC calculation*/
|
||||
UINT8 u8CRC; /* to store CRC value*/
|
||||
SINT16 *ps16GenPtr;
|
||||
SINT32 s32NumOfBlocks;
|
||||
SINT32 s32NumOfSubBands = pstrEncParams->s16NumOfSubBands;
|
||||
SINT32 s32NumOfChannels = pstrEncParams->s16NumOfChannels;
|
||||
UINT32 u32SfRaisedToPow2; /*scale factor raised to power 2*/
|
||||
SINT16 *ps16ScfPtr;
|
||||
SINT32 *ps32SbPtr;
|
||||
UINT16 u16Levels; /*to store levels*/
|
||||
SINT32 s32Temp1; /*used in 64-bit multiplication*/
|
||||
SINT32 s32Low; /*used in 64-bit multiplication*/
|
||||
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
||||
SINT32 s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2;
|
||||
#endif
|
||||
|
||||
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
||||
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
uint8_t * reserved_ptr = NULL;
|
||||
if (pstrEncParams->mSBCEnabled){
|
||||
*pu8PacketPtr++ = (UINT8)0xAD; /*Sync word*/
|
||||
reserved_ptr = pu8PacketPtr;
|
||||
} else {
|
||||
*pu8PacketPtr++ = (UINT8)0x9C; /*Sync word*/
|
||||
}
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
*pu8PacketPtr++=(UINT8)(pstrEncParams->FrameHeader);
|
||||
|
||||
*pu8PacketPtr = (UINT8)(pstrEncParams->s16BitPool & 0x00FF);
|
||||
pu8PacketPtr += 2; /*skip for CRC*/
|
||||
|
||||
/*here it indicate if it is byte boundary or nibble boundary*/
|
||||
s32PresentBit = 8;
|
||||
Temp=0;
|
||||
#if (SBC_JOINT_STE_INCLUDED == TRUE)
|
||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
||||
{
|
||||
/* pack join stero parameters */
|
||||
for (s32Sb = 0; s32Sb < s32NumOfSubBands; s32Sb++)
|
||||
{
|
||||
Temp <<= 1;
|
||||
Temp |= pstrEncParams->as16Join[s32Sb];
|
||||
}
|
||||
|
||||
/* pack RFA */
|
||||
if (s32NumOfSubBands == SUB_BANDS_4)
|
||||
{
|
||||
s32PresentBit = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
*(pu8PacketPtr++)=Temp;
|
||||
Temp = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pack Scale factor */
|
||||
ps16GenPtr = pstrEncParams->as16ScaleFactor;
|
||||
s32Sb=s32NumOfChannels*s32NumOfSubBands;
|
||||
/*Temp=*pu8PacketPtr;*/
|
||||
for (s32Ch = s32Sb; s32Ch >0; s32Ch--)
|
||||
{
|
||||
Temp<<= 4;
|
||||
Temp |= *ps16GenPtr++;
|
||||
|
||||
if(s32PresentBit == 4)
|
||||
{
|
||||
s32PresentBit = 8;
|
||||
*(pu8PacketPtr++)=Temp;
|
||||
Temp = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
s32PresentBit = 4;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pack samples */
|
||||
ps32SbPtr = pstrEncParams->s32SbBuffer;
|
||||
/*Temp=*pu8PacketPtr;*/
|
||||
s32NumOfBlocks= pstrEncParams->s16NumOfBlocks;
|
||||
for (s32Blk = s32NumOfBlocks-1; s32Blk >=0; s32Blk--)
|
||||
{
|
||||
ps16GenPtr = pstrEncParams->as16Bits;
|
||||
ps16ScfPtr = pstrEncParams->as16ScaleFactor;
|
||||
for (s32Ch = s32Sb-1; s32Ch >= 0; s32Ch--)
|
||||
{
|
||||
s32LoopCount = *ps16GenPtr++;
|
||||
if (s32LoopCount != 0)
|
||||
{
|
||||
#if (SBC_IS_64_MULT_IN_QUANTIZER==TRUE)
|
||||
/* finding level from reconstruction part of decoder */
|
||||
u32SfRaisedToPow2 = ((UINT32)1 << ((*ps16ScfPtr)+1));
|
||||
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount) - 1);
|
||||
|
||||
/* quantizer */
|
||||
s32Temp1 = (*ps32SbPtr >> 2) + (u32SfRaisedToPow2 << 12);
|
||||
s32Temp2 = u16Levels;
|
||||
|
||||
Mult64 (s32Temp1, s32Temp2, s32Low, s32Hi);
|
||||
|
||||
s32Low1 = s32Low >> ((*ps16ScfPtr)+2);
|
||||
s32Low1 &= ((UINT32)1 << (32 - ((*ps16ScfPtr)+2))) - 1;
|
||||
s32Hi1 = s32Hi << (32 - ((*ps16ScfPtr) +2));
|
||||
|
||||
u32QuantizedSbValue0 = (UINT16)((s32Low1 | s32Hi1) >> 12);
|
||||
#else
|
||||
/* finding level from reconstruction part of decoder */
|
||||
u32SfRaisedToPow2 = ((UINT32)1 << *ps16ScfPtr);
|
||||
u16Levels = (UINT16)(((UINT32)1 << s32LoopCount)-1);
|
||||
|
||||
/* quantizer */
|
||||
s32Temp1 = (*ps32SbPtr >> 15) + u32SfRaisedToPow2;
|
||||
Mult32(s32Temp1,u16Levels,s32Low);
|
||||
s32Low>>= (*ps16ScfPtr+1);
|
||||
u32QuantizedSbValue0 = (UINT16)s32Low;
|
||||
#endif
|
||||
/*store the number of bits required and the quantized s32Sb
|
||||
sample to ease the coding*/
|
||||
u32QuantizedSbValue = u32QuantizedSbValue0;
|
||||
|
||||
if(s32PresentBit >= s32LoopCount)
|
||||
{
|
||||
Temp <<= s32LoopCount;
|
||||
Temp |= u32QuantizedSbValue;
|
||||
s32PresentBit -= s32LoopCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (s32PresentBit < s32LoopCount)
|
||||
{
|
||||
s32LoopCount -= s32PresentBit;
|
||||
u32QuantizedSbValue >>= s32LoopCount;
|
||||
|
||||
/*remove the unwanted msbs*/
|
||||
/*u32QuantizedSbValue <<= 16 - s32PresentBit;
|
||||
u32QuantizedSbValue >>= 16 - s32PresentBit;*/
|
||||
|
||||
Temp <<= s32PresentBit;
|
||||
|
||||
Temp |= u32QuantizedSbValue ;
|
||||
/*restore the original*/
|
||||
u32QuantizedSbValue=u32QuantizedSbValue0;
|
||||
|
||||
*(pu8PacketPtr++)=Temp;
|
||||
Temp = 0;
|
||||
s32PresentBit = 8;
|
||||
}
|
||||
Temp <<= s32LoopCount;
|
||||
|
||||
/* remove the unwanted msbs */
|
||||
/*u32QuantizedSbValue <<= 16 - s32LoopCount;
|
||||
u32QuantizedSbValue >>= 16 - s32LoopCount;*/
|
||||
|
||||
Temp |= u32QuantizedSbValue;
|
||||
|
||||
s32PresentBit -= s32LoopCount;
|
||||
}
|
||||
}
|
||||
ps16ScfPtr++;
|
||||
ps32SbPtr++;
|
||||
}
|
||||
}
|
||||
|
||||
Temp <<= s32PresentBit;
|
||||
*pu8PacketPtr=Temp;
|
||||
pstrEncParams->u16PacketLength= (uint16_t)(pu8PacketPtr-pstrEncParams->pu8NextPacket)+1;
|
||||
/*find CRC*/
|
||||
pu8PacketPtr = pstrEncParams->pu8NextPacket+1; /*Initialize the ptr*/
|
||||
u8CRC = 0x0F;
|
||||
s32LoopCount = s32Sb >> 1;
|
||||
|
||||
/* BK4BTSTACK_CHANGE START */
|
||||
if (reserved_ptr){
|
||||
// overwrite fixed values for mSBC before CRC calculation
|
||||
*reserved_ptr++ = 0;
|
||||
*reserved_ptr++ = 0;
|
||||
}
|
||||
/* BK4BTSTACK_CHANGE END */
|
||||
|
||||
|
||||
/*
|
||||
The loops is run from the start of the packet till the scale factor
|
||||
parameters. In case of JS, 'join' parameter is included in the packet
|
||||
so that many more bytes are included in CRC calculation.
|
||||
*/
|
||||
Temp=*pu8PacketPtr;
|
||||
for (s32Ch=1; s32Ch < (s32LoopCount+4); s32Ch++)
|
||||
{
|
||||
/* skip sync word and CRC bytes */
|
||||
if (s32Ch != 3)
|
||||
{
|
||||
for (s32LoopCountJ=7; s32LoopCountJ>=0; s32LoopCountJ--)
|
||||
{
|
||||
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
|
||||
u8CRC <<= 1;
|
||||
u8CRC ^= (u8XoredVal * 0x1D);
|
||||
u8CRC &= 0xFF;
|
||||
}
|
||||
}
|
||||
Temp=*(++pu8PacketPtr);
|
||||
}
|
||||
|
||||
if (pstrEncParams->s16ChannelMode == SBC_JOINT_STEREO)
|
||||
{
|
||||
for (s32LoopCountJ = 7; s32LoopCountJ >= (8 - s32NumOfSubBands); s32LoopCountJ--)
|
||||
{
|
||||
u8XoredVal = ((u8CRC >> 7) & 0x01) ^((Temp >> s32LoopCountJ) & 0x01);
|
||||
u8CRC <<= 1;
|
||||
u8CRC ^= (u8XoredVal * 0x1D);
|
||||
u8CRC &= 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
/* CRC calculation ends here */
|
||||
|
||||
/* store CRC in packet */
|
||||
pu8PacketPtr = pstrEncParams->pu8NextPacket; /*Initialize the ptr*/
|
||||
pu8PacketPtr += 3;
|
||||
*pu8PacketPtr = u8CRC;
|
||||
pstrEncParams->pu8NextPacket+=pstrEncParams->u16PacketLength; /* move the pointer to the end in case there is more than one frame to encode */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user