1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "hfp_msbc_encoder"
18 
19 #include "hfp_msbc_encoder.h"
20 
21 #include <cstdint>
22 #include <cstring>
23 
24 #include "embdrv/sbc/encoder/include/sbc_encoder.h"
25 
26 typedef struct {
27   SBC_ENC_PARAMS sbc_encoder_params;
28 } tHFP_MSBC_ENCODER;
29 
30 static tHFP_MSBC_ENCODER hfp_msbc_encoder = {};
31 
hfp_msbc_encoder_init(void)32 void hfp_msbc_encoder_init(void) {
33   SBC_ENC_PARAMS* p_encoder_params = &hfp_msbc_encoder.sbc_encoder_params;
34   p_encoder_params->s16SamplingFreq = SBC_sf16000;
35   p_encoder_params->s16ChannelMode = SBC_MONO;
36   p_encoder_params->s16NumOfSubBands = 8;
37   p_encoder_params->s16NumOfChannels = 1;
38   p_encoder_params->s16NumOfBlocks = 15;
39   p_encoder_params->s16AllocationMethod = SBC_LOUDNESS;
40   p_encoder_params->s16BitPool = 26;
41   p_encoder_params->Format = SBC_FORMAT_MSBC;
42 }
43 
hfp_msbc_encoder_cleanup(void)44 void hfp_msbc_encoder_cleanup(void) { hfp_msbc_encoder = {}; }
45 
hfp_msbc_encode_frames(int16_t * input,uint8_t * output)46 uint32_t hfp_msbc_encode_frames(int16_t* input, uint8_t* output) {
47   return SBC_Encode(&hfp_msbc_encoder.sbc_encoder_params, input, output);
48 }
49