2
* mpadec - MPEG audio decoder
3
* Copyright (C) 2002-2004 Dmitriy Startsev (dstartsev@rambler.ru)
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/* $Id: synth.c,v 1.3 2004/08/03 05:22:22 metal_man Exp $ */
22
#include "mpadec_internal.h"
24
#define ROUND(x) (floor((x) + 0.5))
25
#define LROUND(x) ((int32_t)(ROUND(x)))
26
#define LLROUND(x) ((int64_t)(ROUND(x)))
28
static const MYFLT costab[32] = {
29
0.50060299823519630134550410676638, 0.50547095989754365998444458560696,
30
0.51544730992262454697495130564925, 0.53104259108978417447573393235719,
31
0.55310389603444452782938083813705, 0.58293496820613387367383070125262,
32
0.62250412303566481615725615676281, 0.67480834145500574602596871104104,
33
0.74453627100229844977698119197295, 0.83934964541552703873926374662543,
34
0.97256823786196069369768941405256, 1.16943993343288495515577028404220,
35
1.48416461631416627724332693742810, 2.05778100995341155085655447971040,
36
3.40760841846871878570119133345910, 10.1900081235480568112121092010360,
37
0.50241928618815570551167011928012, 0.52249861493968888062857531905669,
38
0.56694403481635770368053791515488, 0.64682178335999012954836011165200,
39
0.78815462345125022473398248719742, 1.06067768599034747134045174723310,
40
1.72244709823833392781591536415660, 5.10114861868916385810624549234540,
41
0.50979557910415916894193980398784, 0.60134488693504528054372182390922,
42
0.89997622313641570463850954094189, 2.56291544774150617879608629617770,
43
0.54119610014619698439972320536639, 1.30656296487637652785664317342720,
44
0.70710678118654752440084436210485, 0.0
47
static void dct64(MYFLT *outptr0, MYFLT *outptr1, MYFLT *samples)
49
MYFLT tmp1[32], tmp2[32];
52
register MYFLT *in = samples;
54
tmp1[0] = in[0] + in[31];
55
tmp1[1] = in[1] + in[30];
56
tmp1[31] = (in[0] - in[31])*costab[0];
57
tmp1[30] = (in[1] - in[30])*costab[1];
59
tmp1[2] = in[2] + in[29];
60
tmp1[3] = in[3] + in[28];
61
tmp1[29] = (in[2] - in[29])*costab[2];
62
tmp1[28] = (in[3] - in[28])*costab[3];
64
tmp1[4] = in[4] + in[27];
65
tmp1[5] = in[5] + in[26];
66
tmp1[27] = (in[4] - in[27])*costab[4];
67
tmp1[26] = (in[5] - in[26])*costab[5];
69
tmp1[6] = in[6] + in[25];
70
tmp1[7] = in[7] + in[24];
71
tmp1[25] = (in[6] - in[25])*costab[6];
72
tmp1[24] = (in[7] - in[24])*costab[7];
74
tmp1[8] = in[8] + in[23];
75
tmp1[9] = in[9] + in[22];
76
tmp1[23] = (in[8] - in[23])*costab[8];
77
tmp1[22] = (in[9] - in[22])*costab[9];
79
tmp1[10] = in[10] + in[21];
80
tmp1[11] = in[11] + in[20];
81
tmp1[21] = (in[10] - in[21])*costab[10];
82
tmp1[20] = (in[11] - in[20])*costab[11];
84
tmp1[12] = in[12] + in[19];
85
tmp1[13] = in[13] + in[18];
86
tmp1[19] = (in[12] - in[19])*costab[12];
87
tmp1[18] = (in[13] - in[18])*costab[13];
89
tmp1[14] = in[14] + in[17];
90
tmp1[15] = in[15] + in[16];
91
tmp1[17] = (in[14] - in[17])*costab[14];
92
tmp1[16] = (in[15] - in[16])*costab[15];
95
tmp2[0] = tmp1[0] + tmp1[15];
96
tmp2[1] = tmp1[1] + tmp1[14];
97
tmp2[15] = (tmp1[0] - tmp1[15])*costab[16 + 0];
98
tmp2[14] = (tmp1[1] - tmp1[14])*costab[16 + 1];
100
tmp2[2] = tmp1[2] + tmp1[13];
101
tmp2[3] = tmp1[3] + tmp1[12];
102
tmp2[13] = (tmp1[2] - tmp1[13])*costab[16 + 2];
103
tmp2[12] = (tmp1[3] - tmp1[12])*costab[16 + 3];
105
tmp2[4] = tmp1[4] + tmp1[11];
106
tmp2[5] = tmp1[5] + tmp1[10];
107
tmp2[11] = (tmp1[4] - tmp1[11])*costab[16 + 4];
108
tmp2[10] = (tmp1[5] - tmp1[10])*costab[16 + 5];
110
tmp2[6] = tmp1[6] + tmp1[9];
111
tmp2[7] = tmp1[7] + tmp1[8];
112
tmp2[9] = (tmp1[6] - tmp1[9])*costab[16 + 6];
113
tmp2[8] = (tmp1[7] - tmp1[8])*costab[16 + 7];
115
tmp2[16] = tmp1[16] + tmp1[31];
116
tmp2[17] = tmp1[17] + tmp1[30];
117
tmp2[31] = (tmp1[31] - tmp1[16])*costab[16 + 0];
118
tmp2[30] = (tmp1[30] - tmp1[17])*costab[16 + 1];
120
tmp2[18] = tmp1[18] + tmp1[29];
121
tmp2[19] = tmp1[19] + tmp1[28];
122
tmp2[29] = (tmp1[29] - tmp1[18])*costab[16 + 2];
123
tmp2[28] = (tmp1[28] - tmp1[19])*costab[16 + 3];
125
tmp2[20] = tmp1[20] + tmp1[27];
126
tmp2[21] = tmp1[21] + tmp1[26];
127
tmp2[27] = (tmp1[27] - tmp1[20])*costab[16 + 4];
128
tmp2[26] = (tmp1[26] - tmp1[21])*costab[16 + 5];
130
tmp2[22] = tmp1[22] + tmp1[25];
131
tmp2[23] = tmp1[23] + tmp1[24];
132
tmp2[25] = (tmp1[25] - tmp1[22])*costab[16 + 6];
133
tmp2[24] = (tmp1[24] - tmp1[23])*costab[16 + 7];
136
tmp1[0] = tmp2[0] + tmp2[7];
137
tmp1[7] = (tmp2[0] - tmp2[7])*costab[16 + 8 + 0];
138
tmp1[1] = tmp2[1] + tmp2[6];
139
tmp1[6] = (tmp2[1] - tmp2[6])*costab[16 + 8 + 1];
140
tmp1[2] = tmp2[2] + tmp2[5];
141
tmp1[5] = (tmp2[2] - tmp2[5])*costab[16 + 8 + 2];
142
tmp1[3] = tmp2[3] + tmp2[4];
143
tmp1[4] = (tmp2[3] - tmp2[4])*costab[16 + 8 + 3];
145
tmp1[8] = tmp2[8] + tmp2[15];
146
tmp1[15] = (tmp2[15] - tmp2[8])*costab[16 + 8 + 0];
147
tmp1[9] = tmp2[9] + tmp2[14];
148
tmp1[14] = (tmp2[14] - tmp2[9])*costab[16 + 8 + 1];
149
tmp1[10] = tmp2[10] + tmp2[13];
150
tmp1[13] = (tmp2[13] - tmp2[10])*costab[16 + 8 + 2];
151
tmp1[11] = tmp2[11] + tmp2[12];
152
tmp1[12] = (tmp2[12] - tmp2[11])*costab[16 + 8 + 3];
154
tmp1[16] = tmp2[16] + tmp2[23];
155
tmp1[23] = (tmp2[16] - tmp2[23])*costab[16 + 8 + 0];
156
tmp1[17] = tmp2[17] + tmp2[22];
157
tmp1[22] = (tmp2[17] - tmp2[22])*costab[16 + 8 + 1];
158
tmp1[18] = tmp2[18] + tmp2[21];
159
tmp1[21] = (tmp2[18] - tmp2[21])*costab[16 + 8 + 2];
160
tmp1[19] = tmp2[19] + tmp2[20];
161
tmp1[20] = (tmp2[19] - tmp2[20])*costab[16 + 8 + 3];
163
tmp1[24] = tmp2[24] + tmp2[31];
164
tmp1[31] = (tmp2[31] - tmp2[24])*costab[16 + 8 + 0];
165
tmp1[25] = tmp2[25] + tmp2[30];
166
tmp1[30] = (tmp2[30] - tmp2[25])*costab[16 + 8 + 1];
167
tmp1[26] = tmp2[26] + tmp2[29];
168
tmp1[29] = (tmp2[29] - tmp2[26])*costab[16 + 8 + 2];
169
tmp1[27] = tmp2[27] + tmp2[28];
170
tmp1[28] = (tmp2[28] - tmp2[27])*costab[16 + 8 + 3];
173
tmp2[0] = tmp1[0] + tmp1[3];
174
tmp2[3] = (tmp1[0] - tmp1[3])*costab[16 + 8 + 4 + 0];
175
tmp2[1] = tmp1[1] + tmp1[2];
176
tmp2[2] = (tmp1[1] - tmp1[2])*costab[16 + 8 + 4 + 1];
178
tmp2[4] = tmp1[4] + tmp1[7];
179
tmp2[7] = (tmp1[7] - tmp1[4])*costab[16 + 8 + 4 + 0];
180
tmp2[5] = tmp1[5] + tmp1[6];
181
tmp2[6] = (tmp1[6] - tmp1[5])*costab[16 + 8 + 4 + 1];
183
tmp2[8] = tmp1[8] + tmp1[11];
184
tmp2[11] = (tmp1[8] - tmp1[11])*costab[16 + 8 + 4 + 0];
185
tmp2[9] = tmp1[9] + tmp1[10];
186
tmp2[10] = (tmp1[9] - tmp1[10])*costab[16 + 8 + 4 + 1];
188
tmp2[12] = tmp1[12] + tmp1[15];
189
tmp2[15] = (tmp1[15] - tmp1[12])*costab[16 + 8 + 4 + 0];
190
tmp2[13] = tmp1[13] + tmp1[14];
191
tmp2[14] = (tmp1[14] - tmp1[13])*costab[16 + 8 + 4 + 1];
193
tmp2[16] = tmp1[16] + tmp1[19];
194
tmp2[19] = (tmp1[16] - tmp1[19])*costab[16 + 8 + 4 + 0];
195
tmp2[17] = tmp1[17] + tmp1[18];
196
tmp2[18] = (tmp1[17] - tmp1[18])*costab[16 + 8 + 4 + 1];
198
tmp2[20] = tmp1[20] + tmp1[23];
199
tmp2[23] = (tmp1[23] - tmp1[20])*costab[16 + 8 + 4 + 0];
200
tmp2[21] = tmp1[21] + tmp1[22];
201
tmp2[22] = (tmp1[22] - tmp1[21])*costab[16 + 8 + 4 + 1];
203
tmp2[24] = tmp1[24] + tmp1[27];
204
tmp2[27] = (tmp1[24] - tmp1[27])*costab[16 + 8 + 4 + 0];
205
tmp2[25] = tmp1[25] + tmp1[26];
206
tmp2[26] = (tmp1[25] - tmp1[26])*costab[16 + 8 + 4 + 1];
208
tmp2[28] = tmp1[28] + tmp1[31];
209
tmp2[31] = (tmp1[31] - tmp1[28])*costab[16 + 8 + 4 + 0];
210
tmp2[29] = tmp1[29] + tmp1[30];
211
tmp2[30] = (tmp1[30] - tmp1[29])*costab[16 + 8 + 4 + 1];
214
tmp1[0] = tmp2[0] + tmp2[1];
215
tmp1[1] = (tmp2[0] - tmp2[1])*costab[16 + 8 + 4 + 2];
216
tmp1[2] = tmp2[2] + tmp2[3];
217
tmp1[3] = (tmp2[3] - tmp2[2])*costab[16 + 8 + 4 + 2];
220
tmp1[4] = tmp2[4] + tmp2[5];
221
tmp1[5] = (tmp2[4] - tmp2[5])*costab[16 + 8 + 4 + 2];
222
tmp1[6] = tmp2[6] + tmp2[7];
223
tmp1[7] = (tmp2[7] - tmp2[6])*costab[16 + 8 + 4 + 2];
229
tmp1[8] = tmp2[8] + tmp2[9];
230
tmp1[9] = (tmp2[8] - tmp2[9])*costab[16 + 8 + 4 + 2];
231
tmp1[10] = tmp2[10] + tmp2[11];
232
tmp1[11] = (tmp2[11] - tmp2[10])*costab[16 + 8 + 4 + 2];
233
tmp1[10] += tmp1[11];
235
tmp1[12] = tmp2[12] + tmp2[13];
236
tmp1[13] = (tmp2[12] - tmp2[13])*costab[16 + 8 + 4 + 2];
237
tmp1[14] = tmp2[14] + tmp2[15];
238
tmp1[15] = (tmp2[15] - tmp2[14])*costab[16 + 8 + 4 + 2];
239
tmp1[14] += tmp1[15];
240
tmp1[12] += tmp1[14];
241
tmp1[14] += tmp1[13];
242
tmp1[13] += tmp1[15];
244
tmp1[16] = tmp2[16] + tmp2[17];
245
tmp1[17] = (tmp2[16] - tmp2[17])*costab[16 + 8 + 4 + 2];
246
tmp1[18] = tmp2[18] + tmp2[19];
247
tmp1[19] = (tmp2[19] - tmp2[18])*costab[16 + 8 + 4 + 2];
248
tmp1[18] += tmp1[19];
250
tmp1[20] = tmp2[20] + tmp2[21];
251
tmp1[21] = (tmp2[20] - tmp2[21])*costab[16 + 8 + 4 + 2];
252
tmp1[22] = tmp2[22] + tmp2[23];
253
tmp1[23] = (tmp2[23] - tmp2[22])*costab[16 + 8 + 4 + 2];
254
tmp1[22] += tmp1[23];
255
tmp1[20] += tmp1[22];
256
tmp1[22] += tmp1[21];
257
tmp1[21] += tmp1[23];
259
tmp1[24] = tmp2[24] + tmp2[25];
260
tmp1[25] = (tmp2[24] - tmp2[25])*costab[16 + 8 + 4 + 2];
261
tmp1[26] = tmp2[26] + tmp2[27];
262
tmp1[27] = (tmp2[27] - tmp2[26])*costab[16 + 8 + 4 + 2];
263
tmp1[26] += tmp1[27];
265
tmp1[28] = tmp2[28] + tmp2[29];
266
tmp1[29] = (tmp2[28] - tmp2[29])*costab[16 + 8 + 4 + 2];
267
tmp1[30] = tmp2[30] + tmp2[31];
268
tmp1[31] = (tmp2[31] - tmp2[30])*costab[16 + 8 + 4 + 2];
269
tmp1[30] += tmp1[31];
270
tmp1[28] += tmp1[30];
271
tmp1[30] += tmp1[29];
272
tmp1[29] += tmp1[31];
275
register MYFLT tmp, *out0 = outptr0, *out1 = outptr1;
277
out0[16*16] = tmp1[0];
278
out0[12*16] = tmp1[4];
279
out0[8*16] = tmp1[2];
280
out0[4*16] = tmp1[6];
281
out0[0*16] = tmp1[1];
282
out1[0*16] = tmp1[1];
283
out1[4*16] = tmp1[5];
284
out1[8*16] = tmp1[3];
285
out1[12*16] = tmp1[7];
287
out0[14*16] = tmp1[8] + tmp1[12];
288
out0[10*16] = tmp1[12] + tmp1[10];
289
out0[6*16] = tmp1[10] + tmp1[14];
290
out0[2*16] = tmp1[14] + tmp1[9];
291
out1[2*16] = tmp1[9] + tmp1[13];
292
out1[6*16] = tmp1[13] + tmp1[11];
293
out1[10*16] = tmp1[11] + tmp1[15];
294
out1[14*16] = tmp1[15];
296
tmp = tmp1[24] + tmp1[28];
297
out0[15*16] = tmp + tmp1[16];
298
out0[13*16] = tmp + tmp1[20];
299
tmp = tmp1[28] + tmp1[26];
300
out0[11*16] = tmp + tmp1[20];
301
out0[9*16] = tmp + tmp1[18];
302
tmp = tmp1[26] + tmp1[30];
303
out0[7*16] = tmp + tmp1[18];
304
out0[5*16] = tmp + tmp1[22];
305
tmp = tmp1[30] + tmp1[25];
306
out0[3*16] = tmp + tmp1[22];
307
out0[1*16] = tmp + tmp1[17];
308
tmp = tmp1[25] + tmp1[29];
309
out1[1*16] = tmp + tmp1[17];
310
out1[3*16] = tmp + tmp1[21];
311
tmp = tmp1[29] + tmp1[27];
312
out1[5*16] = tmp + tmp1[21];
313
out1[7*16] = tmp + tmp1[19];
314
tmp = tmp1[27] + tmp1[31];
315
out1[9*16] = tmp + tmp1[19];
316
out1[11*16] = tmp + tmp1[23];
317
out1[13*16] = tmp1[23] + tmp1[31];
318
out1[15*16] = tmp1[31];
322
static void synth_full(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
324
register struct mpadec_t *mpa = (struct mpadec_t *)mpadec;
326
MYFLT *b0, (*buf)[0x110];
329
mpa->synth_bufoffs--;
330
mpa->synth_bufoffs &= 0x0F;
331
buf = mpa->synth_buffers[0];
332
} else buf = mpa->synth_buffers[1];
333
if (mpa->synth_bufoffs & 1) {
335
bo = mpa->synth_bufoffs;
336
dct64(buf[1] + ((mpa->synth_bufoffs + 1) & 0x0F),
337
buf[0] + mpa->synth_bufoffs, bandptr);
340
bo = mpa->synth_bufoffs + 1;
341
dct64(buf[0] + mpa->synth_bufoffs, buf[1] + (mpa->synth_bufoffs + 1), bandptr);
345
register MYFLT *out = buffer;
346
register MYFLT *win = mpa->tables.decwin + (16 - bo);
348
for (i = 16; i; i--, win += 32, b0 += 16) {
349
register MYFLT sum = win[0]*b0[0];
359
sum += win[10]*b0[10];
360
sum -= win[11]*b0[11];
361
sum += win[12]*b0[12];
362
sum -= win[13]*b0[13];
363
sum += win[14]*b0[14];
364
sum -= win[15]*b0[15];
368
register MYFLT sum = win[0]*b0[0];
373
sum += win[10]*b0[10];
374
sum += win[12]*b0[12];
375
sum += win[14]*b0[14];
380
for (i = 15; i; i--, win -= 32, b0 -= 16)
382
register MYFLT sum = -win[-1]*b0[0];
383
sum -= win[-2]*b0[1];
384
sum -= win[-3]*b0[2];
385
sum -= win[-4]*b0[3];
386
sum -= win[-5]*b0[4];
387
sum -= win[-6]*b0[5];
388
sum -= win[-7]*b0[6];
389
sum -= win[-8]*b0[7];
390
sum -= win[-9]*b0[8];
391
sum -= win[-10]*b0[9];
392
sum -= win[-11]*b0[10];
393
sum -= win[-12]*b0[11];
394
sum -= win[-13]*b0[12];
395
sum -= win[-14]*b0[13];
396
sum -= win[-15]*b0[14];
397
sum -= win[-0]*b0[15];
403
static void synth_half(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
405
register struct mpadec_t *mpa = (struct mpadec_t *)mpadec;
407
MYFLT *b0, (*buf)[0x110];
410
mpa->synth_bufoffs--;
411
mpa->synth_bufoffs &= 0x0F;
412
buf = mpa->synth_buffers[0];
413
} else buf = mpa->synth_buffers[1];
414
if (mpa->synth_bufoffs & 1) {
416
bo = mpa->synth_bufoffs;
417
dct64(buf[1] + ((mpa->synth_bufoffs + 1) & 0x0F),
418
buf[0] + mpa->synth_bufoffs, bandptr);
421
bo = mpa->synth_bufoffs + 1;
422
dct64(buf[0] + mpa->synth_bufoffs,
423
buf[1] + (mpa->synth_bufoffs + 1), bandptr);
427
register MYFLT *out = buffer;
428
register MYFLT *win = mpa->tables.decwin + (16 - bo);
430
for (i = 8; i; i--, win += 64, b0 += 32) {
431
register MYFLT sum = win[0]*b0[0];
441
sum += win[10]*b0[10];
442
sum -= win[11]*b0[11];
443
sum += win[12]*b0[12];
444
sum -= win[13]*b0[13];
445
sum += win[14]*b0[14];
446
sum -= win[15]*b0[15];
450
register MYFLT sum = win[0]*b0[0];
455
sum += win[10]*b0[10];
456
sum += win[12]*b0[12];
457
sum += win[14]*b0[14];
462
for (i = 7; i; i--, win -= 64, b0 -= 32)
464
register MYFLT sum = -win[-1]*b0[0];
465
sum -= win[-2]*b0[1];
466
sum -= win[-3]*b0[2];
467
sum -= win[-4]*b0[3];
468
sum -= win[-5]*b0[4];
469
sum -= win[-6]*b0[5];
470
sum -= win[-7]*b0[6];
471
sum -= win[-8]*b0[7];
472
sum -= win[-9]*b0[8];
473
sum -= win[-10]*b0[9];
474
sum -= win[-11]*b0[10];
475
sum -= win[-12]*b0[11];
476
sum -= win[-13]*b0[12];
477
sum -= win[-14]*b0[13];
478
sum -= win[-15]*b0[14];
479
sum -= win[-0]*b0[15];
487
/* 16 bit, little-endian */
489
static void synth_full16lmm(mpadec_t mpadec, MYFLT *bandptr,
490
int channel, uint8_t *buffer)
493
register int16_t *out = (int16_t *)buffer;
496
synth_full(mpadec, bandptr, channel, buf);
497
for (i = 0; i < SBLIMIT; i++, out++) {
498
register int32_t tmp = LROUND(buf[i]);
499
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
500
((uint8_t *)out)[0] = (uint8_t)tmp;
501
((int8_t *)out)[1] = (int8_t)(tmp >> 8);
505
#define synth_full16lsm synth_full16lmm
507
static void synth_full16lms(mpadec_t mpadec, MYFLT *bandptr,
508
int channel, uint8_t *buffer)
511
register int16_t *out = (int16_t *)buffer;
514
synth_full(mpadec, bandptr, channel, buf);
515
for (i = 0; i < SBLIMIT; i++, out += 2) {
516
register int32_t tmp = LROUND(buf[i]);
517
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
518
((uint8_t *)out)[0] = ((uint8_t *)out)[2] = (uint8_t)tmp;
519
((int8_t *)out)[1] = ((int8_t *)out)[3] = (int8_t)(tmp >> 8);
523
static void synth_full16lss(mpadec_t mpadec, MYFLT *bandptr,
524
int channel, uint8_t *buffer)
527
register int16_t *out = (int16_t *)buffer;
530
synth_full(mpadec, bandptr, channel, buf);
532
for (i = 0; i < SBLIMIT; i++, out += 2) {
533
register int32_t tmp = LROUND(buf[i]);
534
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
535
((uint8_t *)out)[0] = (uint8_t)tmp;
536
((int8_t *)out)[1] = (int8_t)(tmp >> 8);
540
/* 16 bit, big-endian */
542
static void synth_full16bmm(mpadec_t mpadec, MYFLT *bandptr,
543
int channel, uint8_t *buffer)
546
register int16_t *out = (int16_t *)buffer;
549
synth_full(mpadec, bandptr, channel, buf);
550
for (i = 0; i < SBLIMIT; i++, out++) {
551
register int32_t tmp = LROUND(buf[i]);
552
if (tmp > 32767) tmp = 32767;
553
else if (tmp < -32768) tmp = -32768;
554
((uint8_t *)out)[1] = (uint8_t)tmp;
555
((int8_t *)out)[0] = (int8_t)(tmp >> 8);
559
#define synth_full16bsm synth_full16bmm
561
static void synth_full16bms(mpadec_t mpadec, MYFLT *bandptr,
562
int channel, uint8_t *buffer)
565
register int16_t *out = (int16_t *)buffer;
568
synth_full(mpadec, bandptr, channel, buf);
569
for (i = 0; i < SBLIMIT; i++, out += 2) {
570
register int32_t tmp = LROUND(buf[i]);
571
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
572
((uint8_t *)out)[1] = ((uint8_t *)out)[3] = (uint8_t)tmp;
573
((int8_t *)out)[0] = ((int8_t *)out)[2] = (int8_t)(tmp >> 8);
577
static void synth_full16bss(mpadec_t mpadec, MYFLT *bandptr,
578
int channel, uint8_t *buffer)
581
register int16_t *out = (int16_t *)buffer;
584
synth_full(mpadec, bandptr, channel, buf);
586
for (i = 0; i < SBLIMIT; i++, out += 2) {
587
register int32_t tmp = LROUND(buf[i]);
588
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
589
((uint8_t *)out)[1] = (uint8_t)tmp;
590
((int8_t *)out)[0] = (int8_t)(tmp >> 8);
594
/* 24 bit, little-endian */
596
static void synth_full24lmm(mpadec_t mpadec, MYFLT *bandptr,
597
int channel, uint8_t *buffer)
600
register uint8_t *out = (uint8_t *)buffer;
603
synth_full(mpadec, bandptr, channel, buf);
604
for (i = 0; i < SBLIMIT; i++, out += 3) {
605
register int32_t tmp = LROUND(buf[i]);
606
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
607
else if (tmp < -0x800000) tmp = -0x800000;
608
((uint8_t *)out)[0] = (uint8_t)tmp;
609
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
610
((int8_t *)out)[2] = (int8_t)(tmp >> 16);
614
#define synth_full24lsm synth_full24lmm
616
static void synth_full24lms(mpadec_t mpadec, MYFLT *bandptr,
617
int channel, uint8_t *buffer)
620
register uint8_t *out = (uint8_t *)buffer;
623
synth_full(mpadec, bandptr, channel, buf);
624
for (i = 0; i < SBLIMIT; i++, out += 6) {
625
register int32_t tmp = LROUND(buf[i]);
626
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
627
else if (tmp < -0x800000) tmp = -0x800000;
628
((uint8_t *)out)[0] = ((uint8_t *)out)[3] = (uint8_t)tmp;
629
((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
630
((int8_t *)out)[2] = ((int8_t *)out)[5] = (int8_t)(tmp >> 16);
634
static void synth_full24lss(mpadec_t mpadec, MYFLT *bandptr,
635
int channel, uint8_t *buffer)
638
register uint8_t *out = (uint8_t *)buffer;
641
synth_full(mpadec, bandptr, channel, buf);
642
if (channel) out += 3;
643
for (i = 0; i < SBLIMIT; i++, out += 6) {
644
register int32_t tmp = LROUND(buf[i]);
645
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
646
else if (tmp < -0x800000) tmp = -0x800000;
647
((uint8_t *)out)[0] = (uint8_t)tmp;
648
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
649
((int8_t *)out)[2] = (int8_t)(tmp >> 16);
653
/* 24 bit, big-endian */
655
static void synth_full24bmm(mpadec_t mpadec, MYFLT *bandptr,
656
int channel, uint8_t *buffer)
659
register uint8_t *out = (uint8_t *)buffer;
662
synth_full(mpadec, bandptr, channel, buf);
663
for (i = 0; i < SBLIMIT; i++, out += 3) {
664
register int32_t tmp = LROUND(buf[i]);
665
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
666
else if (tmp < -0x800000) tmp = -0x800000;
667
((uint8_t *)out)[2] = (uint8_t)tmp;
668
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
669
((int8_t *)out)[0] = (int8_t)(tmp >> 16);
673
#define synth_full24bsm synth_full24bmm
675
static void synth_full24bms(mpadec_t mpadec, MYFLT *bandptr,
676
int channel, uint8_t *buffer)
679
register uint8_t *out = (uint8_t *)buffer;
682
synth_full(mpadec, bandptr, channel, buf);
683
for (i = 0; i < SBLIMIT; i++, out += 6) {
684
register int32_t tmp = LROUND(buf[i]);
685
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
686
else if (tmp < -0x800000) tmp = -0x800000;
687
((uint8_t *)out)[2] = ((uint8_t *)out)[5] = (uint8_t)tmp;
688
((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
689
((int8_t *)out)[0] = ((int8_t *)out)[3] = (int8_t)(tmp >> 16);
693
static void synth_full24bss(mpadec_t mpadec, MYFLT *bandptr,
694
int channel, uint8_t *buffer)
697
register uint8_t *out = (uint8_t *)buffer;
700
synth_full(mpadec, bandptr, channel, buf);
701
if (channel) out += 3;
702
for (i = 0; i < SBLIMIT; i++, out += 6) {
703
register int32_t tmp = LROUND(buf[i]);
704
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
705
else if (tmp < -0x800000) tmp = -0x800000;
706
((uint8_t *)out)[2] = (uint8_t)tmp;
707
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
708
((int8_t *)out)[0] = (int8_t)(tmp >> 16);
712
/* 32 bit , little-endian */
714
static void synth_full32lmm(mpadec_t mpadec, MYFLT *bandptr,
715
int channel, uint8_t *buffer)
718
register int32_t *out = (int32_t *)buffer;
721
synth_full(mpadec, bandptr, channel, buf);
722
for (i = 0; i < SBLIMIT; i++, out++) {
723
register int64_t tmp = LLROUND(buf[i]);
724
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
725
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
726
((uint8_t *)out)[0] = (uint8_t)tmp;
727
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
728
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
729
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
733
#define synth_full32lsm synth_full32lmm
735
static void synth_full32lms(mpadec_t mpadec, MYFLT *bandptr,
736
int channel, uint8_t *buffer)
739
register int32_t *out = (int32_t *)buffer;
742
synth_full(mpadec, bandptr, channel, buf);
743
for (i = 0; i < SBLIMIT; i++, out += 2) {
744
register int64_t tmp = LLROUND(buf[i]);
745
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
746
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
747
((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp;
748
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8);
749
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16);
750
((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24);
754
static void synth_full32lss(mpadec_t mpadec, MYFLT *bandptr,
755
int channel, uint8_t *buffer)
758
register int32_t *out = (int32_t *)buffer;
761
synth_full(mpadec, bandptr, channel, buf);
763
for (i = 0; i < SBLIMIT; i++, out += 2) {
764
register int64_t tmp = LLROUND(buf[i]);
765
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
766
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
767
((uint8_t *)out)[0] = (uint8_t)tmp;
768
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
769
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
770
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
774
/* 32 bit, big-endian */
776
static void synth_full32bmm(mpadec_t mpadec, MYFLT *bandptr,
777
int channel, uint8_t *buffer)
780
register int32_t *out = (int32_t *)buffer;
783
synth_full(mpadec, bandptr, channel, buf);
784
for (i = 0; i < SBLIMIT; i++, out++) {
785
register int64_t tmp = LLROUND(buf[i]);
786
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
787
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
788
((uint8_t *)out)[3] = (uint8_t)tmp;
789
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
790
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
791
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
795
#define synth_full32bsm synth_full32bmm
797
static void synth_full32bms(mpadec_t mpadec, MYFLT *bandptr,
798
int channel, uint8_t *buffer)
801
register int32_t *out = (int32_t *)buffer;
804
synth_full(mpadec, bandptr, channel, buf);
805
for (i = 0; i < SBLIMIT; i++, out += 2) {
806
register int64_t tmp = LLROUND(buf[i]);
807
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
808
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
809
((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp;
810
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8);
811
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16);
812
((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24);
816
static void synth_full32bss(mpadec_t mpadec, MYFLT *bandptr,
817
int channel, uint8_t *buffer)
820
register int32_t *out = (int32_t *)buffer;
823
synth_full(mpadec, bandptr, channel, buf);
825
for (i = 0; i < SBLIMIT; i++, out += 2) {
826
register int64_t tmp = LLROUND(buf[i]);
827
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
828
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
829
((uint8_t *)out)[3] = (uint8_t)tmp;
830
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
831
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
832
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
836
/* 32 bit floating-point, little-endian */
838
static void synth_full32flmm(mpadec_t mpadec, MYFLT *bandptr,
839
int channel, uint8_t *buffer)
842
register float *out = (float *)buffer;
845
synth_full(mpadec, bandptr, channel, buf);
846
for (i = 0; i < SBLIMIT; i++, out++) {
848
*((float *)(&tmp)) = (float)buf[i];
849
((uint8_t *)out)[0] = (uint8_t)tmp;
850
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
851
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
852
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
856
#define synth_full32flsm synth_full32flmm
858
static void synth_full32flms(mpadec_t mpadec, MYFLT *bandptr,
859
int channel, uint8_t *buffer)
862
register float *out = (float *)buffer;
865
synth_full(mpadec, bandptr, channel, buf);
866
for (i = 0; i < SBLIMIT; i++, out += 2) {
868
*((float *)(&tmp)) = (float)buf[i];
869
((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp;
870
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8);
871
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16);
872
((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24);
876
static void synth_full32flss(mpadec_t mpadec, MYFLT *bandptr,
877
int channel, uint8_t *buffer)
880
register float *out = (float *)buffer;
883
synth_full(mpadec, bandptr, channel, buf);
885
for (i = 0; i < SBLIMIT; i++, out += 2) {
887
*((float *)(&tmp)) = (float)buf[i];
888
((uint8_t *)out)[0] = (uint8_t)tmp;
889
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
890
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
891
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
895
/* 32 bit floating-point, big-endian */
897
static void synth_full32fbmm(mpadec_t mpadec, MYFLT *bandptr,
898
int channel, uint8_t *buffer)
901
register float *out = (float *)buffer;
904
synth_full(mpadec, bandptr, channel, buf);
905
for (i = 0; i < SBLIMIT; i++, out++) {
907
*((float *)(&tmp)) = (float)buf[i];
908
((uint8_t *)out)[3] = (uint8_t)tmp;
909
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
910
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
911
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
915
#define synth_full32fbsm synth_full32fbmm
917
static void synth_full32fbms(mpadec_t mpadec, MYFLT *bandptr,
918
int channel, uint8_t *buffer)
921
register float *out = (float *)buffer;
924
synth_full(mpadec, bandptr, channel, buf);
925
for (i = 0; i < SBLIMIT; i++, out += 2) {
927
*((float *)(&tmp)) = (float)buf[i];
928
((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp;
929
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8);
930
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16);
931
((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24);
935
static void synth_full32fbss(mpadec_t mpadec, MYFLT *bandptr,
936
int channel, uint8_t *buffer)
939
register float *out = (float *)buffer;
942
synth_full(mpadec, bandptr, channel, buf);
944
for (i = 0; i < SBLIMIT; i++, out += 2) {
946
*((float *)(&tmp)) = (float)buf[i];
947
((uint8_t *)out)[3] = (uint8_t)tmp;
948
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
949
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
950
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
956
/* 16 bit, little-endian */
958
static void synth_half16lmm(mpadec_t mpadec, MYFLT *bandptr,
959
int channel, uint8_t *buffer)
962
register int16_t *out = (int16_t *)buffer;
963
MYFLT buf[SBLIMIT/2];
965
synth_half(mpadec, bandptr, channel, buf);
966
for (i = 0; i < SBLIMIT/2; i++, out++) {
967
register int32_t tmp = LROUND(buf[i]);
968
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
969
((uint8_t *)out)[0] = (uint8_t)tmp;
970
((int8_t *)out)[1] = (int8_t)(tmp >> 8);
974
#define synth_half16lsm synth_half16lmm
976
static void synth_half16lms(mpadec_t mpadec, MYFLT *bandptr,
977
int channel, uint8_t *buffer)
980
register int16_t *out = (int16_t *)buffer;
981
MYFLT buf[SBLIMIT/2];
983
synth_half(mpadec, bandptr, channel, buf);
984
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
985
register int32_t tmp = LROUND(buf[i]);
986
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
987
((uint8_t *)out)[0] = ((uint8_t *)out)[2] = (uint8_t)tmp;
988
((int8_t *)out)[1] = ((int8_t *)out)[3] = (int8_t)(tmp >> 8);
992
static void synth_half16lss(mpadec_t mpadec, MYFLT *bandptr,
993
int channel, uint8_t *buffer)
996
register int16_t *out = (int16_t *)buffer;
997
MYFLT buf[SBLIMIT/2];
999
synth_half(mpadec, bandptr, channel, buf);
1001
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1002
register int32_t tmp = LROUND(buf[i]);
1003
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1004
((uint8_t *)out)[0] = (uint8_t)tmp;
1005
((int8_t *)out)[1] = (int8_t)(tmp >> 8);
1009
/* 16 bit, big-endian */
1011
static void synth_half16bmm(mpadec_t mpadec, MYFLT *bandptr,
1012
int channel, uint8_t *buffer)
1015
register int16_t *out = (int16_t *)buffer;
1016
MYFLT buf[SBLIMIT/2];
1018
synth_half(mpadec, bandptr, channel, buf);
1019
for (i = 0; i < SBLIMIT/2; i++, out++) {
1020
register int32_t tmp = LROUND(buf[i]);
1021
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1022
((uint8_t *)out)[1] = (uint8_t)tmp;
1023
((int8_t *)out)[0] = (int8_t)(tmp >> 8);
1027
#define synth_half16bsm synth_half16bmm
1029
static void synth_half16bms(mpadec_t mpadec, MYFLT *bandptr,
1030
int channel, uint8_t *buffer)
1033
register int16_t *out = (int16_t *)buffer;
1034
MYFLT buf[SBLIMIT/2];
1036
synth_half(mpadec, bandptr, channel, buf);
1037
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1038
register int32_t tmp = LROUND(buf[i]);
1039
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1040
((uint8_t *)out)[1] = ((uint8_t *)out)[3] = (uint8_t)tmp;
1041
((int8_t *)out)[0] = ((int8_t *)out)[2] = (int8_t)(tmp >> 8);
1045
static void synth_half16bss(mpadec_t mpadec, MYFLT *bandptr,
1046
int channel, uint8_t *buffer)
1049
register int16_t *out = (int16_t *)buffer;
1050
MYFLT buf[SBLIMIT/2];
1052
synth_half(mpadec, bandptr, channel, buf);
1054
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1055
register int32_t tmp = LROUND(buf[i]);
1056
if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1057
((uint8_t *)out)[1] = (uint8_t)tmp;
1058
((int8_t *)out)[0] = (int8_t)(tmp >> 8);
1062
/* 24 bit, little-endian */
1064
static void synth_half24lmm(mpadec_t mpadec, MYFLT *bandptr,
1065
int channel, uint8_t *buffer)
1068
register uint8_t *out = (uint8_t *)buffer;
1069
MYFLT buf[SBLIMIT/2];
1071
synth_half(mpadec, bandptr, channel, buf);
1072
for (i = 0; i < SBLIMIT/2; i++, out += 3) {
1073
register int32_t tmp = LROUND(buf[i]);
1074
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1075
else if (tmp < -0x800000) tmp = -0x800000;
1076
((uint8_t *)out)[0] = (uint8_t)tmp;
1077
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1078
((int8_t *)out)[2] = (int8_t)(tmp >> 16);
1082
#define synth_half24lsm synth_half24lmm
1084
static void synth_half24lms(mpadec_t mpadec, MYFLT *bandptr,
1085
int channel, uint8_t *buffer)
1088
register uint8_t *out = (uint8_t *)buffer;
1089
MYFLT buf[SBLIMIT/2];
1091
synth_half(mpadec, bandptr, channel, buf);
1092
for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1093
register int32_t tmp = LROUND(buf[i]);
1094
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1095
else if (tmp < -0x800000) tmp = -0x800000;
1096
((uint8_t *)out)[0] = ((uint8_t *)out)[3] = (uint8_t)tmp;
1097
((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
1098
((int8_t *)out)[2] = ((int8_t *)out)[5] = (int8_t)(tmp >> 16);
1102
static void synth_half24lss(mpadec_t mpadec, MYFLT *bandptr,
1103
int channel, uint8_t *buffer)
1106
register uint8_t *out = (uint8_t *)buffer;
1107
MYFLT buf[SBLIMIT/2];
1109
synth_half(mpadec, bandptr, channel, buf);
1110
if (channel) out += 3;
1111
for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1112
register int32_t tmp = LROUND(buf[i]);
1113
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1114
else if (tmp < -0x800000) tmp = -0x800000;
1115
((uint8_t *)out)[0] = (uint8_t)tmp;
1116
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1117
((int8_t *)out)[2] = (int8_t)(tmp >> 16);
1121
/* 24 bit, big-endian */
1123
static void synth_half24bmm(mpadec_t mpadec, MYFLT *bandptr,
1124
int channel, uint8_t *buffer)
1127
register uint8_t *out = (uint8_t *)buffer;
1128
MYFLT buf[SBLIMIT/2];
1130
synth_half(mpadec, bandptr, channel, buf);
1131
for (i = 0; i < SBLIMIT/2; i++, out += 3) {
1132
register int32_t tmp = LROUND(buf[i]);
1133
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1134
else if (tmp < -0x800000) tmp = -0x800000;
1135
((uint8_t *)out)[2] = (uint8_t)tmp;
1136
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1137
((int8_t *)out)[0] = (int8_t)(tmp >> 16);
1141
#define synth_half24bsm synth_half24bmm
1143
static void synth_half24bms(mpadec_t mpadec, MYFLT *bandptr,
1144
int channel, uint8_t *buffer)
1147
register uint8_t *out = (uint8_t *)buffer;
1148
MYFLT buf[SBLIMIT/2];
1150
synth_half(mpadec, bandptr, channel, buf);
1151
for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1152
register int32_t tmp = LROUND(buf[i]);
1153
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1154
else if (tmp < -0x800000) tmp = -0x800000;
1155
((uint8_t *)out)[2] = ((uint8_t *)out)[5] = (uint8_t)tmp;
1156
((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
1157
((int8_t *)out)[0] = ((int8_t *)out)[3] = (int8_t)(tmp >> 16);
1161
static void synth_half24bss(mpadec_t mpadec, MYFLT *bandptr,
1162
int channel, uint8_t *buffer)
1165
register uint8_t *out = (uint8_t *)buffer;
1166
MYFLT buf[SBLIMIT/2];
1168
synth_half(mpadec, bandptr, channel, buf);
1169
if (channel) out += 3;
1170
for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1171
register int32_t tmp = LROUND(buf[i]);
1172
if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1173
else if (tmp < -0x800000) tmp = -0x800000;
1174
((uint8_t *)out)[2] = (uint8_t)tmp;
1175
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1176
((int8_t *)out)[0] = (int8_t)(tmp >> 16);
1180
/* 32 bit, little-endian */
1182
static void synth_half32lmm(mpadec_t mpadec, MYFLT *bandptr,
1183
int channel, uint8_t *buffer)
1186
register int32_t *out = (int32_t *)buffer;
1187
MYFLT buf[SBLIMIT/2];
1189
synth_half(mpadec, bandptr, channel, buf);
1190
for (i = 0; i < SBLIMIT/2; i++, out++) {
1191
register int64_t tmp = LLROUND(buf[i]);
1192
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1193
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1194
((uint8_t *)out)[0] = (uint8_t)tmp;
1195
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1196
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1197
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1201
#define synth_half32lsm synth_half32lmm
1203
static void synth_half32lms(mpadec_t mpadec, MYFLT *bandptr,
1204
int channel, uint8_t *buffer)
1207
register int32_t *out = (int32_t *)buffer;
1208
MYFLT buf[SBLIMIT/2];
1210
synth_half(mpadec, bandptr, channel, buf);
1211
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1212
register int64_t tmp = LLROUND(buf[i]);
1213
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1214
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1215
((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp;
1216
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8);
1217
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16);
1218
((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24);
1222
static void synth_half32lss(mpadec_t mpadec, MYFLT *bandptr,
1223
int channel, uint8_t *buffer)
1226
register int32_t *out = (int32_t *)buffer;
1227
MYFLT buf[SBLIMIT/2];
1229
synth_half(mpadec, bandptr, channel, buf);
1231
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1232
register int64_t tmp = LLROUND(buf[i]);
1233
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1234
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1235
((uint8_t *)out)[0] = (uint8_t)tmp;
1236
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1237
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1238
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1242
/* 32 bit, big-endian */
1244
static void synth_half32bmm(mpadec_t mpadec, MYFLT *bandptr,
1245
int channel, uint8_t *buffer)
1248
register int32_t *out = (int32_t *)buffer;
1249
MYFLT buf[SBLIMIT/2];
1251
synth_half(mpadec, bandptr, channel, buf);
1252
for (i = 0; i < SBLIMIT/2; i++, out++) {
1253
register int64_t tmp = LLROUND(buf[i]);
1254
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1255
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1256
((uint8_t *)out)[3] = (uint8_t)tmp;
1257
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1258
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1259
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1263
#define synth_half32bsm synth_half32bmm
1265
static void synth_half32bms(mpadec_t mpadec, MYFLT *bandptr,
1266
int channel, uint8_t *buffer)
1269
register int32_t *out = (int32_t *)buffer;
1270
MYFLT buf[SBLIMIT/2];
1272
synth_half(mpadec, bandptr, channel, buf);
1273
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1274
register int64_t tmp = LLROUND(buf[i]);
1275
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1276
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1277
((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp;
1278
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8);
1279
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16);
1280
((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24);
1284
static void synth_half32bss(mpadec_t mpadec, MYFLT *bandptr,
1285
int channel, uint8_t *buffer)
1288
register int32_t *out = (int32_t *)buffer;
1289
MYFLT buf[SBLIMIT/2];
1291
synth_half(mpadec, bandptr, channel, buf);
1293
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1294
register int64_t tmp = LLROUND(buf[i]);
1295
if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1296
else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1297
((uint8_t *)out)[3] = (uint8_t)tmp;
1298
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1299
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1300
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1304
/* 32 bit floating-point, little-endian */
1306
static void synth_half32flmm(mpadec_t mpadec, MYFLT *bandptr,
1307
int channel, uint8_t *buffer)
1310
register float *out = (float *)buffer;
1311
MYFLT buf[SBLIMIT/2];
1313
synth_half(mpadec, bandptr, channel, buf);
1314
for (i = 0; i < SBLIMIT/2; i++, out++) {
1316
*((float *)(&tmp)) = (float)buf[i];
1317
((uint8_t *)out)[0] = (uint8_t)tmp;
1318
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1319
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1320
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1324
#define synth_half32flsm synth_half32flmm
1326
static void synth_half32flms(mpadec_t mpadec, MYFLT *bandptr,
1327
int channel, uint8_t *buffer)
1330
register float *out = (float *)buffer;
1331
MYFLT buf[SBLIMIT/2];
1333
synth_half(mpadec, bandptr, channel, buf);
1334
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1336
*((float *)(&tmp)) = (float)buf[i];
1337
((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp;
1338
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8);
1339
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16);
1340
((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24);
1344
static void synth_half32flss(mpadec_t mpadec, MYFLT *bandptr,
1345
int channel, uint8_t *buffer)
1348
register float *out = (float *)buffer;
1349
MYFLT buf[SBLIMIT/2];
1351
synth_half(mpadec, bandptr, channel, buf);
1353
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1355
*((float *)(&tmp)) = (float)buf[i];
1356
((uint8_t *)out)[0] = (uint8_t)tmp;
1357
((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1358
((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1359
((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1363
/* 32 bit floating-point, big-endian */
1365
static void synth_half32fbmm(mpadec_t mpadec, MYFLT *bandptr,
1366
int channel, uint8_t *buffer)
1369
register float *out = (float *)buffer;
1370
MYFLT buf[SBLIMIT/2];
1372
synth_half(mpadec, bandptr, channel, buf);
1373
for (i = 0; i < SBLIMIT/2; i++, out++) {
1375
*((float *)(&tmp)) = (float)buf[i];
1376
((uint8_t *)out)[3] = (uint8_t)tmp;
1377
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1378
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1379
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1383
#define synth_half32fbsm synth_half32fbmm
1385
static void synth_half32fbms(mpadec_t mpadec, MYFLT *bandptr,
1386
int channel, uint8_t *buffer)
1389
register float *out = (float *)buffer;
1390
MYFLT buf[SBLIMIT/2];
1392
synth_half(mpadec, bandptr, channel, buf);
1393
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1395
*((float *)(&tmp)) = (float)buf[i];
1396
((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp;
1397
((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8);
1398
((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16);
1399
((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24);
1403
static void synth_half32fbss(mpadec_t mpadec, MYFLT *bandptr,
1404
int channel, uint8_t *buffer)
1407
register float *out = (float *)buffer;
1408
MYFLT buf[SBLIMIT/2];
1410
synth_half(mpadec, bandptr, channel, buf);
1412
for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1414
*((float *)(&tmp)) = (float)buf[i];
1415
((uint8_t *)out)[3] = (uint8_t)tmp;
1416
((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1417
((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1418
((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1422
void *synth_table[2][2][4][4] = {
1423
{ { { synth_full16lmm, synth_full16lms, synth_full16lsm, synth_full16lss },
1424
{ synth_full24lmm, synth_full24lms, synth_full24lsm, synth_full24lss },
1425
{ synth_full32lmm, synth_full32lms, synth_full32lsm, synth_full32lss },
1426
{ synth_full32flmm, synth_full32flms, synth_full32flsm, synth_full32flss } },
1427
{ { synth_full16bmm, synth_full16bms, synth_full16bsm, synth_full16bss },
1428
{ synth_full24bmm, synth_full24bms, synth_full24bsm, synth_full24bss },
1429
{ synth_full32bmm, synth_full32bms, synth_full32bsm, synth_full32bss },
1430
{ synth_full32fbmm, synth_full32fbms, synth_full32fbsm, synth_full32fbss } } },
1431
{ { { synth_half16lmm, synth_half16lms, synth_half16lsm, synth_half16lss },
1432
{ synth_half24lmm, synth_half24lms, synth_half24lsm, synth_half24lss },
1433
{ synth_half32lmm, synth_half32lms, synth_half32lsm, synth_half32lss },
1434
{ synth_half32flmm, synth_half32flms, synth_half32flsm, synth_half32flss } },
1435
{ { synth_half16bmm, synth_half16bms, synth_half16bsm, synth_half16bss },
1436
{ synth_half24bmm, synth_half24bms, synth_half24bsm, synth_half24bss },
1437
{ synth_half32bmm, synth_half32bms, synth_half32bsm, synth_half32bss },
1438
{ synth_half32fbmm, synth_half32fbms, synth_half32fbsm, synth_half32fbss } } }