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