1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
28
29
30
31
32
33
34
35
36
37
38
41
42
43
44
45
46
47
48
51
52
53
54
55
56
57
58
59
60
62
64
65
66
67
68
69
70
71
72
73
76
77
78
83
84
85
86
87
88
89
90
91
92
93
94
95
96
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
403
404
405
406
407
408
409
410
411
412
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
568
569
570
571
572
573
574
575
576
577
578
579
580
581
586
587
588
589
590
611
612
613
619
620
621
622
623
624
625
626
627
628
629
630
631
632
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
667
668
669
670
671
672
673
674
/* ... */
/* ... */
#include <string.h>
#include "bta/bta_api.h"
#include "bta/bta_sys.h"
#include "osi/allocator.h"
#if (BTM_SCO_HCI_INCLUDED == TRUE)
#ifndef BTA_DM_SCO_DEBUG
#define BTA_DM_SCO_DEBUG FALSE
#endif
/* ... */
#define BTA_DM_PCM_OVERLAP_SIZE 48
#define BTA_DM_PCM_SMPL_RATE_44100 44100
#define BTA_DM_PCM_SMPL_RATE_22050 22050
#define BTA_DM_PCM_SMPL_RATE_11025 11025
/* ... */
typedef INT32 (*PCONVERT_TO_BT_FILTERED) (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea);
typedef INT32 (*PCONVERT_TO_BT_NOFILTER) (void *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps);
typedef struct {
UINT8 overlap_area[BTA_DM_PCM_OVERLAP_SIZE * 4];
UINT32 cur_pos;
UINT32 src_sps;
PCONVERT_TO_BT_FILTERED filter;
/* ... */
PCONVERT_TO_BT_NOFILTER nofilter;
/* ... */
UINT32 bits;
UINT32 n_channels;
UINT32 sample_size;
UINT32 can_be_filtered;
UINT32 divisor;
}{...} tBTA_DM_PCM_RESAMPLE_CB;
static tBTA_DM_PCM_RESAMPLE_CB* p_bta_dm_pcm_cb;
/* ... */
#define CHECK_SATURATION16(x) \
if (x > 32767) \
x = 32767; \
else if (x < -32768) \
x = -32768;...
#define CONVERT_44100_TO_BLUETOOTH(pStart, pEnd) \
{ \
INT32 out1, out2, out3, out4, out5; \
SRC_TYPE *pS = (SRC_TYPE *)pStart; \
SRC_TYPE *pSEnd = (SRC_TYPE *)pEnd; \
\
while (pS < pSEnd) \
{ \
CurrentPos -= 8000; \
\
if (CurrentPos >= 0) \
{ \
pS += SRC_CHANNELS; \
continue; \
}{...} \
CurrentPos += dwSrcSps; \
\
out1 = (SRC_SAMPLE(0) * 1587) \
+ ((SRC_SAMPLE(1) + SRC_SAMPLE(-1)) * 1522) \
+ ((SRC_SAMPLE(2) + SRC_SAMPLE(-2)) * 1337) \
+ ((SRC_SAMPLE(3) + SRC_SAMPLE(-3)) * 1058); \
\
out1 = out1 / 30000; \
\
out2 = ((SRC_SAMPLE(4) + SRC_SAMPLE(-4)) * 725) \
+ ((SRC_SAMPLE(5) + SRC_SAMPLE(-5)) * 384) \
+ ((SRC_SAMPLE(6) + SRC_SAMPLE(-6)) * 79); \
\
out2 = out2 / 30000; \
\
out3 = ((SRC_SAMPLE(7) + SRC_SAMPLE(-7)) * 156) \
+ ((SRC_SAMPLE(8) + SRC_SAMPLE(-8)) * 298) \
+ ((SRC_SAMPLE(9) + SRC_SAMPLE(-9)) * 345); \
\
out3 = out3 / 30000; \
\
out4 = ((SRC_SAMPLE(10) + SRC_SAMPLE(-10)) * 306) \
+ ((SRC_SAMPLE(11) + SRC_SAMPLE(-11)) * 207) \
+ ((SRC_SAMPLE(12) + SRC_SAMPLE(-12)) * 78); \
\
out4 = out4 / 30000; \
\
out5 = out1 + out2 - out3 - out4; \
\
CHECK_SATURATION16(out5); \
*psBtOut++ = (INT16)out5; \
\
pS += SRC_CHANNELS; \
}{...} \
}{...}
...
#define CONVERT_22050_TO_BLUETOOTH(pStart, pEnd) \
{ \
INT32 out1, out2, out3, out4, out5; \
SRC_TYPE *pS = (SRC_TYPE *)pStart; \
SRC_TYPE *pSEnd = (SRC_TYPE *)pEnd; \
\
while (pS < pSEnd) \
{ \
CurrentPos -= 8000; \
\
if (CurrentPos >= 0) \
{ \
pS += SRC_CHANNELS; \
continue; \
}{...} \
CurrentPos += dwSrcSps; \
\
out1 = (SRC_SAMPLE(0) * 2993) \
+ ((SRC_SAMPLE(1) + SRC_SAMPLE(-1)) * 2568) \
+ ((SRC_SAMPLE(2) + SRC_SAMPLE(-2)) * 1509) \
+ ((SRC_SAMPLE(3) + SRC_SAMPLE(-3)) * 331); \
\
out1 = out1 / 30000; \
\
out2 = ((SRC_SAMPLE(4) + SRC_SAMPLE(-4)) * 454) \
+ ((SRC_SAMPLE(5) + SRC_SAMPLE(-5)) * 620) \
+ ((SRC_SAMPLE(6) + SRC_SAMPLE(-6)) * 305); \
\
out2 = out2 / 30000; \
\
out3 = ((SRC_SAMPLE(7) + SRC_SAMPLE(-7)) * 127) \
+ ((SRC_SAMPLE(8) + SRC_SAMPLE(-8)) * 350) \
+ ((SRC_SAMPLE(9) + SRC_SAMPLE(-9)) * 265) \
+ ((SRC_SAMPLE(10) + SRC_SAMPLE(-10)) * 6); \
\
out3 = out3 / 30000; \
\
out4 = ((SRC_SAMPLE(11) + SRC_SAMPLE(-11)) * 201); \
\
out4 = out4 / 30000; \
\
out5 = out1 - out2 + out3 - out4; \
\
CHECK_SATURATION16(out5); \
*psBtOut++ = (INT16)out5; \
\
pS += SRC_CHANNELS; \
}{...} \
}{...}
...
#define CONVERT_11025_TO_BLUETOOTH(pStart, pEnd) \
{ \
INT32 out1; \
SRC_TYPE *pS = (SRC_TYPE *)pStart; \
SRC_TYPE *pSEnd = (SRC_TYPE *)pEnd; \
\
while (pS < pSEnd) \
{ \
CurrentPos -= 8000; \
\
if (CurrentPos >= 0) \
{ \
pS += SRC_CHANNELS; \
continue; \
}{...} \
CurrentPos += dwSrcSps; \
\
out1 = (SRC_SAMPLE(0) * 6349) \
+ ((SRC_SAMPLE(1) + SRC_SAMPLE(-1)) * 2874) \
- ((SRC_SAMPLE(2) + SRC_SAMPLE(-2)) * 1148) \
- ((SRC_SAMPLE(3) + SRC_SAMPLE(-3)) * 287) \
+ ((SRC_SAMPLE(4) + SRC_SAMPLE(-4)) * 675) \
- ((SRC_SAMPLE(5) + SRC_SAMPLE(-5)) * 258) \
- ((SRC_SAMPLE(6) + SRC_SAMPLE(-6)) * 206) \
+ ((SRC_SAMPLE(7) + SRC_SAMPLE(-7)) * 266); \
\
out1 = out1 / 30000; \
\
CHECK_SATURATION16(out1); \
*psBtOut++ = (INT16)out1; \
\
pS += SRC_CHANNELS; \
}{...} \
}{...}
...
#undef SRC_CHANNELS
#undef SRC_SAMPLE
#undef SRC_TYPE
#define SRC_TYPE UINT8
#define SRC_CHANNELS 1
#define SRC_SAMPLE(x) ((pS[x] - 0x80) << 8)
/* ... */
INT32 Convert_8M_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea)
{
INT32 CurrentPos = *pLastCurPos;
SRC_TYPE *pIn, *pInEnd;
SRC_TYPE *pOv, *pOvEnd;
INT16 *psBtOut = (INT16 *)pDst;
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("Convert_8M_ToBT_Filtered, CurrentPos %d\n", CurrentPos);
#endif
memcpy (pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 2), pSrc, BTA_DM_PCM_OVERLAP_SIZE * 2);
pOv = (SRC_TYPE *)(pOverlapArea + BTA_DM_PCM_OVERLAP_SIZE);
pOvEnd = (SRC_TYPE *)(pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 3));
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}{...}
memcpy (pOverlapArea, pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
(BTA_DM_PCM_OVERLAP_SIZE * 2), BTA_DM_PCM_OVERLAP_SIZE * 2);
*pLastCurPos = CurrentPos;
return (psBtOut - (INT16 *)pDst);
}{...}
INT32 Convert_8M_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UINT32 dwSrcSps)
{
INT32 CurrentPos;
UINT8 *pbSrc = (UINT8 *)pSrc;
INT16 *psDst = (INT16 *)pDst;
INT16 sWorker;
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0) {
pbSrc++;
}{...} else {
sWorker = *pbSrc++;
sWorker -= 0x80;
sWorker <<= 8;
*psDst++ = sWorker;
CurrentPos += dwSrcSps;
}{...}
}{...}
return (psDst - (INT16 *)pDst);
}{...}
#undef SRC_CHANNELS
#undef SRC_SAMPLE
#undef SRC_TYPE
#define SRC_TYPE INT16
#define SRC_CHANNELS 1
#define SRC_SAMPLE(x) pS[x]
INT32 Convert_16M_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea)
{
INT32 CurrentPos = *pLastCurPos;
SRC_TYPE *pIn, *pInEnd;
SRC_TYPE *pOv, *pOvEnd;
INT16 *psBtOut = (INT16 *)pDst;
memcpy (pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 2), pSrc, BTA_DM_PCM_OVERLAP_SIZE * 2);
pOv = (SRC_TYPE *)(pOverlapArea + BTA_DM_PCM_OVERLAP_SIZE);
pOvEnd = (SRC_TYPE *)(pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 3));
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}{...}
memcpy (pOverlapArea, pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
(BTA_DM_PCM_OVERLAP_SIZE * 2), BTA_DM_PCM_OVERLAP_SIZE * 2);
*pLastCurPos = CurrentPos;
return (psBtOut - (INT16 *)pDst);
}{...}
INT32 Convert_16M_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UINT32 dwSrcSps)
{
INT32 CurrentPos;
INT16 *psSrc = (INT16 *)pSrc;
INT16 *psDst = (INT16 *)pDst;
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0) {
psSrc++;
}{...} else {
*psDst++ = *psSrc++;
CurrentPos += dwSrcSps;
}{...}
}{...}
return (psDst - (INT16 *)pDst);
}{...}
#undef SRC_CHANNELS
#undef SRC_SAMPLE
#undef SRC_TYPE
#define SRC_TYPE UINT8
#define SRC_CHANNELS 2
#define SRC_SAMPLE(x) ((((pS[x * 2] - 0x80) << 8) + ((pS[(x * 2) + 1] - 0x80) << 8)) >> 1)
INT32 Convert_8S_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea)
{
INT32 CurrentPos = *pLastCurPos;
SRC_TYPE *pIn, *pInEnd;
SRC_TYPE *pOv, *pOvEnd;
INT16 *psBtOut = (INT16 *)pDst;
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("Convert_8S_ToBT_Filtered CurrentPos %d, SRC_TYPE %d, SRC_CHANNELS %d, \
dwSrcSamples %d, dwSrcSps %d", CurrentPos, sizeof (SRC_TYPE), SRC_CHANNELS, \
dwSrcSamples, dwSrcSps);/* ... */
#endif
memcpy (pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 2), pSrc, BTA_DM_PCM_OVERLAP_SIZE * 2);
pOv = (SRC_TYPE *)(pOverlapArea + BTA_DM_PCM_OVERLAP_SIZE);
pOvEnd = (SRC_TYPE *)(pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 3));
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}{...}
memcpy (pOverlapArea, pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
(BTA_DM_PCM_OVERLAP_SIZE * 2), BTA_DM_PCM_OVERLAP_SIZE * 2);
*pLastCurPos = CurrentPos;
return (psBtOut - (INT16 *)pDst);
}{...}
INT32 Convert_8S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UINT32 dwSrcSps)
{
INT32 CurrentPos;
UINT8 *pbSrc = (UINT8 *)pSrc;
INT16 *psDst = (INT16 *)pDst;
INT16 sWorker, sWorker2;
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0) {
pbSrc += 2;
}{...} else {
sWorker = *(unsigned char *)pbSrc;
sWorker -= 0x80;
sWorker <<= 8;
pbSrc++;
sWorker2 = *(unsigned char *)pbSrc;
sWorker2 -= 0x80;
sWorker2 <<= 8;
pbSrc++;
sWorker += sWorker2;
sWorker >>= 1;
*psDst++ = sWorker;
CurrentPos += dwSrcSps;
}{...}
}{...}
return (psDst - (INT16 *)pDst);
}{...}
#undef SRC_CHANNELS
#undef SRC_SAMPLE
#undef SRC_TYPE
#define SRC_TYPE INT16
#define SRC_CHANNELS 2
#define SRC_SAMPLE(x) ((pS[x * 2] + pS[(x * 2) + 1]) >> 1)
INT32 Convert_16S_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea)
{
INT32 CurrentPos = *pLastCurPos;
SRC_TYPE *pIn, *pInEnd;
SRC_TYPE *pOv, *pOvEnd;
INT16 *psBtOut = (INT16 *)pDst;
memcpy (pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 2), pSrc, BTA_DM_PCM_OVERLAP_SIZE * 2);
pOv = (SRC_TYPE *)(pOverlapArea + BTA_DM_PCM_OVERLAP_SIZE);
pOvEnd = (SRC_TYPE *)(pOverlapArea + (BTA_DM_PCM_OVERLAP_SIZE * 3));
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}{...} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}{...}
memcpy (pOverlapArea, pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
(BTA_DM_PCM_OVERLAP_SIZE * 2), BTA_DM_PCM_OVERLAP_SIZE * 2);
*pLastCurPos = CurrentPos;
return (psBtOut - (INT16 *)pDst);
}{...}
INT32 Convert_16S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UINT32 dwSrcSps)
{
INT32 CurrentPos;
INT16 *psSrc = (INT16 *)pSrc;
INT16 *psDst = (INT16 *)pDst;
INT16 sWorker;
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0) {
psSrc += 2;
}{...} else {
sWorker = ((*psSrc) >> 1 );
psSrc++;
sWorker += ((*psSrc) >> 1 );
psSrc++;
*psDst++ = sWorker;
CurrentPos += dwSrcSps;
}{...}
}{...}
return (psDst - (INT16 *)pDst);
}{...}
/* ... */
void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels)
{
if ((p_bta_dm_pcm_cb = (tBTA_DM_PCM_RESAMPLE_CB *)osi_malloc(sizeof(tBTA_DM_PCM_RESAMPLE_CB))) == NULL) {
APPL_TRACE_ERROR("%s malloc failed!", __func__);
return;
}{...}
tBTA_DM_PCM_RESAMPLE_CB *p_cb = p_bta_dm_pcm_cb;
p_cb->cur_pos = src_sps / 2;
p_cb->src_sps = src_sps;
p_cb->bits = bits;
p_cb->n_channels = n_channels;
p_cb->sample_size = 2;
p_cb->divisor = 2;
memset(p_cb->overlap_area, 0, sizeof(p_cb->overlap_area) );
if ((src_sps == BTA_DM_PCM_SMPL_RATE_44100) ||
(src_sps == BTA_DM_PCM_SMPL_RATE_22050) ||
(src_sps == BTA_DM_PCM_SMPL_RATE_11025)) {
p_cb->can_be_filtered = 1;
}{...} else {
p_cb->can_be_filtered = 0;
}{...}
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_dm_pcm_init_samples: n_channels = %d bits = %d", n_channels, bits);
#endif
if (n_channels == 1) {
if (bits == 8) {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_8M_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_8M_ToBT_NoFilter;
p_cb->divisor = 1;
}{...} else {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_16M_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_16M_ToBT_NoFilter;
}{...}
}{...} else {
if (bits == 8) {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_8S_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_8S_ToBT_NoFilter;
}{...} else {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_16S_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_16S_ToBT_NoFilter;
p_cb->divisor = 4;
}{...}
}{...}
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_pcm_init_dwn_sample: cur_pos %d, src_sps %d", \
p_cb->cur_pos, p_cb->src_sps);
APPL_TRACE_DEBUG("bta_pcm_init_dwn_sample: bits %d, n_channels %d, sample_size %d, ", \
p_cb->bits, p_cb->n_channels, p_cb->sample_size);
APPL_TRACE_DEBUG("bta_pcm_init_dwn_sample: can_be_filtered %d, n_channels: %d, \
divisor %d", p_cb->can_be_filtered, p_cb->n_channels, p_cb->divisor);/* ... */
#endif
}{...}
/* ... */
void BTA_DmPcmDeinitSamples(void) {
osi_free(p_bta_dm_pcm_cb);
p_bta_dm_pcm_cb = NULL;
}{...}
/* ... */
INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst)
{
UINT32 out_sample;
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / p_bta_dm_pcm_cb->divisor));
#endif
if (p_bta_dm_pcm_cb->can_be_filtered) {
out_sample = (*p_bta_dm_pcm_cb->filter) (p_src, p_dst, (in_bytes / p_bta_dm_pcm_cb->divisor),
p_bta_dm_pcm_cb->src_sps, (INT32 *) &(p_bta_dm_pcm_cb->cur_pos), p_bta_dm_pcm_cb->overlap_area);
}{...} else {
out_sample = (*p_bta_dm_pcm_cb->nofilter) (p_src, p_dst,
(in_bytes / p_bta_dm_pcm_cb->divisor), p_bta_dm_pcm_cb->src_sps);
}{...}
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_pcm_resample : outsamples %d", out_sample);
#endif
return (out_sample);
}{...}
/* ... */#endif