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
16 #include <common/bk_include.h>
17 #include "sys_driver.h"
18 #include "sbc_hal.h"
19 #include "sbc_driver.h"
20 #include <driver/int.h>
21 #include <driver/sbc.h>
22 #include <driver/sbc_types.h>
23 #include "sbc_ll_macro_def.h"
24 #include <os/mem.h>
25
26
27 typedef struct {
28 sbc_decoder_isr_t callback;
29 void *param;
30 } sbc_decoder_callback_t;
31
32 static sbc_decoder_callback_t s_sbc_decoder_isr = {NULL};
33
34 static void sbc_decoder_isr(void);
35
36
37 /**
38 * SBC constant table OFFSET4 for calculate bit allocation
39 */
40 static const int32_t SBC_COMMON_OFFSET4[4][4] =
41 {
42 { -1, 0, 0, 0 },
43 { -2, 0, 0, 1 },
44 { -2, 0, 0, 1 },
45 { -2, 0, 0, 1 }
46 };
47
48 /**
49 * SBC constant table OFFSET8 for calculate bit allocation
50 */
51 static const int32_t SBC_COMMON_OFFSET8[4][8] =
52 {
53 { -2, 0, 0, 0, 0, 0, 0, 1 },
54 { -3, 0, 0, 0, 0, 0, 1, 2 },
55 { -4, 0, 0, 0, 0, 0, 1, 2 },
56 { -4, 0, 0, 0, 0, 0, 1, 2 }
57 };
58
59 static const uint16_t SBC_SAMPLE_RATES[4] = { 16000, 32000, 44100, 48000 };
60
sbc_common_sample_rate_get(uint32_t idx)61 uint16_t sbc_common_sample_rate_get(uint32_t idx)
62 {
63 return SBC_SAMPLE_RATES[idx];
64 }
65
bk_sbc_decoder_get_mem0_addr(uint32_t * mem0_addr)66 static uint32_t bk_sbc_decoder_get_mem0_addr(uint32_t *mem0_addr)
67 {
68 *mem0_addr = SBC_SBC_MEM0_ADDR;
69
70 return BK_OK;
71 }
72
sbc_decoder_frame_length_calc(sbcdecodercontext_t * sbc)73 static uint32_t sbc_decoder_frame_length_calc(sbcdecodercontext_t *sbc)
74 {
75 uint32_t frame_length = 0;
76 uint32_t blocks = (uint32_t)sbc->frame.blocks;
77 uint32_t subbands = (uint32_t)sbc->frame.subbands;
78 uint32_t num_channels = (uint32_t)sbc->channel_number;
79
80 frame_length = 4 + ((4 * subbands * num_channels) >> 3);
81
82 //for MONO and DUAL_CHANNEL
83 if(sbc->frame.channel_mode < 2) {
84 frame_length += (blocks * num_channels * (uint32_t)(sbc->frame.bitpool) + 7) >> 3;
85 }
86 //for STEREO and JOINT_STEREO
87 else {
88 frame_length += ((sbc->frame.channel_mode == SBC_CHANNEL_MODE_JOINT_STEREO) * subbands + blocks * ((uint32_t)sbc->frame.bitpool) + 7) >> 3;
89 }
90
91 return frame_length;
92
93 }
94
bk_sbc_decoder_frame_decode(sbcdecodercontext_t * sbc,const uint8_t * data,uint32_t length)95 bk_err_t bk_sbc_decoder_frame_decode(sbcdecodercontext_t *sbc, const uint8_t *data, uint32_t length)
96 {
97 int32_t channel, subband, block, consumed;
98 uint32_t mem0_addr = 0;
99 uint32_t pcm_data = 0;
100 sbc_config_t sbc_config;
101
102 sbccommoncontext_t *frame = &sbc->frame;
103
104 bk_sbc_decoder_get_mem0_addr(&mem0_addr);
105
106 /* frame_header */
107 switch(data[0])
108 {
109 case SBC_SYNCWORD:
110 frame->sample_rate_index = (data[1] >> 6) & 0x03;
111 frame->blocks = (((data[1] >> 4) & 0x03) + 1) << 2;
112 frame->channel_mode = (data[1] >> 2) & 0x03;
113 frame->allocation_method = (data[1] >> 1) & 0x01;
114 frame->subbands = ((data[1] & 0x01) + 1) << 2;
115 frame->bitpool = data[2];
116 break;
117
118 case MSBC_SYNCWORD:
119 frame->blocks = 15;
120 if(data[1] || data[2]) {
121 frame->sample_rate_index = (data[1] >> 6) & 0x03;
122 frame->channel_mode = (data[1] >> 2) & 0x03;
123 frame->allocation_method = (data[1] >> 1) & 0x01;
124 frame->subbands = ((data[1] & 0x01) + 1) << 2;
125 frame->bitpool = data[2];
126 } else {
127 frame->sample_rate_index = 0;
128 frame->channel_mode = 0;
129 frame->allocation_method = 0;
130 frame->subbands = 8;
131 frame->bitpool = 26;
132 }
133 break;
134
135 default:
136 return SBC_DECODER_ERROR_SYNC_INCORRECT;
137 }
138
139 sbc->channel_number = (frame->channel_mode == SBC_CHANNEL_MODE_MONO) ? 1 : 2;
140 sbc->pcm_length = frame->blocks * frame->subbands;
141 sbc->sample_rate = sbc_common_sample_rate_get(frame->sample_rate_index);
142
143 if (sbc_decoder_frame_length_calc(sbc) > length) {
144 return SBC_DECODER_ERROR_STREAM_EMPTY;
145 }
146
147 if (((frame->channel_mode == SBC_CHANNEL_MODE_MONO || frame->channel_mode == SBC_CHANNEL_MODE_DUAL) && (frame->bitpool > (frame->subbands << 4))) ||
148 ((frame->channel_mode == SBC_CHANNEL_MODE_STEREO || frame->channel_mode == SBC_CHANNEL_MODE_JOINT_STEREO) && (frame->bitpool > (frame->subbands << 5)))) {
149
150 return SBC_DECODER_ERROR_BITPOOL_OUT_BOUNDS;
151 }
152
153 consumed = 32;
154
155 if(frame->channel_mode == SBC_CHANNEL_MODE_JOINT_STEREO)
156 {
157 int32_t subband;
158 uint32_t join = 0;
159
160 for(subband = 0; subband < frame->subbands - 1; subband++)
161 {
162 join |= ((data[4] >> (7 - subband)) & 0x01) << subband;
163 }
164
165 frame->join = (uint8_t)join;
166
167 consumed += frame->subbands;
168 }
169
170 /* scale_factor */
171 for(channel = 0; channel < sbc->channel_number; channel++)
172 {
173 int8_t *scale_factor = frame->scale_factor[channel];
174
175 for(subband = 0; subband < frame->subbands; subband++)
176 {
177 scale_factor[subband] = (data[consumed >> 3] >> (4 - (consumed & 0x7))) & 0x0F;
178 consumed += 4;
179 }
180 }
181
182 /* bit_allocation */
183 bk_sbc_decoder_bit_allocation(frame);
184
185 /* subband Level */
186 for(channel = 0; channel < sbc->channel_number; channel++)
187 {
188 int8_t *bits = frame->bits[channel];
189 int32_t *levels = frame->mem[channel];
190
191 for(subband = 0; subband < frame->subbands; subband++)
192 {
193 levels[subband] = (0x1 << bits[subband]) - 1;
194 }
195 }
196
197 /* audio_samples & reconstruction */
198 for(block = 0; block < frame->blocks; block++)
199 {
200 for(channel = 0; channel < sbc->channel_number; channel++)
201 {
202 int8_t *bits = frame->bits[channel];
203 uint8_t *scale_factor = (uint8_t *)frame->scale_factor[channel];
204 uint32_t *levels = (uint32_t *)frame->mem[channel];
205 int32_t *pcm;
206
207 bk_sbc_decoder_get_mem0_addr(&mem0_addr);
208 pcm = (int32_t *)(mem0_addr + channel * sbc->pcm_length + block * frame->subbands);
209 for(subband = 0; subband < frame->subbands; subband++)
210 {
211 if (levels[subband] > 0) {
212 int32_t consumed_byte = consumed >> 3;
213 bk_sbc_decoder_set_sbc_bit_num(bits[subband]);
214 bk_sbc_decoder_set_scale_factor(scale_factor[subband]);
215 bk_sbc_decoder_set_sbc_level(levels[subband]);
216 bk_sbc_decoder_set_sbc_res_bit(consumed_byte & 0x7);
217 sbc_decoder_hal_set_res_bytel_value(data[consumed_byte]);
218 sbc_decoder_hal_set_res_bytem_value(data[consumed_byte + 1]);
219 sbc_decoder_hal_set_res_byteh_value(data[consumed_byte + 2]);
220 bk_sbc_decoder_start_decode();
221 while(bk_sbc_decoder_get_decode_enable_value());
222 pcm_data = bk_sbc_decoder_get_pcm_data();
223 *pcm++ = pcm_data;
224 consumed = consumed + bits[subband];
225 } else {
226 *pcm++ = 0;
227 }
228 }
229 }
230 }
231
232 /* joint_stereo */
233 if (frame->channel_mode == SBC_CHANNEL_MODE_JOINT_STEREO) {
234 int32_t idx, t0, t1;
235 int32_t *pcm0;
236 int32_t *pcm1;
237
238 pcm0 = (int32_t *)(mem0_addr);
239 pcm1 = (int32_t *)(mem0_addr + sbc->pcm_length);
240
241 for(block = 0; block < frame->blocks; block++)
242 {
243 idx = block * frame->subbands;
244
245 for(subband = 0; subband < frame->subbands; subband++)
246 {
247 if (frame->join & (0x01 << subband)) {
248 t0 = pcm0[idx];
249 t1 = pcm1[idx];
250 pcm0[idx] = t0 + t1;
251 pcm1[idx] = t0 - t1;
252 }
253 idx++;
254 }
255 }
256 }
257
258 /* padding */
259 consumed = ((consumed + 7) & 0xFFFFFFF8) >> 3;
260
261 sbc_config.channel_num = sbc->channel_number == 2 ? SBC_CHANNEL_NUM_TWO : SBC_CHANNEL_NUM_ONE;
262 sbc_config.subbands = frame->subbands == 8 ? SBC_SUBBAND_NUMBER_8 : SBC_SUBBAND_NUMBER_4;
263 sbc_config.chn_comb = (sbc->channel_number == 2 ? SBC_DECODE_OUTPUT_DOUBLE : SBC_DECODE_OUTPUT_SINGLE);
264 sbc_config.blocks = frame->blocks / 4 - 1;
265
266 sbc_decoder_hal_sbc_config(&sbc_config);
267
268 if (frame->blocks == 15) {
269 bk_sbc_decoder_support_msbc(1);
270 } else {
271 bk_sbc_decoder_support_msbc(0);
272 }
273
274 bk_sbc_decoder_sbc_enable();
275 while(bk_sbc_decoder_get_sbc_enable_status());
276
277 if (sbc->channel_number == 2) {
278 uint32_t i;
279 int32_t *src ;
280 src = (int32_t *)mem0_addr;
281 int32_t *dst = (int32_t *)sbc->pcm_sample;
282
283 for(i = 0; i < sbc->pcm_length; i++)
284 {
285 *dst++ = *src++;
286 }
287 } else {
288 uint32_t i;
289 int32_t *src;
290 src = (int32_t *)mem0_addr;
291 int16_t *dst = (int16_t*)sbc->pcm_sample;
292
293 for(i = 0; i < sbc->pcm_length; i++)
294 {
295 *dst++ = *src++;
296 }
297 }
298 os_printf("consumed = %d\r\n", consumed);
299
300 return consumed;
301
302 }
303
bk_sbc_decoder_bit_allocation(sbccommoncontext_t * sbc)304 bk_err_t bk_sbc_decoder_bit_allocation(sbccommoncontext_t *sbc)
305 {
306 int32_t channel, subband, slicecount, bitcount, bitslice, loudness, max_bitneed;
307
308 int8_t *scale_factor = NULL;
309 int8_t *bits = NULL;
310 int32_t *bitneed = NULL;
311
312 if ((sbc->channel_mode == SBC_CHANNEL_MODE_MONO) || (sbc->channel_mode == SBC_CHANNEL_MODE_DUAL)) {
313 for(channel = 0; channel < sbc->channel_mode + 1; channel++)
314 {
315 scale_factor = sbc->scale_factor[channel];
316 bits = sbc->bits[channel];
317 bitneed = sbc->mem[channel];
318
319 max_bitneed = 0;
320
321 if (sbc->allocation_method == SBC_ALLOCATION_METHOD_SNR) {
322 for(subband = 0; subband < sbc->subbands; subband++)
323 {
324 bitneed[subband] = scale_factor[subband];
325 if(bitneed[subband] > max_bitneed) {
326 max_bitneed = bitneed[subband];
327 }
328 }
329
330 } else {
331 uint8_t sample_rate_index = sbc->sample_rate_index;
332
333 for(subband = 0; subband < sbc->subbands; subband++)
334 {
335 if (scale_factor[subband] == 0) {
336 bitneed[subband] = -5;
337 } else {
338 if (sbc->subbands == 4) {
339 loudness = scale_factor[subband] - SBC_COMMON_OFFSET4[sample_rate_index][subband];
340 } else {
341 loudness = scale_factor[subband] - SBC_COMMON_OFFSET8[sample_rate_index][subband];
342 }
343
344 if (loudness > 0) {
345 bitneed[subband] = loudness / 2;
346 } else {
347 bitneed[subband] = loudness;
348 }
349 }
350
351 if (bitneed[subband] > max_bitneed) {
352 max_bitneed = bitneed[subband];
353 }
354 }
355 }
356
357 bitcount = 0;
358 slicecount = 0;
359 bitslice = max_bitneed + 1;
360
361 do
362 {
363 bitslice--;
364 bitcount += slicecount;
365 slicecount = 0;
366
367 for(subband = 0; subband < sbc->subbands; subband++)
368 {
369 if ((bitneed[subband] > bitslice + 1) && (bitneed[subband] < bitslice + 16)) {
370 slicecount++;
371 } else if(bitneed[subband] == bitslice + 1) {
372 slicecount += 2;
373 }
374 }
375 } while(bitcount + slicecount < sbc->bitpool);
376
377 if (bitcount + slicecount == sbc->bitpool) {
378 bitcount += slicecount;
379 bitslice--;
380 }
381
382 for(subband = 0; subband < sbc->subbands; subband++)
383 {
384 if (bitneed[subband] < bitslice + 2) {
385 bits[subband] = 0;
386 } else {
387 bits[subband] = bitneed[subband] - bitslice;
388 if (bits[subband] > 16) {
389 bits[subband] = 16;
390 }
391 }
392 }
393
394 for(subband = 0; bitcount < sbc->bitpool && subband < sbc->subbands; subband++)
395 {
396 if ((bits[subband] >= 2) && (bits[subband] < 16)) {
397 bits[subband]++;
398 bitcount++;
399 } else if ((bitneed[subband] == bitslice + 1) && (sbc->bitpool > bitcount + 1)) {
400 bits[subband] = 2;
401 bitcount += 2;
402 }
403 }
404
405 for(subband = 0; bitcount < sbc->bitpool && subband < sbc->subbands; subband++)
406 {
407 if (bits[subband] < 16) {
408 bits[subband]++;
409 bitcount++;
410 }
411 }
412 }
413 }else if ((sbc->channel_mode == SBC_CHANNEL_MODE_STEREO) || (sbc->channel_mode == SBC_CHANNEL_MODE_JOINT_STEREO)) {
414 max_bitneed = 0;
415 if (sbc->allocation_method == SBC_ALLOCATION_METHOD_SNR) {
416 for(channel = 0; channel < 2; channel++)
417 {
418 scale_factor = sbc->scale_factor[channel];
419 bitneed = sbc->mem[channel];
420
421 for(subband = 0; subband < sbc->subbands; subband++)
422 {
423 bitneed[subband] = scale_factor[subband];
424
425 if (bitneed[subband] > max_bitneed) {
426 max_bitneed = bitneed[subband];
427 }
428 }
429 }
430 } else {
431 uint8_t sample_rate_index = sbc->sample_rate_index;
432 for(channel = 0; channel < 2; channel++)
433 {
434 scale_factor = sbc->scale_factor[channel];
435 bitneed = sbc->mem[channel];
436
437 for(subband = 0; subband < sbc->subbands; subband++)
438 {
439 if (scale_factor[subband] == 0) {
440 bitneed[subband] = -5;
441 } else {
442 if (sbc->subbands == 4) {
443 loudness = scale_factor[subband] - SBC_COMMON_OFFSET4[sample_rate_index][subband];
444 } else {
445 loudness = scale_factor[subband] - SBC_COMMON_OFFSET8[sample_rate_index][subband];
446 }
447
448 if (loudness > 0) {
449 bitneed[subband] = loudness / 2;
450 } else {
451 bitneed[subband] = loudness;
452 }
453 }
454
455 if (bitneed[subband] > max_bitneed) {
456 max_bitneed = bitneed[subband];
457 }
458 }
459 }
460 }
461
462 bitcount = 0;
463 slicecount = 0;
464 bitslice = max_bitneed + 1;
465
466 do
467 {
468 bitslice--;
469 bitcount += slicecount;
470 slicecount = 0;
471
472 for(channel = 0; channel < 2; channel++)
473 {
474 bitneed = sbc->mem[channel];
475
476 for(subband = 0; subband < sbc->subbands; subband++)
477 {
478 if ((bitneed[subband] > bitslice + 1) && (bitneed[subband] < bitslice + 16)) {
479 slicecount++;
480 } else if (bitneed[subband] == bitslice + 1) {
481 slicecount += 2;
482 }
483 }
484 }
485 } while(bitcount + slicecount < sbc->bitpool);
486
487 if (bitcount + slicecount == sbc->bitpool) {
488 bitcount += slicecount;
489 bitslice--;
490 }
491
492 for(channel = 0; channel < 2; channel++)
493 {
494 bits = sbc->bits[channel];
495 bitneed = sbc->mem[channel];
496
497 for(subband = 0; subband < sbc->subbands; subband++)
498 {
499 if (bitneed[subband] < bitslice + 2) {
500 bits[subband] = 0;
501 } else {
502 bits[subband] = bitneed[subband] - bitslice;
503 if (bits[subband] > 16) {
504 bits[subband] = 16;
505 }
506 }
507 }
508 }
509
510 subband = 0;
511
512 while(bitcount < sbc->bitpool)
513 {
514 bits = sbc->bits[0];
515 bitneed = sbc->mem[0];
516
517 if ((bits[subband] >= 2) && (bits[subband] < 16)) {
518 bits[subband]++;
519 bitcount++;
520 } else if ((bitneed[subband] == bitslice + 1) && (sbc->bitpool > bitcount + 1)) {
521 bits[subband] = 2;
522 bitcount += 2;
523 }
524
525 if (bitcount >= sbc->bitpool) {
526 break;
527 }
528
529 bits = sbc->bits[1];
530 bitneed = sbc->mem[1];
531
532 if ((bits[subband] >= 2) && (bits[subband] < 16)) {
533 bits[subband]++;
534 bitcount++;
535 } else if ((bitneed[subband] == bitslice + 1) && (sbc->bitpool > bitcount + 1)) {
536 bits[subband] = 2;
537 bitcount += 2;
538 }
539
540 if (++subband >= sbc->subbands) {
541 break;
542 }
543 }
544
545 subband = 0;
546
547 while(bitcount < sbc->bitpool)
548 {
549 bits = sbc->bits[0];
550
551 if (bits[subband] < 16) {
552 bits[subband]++;
553
554 if (++bitcount >= sbc->bitpool) {
555 break;
556 }
557 }
558
559 bits = sbc->bits[1];
560
561 if (bits[subband] < 16) {
562 bits[subband]++;
563 bitcount++;
564 }
565
566 if (++subband >= sbc->subbands) {
567 break;
568 }
569 }
570 }
571
572 return BK_OK;
573 }
574
bk_sbc_decoder_init(sbcdecodercontext_t * sbc)575 bk_err_t bk_sbc_decoder_init(sbcdecodercontext_t *sbc)
576 {
577 uint32_t channel, i;
578
579 bk_sbc_decoder_mem_init();
580 os_memset((void *)sbc, 0, sizeof(sbcdecodercontext_t));
581
582 for(channel = 0; channel < 2; channel++)
583 {
584 for(i = 0; i < 8 * 2; i++)
585 {
586 sbc->offset[channel][i] = 10 * i + 10;
587 }
588 }
589
590 return BK_OK;
591 }
592
bk_sbc_decoder_deinit(void)593 bk_err_t bk_sbc_decoder_deinit(void)
594 {
595 sbc_config_t sbc_config;
596
597 sbc_config.blocks = SBC_BLOCK_NUMBER_4;
598 sbc_config.channel_num = SBC_CHANNEL_NUM_ONE;
599 sbc_config.chn_comb = SBC_DECODE_OUTPUT_SINGLE;
600 sbc_config.subbands = SBC_SUBBAND_NUMBER_4;
601
602 sbc_decoder_hal_sbc_config(&sbc_config);
603
604 bk_sbc_decoder_set_sbc_bit_num(0);
605 bk_sbc_decoder_set_scale_factor(0);
606 bk_sbc_decoder_set_sbc_level(0);
607 bk_sbc_decoder_set_sbc_res_bit(0);
608 bk_sbc_decoder_set_res_bytel_value(0);
609 bk_sbc_decoder_set_res_bytem_value(0);
610 bk_sbc_decoder_set_res_byteh_value(0);
611
612 bk_sbc_decoder_mem_init();
613
614 return BK_OK;
615 }
616
bk_sbc_decoder_mem_init(void)617 bk_err_t bk_sbc_decoder_mem_init(void)
618 {
619 sbc_decoder_hal_mem_init();
620
621 return BK_OK;
622 }
623
bk_sbc_decoder_sbc_enable(void)624 bk_err_t bk_sbc_decoder_sbc_enable(void)
625 {
626 sbc_decoder_hal_sbc_enable();
627
628 return BK_OK;
629 }
630
bk_sbc_decoder_get_sbc_enable_status(void)631 bk_err_t bk_sbc_decoder_get_sbc_enable_status(void)
632 {
633 return sbc_decoder_hal_get_sbc_status_value();
634 }
635
bk_sbc_decoder_interrupt_enable(bool enable)636 bk_err_t bk_sbc_decoder_interrupt_enable(bool enable)
637 {
638 if(enable) {
639 bk_int_isr_register(INT_SRC_SBC, sbc_decoder_isr, NULL);
640 sys_drv_sbc_int_en(1);
641
642 } else {
643 bk_int_isr_unregister(INT_SRC_SBC);
644 sys_drv_sbc_int_en(0);
645 }
646
647 return BK_OK;
648 }
649
bk_sbc_decoder_support_msbc(bool enable)650 bk_err_t bk_sbc_decoder_support_msbc(bool enable)
651 {
652 sbc_decoder_hal_sbc_support_msbc(enable);
653
654 return BK_OK;
655 }
656
bk_sbc_decoder_get_sbc_ctrl_value(void)657 bk_err_t bk_sbc_decoder_get_sbc_ctrl_value(void)
658 {
659 return sbc_decoder_hal_get_sbc_ctrl_value();
660 }
661
bk_sbc_decoder_clear_interrupt_status(void)662 bk_err_t bk_sbc_decoder_clear_interrupt_status(void)
663 {
664 sbc_decoder_hal_sbc_clear_interrupt_status();
665 return BK_OK;
666 }
667
bk_sbc_decoder_get_interrupt_status(void)668 bk_err_t bk_sbc_decoder_get_interrupt_status(void)
669 {
670 return sbc_decoder_hal_get_sbc_interrupt_status();
671 }
672
bk_sbc_decoder_get_idle_status(void)673 bk_err_t bk_sbc_decoder_get_idle_status(void)
674 {
675 return sbc_decoder_hal_get_sbc_idle_status();
676 }
677
bk_sbc_decoder_set_res_bytel_value(uint32_t resl_value)678 bk_err_t bk_sbc_decoder_set_res_bytel_value(uint32_t resl_value)
679 {
680 sbc_decoder_hal_set_res_bytel_value(resl_value);
681
682 return BK_OK;
683 }
684
bk_sbc_decoder_set_res_bytem_value(uint32_t resm_value)685 bk_err_t bk_sbc_decoder_set_res_bytem_value(uint32_t resm_value)
686 {
687 sbc_decoder_hal_set_res_bytem_value(resm_value);
688
689 return BK_OK;
690 }
691
bk_sbc_decoder_set_res_byteh_value(uint32_t resh_value)692 bk_err_t bk_sbc_decoder_set_res_byteh_value(uint32_t resh_value)
693 {
694 sbc_decoder_hal_set_res_byteh_value(resh_value);
695
696 return BK_OK;
697 }
698
bk_sbc_decoder_set_sbc_bit_num(uint32_t bit_num)699 bk_err_t bk_sbc_decoder_set_sbc_bit_num(uint32_t bit_num)
700 {
701 sbc_decoder_hal_set_sbc_bit_num(bit_num);
702
703 return BK_OK;
704 }
705
bk_sbc_decoder_set_scale_factor(uint32_t sf)706 bk_err_t bk_sbc_decoder_set_scale_factor(uint32_t sf)
707 {
708 sbc_decoder_hal_set_scale_factor(sf);
709
710 return BK_OK;
711 }
712
bk_sbc_decoder_set_sbc_level(uint32_t level)713 bk_err_t bk_sbc_decoder_set_sbc_level(uint32_t level)
714 {
715 sbc_decoder_hal_set_sbc_level(level);
716
717 return BK_OK;
718 }
719
bk_sbc_decoder_set_sbc_res_bit(uint32_t res_bit)720 bk_err_t bk_sbc_decoder_set_sbc_res_bit(uint32_t res_bit)
721 {
722 sbc_decoder_hal_set_sbc_res_bit(res_bit);
723
724 return BK_OK;
725 }
726
bk_sbc_decoder_start_decode(void)727 bk_err_t bk_sbc_decoder_start_decode(void)
728 {
729 sbc_decoder_hal_decode_enable();
730
731 return BK_OK;
732 }
733
bk_sbc_decoder_get_decode_enable_value(void)734 uint32_t bk_sbc_decoder_get_decode_enable_value(void)
735 {
736 return sbc_decoder_hal_get_decode_enable_value();
737 }
738
bk_sbc_decoder_get_pcm_data(void)739 bk_err_t bk_sbc_decoder_get_pcm_data(void)
740 {
741 return sbc_decoder_hal_get_pcm_data();
742
743 }
bk_sbc_decoder_register_sbc_isr(sbc_decoder_isr_t isr,void * param)744
745 bk_err_t bk_sbc_decoder_register_sbc_isr(sbc_decoder_isr_t isr, void *param)
746 {
747 GLOBAL_INT_DECLARATION();
748 GLOBAL_INT_DISABLE();
749 s_sbc_decoder_isr.callback = isr;
750 s_sbc_decoder_isr.param = param;
751 GLOBAL_INT_RESTORE();
752
753 return BK_OK;
754 }
sbc_decoder_isr(void)755
756 static void sbc_decoder_isr(void)
757 {
758 uint32_t int_status = 0;
759 int_status = bk_sbc_decoder_get_interrupt_status();
760
761 if (int_status) {
762 bk_sbc_decoder_clear_interrupt_status();
763 if (s_sbc_decoder_isr.callback) {
764 s_sbc_decoder_isr.callback(s_sbc_decoder_isr.param);
765 }
766 }
767 }
768
769
770