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

Commit 6de1be21 authored by En-Shuo Hsu's avatar En-Shuo Hsu
Browse files

floss: Fix mSBC encoder

The two bytes after sync word should be reserved as zero based on HFP
specification. Setting non-zero value to them may cause HF side not able
to decode the encoded mSBC packet correctly.

Bug: 236413634
Tag: #floss
Test: Build and verify with devices supporting WBS

Change-Id: Ia9a71eb5243ed4b9b335a3b9006d650dc00bf2ca
parent 6f73cd78
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -68,7 +68,8 @@

#define SBC_NULL 0

#define SBC_MSBC_SYNCWORD 0xAD
#define SBC_FORMAT_GENERAL 0
#define SBC_FORMAT_MSBC 1

#ifndef SBC_MAX_NUM_FRAME
#define SBC_MAX_NUM_FRAME 1
@@ -189,8 +190,8 @@ typedef struct SBC_ENC_PARAMS_TAG {
  int16_t as16Bits[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];

  uint16_t FrameHeader;
  uint8_t SyncWord; /* Default to be 0x9C for SBC if not assigned.
                       Assigning to 0xAD for mSBC */
  uint8_t Format; /* Default to be SBC_FORMAT_GENERAL for SBC if not assigned.
                    Assigning to SBC_FORMAT_MSBC for mSBC */

} SBC_ENC_PARAMS;

+10 −6
Original line number Diff line number Diff line
@@ -80,15 +80,19 @@ uint32_t EncPacking(SBC_ENC_PARAMS* pstrEncParams, uint8_t* output) {
#endif

  pu8PacketPtr = output; /*Initialize the ptr*/
  if (!pstrEncParams->SyncWord) {
    *pu8PacketPtr++ = (uint8_t)0x9C; /*Sync word*/
  if (pstrEncParams->Format == SBC_FORMAT_MSBC) {
    *pu8PacketPtr++ = (uint8_t)0xAD; /*Sync word*/
  } else {
    *pu8PacketPtr++ = pstrEncParams->SyncWord; /*Sync word*/
    *pu8PacketPtr++ = (uint8_t)0x9C; /*Sync word*/
  }
  *pu8PacketPtr++ = (uint8_t)(pstrEncParams->FrameHeader);

  if (pstrEncParams->Format == SBC_FORMAT_MSBC) {
    pu8PacketPtr += 3; /* Skip reserved bytes and CRC */
  } else {
    *pu8PacketPtr++ = (uint8_t)(pstrEncParams->FrameHeader);
    *pu8PacketPtr = (uint8_t)(pstrEncParams->s16BitPool & 0x00FF);
  pu8PacketPtr += 2; /*skip for CRC*/
    pu8PacketPtr += 2; /* Skip for CRC */
  }

  /*here it indicate if it is byte boundary or nibble boundary*/
  s32PresentBit = 8;
+6 −9
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@

#include "hfp_msbc_encoder.h"

#include <cstring>

#include "embdrv/sbc/encoder/include/sbc_encoder.h"
#include "osi/include/log.h"

@@ -25,9 +27,9 @@ typedef struct {
  SBC_ENC_PARAMS sbc_encoder_params;
} tHFP_MSBC_ENCODER;

static tHFP_MSBC_ENCODER hfp_msbc_encoder;
static tHFP_MSBC_ENCODER hfp_msbc_encoder = {};

bool hfp_msbc_encoder_init(void) {
void hfp_msbc_encoder_init(void) {
  SBC_ENC_PARAMS* p_encoder_params = &hfp_msbc_encoder.sbc_encoder_params;
  p_encoder_params->s16SamplingFreq = SBC_sf16000;
  p_encoder_params->s16ChannelMode = SBC_MONO;
@@ -36,15 +38,10 @@ bool hfp_msbc_encoder_init(void) {
  p_encoder_params->s16NumOfBlocks = 15;
  p_encoder_params->s16AllocationMethod = SBC_LOUDNESS;
  p_encoder_params->s16BitPool = 26;
  p_encoder_params->FrameHeader = 0;
  p_encoder_params->SyncWord = SBC_MSBC_SYNCWORD;

  return true;
  p_encoder_params->Format = SBC_FORMAT_MSBC;
}

void hfp_msbc_encoder_cleanup(void) {
  memset(&hfp_msbc_encoder, 0, sizeof(hfp_msbc_encoder));
}
void hfp_msbc_encoder_cleanup(void) { hfp_msbc_encoder = {}; }

// Get the HFP MSBC encoded maximum frame size
uint32_t hfp_msbc_encode_frames(int16_t* input, uint8_t* output) {
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
#include <stdint.h>

// Initialize the HFP MSBC encoder.
bool hfp_msbc_encoder_init();
void hfp_msbc_encoder_init();

// Cleanup the HFP MSBC encoder.
void hfp_msbc_encoder_cleanup(void);