summaryrefslogtreecommitdiffstats
path: root/src/modules/bluetooth/sbc_tables.h
blob: 0057c73f7be1efb2004d7f391558f8fe5ed98fc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
151
152
153
154
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
204
205
206
207
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
/*
 *
 *  Bluetooth low-complexity, subband codec (SBC) library
 *
 *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
 *  Copyright (C) 2004-2005  Henryk Ploetz <henryk@ploetzli.ch>
 *  Copyright (C) 2005-2006  Brad Midgley <bmidgley@xmission.com>
 *
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

/* A2DP specification: Appendix B, page 69 */
static const int sbc_offset4[4][4] = {
	{ -1, 0, 0, 0 },
	{ -2, 0, 0, 1 },
	{ -2, 0, 0, 1 },
	{ -2, 0, 0, 1 }
};

/* A2DP specification: Appendix B, page 69 */
static const int sbc_offset8[4][8] = {
	{ -2, 0, 0, 0, 0, 0, 0, 1 },
	{ -3, 0, 0, 0, 0, 0, 1, 2 },
	{ -4, 0, 0, 0, 0, 0, 1, 2 },
	{ -4, 0, 0, 0, 0, 0, 1, 2 }
};


#define SS4(val) ASR(val, SCALE_SPROTO4_TBL)
#define SS8(val) ASR(val, SCALE_SPROTO8_TBL)
#define SN4(val) ASR(val, SCALE_NPROTO4_TBL)
#define SN8(val) ASR(val, SCALE_NPROTO8_TBL)

static const int32_t sbc_proto_4_40m0[] = {
	SS4(0x00000000), SS4(0xffa6982f), SS4(0xfba93848), SS4(0x0456c7b8),
	SS4(0x005967d1), SS4(0xfffb9ac7), SS4(0xff589157), SS4(0xf9c2a8d8),
	SS4(0x027c1434), SS4(0x0019118b), SS4(0xfff3c74c), SS4(0xff137330),
	SS4(0xf81b8d70), SS4(0x00ec1b8b), SS4(0xfff0b71a), SS4(0xffe99b00),
	SS4(0xfef84470), SS4(0xf6fb4370), SS4(0xffcdc351), SS4(0xffe01dc7)
};

static const int32_t sbc_proto_4_40m1[] = {
	SS4(0xffe090ce), SS4(0xff2c0475), SS4(0xf694f800), SS4(0xff2c0475),
	SS4(0xffe090ce), SS4(0xffe01dc7), SS4(0xffcdc351), SS4(0xf6fb4370),
	SS4(0xfef84470), SS4(0xffe99b00), SS4(0xfff0b71a), SS4(0x00ec1b8b),
	SS4(0xf81b8d70), SS4(0xff137330), SS4(0xfff3c74c), SS4(0x0019118b),
	SS4(0x027c1434), SS4(0xf9c2a8d8), SS4(0xff589157), SS4(0xfffb9ac7)
};

static const int32_t sbc_proto_8_80m0[] = {
	SS8(0x00000000), SS8(0xfe8d1970), SS8(0xee979f00), SS8(0x11686100),
	SS8(0x0172e690), SS8(0xfff5bd1a), SS8(0xfdf1c8d4), SS8(0xeac182c0),
	SS8(0x0d9daee0), SS8(0x00e530da), SS8(0xffe9811d), SS8(0xfd52986c),
	SS8(0xe7054ca0), SS8(0x0a00d410), SS8(0x006c1de4), SS8(0xffdba705),
	SS8(0xfcbc98e8), SS8(0xe3889d20), SS8(0x06af2308), SS8(0x000bb7db),
	SS8(0xffca00ed), SS8(0xfc3fbb68), SS8(0xe071bc00), SS8(0x03bf7948),
	SS8(0xffc4e05c), SS8(0xffb54b3b), SS8(0xfbedadc0), SS8(0xdde26200),
	SS8(0x0142291c), SS8(0xff960e94), SS8(0xff9f3e17), SS8(0xfbd8f358),
	SS8(0xdbf79400), SS8(0xff405e01), SS8(0xff7d4914), SS8(0xff8b1a31),
	SS8(0xfc1417b8), SS8(0xdac7bb40), SS8(0xfdbb828c), SS8(0xff762170)
};

static const int32_t sbc_proto_8_80m1[] = {
	SS8(0xff7c272c), SS8(0xfcb02620), SS8(0xda612700), SS8(0xfcb02620),
	SS8(0xff7c272c), SS8(0xff762170), SS8(0xfdbb828c), SS8(0xdac7bb40),
	SS8(0xfc1417b8), SS8(0xff8b1a31), SS8(0xff7d4914), SS8(0xff405e01),
	SS8(0xdbf79400), SS8(0xfbd8f358), SS8(0xff9f3e17), SS8(0xff960e94),
	SS8(0x0142291c), SS8(0xdde26200), SS8(0xfbedadc0), SS8(0xffb54b3b),
	SS8(0xffc4e05c), SS8(0x03bf7948), SS8(0xe071bc00), SS8(0xfc3fbb68),
	SS8(0xffca00ed), SS8(0x000bb7db), SS8(0x06af2308), SS8(0xe3889d20),
	SS8(0xfcbc98e8), SS8(0xffdba705), SS8(0x006c1de4), SS8(0x0a00d410),
	SS8(0xe7054ca0), SS8(0xfd52986c), SS8(0xffe9811d), SS8(0x00e530da),
	SS8(0x0d9daee0), SS8(0xeac182c0), SS8(0xfdf1c8d4), SS8(0xfff5bd1a)
};

static const int32_t synmatrix4[8][4] = {
	{ SN4(0x05a82798), SN4(0xfa57d868), SN4(0xfa57d868), SN4(0x05a82798) },
	{ SN4(0x030fbc54), SN4(0xf89be510), SN4(0x07641af0), SN4(0xfcf043ac) },
	{ SN4(0x00000000), SN4(0x00000000), SN4(0x00000000), SN4(0x00000000) },
	{ SN4(0xfcf043ac), SN4(0x07641af0), SN4(0xf89be510), SN4(0x030fbc54) },
	{ SN4(0xfa57d868), SN4(0x05a82798), SN4(0x05a82798), SN4(0xfa57d868) },
	{ SN4(0xf89be510), SN4(0xfcf043ac), SN4(0x030fbc54), SN4(0x07641af0) },
	{ SN4(0xf8000000), SN4(0xf8000000), SN4(0xf8000000), SN4(0xf8000000) },
	{ SN4(0xf89be510), SN4(0xfcf043ac), SN4(0x030fbc54), SN4(0x07641af0) }
};

static const int32_t synmatrix8[16][8] = {
	{ SN8(0x05a82798), SN8(0xfa57d868), SN8(0xfa57d868), SN8(0x05a82798),
	  SN8(0x05a82798), SN8(0xfa57d868), SN8(0xfa57d868), SN8(0x05a82798) },
	{ SN8(0x0471ced0), SN8(0xf8275a10), SN8(0x018f8b84), SN8(0x06a6d988),
	  SN8(0xf9592678), SN8(0xfe70747c), SN8(0x07d8a5f0), SN8(0xfb8e3130) },
	{ SN8(0x030fbc54), SN8(0xf89be510), SN8(0x07641af0), SN8(0xfcf043ac),
	  SN8(0xfcf043ac), SN8(0x07641af0), SN8(0xf89be510), SN8(0x030fbc54) },
	{ SN8(0x018f8b84), SN8(0xfb8e3130), SN8(0x06a6d988), SN8(0xf8275a10),
	  SN8(0x07d8a5f0), SN8(0xf9592678), SN8(0x0471ced0), SN8(0xfe70747c) },
	{ SN8(0x00000000), SN8(0x00000000), SN8(0x00000000), SN8(0x00000000),
	  SN8(0x00000000), SN8(0x00000000), SN8(0x00000000), SN8(0x00000000) },
	{ SN8(0xfe70747c), SN8(0x0471ced0), SN8(0xf9592678), SN8(0x07d8a5f0),
	  SN8(0xf8275a10), SN8(0x06a6d988), SN8(0xfb8e3130), SN8(0x018f8b84) },
	{ SN8(0xfcf043ac), SN8(0x07641af0), SN8(0xf89be510), SN8(0x030fbc54),
	  SN8(0x030fbc54), SN8(0xf89be510), SN8(0x07641af0), SN8(0xfcf043ac) },
	{ SN8(0xfb8e3130), SN8(0x07d8a5f0), SN8(0xfe70747c), SN8(0xf9592678),
	  SN8(0x06a6d988), SN8(0x018f8b84), SN8(0xf8275a10), SN8(0x0471ced0) },
	{ SN8(0xfa57d868), SN8(0x05a82798), SN8(0x05a82798), SN8(0xfa57d868),
	  SN8(0xfa57d868), SN8(0x05a82798), SN8(0x05a82798), SN8(0xfa57d868) },
	{ SN8(0xf9592678), SN8(0x018f8b84), SN8(0x07d8a5f0), SN8(0x0471ced0),
	  SN8(0xfb8e3130), SN8(0xf8275a10), SN8(0xfe70747c), SN8(0x06a6d988) },
	{ SN8(0xf89be510), SN8(0xfcf043ac), SN8(0x030fbc54), SN8(0x07641af0),
	  SN8(0x07641af0), SN8(0x030fbc54), SN8(0xfcf043ac), SN8(0xf89be510) },
	{ SN8(0xf8275a10), SN8(0xf9592678), SN8(0xfb8e3130), SN8(0xfe70747c),
	  SN8(0x018f8b84), SN8(0x0471ced0), SN8(0x06a6d988), SN8(0x07d8a5f0) },
	{ SN8(0xf8000000), SN8(0xf8000000), SN8(0xf8000000), SN8(0xf8000000),
	  SN8(0xf8000000), SN8(0xf8000000), SN8(0xf8000000), SN8(0xf8000000) },
	{ SN8(0xf8275a10), SN8(0xf9592678), SN8(0xfb8e3130), SN8(0xfe70747c),
	  SN8(0x018f8b84), SN8(0x0471ced0), SN8(0x06a6d988), SN8(0x07d8a5f0) },
	{ SN8(0xf89be510), SN8(0xfcf043ac), SN8(0x030fbc54), SN8(0x07641af0),
	  SN8(0x07641af0), SN8(0x030fbc54), SN8(0xfcf043ac), SN8(0xf89be510) },
	{ SN8(0xf9592678), SN8(0x018f8b84), SN8(0x07d8a5f0), SN8(0x0471ced0),
	  SN8(0xfb8e3130), SN8(0xf8275a10), SN8(0xfe70747c), SN8(0x06a6d988) }
};

