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