1 // Copyright (C) 2022 Beken Corporation 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #pragma once 16 17 #include <driver/int_types.h> 18 #include <common/bk_include.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 25 typedef void (*sbc_decoder_isr_t)(void *param); 26 27 #define SBC_SYNCWORD 0x9C /**< SBC synchronize word */ 28 #define MSBC_SYNCWORD 0xAD /**< MSBC synchronize word */ 29 #define SBC_CHANNEL_MODE_MONO 0x00 /**< SBC channel mode : MONO */ 30 #define SBC_CHANNEL_MODE_DUAL 0x01 /**< SBC channel mode : Dual Channels */ 31 #define SBC_CHANNEL_MODE_STEREO 0x02 /**< SBC channel mode : Stereo */ 32 #define SBC_CHANNEL_MODE_JOINT_STEREO 0x03 /**< SBC channel mode : Joint Stereo */ 33 34 #define SBC_DECODER_ERRORS BK_ERR_SBC_BASE 35 #define SBC_DECODER_ERROR_BUFFER_OVERFLOW BK_ERR_SBC_BASE - 1 /**< buffer overflow */ 36 #define SBC_DECODER_ERROR_SYNC_INCORRECT BK_ERR_SBC_BASE - 2 /**< synchronize incorrect */ 37 #define SBC_DECODER_ERROR_BITPOOL_OUT_BOUNDS BK_ERR_SBC_BASE - 3 /**< bitpool out of bounds */ 38 #define SBC_DECODER_ERROR_STREAM_EMPTY BK_ERR_SBC_BASE - 4 /**< stream empty */ 39 #define SBC_DECODER_ERROR_OK 0x0 /**< no error */ 40 41 42 typedef enum { 43 SBC_SAMPLE_RATE_16000 = 0, /**< SBC sampling frequency : 16.0KHz */ 44 SBC_SAMPLE_RATE_32000, /**< SBC sampling frequency : 32.0KHz */ 45 SBC_SAMPLE_RATE_44100, /**< SBC sampling frequency : 44.1KHz */ 46 SBC_SAMPLE_RATE_48000, /**< SBC sampling frequency : 48.0KHz */ 47 SBC_SAMPLE_RATE_MAX, 48 } sbc_sample_rates_t; 49 50 typedef enum { 51 SBC_CHANNEL_NUM_ONE = 0, /**< SBC channel number : 1 channel */ 52 SBC_CHANNEL_NUM_TWO, /**< SBC channel number : 2 channels */ 53 SBC_CHANNEL_MODE_INVALID, 54 } sbc_channel_num_t; 55 56 typedef enum { 57 SBC_SUBBAND_NUMBER_4 = 0, /**< SBC subbands number 4 */ 58 SBC_SUBBAND_NUMBER_8, /**< SBC subbands number 8 */ 59 SBC_SUBBAND_MAX, 60 } sbc_subband_number_t; 61 62 typedef enum { 63 SBC_DECODE_OUTPUT_SINGLE = 0, /**< SBC decoder output struct:{16'd0, pcm} */ 64 SBC_DECODE_OUTPUT_DOUBLE, /**< SBC decoder output struct:{pcm_chn2, pcm_chn1} */ 65 SBC_DECODE_OUTPUT_INVALID, 66 } sbc_chn_comb_t; 67 68 typedef enum { 69 SBC_BLOCK_NUMBER_4 = 0, /**< SBC blocks number 4 */ 70 SBC_BLOCK_NUMBER_8, /**< SBC blocks number 8 */ 71 SBC_BLOCK_NUMBER_12, /**< SBC blocks number 12 */ 72 SBC_BLOCK_NUMBER_16, /**< SBC blocks number 16 */ 73 SBC_BLOCK_NUMBER_MAX, 74 } sbc_blocks_number_t; 75 76 typedef enum { 77 SBC_ALLOCATION_METHOD_LOUDNESS = 0, /**< SBC allocation method : Loudness */ 78 SBC_ALLOCATION_METHOD_SNR, /**< SBC allocation method : SNR */ 79 SBC_ALLOCATION_METHOD_INVALID, 80 } sbc_allocation_method_t; 81 82 /** 83 * @brief SBC decoder context 84 */ 85 typedef struct { 86 int8_t blocks; /**< block number */ 87 int8_t subbands; /**< subbands number */ 88 uint8_t join; /**< bit number x set means joint stereo has been used in subband x */ 89 uint8_t bitpool; /**< indicate the size of the bit allocation pool that has been used for encoding the stream */ 90 91 int8_t channel_mode; /**< channel mode */ 92 int8_t sample_rate_index; /**< sample rate index, 0:16000, 1:32000, 2:44100, 3:48000 */ 93 int8_t allocation_method; /**< allocation method */ 94 int8_t reserved8; /**< dummy, reserved for byte align */ 95 96 int8_t bits[2][8]; /**< calculate result by bit allocation */ 97 98 int8_t scale_factor[2][8]; /**< only the lower 4 bits of every element are to be used */ 99 100 int32_t mem[2][8]; /**< Memory used as bit need and levels */ 101 102 }sbccommoncontext_t; 103 104 /** 105 * @brief SBC decoder context 106 */ 107 typedef struct { 108 sbccommoncontext_t frame; 109 110 int8_t channel_number; /**< channels number */ 111 uint8_t pcm_length; /**< PCM length */ 112 uint16_t sample_rate; /**< sample rate */ 113 114 int32_t pcm_sample[2][128]; /**< PCM frame buffer */ 115 116 int32_t vfifo[2][170]; /**< FIFO V for subbands synthesis calculation. */ 117 118 int32_t offset[2][16]; 119 120 }sbcdecodercontext_t; 121 122 typedef struct { 123 sbc_channel_num_t channel_num; /**< channels number */ 124 sbc_subband_number_t subbands; /**< subband number */ 125 sbc_chn_comb_t chn_comb; /**< pcm output struct */ 126 sbc_blocks_number_t blocks; /**< block number */ 127 } sbc_config_t; 128 129 130 #ifdef __cplusplus 131 } 132 #endif 133 134 135