/* Uncomment the following line to enable high precision build of SBC encoder */

/* #define SBC_HIGH_PRECISION */

#ifdef SBC_HIGH_PRECISION
#define FIXED_A int64_t /* data type for fixed point accumulator */
#define FIXED_T int32_t /* data type for fixed point constants */
#define SBC_FIXED_EXTRA_BITS 16
#else
#define FIXED_A int32_t /* data type for fixed point accumulator */
#define FIXED_T int16_t /* data type for fixed point constants */
#define SBC_FIXED_EXTRA_BITS 0
#endif

/* A2DP specification: Section 12.8 Tables
 *
 * Original values are premultiplied by 2 for better precision (that is the
 * maximum which is possible without overflows)
 *
 * Note: in each block of 8 numbers sign was changed for elements 2 and 7
 * in order to compensate the same change applied to cos_table_fixed_4
 */
#define SBC_PROTO_FIXED4_SCALE \
	((sizeof(FIXED_T) * CHAR_BIT - 1) - SBC_FIXED_EXTRA_BITS + 1)
#define F_PROTO4(x) (FIXED_A) ((x * 2) * \
	((FIXED_A) 1 << (sizeof(FIXED_T) * CHAR_BIT - 1)) + 0.5)
#define F(x) F_PROTO4(x)
static const FIXED_T _sbc_proto_fixed4[40] = {
	F(0.00000000E+00),  F(5.36548976E-04),
	-F(1.49188357E-03),  F(2.73370904E-03),
	F(3.83720193E-03),  F(3.89205149E-03),
	F(1.86581691E-03),  F(3.06012286E-03),

	F(1.09137620E-02),  F(2.04385087E-02),
	-F(2.88757392E-02),  F(3.21939290E-02),
	F(2.58767811E-02),  F(6.13245186E-03),
	-F(2.88217274E-02),  F(7.76463494E-02),

	F(1.35593274E-01),  F(1.94987841E-01),
	-F(2.46636662E-01),  F(2.81828203E-01),
	F(2.94315332E-01),  F(2.81828203E-01),
	F(2.46636662E-01), -F(1.94987841E-01),

	-F(1.35593274E-01), -F(7.76463494E-02),
	F(2.88217274E-02),  F(6.13245186E-03),
	F(2.58767811E-02),  F(3.21939290E-02),
	F(2.88757392E-02), -F(2.04385087E-02),

	-F(1.09137620E-02), -F(3.06012286E-03),
	-F(1.86581691E-03),  F(3.89205149E-03),
	F(3.83720193E-03),  F(2.73370904E-03),
	F(1.49188357E-03), -F(5.36548976E-04),
};
#undef F

/*
 * To produce this cosine matrix in Octave:
 *
 * b = zeros(4, 8);
 * for i = 0:3
 * for j = 0:7 b(i+1, j+1) = cos((i + 0.5) * (j - 2) * (pi/4))
 * endfor
 * endfor;
 * printf("%.10f, ", b');
 *
 * Note: in each block of 8 numbers sign was changed for elements 2 and 7
 *
 * Change of sign for element 2 allows to replace constant 1.0 (not
 * representable in Q15 format) with -1.0 (fine with Q15).
 * Changed sign for element 7 allows to have more similar constants
 * and simplify subband filter function code.
 */
#define SBC_COS_TABLE_FIXED4_SCALE \
	((sizeof(FIXED_T) * CHAR_BIT - 1) + SBC_FIXED_EXTRA_BITS)
#define F_COS4(x) (FIXED_A) ((x) * \
	((FIXED_A) 1 << (sizeof(FIXED_T) * CHAR_BIT - 1)) + 0.5)
#define F(x) F_COS4(x)
static const FIXED_T cos_table_fixed_4[32] = {
	F(0.7071067812),  F(0.9238795325), -F(1.0000000000),  F(0.9238795325),
	F(0.7071067812),  F(0.3826834324),  F(0.0000000000),  F(0.3826834324),

	-F(0.7071067812),  F(0.3826834324), -F(1.0000000000),  F(0.3826834324),
	-F(0.7071067812), -F(0.9238795325), -F(0.0000000000), -F(0.9238795325),

	-F(0.7071067812), -F(0.3826834324), -F(1.0000000000), -F(0.3826834324),
	-F(0.7071067812),  F(0.9238795325),  F(0.0000000000),  F(0.9238795325),

	F(0.7071067812), -F(0.9238795325), -F(1.0000000000), -F(0.9238795325),
	F(0.7071067812), -F(0.3826834324), -F(0.0000000000), -F(0.3826834324),
};
#undef F

/* A2DP specification: Section 12.8 Tables
 *
 * Original values are premultiplied by 4 for better precision (that is the
 * maximum which is possible without overflows)
 *
 * Note: in each block of 16 numbers sign was changed for elements 4, 13, 14, 15
 * in order to compensate the same change applied to cos_table_fixed_8
 */
