Commit f0d1199e0d215319f70f5f209a85f7fb57f0aba5

Authored by LuoZheSi
1 parent fed675ea

refactor(hfp msbc decode):improve PLC and fix no sound issue when connect with win10 in hfp mode

@@ -688,8 +688,8 @@ void xa_msbc_dec_init (void) @@ -688,8 +688,8 @@ void xa_msbc_dec_init (void)
688 688
689 /* End second part */ 689 /* End second part */
690 } /* end xa_param_file_process */ 690 } /* end xa_param_file_process */
691 -void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen) __attribute__ ((section (".internal_ram_1_text")));  
692 -void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen) 691 +void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen, U8 loss_flag) __attribute__ ((section (".internal_ram_1_text")));
  692 +void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen, U8 loss_flag)
693 { 693 {
694 /* Error code */ 694 /* Error code */
695 XA_ERRORCODE err_code = XA_NO_ERROR; 695 XA_ERRORCODE err_code = XA_NO_ERROR;
@@ -709,8 +709,7 @@ void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen) @@ -709,8 +709,7 @@ void xa_msbc_dec_frame(U8 *pInBuf, U16 inLen, U8 **pOutBuf, U32 *pOutDataLen)
709 p_xa_process_api = xa_msbc_dec; 709 p_xa_process_api = xa_msbc_dec;
710 p_proc_err_info = &xa_msbc_dec_error_info; 710 p_proc_err_info = &xa_msbc_dec_error_info;
711 711
712 -  
713 - if (pInBuf[0] == 0xAD) 712 + if (!loss_flag)
714 { 713 {
715 //*pOutDataLen = 0; 714 //*pOutDataLen = 0;
716 //*pOutBuf = 0; 715 //*pOutBuf = 0;
@@ -736,6 +736,9 @@ extern FIFO *hfp_upstream_fifo; @@ -736,6 +736,9 @@ extern FIFO *hfp_upstream_fifo;
736 #define HFP_PCM_FRAME_SIZE (120*2*3*2) 736 #define HFP_PCM_FRAME_SIZE (120*2*3*2)
737 #define HFP_mSBC_READ_SIZE 60 737 #define HFP_mSBC_READ_SIZE 60
738 738
  739 +U8 msbc_data_size;
  740 +U8 last_sepuence;
  741 +
739 U8 *pmsbc; 742 U8 *pmsbc;
740 U8 *p48kpcm; 743 U8 *p48kpcm;
741 744
@@ -753,6 +756,11 @@ void hfp_dec_init(void) @@ -753,6 +756,11 @@ void hfp_dec_init(void)
753 756
754 DBG_Printf("hfp dec init\n\r"); 757 DBG_Printf("hfp dec init\n\r");
755 758
  759 +
  760 + msbc_data_size = 0;
  761 +
  762 + last_sepuence = 0xff;
  763 +
756 app_main_data.audio_src_bit = AUDIO_SRC_16BIT; 764 app_main_data.audio_src_bit = AUDIO_SRC_16BIT;
757 765
758 app_main_data.playing_stream_chans = 2; 766 app_main_data.playing_stream_chans = 2;
@@ -844,6 +852,7 @@ int hfp_dec_decode(U8 **pout,U16 *plen) @@ -844,6 +852,7 @@ int hfp_dec_decode(U8 **pout,U16 *plen)
844 852
845 if (hfp_get_codec() == 2) 853 if (hfp_get_codec() == 2)
846 { 854 {
  855 + /**********upstream part start*************/
847 fifo_put_data_by_dma (&AdcInFifo,DMA_2_DEST); 856 fifo_put_data_by_dma (&AdcInFifo,DMA_2_DEST);
848 857
849 dlen = fifo_get_fifo_data_len(&AdcInFifo); 858 dlen = fifo_get_fifo_data_len(&AdcInFifo);
@@ -892,12 +901,109 @@ int hfp_dec_decode(U8 **pout,U16 *plen) @@ -892,12 +901,109 @@ int hfp_dec_decode(U8 **pout,U16 *plen)
892 901
893 fifo_put_data (hfp_upstream_fifo, pOutBuf,size); 902 fifo_put_data (hfp_upstream_fifo, pOutBuf,size);
894 903
  904 + /**********upstream part end*************/
  905 +
  906 +
  907 + /**********downstream part start*************/
  908 +
  909 + U8 sepuence;
  910 +
895 dlen = AUDIO_FIFO_STREAM_DATA_LEN(); 911 dlen = AUDIO_FIFO_STREAM_DATA_LEN();
896 912
897 if (dlen >= HFP_mSBC_READ_SIZE) 913 if (dlen >= HFP_mSBC_READ_SIZE)
898 { 914 {
899 - dlen = AUDIO_FIFO_STREAM_GET_DATA(pmsbc, HFP_mSBC_READ_SIZE);  
900 - xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize); 915 + dlen = AUDIO_FIFO_STREAM_GET_DATA(pmsbc + msbc_data_size, HFP_mSBC_READ_SIZE - msbc_data_size);
  916 +
  917 + sepuence = (pmsbc[1]&0xf0);
  918 +
  919 + switch (sepuence)
  920 + {
  921 + case 0x0:
  922 + //sepuence = 0;
  923 + break;
  924 + case 0x30:
  925 + sepuence = 1;
  926 + break;
  927 + case 0xc0:
  928 + sepuence = 2;
  929 + break;
  930 + case 0xf0:
  931 + sepuence = 3;
  932 + break;
  933 + default :
  934 + sepuence = 0xff;
  935 + break;
  936 + }
  937 +
  938 + if (last_sepuence == 0xff)
  939 + last_sepuence = sepuence;
  940 + else
  941 + {
  942 + last_sepuence++;
  943 + last_sepuence %= 4;
  944 + }
  945 +
  946 + if (pmsbc[2] == 0xAD)
  947 + {
  948 + if (last_sepuence == sepuence)
  949 + {
  950 + msbc_data_size = 0;
  951 + xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize,FALSE);
  952 + }
  953 + else
  954 + {
  955 + DBG_printf("sepuence number is discontinuous,should be %d, curr is %d\r\n",last_sepuence,sepuence);
  956 + if (sepuence == 0xff)
  957 + {
  958 + //wrong sepuence number
  959 + msbc_data_size = 0;
  960 + xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize,TRUE);
  961 + }
  962 + else
  963 + {
  964 + msbc_data_size = 60;
  965 + xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize,TRUE);
  966 + }
  967 + }
  968 + }
  969 + else
  970 + {
  971 + //msbc sync data is wrong
  972 + xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize,TRUE);
  973 +
  974 + for (i=0; i<(HFP_mSBC_READ_SIZE-2); i++)
  975 + {
  976 + if (pmsbc[i] == 1 && pmsbc[i+2] == 0xAD)
  977 + {
  978 + break;
  979 + }
  980 + }
  981 +
  982 + if (i != (HFP_mSBC_READ_SIZE-2))
  983 + {
  984 + U8 start_p = i;
  985 +
  986 + msbc_data_size = HFP_mSBC_READ_SIZE - i;
  987 + for (i=0; i<msbc_data_size; i++)
  988 + {
  989 + pmsbc[i] = pmsbc[i+start_p];
  990 + }
  991 +
  992 + }
  993 + else
  994 + {
  995 + msbc_data_size = 0;
  996 + }
  997 +
  998 + //DBG_printf("msbc sync data is wrong\r\n");
  999 + }
  1000 +
  1001 + if (outputsize != 240)
  1002 + {
  1003 + //outputsize not right,maybe is decode err
  1004 + xa_msbc_dec_frame(pmsbc+2,57,&pOut,&outputsize,TRUE);
  1005 + DBG_printf("decode err:%d\r\n",outputsize);
  1006 + }
901 } 1007 }
902 else 1008 else
903 { 1009 {
@@ -923,12 +1029,12 @@ int hfp_dec_decode(U8 **pout,U16 *plen) @@ -923,12 +1029,12 @@ int hfp_dec_decode(U8 **pout,U16 *plen)
923 } 1029 }
924 else 1030 else
925 { 1031 {
926 - DBG_Printf("msbc dec err\r\n");  
927 memset(p48kpcm,0,HFP_PCM_FRAME_SIZE); 1032 memset(p48kpcm,0,HFP_PCM_FRAME_SIZE);
928 } 1033 }
929 - //dec_direct_out(p48kpcm,HFP_PCM_FRAME_SIZE); 1034 +
930 *pout = p48kpcm; 1035 *pout = p48kpcm;
931 *plen = HFP_PCM_FRAME_SIZE; 1036 *plen = HFP_PCM_FRAME_SIZE;
  1037 + /**********downstream part end*************/
932 1038
933 return DECODE_SUCCESS; 1039 return DECODE_SUCCESS;
934 } 1040 }
@@ -2336,7 +2336,7 @@ U32 app_dec_hfp_stream_write(U8 *ptr, U32 len) @@ -2336,7 +2336,7 @@ U32 app_dec_hfp_stream_write(U8 *ptr, U32 len)
2336 //codec err, dead??? 2336 //codec err, dead???
2337 2337
2338 //codec err, dead??? 2338 //codec err, dead???
2339 - //ukMsgSend(app_nav_codec_reinit); 2339 + ukMsgSend(app_nav_bt_codec_reinit);
2340 //return; 2340 //return;
2341 } 2341 }
2342 2342
Please register or login to post a comment