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