#define SBC_PROTO_FIXED8_SCALE \
	((sizeof(FIXED_T) * CHAR_BIT - 1) - SBC_FIXED_EXTRA_BITS + 1)
#define F_PROTO8(x) (FIXED_A) ((x * 2) * \
	((FIXED_A) 1 << (sizeof(FIXED_T) * CHAR_BIT - 1)) + 0.5)
#define F(x) F_PROTO8(x)
static const FIXED_T _sbc_proto_fixed8[80] = {
	F(0.00000000E+00),  F(1.56575398E-04),
	F(3.43256425E-04),  F(5.54620202E-04),
	-F(8.23919506E-04),  F(1.13992507E-03),
	F(1.47640169E-03),  F(1.78371725E-03),
	F(2.01182542E-03),  F(2.10371989E-03),
	F(1.99454554E-03),  F(1.61656283E-03),
	F(9.02154502E-04),  F(1.78805361E-04),
	F(1.64973098E-03),  F(3.49717454E-03),

	F(5.65949473E-03),  F(8.02941163E-03),
	F(1.04584443E-02),  F(1.27472335E-02),
	-F(1.46525263E-02),  F(1.59045603E-02),
	F(1.62208471E-02),  F(1.53184106E-02),
	F(1.29371806E-02),  F(8.85757540E-03),
	F(2.92408442E-03), -F(4.91578024E-03),
	-F(1.46404076E-02),  F(2.61098752E-02),
	F(3.90751381E-02),  F(5.31873032E-02),

	F(6.79989431E-02),  F(8.29847578E-02),
	F(9.75753918E-02),  F(1.11196689E-01),
	-F(1.23264548E-01),  F(1.33264415E-01),
	F(1.40753505E-01),  F(1.45389847E-01),
	F(1.46955068E-01),  F(1.45389847E-01),
	F(1.40753505E-01),  F(1.33264415E-01),
	F(1.23264548E-01), -F(1.11196689E-01),
	-F(9.75753918E-02), -F(8.29847578E-02),

	-F(6.79989431E-02), -F(5.31873032E-02),
	-F(3.90751381E-02), -F(2.61098752E-02),
	F(1.46404076E-02), -F(4.91578024E-03),
	F(2.92408442E-03),  F(8.85757540E-03),
	F(1.29371806E-02),  F(1.53184106E-02),
	F(1.62208471E-02),  F(1.59045603E-02),
	F(1.46525263E-02), -F(1.27472335E-02),
	-F(1.04584443E-02), -F(8.02941163E-03),

	-F(5.65949473E-03), -F(3.49717454E-03),
	-F(1.64973098E-03), -F(1.78805361E-04),
	-F(9.02154502E-04),  F(1.61656283E-03),
	F(1.99454554E-03),  F(2.10371989E-03),
	F(2.01182542E-03),  F(1.78371725E-03),
	F(1.47640169E-03),  F(1.13992507E-03),
	F(8.23919506E-04), -F(5.54620202E-04),
	-F(3.43256425E-04), -F(1.56575398E-04),
};
#undef F

/*
 * To produce this cosine matrix in Octave:
 *
 * b = zeros(8, 16);
 * for i = 0:7
 * for j = 0:15 b(i+1, j+1) = cos((i + 0.5) * (j - 4) * (pi/8))
 * endfor endfor;
 * printf("%.10f, ", b');
 *
 * Note: in each block of 16 numbers sign was changed for elements 4, 13, 14, 15
 *
 * Change of sign for element 4 allows to replace constant 1.0 (not
 * representable in Q15 format) with -1.0 (fine with Q15).
 * Changed signs for elements 13, 14, 15 allow to have more similar constants
 * and simplify subband filter function code.
 */
#define SBC_COS_TABLE_FIXED8_SCALE \
	((sizeof(FIXED_T) * CHAR_BIT - 1) + SBC_FIXED_EXTRA_BITS)
#define F_COS8(x) (FIXED_A) ((x) * \
	((FIXED_A) 1 << (sizeof(FIXED_T) * CHAR_BIT - 1)) + 0.5)
#define F(x) F_COS8(x)
static const FIXED_T cos_table_fixed_8[128] = {
	F(0.7071067812),  F(0.8314696123),  F(0.9238795325),  F(0.9807852804),
	-F(1.0000000000),  F(0.9807852804),  F(0.9238795325),  F(0.8314696123),
	F(0.7071067812),  F(0.5555702330),  F(0.3826834324),  F(0.1950903220),
	F(0.0000000000),  F(0.1950903220),  F(0.3826834324),  F(0.5555702330),

	-F(0.7071067812), -F(0.1950903220),  F(0.3826834324),  F(0.8314696123),
	-F(1.0000000000),  F(0.8314696123),  F(0.3826834324), -F(0.1950903220),
	-F(0.7071067812), -F(0.9807852804), -F(0.9238795325), -F(0.5555702330),
	-F(0.0000000000), -F(0.5555702330), -F(0.9238795325), -F(0.9807852804),

	-F(0.7071067812), -F(0.9807852804), -F(0.3826834324),  F(0.5555702330),
	-F(1.0000000000),  F(0.5555702330), -F(0.3826834324), -F(0.9807852804),
	-F(0.7071067812),  F(0.1950903220),  F(0.9238795325),  F(0.8314696123),
	F(0.0000000000),  F(0.8314696123),  F(0.9238795325),  F(0.1950903220),

	F(0.7071067812), -F(0.5555702330), -F(0.9238795325),  F(0.1950903220),
	-F(1.0000000000),  F(0.1950903220), -F(0.9238795325), -F(0.5555702330),
	F(0.7071067812),  F(0.8314696123), -F(0.3826834324), -F(0.9807852804),
	-F(0.0000000000), -F(0.9807852804), -F(0.3826834324),  F(0.8314696123),

	F(0.7071067812),  F(0.5555702330), -F(0.9238795325), -F(0.1950903220),
	-F(1.0000000000), -F(0.1950903220), -F(0.9238795325),  F(0.5555702330),
	F(0.7071067812), -F(0.8314696123), -F(0.3826834324),  F(0.9807852804),
	F(0.0000000000),  F(0.9807852804), -F(0.3826834324), -F(0.8314696123),

	-F(0.7071067812),  F(0.9807852804), -F(0.3826834324), -F(0.5555702330),
	-F(1.0000000000), -F(0.5555702330), -F(0.3826834324),  F(0.9807852804),
	-F(0.7071067812), -F(0.1950903220),  F(0.9238795325), -F(0.8314696123),
	-F(0.0000000000), -F(0.8314696123),  F(0.9238795325), -F(0.1950903220),

	-F(0.7071067812),  F(0.1950903220),  F(0.3826834324), -F(0.8314696123),
	-F(1.0000000000), -F(0.8314696123),  F(0.3826834324),  F(0.1950903220),
	-F(0.7071067812),  F(0.9807852804), -F(0.9238795325),  F(0.5555702330),
	-F(0.0000000000),  F(0.5555702330), -F(0.9238795325),  F(0.9807852804),

	F(0.7071067812), -F(0.8314696123),  F(0.9238795325), -F(0.9807852804),
	-F(1.0000000000), -F(0.9807852804),  F(0.9238795325), -F(0.8314696123),
	F(0.7071067812), -F(0.5555702330),  F(0.3826834324), -F(0.1950903220),
	-F(0.0000000000), -F(0.1950903220),  F(0.3826834324), -F(0.5555702330),
};
#undef F

/*
 * Enforce 16 byte alignment for the data, which is supposed to be used
 * with SIMD optimized code.
 */

#define SBC_ALIGN_BITS 4
#define SBC_ALIGN_MASK ((1 << (SBC_ALIGN_BITS)) - 1)

#ifdef __GNUC__
#define SBC_ALIGNED __attribute__((aligned(1 << (SBC_ALIGN_BITS))))
#else
#define SBC_ALIGNED
#endif

/*
 * Constant tables for the use in SIMD optimized analysis filters
 * Each table consists of two parts:
 * 1. reordered "proto" table
 * 2. reordered "cos" table
 *
 * Due to non-symmetrical reordering, separate tables for "even"
 * and "odd" cases are needed
 */

static const FIXED_T SBC_ALIGNED analysis_consts_fixed4_simd_even[40 + 16] = {
#define C0 1.0932568993
#define C1 1.3056875580
#define C2 1.3056875580
#define C3 1.6772280856

#define F(x) F_PROTO4(x)
	 F(0.00000000E+00 * C0),  F(3.83720193E-03 * C0),
	 F(5.36548976E-04 * C1),  F(2.73370904E-03 * C1),
	 F(3.06012286E-03 * C2),  F(3.89205149E-03 * C2),
	 F(0.00000000E+00 * C3), -F(1.49188357E-03 * C3),
	 F(1.09137620E-02 * C0),  F(2.58767811E-02 * C0),
	 F(2.04385087E-02 * C1),  F(3.21939290E-02 * C1),
	 F(7.76463494E-02 * C2),  F(6.13245186E-03 * C2),
	 F(0.00000000E+00 * C3), -F(2.88757392E-02 * C3),
	 F(1.35593274E-01 * C0),  F(2.94315332E-01 * C0),
	 F(1.94987841E-01 * C1),  F(2.81828203E-01 * C1),
	-F(1.94987841E-01 * C2),  F(2.81828203E-01 * C2),
	 F(0.00000000E+00 * C3), -F(2.46636662E-01 * C3),
	-F(1.35593274E-01 * C0),  F(2.58767811E-02 * C0),
	-F(7.76463494E-02 * C1),  F(6.13245186E-03 * C1),
	-F(2.04385087E-02 * C2),  F(3.21939290E-02 * C2),
	 F(0.00000000E+00 * C3),  F(2.88217274E-02 * C3),
	-F(1.09137620E-02 * C0),  F(3.83720193E-03 * C0),
	-F(3.06012286E-03 * C1),  F(3.89205149E-03 * C1),
	-F(5.36548976E-04 * C2),  F(2.73370904E-03 * C2),
	 F(0.00000000E+00 * C3), -F(1.86581691E-03 * C3),
#undef F
#define F(x) F_COS4(x)
	 F(0.7071067812 / C0),  F(0.9238795325 / C1),
	-F(0.7071067812 / C0),  F(0.3826834324 / C1),
	-F(0.7071067812 / C0), -F(0.3826834324 / C1),
	 F(0.7071067812 / C0), -F(0.9238795325 / C1),
	 F(0.3826834324 / C2), -F(1.0000000000 / C3),
	-F(0.9238795325 / C2), -F(1.0000000000 / C3),
	 F(0.9238795325 / C2), -F(1.0000000000 / C3),
	-F(0.3826834324 / C2), -F(1.0000000000 / C3),
#undef F

#undef C0
#undef C1
#undef C2
#undef C3
};

