sbc_encoder.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains constants and structures used by Encoder.
  21. *
  22. ******************************************************************************/
  23. #ifndef SBC_ENCODER_H
  24. #define SBC_ENCODER_H
  25. #define ENCODER_VERSION "0025"
  26. #ifdef BUILDCFG
  27. #include "bt_target.h"
  28. #endif
  29. /*DEFINES*/
  30. #ifndef FALSE
  31. #define FALSE 0
  32. #endif
  33. #ifndef TRUE
  34. #define TRUE (!FALSE)
  35. #endif
  36. /* BK4BTSTACK_CHANGE START */
  37. #define SBC_NO_PCM_CPY_OPTION TRUE
  38. /* BK4BTSTACK_CHANGE END */
  39. #define SBC_MAX_NUM_OF_SUBBANDS 8
  40. #define SBC_MAX_NUM_OF_CHANNELS 2
  41. #define SBC_MAX_NUM_OF_BLOCKS 16
  42. #define SBC_LOUDNESS 0
  43. #define SBC_SNR 1
  44. #define SUB_BANDS_8 8
  45. #define SUB_BANDS_4 4
  46. #define SBC_sf16000 0
  47. #define SBC_sf32000 1
  48. #define SBC_sf44100 2
  49. #define SBC_sf48000 3
  50. #define SBC_MONO 0
  51. #define SBC_DUAL 1
  52. #define SBC_STEREO 2
  53. #define SBC_JOINT_STEREO 3
  54. #define SBC_BLOCK_0 4
  55. #define SBC_BLOCK_1 8
  56. #define SBC_BLOCK_2 12
  57. #define SBC_BLOCK_3 16
  58. #define SBC_NULL 0
  59. #ifndef SBC_MAX_NUM_FRAME
  60. #define SBC_MAX_NUM_FRAME 1
  61. #endif
  62. #ifndef SBC_DSP_OPT
  63. #define SBC_DSP_OPT FALSE
  64. #endif
  65. /* Set SBC_USE_ARM_PRAGMA to TRUE to use "#pragma arm section zidata" */
  66. #ifndef SBC_USE_ARM_PRAGMA
  67. #define SBC_USE_ARM_PRAGMA FALSE
  68. #endif
  69. /* Set SBC_ARM_ASM_OPT to TRUE in case the target is an ARM */
  70. /* this will replace all the 32 and 64 bit mult by in line assembly code */
  71. #ifndef SBC_ARM_ASM_OPT
  72. #define SBC_ARM_ASM_OPT FALSE
  73. #endif
  74. /* green hill compiler option -> Used to distinguish the syntax for inline assembly code*/
  75. #ifndef SBC_GHS_COMPILER
  76. #define SBC_GHS_COMPILER FALSE
  77. #endif
  78. /* ARM compiler option -> Used to distinguish the syntax for inline assembly code */
  79. #ifndef SBC_ARM_COMPILER
  80. #define SBC_ARM_COMPILER TRUE
  81. #endif
  82. /* Set SBC_IPAQ_OPT to TRUE in case the target is an ARM */
  83. /* 32 and 64 bit mult will be performed using SINT64 ( usualy __int64 ) cast that usualy give optimal performance if supported */
  84. #ifndef SBC_IPAQ_OPT
  85. #define SBC_IPAQ_OPT TRUE
  86. #endif
  87. /* Debug only: set SBC_IS_64_MULT_IN_WINDOW_ACCU to TRUE to use 64 bit multiplication in the windowing */
  88. /* -> not recomended, more MIPS for the same restitution. */
  89. #ifndef SBC_IS_64_MULT_IN_WINDOW_ACCU
  90. #define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE
  91. #endif /*SBC_IS_64_MULT_IN_WINDOW_ACCU */
  92. /* Set SBC_IS_64_MULT_IN_IDCT to TRUE to use 64 bits multiplication in the DCT of Matrixing */
  93. /* -> more MIPS required for a better audio quality. comparasion with the SIG utilities shows a division by 10 of the RMS */
  94. /* CAUTION: It only apply in the if SBC_FAST_DCT is set to TRUE */
  95. #ifndef SBC_IS_64_MULT_IN_IDCT
  96. #define SBC_IS_64_MULT_IN_IDCT FALSE
  97. #endif /*SBC_IS_64_MULT_IN_IDCT */
  98. /* set SBC_IS_64_MULT_IN_QUANTIZER to TRUE to use 64 bits multiplication in the quantizer */
  99. /* setting this flag to FALSE add whistling noise at 5.5 and 11 KHz usualy not perceptible by human's hears. */
  100. #ifndef SBC_IS_64_MULT_IN_QUANTIZER
  101. #define SBC_IS_64_MULT_IN_QUANTIZER TRUE
  102. #endif /*SBC_IS_64_MULT_IN_IDCT */
  103. /* Debug only: set this flag to FALSE to disable fast DCT algorithm */
  104. #ifndef SBC_FAST_DCT
  105. #define SBC_FAST_DCT TRUE
  106. #endif /*SBC_FAST_DCT */
  107. /* In case we do not use joint stereo mode the flag save some RAM and ROM in case it is set to FALSE */
  108. #ifndef SBC_JOINT_STE_INCLUDED
  109. #define SBC_JOINT_STE_INCLUDED TRUE
  110. #endif
  111. /* TRUE -> application should provide PCM buffer, FALSE PCM buffer reside in SBC_ENC_PARAMS */
  112. #ifndef SBC_NO_PCM_CPY_OPTION
  113. #define SBC_NO_PCM_CPY_OPTION FALSE
  114. #endif
  115. #define MINIMUM_ENC_VX_BUFFER_SIZE (8*10*2)
  116. #ifndef ENC_VX_BUFFER_SIZE
  117. #define ENC_VX_BUFFER_SIZE (MINIMUM_ENC_VX_BUFFER_SIZE + 64)
  118. /*#define ENC_VX_BUFFER_SIZE MINIMUM_ENC_VX_BUFFER_SIZE + 1024*/
  119. #endif
  120. #ifndef SBC_FOR_EMBEDDED_LINUX
  121. #define SBC_FOR_EMBEDDED_LINUX FALSE
  122. #endif
  123. /*constants used for index calculation*/
  124. #define SBC_BLK (SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS)
  125. #include "sbc_types.h"
  126. typedef struct SBC_ENC_PARAMS_TAG
  127. {
  128. SINT16 s16SamplingFreq; /* 16k, 32k, 44.1k or 48k*/
  129. SINT16 s16ChannelMode; /* mono, dual, streo or joint streo*/
  130. SINT16 s16NumOfSubBands; /* 4 or 8 */
  131. SINT16 s16NumOfChannels;
  132. SINT16 s16NumOfBlocks; /* SBC: 4, 8, 12 or 16; mSBC: 15*/
  133. SINT16 s16AllocationMethod; /* loudness or SNR*/
  134. SINT16 s16BitPool; /* 16*numOfSb for mono & dual;
  135. 32*numOfSb for stereo & joint stereo */
  136. /* BK4BTSTACK_CHANGE START */
  137. // UINT16 u16BitRate;
  138. /* BK4BTSTACK_CHANGE END */
  139. UINT8 u8NumPacketToEncode; /* number of sbc frame to encode. Default is 1 */
  140. #if (SBC_JOINT_STE_INCLUDED == TRUE)
  141. SINT16 as16Join[SBC_MAX_NUM_OF_SUBBANDS]; /*1 if JS, 0 otherwise*/
  142. #endif
  143. SINT16 s16MaxBitNeed;
  144. SINT16 as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
  145. SINT16 *ps16NextPcmBuffer;
  146. #if (SBC_NO_PCM_CPY_OPTION == TRUE)
  147. SINT16 *ps16PcmBuffer;
  148. #else
  149. SINT16 as16PcmBuffer[SBC_MAX_NUM_FRAME*SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
  150. #endif
  151. SINT16 s16ScartchMemForBitAlloc[16];
  152. SINT32 s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS * SBC_MAX_NUM_OF_BLOCKS];
  153. SINT16 as16Bits[SBC_MAX_NUM_OF_CHANNELS*SBC_MAX_NUM_OF_SUBBANDS];
  154. UINT8 *pu8Packet;
  155. UINT8 *pu8NextPacket;
  156. UINT16 FrameHeader;
  157. UINT16 u16PacketLength;
  158. /* BK4BTSTACK_CHANGE START */
  159. UINT8 mSBCEnabled;
  160. /* BK4BTSTACK_CHANGE END */
  161. }SBC_ENC_PARAMS;
  162. #ifdef __cplusplus
  163. extern "C"
  164. {
  165. #endif
  166. SBC_API extern void SBC_Encoder(SBC_ENC_PARAMS *strEncParams);
  167. SBC_API extern void SBC_Encoder_Init(SBC_ENC_PARAMS *strEncParams);
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif