• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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  *
21  *  This file contains constants and structures used by Encoder.
22  *
23  ******************************************************************************/
24 
25 #ifndef SBC_ENCODER_H
26 #define SBC_ENCODER_H
27 
28 #define ENCODER_VERSION "0025"
29 
30 #include <stdbool.h>
31 #include <string.h>
32 
33 #include "bt_target.h"
34 
35 /*DEFINES*/
36 #ifndef FALSE
37 #define FALSE 0
38 #endif
39 
40 #ifndef TRUE
41 #define TRUE (!FALSE)
42 #endif
43 
44 #define SBC_MAX_NUM_OF_SUBBANDS 8
45 #define SBC_MAX_NUM_OF_CHANNELS 2
46 #define SBC_MAX_NUM_OF_BLOCKS 16
47 
48 #define SBC_LOUDNESS 0
49 #define SBC_SNR 1
50 
51 #define SUB_BANDS_8 8
52 #define SUB_BANDS_4 4
53 
54 #define SBC_sf16000 0
55 #define SBC_sf32000 1
56 #define SBC_sf44100 2
57 #define SBC_sf48000 3
58 
59 #define SBC_MONO 0
60 #define SBC_DUAL 1
61 #define SBC_STEREO 2
62 #define SBC_JOINT_STEREO 3
63 
64 #define SBC_BLOCK_0 4
65 #define SBC_BLOCK_1 8
66 #define SBC_BLOCK_2 12
67 #define SBC_BLOCK_3 16
68 
69 #define SBC_NULL 0
70 
71 #define SBC_FORMAT_GENERAL 0
72 #define SBC_FORMAT_MSBC 1
73 
74 #ifndef SBC_MAX_NUM_FRAME
75 #define SBC_MAX_NUM_FRAME 1
76 #endif
77 
78 #ifndef SBC_DSP_OPT
79 #define SBC_DSP_OPT FALSE
80 #endif
81 
82 /* Set SBC_USE_ARM_PRAGMA to TRUE to use "#pragma arm section zidata" */
83 #ifndef SBC_USE_ARM_PRAGMA
84 #define SBC_USE_ARM_PRAGMA FALSE
85 #endif
86 
87 /* Set SBC_ARM_ASM_OPT to TRUE in case the target is an ARM */
88 /* this will replace all the 32 and 64 bit mult by in line assembly code */
89 #ifndef SBC_ARM_ASM_OPT
90 #define SBC_ARM_ASM_OPT FALSE
91 #endif
92 
93 /* green hill compiler option -> Used to distinguish the syntax for inline
94  * assembly code
95  */
96 #ifndef SBC_GHS_COMPILER
97 #define SBC_GHS_COMPILER FALSE
98 #endif
99 
100 /* ARM compiler option -> Used to distinguish the syntax for inline assembly
101  * code */
102 #ifndef SBC_ARM_COMPILER
103 #define SBC_ARM_COMPILER TRUE
104 #endif
105 
106 /* Set SBC_IPAQ_OPT to TRUE in case the target is an ARM */
107 /* 32 and 64 bit mult will be performed using int64_t ( usualy __int64 ) cast
108  * that usualy give optimal performance if supported
109  */
110 #ifndef SBC_IPAQ_OPT
111 #define SBC_IPAQ_OPT TRUE
112 #endif
113 
114 /* Debug only: set SBC_IS_64_MULT_IN_WINDOW_ACCU to TRUE to use 64 bit
115  * multiplication in the windowing
116  */
117 /* -> not recomended, more MIPS for the same restitution.  */
118 #ifndef SBC_IS_64_MULT_IN_WINDOW_ACCU
119 #define SBC_IS_64_MULT_IN_WINDOW_ACCU FALSE
120 #endif /*SBC_IS_64_MULT_IN_WINDOW_ACCU */
121 
122 /* Set SBC_IS_64_MULT_IN_IDCT to TRUE to use 64 bits multiplication in the DCT
123  * of Matrixing
124  */
125 /* -> more MIPS required for a better audio quality. comparasion with the SIG
126  * utilities shows a division by 10 of the RMS
127  */
128 /* CAUTION: It only apply in the if SBC_FAST_DCT is set to TRUE */
129 #ifndef SBC_IS_64_MULT_IN_IDCT
130 #define SBC_IS_64_MULT_IN_IDCT FALSE
131 #endif /*SBC_IS_64_MULT_IN_IDCT */
132 
133 /* set SBC_IS_64_MULT_IN_QUANTIZER to TRUE to use 64 bits multiplication in the
134  * quantizer
135  */
136 /* setting this flag to FALSE adds a whistling noise at 5.5 and 11 KHz usualy
137  * not perceptible by human's hears. */
138 #ifndef SBC_IS_64_MULT_IN_QUANTIZER
139 #define SBC_IS_64_MULT_IN_QUANTIZER TRUE
140 #endif /*SBC_IS_64_MULT_IN_IDCT */
141 
142 /* Debug only: set this flag to FALSE to disable fast DCT algorithm */
143 #ifndef SBC_FAST_DCT
144 #define SBC_FAST_DCT TRUE
145 #endif /*SBC_FAST_DCT */
146 
147 /* In case we do not use joint stereo mode the flag save some RAM and ROM in
148  * case it is set to FALSE */
149 #ifndef SBC_JOINT_STE_INCLUDED
150 #define SBC_JOINT_STE_INCLUDED TRUE
151 #endif
152 
153 #define MINIMUM_ENC_VX_BUFFER_SIZE (8 * 10 * 2)
154 #ifndef ENC_VX_BUFFER_SIZE
155 #define ENC_VX_BUFFER_SIZE (MINIMUM_ENC_VX_BUFFER_SIZE + 64)
156 /*#define ENC_VX_BUFFER_SIZE MINIMUM_ENC_VX_BUFFER_SIZE + 1024*/
157 #endif
158 
159 /*constants used for index calculation*/
160 #define SBC_BLK (SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS)
161 
162 #define SBC_MAX_PCM_BUFFER_SIZE                                          \
163   (SBC_MAX_NUM_FRAME * SBC_MAX_NUM_OF_BLOCKS * SBC_MAX_NUM_OF_CHANNELS * \
164    SBC_MAX_NUM_OF_SUBBANDS)
165 
166 #include "sbc_types.h"
167 
168 typedef struct SBC_ENC_PARAMS_TAG {
169   int16_t s16SamplingFreq;  /* 16k, 32k, 44.1k or 48k*/
170   int16_t s16ChannelMode;   /* mono, dual, streo or joint streo*/
171   int16_t s16NumOfSubBands; /* 4 or 8 */
172   int16_t s16NumOfChannels;
173   int16_t s16NumOfBlocks;      /* 4, 8, 12 or 16*/
174   int16_t s16AllocationMethod; /* loudness or SNR*/
175   int16_t s16BitPool;          /* 16*numOfSb for mono & dual;
176                                  32*numOfSb for stereo & joint stereo */
177   uint16_t u16BitRate;
178 #if (SBC_JOINT_STE_INCLUDED == TRUE)
179   int16_t as16Join[SBC_MAX_NUM_OF_SUBBANDS]; /*1 if JS, 0 otherwise*/
180 #endif
181 
182   int16_t s16MaxBitNeed;
183   int16_t as16ScaleFactor[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
184 
185   int16_t s16ScartchMemForBitAlloc[16];
186 
187   int32_t s32SbBuffer[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS *
188                       SBC_MAX_NUM_OF_BLOCKS];
189 
190   int16_t as16Bits[SBC_MAX_NUM_OF_CHANNELS * SBC_MAX_NUM_OF_SUBBANDS];
191 
192   uint16_t FrameHeader;
193   uint8_t Format; /* Default to be SBC_FORMAT_GENERAL for SBC if not assigned.
194                     Assigning to SBC_FORMAT_MSBC for mSBC */
195 
196 } SBC_ENC_PARAMS;
197 
198 #ifdef __cplusplus
199 extern "C" {
200 #endif
201 
202 /* Encode the frame using SBC. The output is written into |output|. Return
203  * number of bytes written. */
204 uint32_t SBC_Encode(SBC_ENC_PARAMS* strEncParams, int16_t* input,
205                     uint8_t* output);
206 void SBC_Encoder_Init(SBC_ENC_PARAMS* strEncParams);
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 
212 #endif /* SBC_ENCODER_H */
213