static const FIXED_T SBC_ALIGNED analysis_consts_fixed4_simd_odd[40 + 16] = {
#define C0 1.3056875580
#define C1 1.6772280856
#define C2 1.0932568993
#define C3 1.3056875580

#define F(x) F_PROTO4(x)
	 F(2.73370904E-03 * C0),  F(5.36548976E-04 * C0),
	-F(1.49188357E-03 * C1),  F(0.00000000E+00 * C1),
	 F(3.83720193E-03 * C2),  F(1.09137620E-02 * C2),
	 F(3.89205149E-03 * C3),  F(3.06012286E-03 * C3),
	 F(3.21939290E-02 * C0),  F(2.04385087E-02 * C0),
	-F(2.88757392E-02 * C1),  F(0.00000000E+00 * C1),
	 F(2.58767811E-02 * C2),  F(1.35593274E-01 * C2),
	 F(6.13245186E-03 * C3),  F(7.76463494E-02 * C3),
	 F(2.81828203E-01 * C0),  F(1.94987841E-01 * C0),
	-F(2.46636662E-01 * C1),  F(0.00000000E+00 * C1),
	 F(2.94315332E-01 * C2), -F(1.35593274E-01 * C2),
	 F(2.81828203E-01 * C3), -F(1.94987841E-01 * C3),
	 F(6.13245186E-03 * C0), -F(7.76463494E-02 * C0),
	 F(2.88217274E-02 * C1),  F(0.00000000E+00 * C1),
	 F(2.58767811E-02 * C2), -F(1.09137620E-02 * C2),
	 F(3.21939290E-02 * C3), -F(2.04385087E-02 * C3),
	 F(3.89205149E-03 * C0), -F(3.06012286E-03 * C0),
	-F(1.86581691E-03 * C1),  F(0.00000000E+00 * C1),
	 F(3.83720193E-03 * C2),  F(0.00000000E+00 * C2),
	 F(2.73370904E-03 * C3), -F(5.36548976E-04 * C3),
#undef F
#define F(x) F_COS4(x)
	 F(0.9238795325 / C0), -F(1.0000000000 / C1),
	 F(0.3826834324 / C0), -F(1.0000000000 / C1),
	-F(0.3826834324 / C0), -F(1.0000000000 / C1),
	-F(0.9238795325 / C0), -F(1.0000000000 / C1),
	 F(0.7071067812 / C2),  F(0.3826834324 / C3),
	-F(0.7071067812 / C2), -F(0.9238795325 / C3),
	-F(0.7071067812 / C2),  F(0.9238795325 / C3),
	 F(0.7071067812 / C2), -F(0.3826834324 / C3),
#undef F

#undef C0
#undef C1
#undef C2
#undef C3
};

