Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit adc40aa5 authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Simplify SBC encoder API

Currently it is unclear what the input, output, and configuration of
the SBC codec are. This patch refactors the use of the SBC_Encoder
function. Parameters for input and output are added, instead of passing
them in alongside the configuration.

Test: Tested A2DP playback
Change-Id: I755a022983f823475c14815cc0610f90a5fbc813
parent 22a09e84
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -42,13 +42,13 @@ extern void sbc_enc_bit_alloc_ste(SBC_ENC_PARAMS *CodecParams);

extern void SbcAnalysisInit (void);

extern void SbcAnalysisFilter4(SBC_ENC_PARAMS *strEncParams);
extern void SbcAnalysisFilter8(SBC_ENC_PARAMS *strEncParams);
extern void SbcAnalysisFilter4(SBC_ENC_PARAMS *strEncParams, int16_t *input);
extern void SbcAnalysisFilter8(SBC_ENC_PARAMS *strEncParams, int16_t *input);

extern void SBC_FastIDCT8 (int32_t *pInVect, int32_t *pOutVect);
extern void SBC_FastIDCT4 (int32_t *x0, int32_t *pOutVect);

extern void EncPacking(SBC_ENC_PARAMS *strEncParams);
extern uint32_t EncPacking(SBC_ENC_PARAMS *strEncParams, uint8_t *output);
extern void EncQuantizer(SBC_ENC_PARAMS *);
#if (SBC_DSP_OPT == TRUE)
    int32_t SBC_Multiply_32_16_Simplified(int32_t s32In2Temp,int32_t s32In1Temp);
+5 −17
Original line number Diff line number Diff line
@@ -131,11 +131,6 @@
#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)
@@ -149,6 +144,8 @@
/*constants used for index calculation*/
#define SBC_BLK (SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS)

#define SBC_MAX_PCM_BUFFER_SIZE (SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS)

#include "sbc_types.h"

typedef struct SBC_ENC_PARAMS_TAG
@@ -162,7 +159,6 @@ typedef struct SBC_ENC_PARAMS_TAG
    int16_t s16BitPool;                              /* 16*numOfSb for mono & dual;
                                                       32*numOfSb for stereo & joint stereo */
    uint16_t u16BitRate;
    uint8_t u8NumPacketToEncode;                    /* number of sbc frame to encode. Default is 1 */
#if (SBC_JOINT_STE_INCLUDED == TRUE)
    int16_t as16Join[SBC_MAX_NUM_OF_SUBBANDS];       /*1 if JS, 0 otherwise*/
#endif
@@ -170,23 +166,13 @@ typedef struct SBC_ENC_PARAMS_TAG
    int16_t s16MaxBitNeed;
    int16_t as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];

    int16_t *ps16NextPcmBuffer;
#if (SBC_NO_PCM_CPY_OPTION == TRUE)
    int16_t *ps16PcmBuffer;
#else
    int16_t as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
#endif

    int16_t  s16ScartchMemForBitAlloc[16];

    int32_t  s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];

    int16_t as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];

    uint8_t  *pu8Packet;
    uint8_t  *pu8NextPacket;
    uint16_t FrameHeader;
    uint16_t u16PacketLength;

}SBC_ENC_PARAMS;

@@ -194,7 +180,9 @@ typedef struct SBC_ENC_PARAMS_TAG
extern "C" {
#endif

extern void SBC_Encoder(SBC_ENC_PARAMS *strEncParams);
/* Encode the frame using SBC. The output is written into |output|. Return number of
 * bytes written. */
extern uint32_t SBC_Encode(SBC_ENC_PARAMS *strEncParams, int16_t *input, uint8_t *output);
extern void SBC_Encoder_Init(SBC_ENC_PARAMS *strEncParams);

#ifdef __cplusplus
+4 −4
Original line number Diff line number Diff line
@@ -904,7 +904,7 @@ extern int16_t EncMaxShiftCounter;
*
* RETURNS : N/A
*/
void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams, int16_t *input)
{
    int16_t *ps16PcmBuf;
    int32_t *ps32SbBuf;
@@ -933,7 +933,7 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
    s32NumOfChannels = pstrEncParams->s16NumOfChannels;
    s32NumOfBlocks   = pstrEncParams->s16NumOfBlocks;

    ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
    ps16PcmBuf = input;

    ps32SbBuf  = pstrEncParams->s32SbBuffer;
    Offset2=(int32_t)(EncMaxShiftCounter+40);
@@ -997,7 +997,7 @@ void SbcAnalysisFilter4(SBC_ENC_PARAMS *pstrEncParams)
}

/* //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams, int16_t *input)
{
    int16_t *ps16PcmBuf;
    int32_t *ps32SbBuf;
@@ -1025,7 +1025,7 @@ void SbcAnalysisFilter8 (SBC_ENC_PARAMS *pstrEncParams)
    s32NumOfChannels = pstrEncParams->s16NumOfChannels;
    s32NumOfBlocks   = pstrEncParams->s16NumOfBlocks;

    ps16PcmBuf = pstrEncParams->ps16NextPcmBuffer;
    ps16PcmBuf = input;

    ps32SbBuf  = pstrEncParams->s32SbBuffer;
    Offset2=(int32_t)(EncMaxShiftCounter+80);
+90 −111
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ int32_t s32LRDiff[SBC_MAX_NUM_OF_BLOCKS] = {0};
int32_t   s32LRSum[SBC_MAX_NUM_OF_BLOCKS]     = {0};
#endif

void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
uint32_t SBC_Encode(SBC_ENC_PARAMS *pstrEncParams, int16_t *input, uint8_t *output)
{
    int32_t s32Ch;                               /* counter for ch*/
    int32_t s32Sb;                               /* counter for sub-band*/
@@ -50,30 +50,18 @@ void SBC_Encoder(SBC_ENC_PARAMS *pstrEncParams)
    uint32_t u32CountSum,u32CountDiff;
    int32_t *pSum, *pDiff;
#endif
    uint8_t  *pu8;
    register int32_t  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);
        SbcAnalysisFilter4(pstrEncParams, input);
    else
            SbcAnalysisFilter8(pstrEncParams);
        SbcAnalysisFilter8(pstrEncParams, input);

    /* 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;
@@ -183,15 +171,8 @@ void SBC_Encoder(SBC_ENC_PARAMS *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 */

    return EncPacking(pstrEncParams, output);
}

/****************************************************************************
@@ -207,8 +188,6 @@ void SBC_Encoder_Init(SBC_ENC_PARAMS *pstrEncParams)
    int16_t s16FrameLen;     /*to store frame length*/
    uint16_t HeaderParams;

    pstrEncParams->u8NumPacketToEncode = 1; /* default is one for retrocompatibility purpose */

    /* Required number of channels */
    if (pstrEncParams->s16ChannelMode == SBC_MONO)
        pstrEncParams->s16NumOfChannels = 1;
+7 −8
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@
}
#endif

void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
/* return number of bytes written to output */
uint32_t EncPacking(SBC_ENC_PARAMS *pstrEncParams, uint8_t *output)
{
    uint8_t     *pu8PacketPtr;                      /* packet ptr*/
    uint8_t Temp;
@@ -81,7 +82,7 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
	int32_t s32Hi1,s32Low1,s32Carry,s32TempVal2,s32Hi, s32Temp2;
#endif

    pu8PacketPtr    = pstrEncParams->pu8NextPacket;    /*Initialize the ptr*/
    pu8PacketPtr    = output;    /*Initialize the ptr*/
    *pu8PacketPtr++ = (uint8_t)0x9C;  /*Sync word*/
    *pu8PacketPtr++=(uint8_t)(pstrEncParams->FrameHeader);

@@ -224,9 +225,9 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)

    Temp <<= s32PresentBit;
    *pu8PacketPtr=Temp;
    pstrEncParams->u16PacketLength=pu8PacketPtr-pstrEncParams->pu8NextPacket+1;
    uint32_t u16PacketLength=pu8PacketPtr-output+1;
    /*find CRC*/
    pu8PacketPtr = pstrEncParams->pu8NextPacket+1;    /*Initialize the ptr*/
    pu8PacketPtr = output+1;    /*Initialize the ptr*/
    u8CRC = 0x0F;
    s32LoopCount = s32Sb >> 1;

@@ -266,9 +267,7 @@ void EncPacking(SBC_ENC_PARAMS *pstrEncParams)
    /* 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 */
    output[3] = u8CRC;
    return u16PacketLength;
}
Loading