static const FIXED_T SBC_ALIGNED analysis_consts_fixed8_simd_even[80 + 64] = {
#define C0 2.7906148894
#define C1 2.4270044280
#define C2 2.8015616024
#define C3 3.1710363741
#define C4 2.5377944043
#define C5 2.4270044280
#define C6 2.8015616024
#define C7 3.1710363741

#define F(x) F_PROTO8(x)
	 F(0.00000000E+00 * C0),  F(2.01182542E-03 * C0),
	 F(1.56575398E-04 * C1),  F(1.78371725E-03 * C1),
	 F(3.43256425E-04 * C2),  F(1.47640169E-03 * C2),
	 F(5.54620202E-04 * C3),  F(1.13992507E-03 * C3),
	-F(8.23919506E-04 * C4),  F(0.00000000E+00 * C4),
	 F(2.10371989E-03 * C5),  F(3.49717454E-03 * C5),
	 F(1.99454554E-03 * C6),  F(1.64973098E-03 * C6),
	 F(1.61656283E-03 * C7),  F(1.78805361E-04 * C7),
	 F(5.65949473E-03 * C0),  F(1.29371806E-02 * C0),
	 F(8.02941163E-03 * C1),  F(1.53184106E-02 * C1),
	 F(1.04584443E-02 * C2),  F(1.62208471E-02 * C2),
	 F(1.27472335E-02 * C3),  F(1.59045603E-02 * C3),
	-F(1.46525263E-02 * C4),  F(0.00000000E+00 * C4),
	 F(8.85757540E-03 * C5),  F(5.31873032E-02 * C5),
	 F(2.92408442E-03 * C6),  F(3.90751381E-02 * C6),
	-F(4.91578024E-03 * C7),  F(2.61098752E-02 * C7),
	 F(6.79989431E-02 * C0),  F(1.46955068E-01 * C0),
	 F(8.29847578E-02 * C1),  F(1.45389847E-01 * C1),
	 F(9.75753918E-02 * C2),  F(1.40753505E-01 * C2),
	 F(1.11196689E-01 * C3),  F(1.33264415E-01 * C3),
	-F(1.23264548E-01 * C4),  F(0.00000000E+00 * C4),
	 F(1.45389847E-01 * C5), -F(8.29847578E-02 * C5),
	 F(1.40753505E-01 * C6), -F(9.75753918E-02 * C6),
	 F(1.33264415E-01 * C7), -F(1.11196689E-01 * C7),
	-F(6.79989431E-02 * C0),  F(1.29371806E-02 * C0),
	-F(5.31873032E-02 * C1),  F(8.85757540E-03 * C1),
	-F(3.90751381E-02 * C2),  F(2.92408442E-03 * C2),
	-F(2.61098752E-02 * C3), -F(4.91578024E-03 * C3),
	 F(1.46404076E-02 * C4),  F(0.00000000E+00 * C4),
	 F(1.53184106E-02 * C5), -F(8.02941163E-03 * C5),
	 F(1.62208471E-02 * C6), -F(1.04584443E-02 * C6),
	 F(1.59045603E-02 * C7), -F(1.27472335E-02 * C7),
	-F(5.65949473E-03 * C0),  F(2.01182542E-03 * C0),
	-F(3.49717454E-03 * C1),  F(2.10371989E-03 * C1),
	-F(1.64973098E-03 * C2),  F(1.99454554E-03 * C2),
	-F(1.78805361E-04 * C3),  F(1.61656283E-03 * C3),
	-F(9.02154502E-04 * C4),  F(0.00000000E+00 * C4),
	 F(1.78371725E-03 * C5), -F(1.56575398E-04 * C5),
	 F(1.47640169E-03 * C6), -F(3.43256425E-04 * C6),
	 F(1.13992507E-03 * C7), -F(5.54620202E-04 * C7),
#undef F
#define F(x) F_COS8(x)
	 F(0.7071067812 / C0),  F(0.8314696123 / C1),
	-F(0.7071067812 / C0), -F(0.1950903220 / C1),
	-F(0.7071067812 / C0), -F(0.9807852804 / C1),
	 F(0.7071067812 / C0), -F(0.5555702330 / C1),
	 F(0.7071067812 / C0),  F(0.5555702330 / C1),
	-F(0.7071067812 / C0),  F(0.9807852804 / C1),
	-F(0.7071067812 / C0),  F(0.1950903220 / C1),
	 F(0.7071067812 / C0), -F(0.8314696123 / C1),
	 F(0.9238795325 / C2),  F(0.9807852804 / C3),
	 F(0.3826834324 / C2),  F(0.8314696123 / C3),
	-F(0.3826834324 / C2),  F(0.5555702330 / C3),
	-F(0.9238795325 / C2),  F(0.1950903220 / C3),
	-F(0.9238795325 / C2), -F(0.1950903220 / C3),
	-F(0.3826834324 / C2), -F(0.5555702330 / C3),
	 F(0.3826834324 / C2), -F(0.8314696123 / C3),
	 F(0.9238795325 / C2), -F(0.9807852804 / C3),
	-F(1.0000000000 / C4),  F(0.5555702330 / C5),
	-F(1.0000000000 / C4), -F(0.9807852804 / C5),
	-F(1.0000000000 / C4),  F(0.1950903220 / C5),
	-F(1.0000000000 / C4),  F(0.8314696123 / C5),
	-F(1.0000000000 / C4), -F(0.8314696123 / C5),
	-F(1.0000000000 / C4), -F(0.1950903220 / C5),
	-F(1.0000000000 / C4),  F(0.9807852804 / C5),
	-F(1.0000000000 / C4), -F(0.5555702330 / C5),
	 F(0.3826834324 / C6),  F(0.1950903220 / C7),
	-F(0.9238795325 / C6), -F(0.5555702330 / C7),
	 F(0.9238795325 / C6),  F(0.8314696123 / C7),
	-F(0.3826834324 / C6), -F(0.9807852804 / C7),
	-F(0.3826834324 / C6),  F(0.9807852804 / C7),
	 F(0.9238795325 / C6), -F(0.8314696123 / C7),
	-F(0.9238795325 / C6),  F(0.5555702330 / C7),
	 F(0.3826834324 / C6), -F(0.1950903220 / C7),
#undef F

#undef C0
#undef C1
#undef C2
#undef C3
#undef C4
#undef C5
#undef C6
#undef C7
};

static const FIXED_T SBC_ALIGNED analysis_consts_fixed8_simd_odd[80 + 64] = {
#define C0 2.5377944043
#define C1 2.4270044280
#define C2 2.8015616024
#define C3 3.1710363741
#define C4 2.7906148894
#define C5 2.4270044280
#define C6 2.8015616024
#define C7 3.1710363741

#define F(x) F_PROTO8(x)
	 F(0.00000000E+00 * C0), -F(8.23919506E-04 * C0),
	 F(1.56575398E-04 * C1),  F(1.78371725E-03 * C1),
	 F(3.43256425E-04 * C2),  F(1.47640169E-03 * C2),
	 F(5.54620202E-04 * C3),  F(1.13992507E-03 * C3),
	 F(2.01182542E-03 * C4),  F(5.65949473E-03 * C4),
	 F(2.10371989E-03 * C5),  F(3.49717454E-03 * C5),
	 F(1.99454554E-03 * C6),  F(1.64973098E-03 * C6),
	 F(1.61656283E-03 * C7),  F(1.78805361E-04 * C7),
	 F(0.00000000E+00 * C0), -F(1.46525263E-02 * C0),
	 F(8.02941163E-03 * C1),  F(1.53184106E-02 * C1),
	 F(1.04584443E-02 * C2),  F(1.62208471E-02 * C2),
	 F(1.27472335E-02 * C3),  F(1.59045603E-02 * C3),
	 F(1.29371806E-02 * C4),  F(6.79989431E-02 * C4),
	 F(8.85757540E-03 * C5),  F(5.31873032E-02 * C5),
	 F(2.92408442E-03 * C6),  F(3.90751381E-02 * C6),
	-F(4.91578024E-03 * C7),  F(2.61098752E-02 * C7),
	 F(0.00000000E+00 * C0), -F(1.23264548E-01 * C0),
	 F(8.29847578E-02 * C1),  F(1.45389847E-01 * C1),
	 F(9.75753918E-02 * C2),  F(1.40753505E-01 * C2),
	 F(1.11196689E-01 * C3),  F(1.33264415E-01 * C3),
	 F(1.46955068E-01 * C4), -F(6.79989431E-02 * C4),
	 F(1.45389847E-01 * C5), -F(8.29847578E-02 * C5),
	 F(1.40753505E-01 * C6), -F(9.75753918E-02 * C6),
	 F(1.33264415E-01 * C7), -F(1.11196689E-01 * C7),
	 F(0.00000000E+00 * C0),  F(1.46404076E-02 * C0),
	-F(5.31873032E-02 * C1),  F(8.85757540E-03 * C1),
	-F(3.90751381E-02 * C2),  F(2.92408442E-03 * C2),
	-F(2.61098752E-02 * C3), -F(4.91578024E-03 * C3),
	 F(1.29371806E-02 * C4), -F(5.65949473E-03 * C4),
	 F(1.53184106E-02 * C5), -F(8.02941163E-03 * C5),
	 F(1.62208471E-02 * C6), -F(1.04584443E-02 * C6),
	 F(1.59045603E-02 * C7), -F(1.27472335E-02 * C7),
	 F(0.00000000E+00 * C0), -F(9.02154502E-04 * C0),
	-F(3.49717454E-03 * C1),  F(2.10371989E-03 * C1),
	-F(1.64973098E-03 * C2),  F(1.99454554E-03 * C2),
	-F(1.78805361E-04 * C3),  F(1.61656283E-03 * C3),
	 F(2.01182542E-03 * C4),  F(0.00000000E+00 * C4),
	 F(1.78371725E-03 * C5), -F(1.56575398E-04 * C5),
	 F(1.47640169E-03 * C6), -F(3.43256425E-04 * C6),
	 F(1.13992507E-03 * C7), -F(5.54620202E-04 * C7),
#undef F
#define F(x) F_COS8(x)
	-F(1.0000000000 / C0),  F(0.8314696123 / C1),
	-F(1.0000000000 / C0), -F(0.1950903220 / C1),
	-F(1.0000000000 / C0), -F(0.9807852804 / C1),
	-F(1.0000000000 / C0), -F(0.5555702330 / C1),
	-F(1.0000000000 / C0),  F(0.5555702330 / C1),
	-F(1.0000000000 / C0),  F(0.9807852804 / C1),
	-F(1.0000000000 / C0),  F(0.1950903220 / C1),
	-F(1.0000000000 / C0), -F(0.8314696123 / C1),
	 F(0.9238795325 / C2),  F(0.9807852804 / C3),
	 F(0.3826834324 / C2),  F(0.8314696123 / C3),
	-F(0.3826834324 / C2),  F(0.5555702330 / C3),
	-F(0.9238795325 / C2),  F(0.1950903220 / C3),
	-F(0.9238795325 / C2), -F(0.1950903220 / C3),
	-F(0.3826834324 / C2), -F(0.5555702330 / C3),
	 F(0.3826834324 / C2), -F(0.8314696123 / C3),
	 F(0.9238795325 / C2), -F(0.9807852804 / C3),
	 F(0.7071067812 / C4),  F(0.5555702330 / C5),
	-F(0.7071067812 / C4), -F(0.9807852804 / C5),
	-F(0.7071067812 / C4),  F(0.1950903220 / C5),
	 F(0.7071067812 / C4),  F(0.8314696123 / C5),
	 F(0.7071067812 / C4), -F(0.8314696123 / C5),
	-F(0.7071067812 / C4), -F(0.1950903220 / C5),
	-F(0.7071067812 / C4),  F(0.9807852804 / C5),
	 F(0.7071067812 / C4), -F(0.5555702330 / C5),
	 F(0.3826834324 / C6),  F(0.1950903220 / C7),
	-F(0.9238795325 / C6), -F(0.5555702330 / C7),
	 F(0.9238795325 / C6),  F(0.8314696123 / C7),
	-F(0.3826834324 / C6), -F(0.9807852804 / C7),
	-F(0.3826834324 / C6),  F(0.9807852804 / C7),
	 F(0.9238795325 / C6), -F(0.8314696123 / C7),
	-F(0.9238795325 / C6),  F(0.5555702330 / C7),
	 F(0.3826834324 / C6), -F(0.1950903220 / C7),
#undef F

#undef C0
#undef C1
#undef C2
#undef C3
#undef C4
#undef C5
#undef C6
#undef C7
};