~ubuntu-branches/ubuntu/precise/csound/precise

« back to all changes in this revision

Viewing changes to InOut/libmpadec/synth.c

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2012-04-19 09:26:46 UTC
  • mfrom: (3.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20120419092646-96xbj1n6atuqosk2
Tags: 1:5.17.6~dfsg-1
* New upstream release
 - Do not build the wiimote opcodes (we need wiiuse).
* Add new API function to symbols file
* Disable lua opcodes, they were broken. Requires OpenMP to be enabled.
* Backport fixes from upstream:
  - Link dssi4cs with dl. Backport
  - Fix building of CsoundAC

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  mpadec - MPEG audio decoder
 
3
 *  Copyright (C) 2002-2004 Dmitriy Startsev (dstartsev@rambler.ru)
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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
 
18
 */
 
19
 
 
20
/* $Id: synth.c,v 1.3 2004/08/03 05:22:22 metal_man Exp $ */
 
21
 
 
22
#include "mpadec_internal.h"
 
23
 
 
24
#define ROUND(x) (floor((x) + 0.5))
 
25
#define LROUND(x) ((int32_t)(ROUND(x)))
 
26
#define LLROUND(x) ((int64_t)(ROUND(x)))
 
27
 
 
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
 
45
};
 
46
 
 
47
static void dct64(MYFLT *outptr0, MYFLT *outptr1, MYFLT *samples)
 
48
{
 
49
  MYFLT tmp1[32], tmp2[32];
 
50
 
 
51
  {
 
52
    register MYFLT *in = samples;
 
53
 
 
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];
 
58
 
 
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];
 
63
 
 
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];
 
68
 
 
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];
 
73
 
 
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];
 
78
 
 
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];
 
83
 
 
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];
 
88
 
 
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];
 
93
  }
 
94
  {
 
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];
 
99
 
 
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];
 
104
 
 
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];
 
109
 
 
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];
 
114
 
 
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];
 
119
 
 
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];
 
124
 
 
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];
 
129
 
 
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];
 
134
  }
 
135
  {
 
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];
 
144
 
 
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];
 
153
 
 
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];
 
162
 
 
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];
 
171
  }
 
172
  {
 
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];
 
177
 
 
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];
 
182
 
 
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];
 
187
 
 
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];
 
192
 
 
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];
 
197
 
 
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];
 
202
 
 
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];
 
207
 
 
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];
 
212
  }
 
213
  {
 
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];
 
218
    tmp1[2] += tmp1[3];
 
219
 
 
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];
 
224
    tmp1[6] += tmp1[7];
 
225
    tmp1[4] += tmp1[6];
 
226
    tmp1[6] += tmp1[5];
 
227
    tmp1[5] += tmp1[7];
 
228
 
 
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];
 
234
 
 
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];
 
243
 
 
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];
 
249
 
 
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];
 
258
 
 
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];
 
264
 
 
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];
 
273
  }
 
274
  {
 
275
    register MYFLT tmp, *out0 = outptr0, *out1 = outptr1;
 
276
 
 
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];
 
286
 
 
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];
 
295
 
 
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];
 
319
  }
 
320
}
 
321
 
 
322
static void synth_full(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
 
323
{
 
324
  register struct mpadec_t *mpa = (struct mpadec_t *)mpadec;
 
325
  unsigned bo;
 
326
  MYFLT *b0, (*buf)[0x110];
 
327
 
 
328
  if (!channel) {
 
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) {
 
334
    b0 = buf[0];
 
335
    bo = mpa->synth_bufoffs;
 
336
    dct64(buf[1] + ((mpa->synth_bufoffs + 1) & 0x0F),
 
337
          buf[0] + mpa->synth_bufoffs, bandptr);
 
338
  } else {
 
339
    b0 = buf[1];
 
340
    bo = mpa->synth_bufoffs + 1;
 
341
    dct64(buf[0] + mpa->synth_bufoffs, buf[1] + (mpa->synth_bufoffs + 1), bandptr);
 
342
  }
 
343
  {
 
344
    register int i;
 
345
    register MYFLT *out = buffer;
 
346
    register MYFLT *win = mpa->tables.decwin + (16 - bo);
 
347
 
 
348
    for (i = 16; i; i--, win += 32, b0 += 16) {
 
349
      register MYFLT sum = win[0]*b0[0];
 
350
      sum -= win[1]*b0[1];
 
351
      sum += win[2]*b0[2];
 
352
      sum -= win[3]*b0[3];
 
353
      sum += win[4]*b0[4];
 
354
      sum -= win[5]*b0[5];
 
355
      sum += win[6]*b0[6];
 
356
      sum -= win[7]*b0[7];
 
357
      sum += win[8]*b0[8];
 
358
      sum -= win[9]*b0[9];
 
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];
 
365
      *out++ = sum;
 
366
    }
 
367
    {
 
368
      register MYFLT sum = win[0]*b0[0];
 
369
      sum += win[2]*b0[2];
 
370
      sum += win[4]*b0[4];
 
371
      sum += win[6]*b0[6];
 
372
      sum += win[8]*b0[8];
 
373
      sum += win[10]*b0[10];
 
374
      sum += win[12]*b0[12];
 
375
      sum += win[14]*b0[14];
 
376
      *out++ = sum;
 
377
      win -= 32; b0 -= 16;
 
378
    }
 
379
    win += (bo << 1);
 
380
    for (i = 15; i; i--, win -= 32, b0 -= 16)
 
381
    {
 
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];
 
398
      *out++ = sum;
 
399
    }
 
400
  }
 
401
}
 
402
 
 
403
static void synth_half(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
 
404
{
 
405
  register struct mpadec_t *mpa = (struct mpadec_t *)mpadec;
 
406
  unsigned bo;
 
407
  MYFLT *b0, (*buf)[0x110];
 
408
 
 
409
  if (!channel) {
 
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) {
 
415
    b0 = buf[0];
 
416
    bo = mpa->synth_bufoffs;
 
417
    dct64(buf[1] + ((mpa->synth_bufoffs + 1) & 0x0F),
 
418
          buf[0] + mpa->synth_bufoffs, bandptr);
 
419
  } else {
 
420
    b0 = buf[1];
 
421
    bo = mpa->synth_bufoffs + 1;
 
422
    dct64(buf[0] + mpa->synth_bufoffs,
 
423
          buf[1] + (mpa->synth_bufoffs + 1), bandptr);
 
424
  }
 
425
  {
 
426
    register int i;
 
427
    register MYFLT *out = buffer;
 
428
    register MYFLT *win = mpa->tables.decwin + (16 - bo);
 
429
 
 
430
    for (i = 8; i; i--, win += 64, b0 += 32) {
 
431
      register MYFLT sum = win[0]*b0[0];
 
432
      sum -= win[1]*b0[1];
 
433
      sum += win[2]*b0[2];
 
434
      sum -= win[3]*b0[3];
 
435
      sum += win[4]*b0[4];
 
436
      sum -= win[5]*b0[5];
 
437
      sum += win[6]*b0[6];
 
438
      sum -= win[7]*b0[7];
 
439
      sum += win[8]*b0[8];
 
440
      sum -= win[9]*b0[9];
 
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];
 
447
      *out++ = sum;
 
448
    }
 
449
    {
 
450
      register MYFLT sum = win[0]*b0[0];
 
451
      sum += win[2]*b0[2];
 
452
      sum += win[4]*b0[4];
 
453
      sum += win[6]*b0[6];
 
454
      sum += win[8]*b0[8];
 
455
      sum += win[10]*b0[10];
 
456
      sum += win[12]*b0[12];
 
457
      sum += win[14]*b0[14];
 
458
      *out++ = sum;
 
459
      win -= 64; b0 -= 32;
 
460
    }
 
461
    win += (bo << 1);
 
462
    for (i = 7; i; i--, win -= 64, b0 -= 32)
 
463
    {
 
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];
 
480
      *out++ = sum;
 
481
    }
 
482
  }
 
483
}
 
484
 
 
485
/* Full quality */
 
486
 
 
487
/* 16 bit, little-endian */
 
488
 
 
489
static void synth_full16lmm(mpadec_t mpadec, MYFLT *bandptr,
 
490
                            int channel, uint8_t *buffer)
 
491
{
 
492
  register int i;
 
493
  register int16_t *out = (int16_t *)buffer;
 
494
  MYFLT buf[SBLIMIT];
 
495
 
 
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);
 
502
  }
 
503
}
 
504
 
 
505
#define synth_full16lsm synth_full16lmm
 
506
 
 
507
static void synth_full16lms(mpadec_t mpadec, MYFLT *bandptr,
 
508
                            int channel, uint8_t *buffer)
 
509
{
 
510
  register int i;
 
511
  register int16_t *out = (int16_t *)buffer;
 
512
  MYFLT buf[SBLIMIT];
 
513
 
 
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);
 
520
  }
 
521
}
 
522
 
 
523
static void synth_full16lss(mpadec_t mpadec, MYFLT *bandptr,
 
524
                            int channel, uint8_t *buffer)
 
525
{
 
526
  register int i;
 
527
  register int16_t *out = (int16_t *)buffer;
 
528
  MYFLT buf[SBLIMIT];
 
529
 
 
530
  synth_full(mpadec, bandptr, channel, buf);
 
531
  if (channel) out++;
 
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);
 
537
  }
 
538
}
 
539
 
 
540
/* 16 bit, big-endian */
 
541
 
 
542
static void synth_full16bmm(mpadec_t mpadec, MYFLT *bandptr,
 
543
                            int channel, uint8_t *buffer)
 
544
{
 
545
  register int i;
 
546
  register int16_t *out = (int16_t *)buffer;
 
547
  MYFLT buf[SBLIMIT];
 
548
 
 
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);
 
556
  }
 
557
}
 
558
 
 
559
#define synth_full16bsm synth_full16bmm
 
560
 
 
561
static void synth_full16bms(mpadec_t mpadec, MYFLT *bandptr,
 
562
                            int channel, uint8_t *buffer)
 
563
{
 
564
  register int i;
 
565
  register int16_t *out = (int16_t *)buffer;
 
566
  MYFLT buf[SBLIMIT];
 
567
 
 
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);
 
574
  }
 
575
}
 
576
 
 
577
static void synth_full16bss(mpadec_t mpadec, MYFLT *bandptr,
 
578
                            int channel, uint8_t *buffer)
 
579
{
 
580
  register int i;
 
581
  register int16_t *out = (int16_t *)buffer;
 
582
  MYFLT buf[SBLIMIT];
 
583
 
 
584
  synth_full(mpadec, bandptr, channel, buf);
 
585
  if (channel) out++;
 
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);
 
591
  }
 
592
}
 
593
 
 
594
/* 24 bit, little-endian */
 
595
 
 
596
static void synth_full24lmm(mpadec_t mpadec, MYFLT *bandptr,
 
597
                            int channel, uint8_t *buffer)
 
598
{
 
599
  register int i;
 
600
  register uint8_t *out = (uint8_t *)buffer;
 
601
  MYFLT buf[SBLIMIT];
 
602
 
 
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);
 
611
  }
 
612
}
 
613
 
 
614
#define synth_full24lsm synth_full24lmm
 
615
 
 
616
static void synth_full24lms(mpadec_t mpadec, MYFLT *bandptr, 
 
617
                            int channel, uint8_t *buffer)
 
618
{
 
619
  register int i;
 
620
  register uint8_t *out = (uint8_t *)buffer;
 
621
  MYFLT buf[SBLIMIT];
 
622
 
 
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);
 
631
  }
 
632
}
 
633
 
 
634
static void synth_full24lss(mpadec_t mpadec, MYFLT *bandptr,
 
635
                            int channel, uint8_t *buffer)
 
636
{
 
637
  register int i;
 
638
  register uint8_t *out = (uint8_t *)buffer;
 
639
  MYFLT buf[SBLIMIT];
 
640
 
 
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);
 
650
  }
 
651
}
 
652
 
 
653
/* 24 bit, big-endian */
 
654
 
 
655
static void synth_full24bmm(mpadec_t mpadec, MYFLT *bandptr,
 
656
                            int channel, uint8_t *buffer)
 
657
{
 
658
  register int i;
 
659
  register uint8_t *out = (uint8_t *)buffer;
 
660
  MYFLT buf[SBLIMIT];
 
661
 
 
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);
 
670
  }
 
671
}
 
672
 
 
673
#define synth_full24bsm synth_full24bmm
 
674
 
 
675
static void synth_full24bms(mpadec_t mpadec, MYFLT *bandptr,
 
676
                            int channel, uint8_t *buffer)
 
677
{
 
678
  register int i;
 
679
  register uint8_t *out = (uint8_t *)buffer;
 
680
  MYFLT buf[SBLIMIT];
 
681
 
 
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);
 
690
  }
 
691
}
 
692
 
 
693
static void synth_full24bss(mpadec_t mpadec, MYFLT *bandptr,
 
694
                            int channel, uint8_t *buffer)
 
695
{
 
696
  register int i;
 
697
  register uint8_t *out = (uint8_t *)buffer;
 
698
  MYFLT buf[SBLIMIT];
 
699
 
 
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);
 
709
  }
 
710
}
 
711
 
 
712
/* 32 bit , little-endian */
 
713
 
 
714
static void synth_full32lmm(mpadec_t mpadec, MYFLT *bandptr, 
 
715
                            int channel, uint8_t *buffer)
 
716
{
 
717
  register int i;
 
718
  register int32_t *out = (int32_t *)buffer;
 
719
  MYFLT buf[SBLIMIT];
 
720
 
 
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);
 
730
  }
 
731
}
 
732
 
 
733
#define synth_full32lsm synth_full32lmm
 
734
 
 
735
static void synth_full32lms(mpadec_t mpadec, MYFLT *bandptr,
 
736
                            int channel, uint8_t *buffer)
 
737
{
 
738
  register int i;
 
739
  register int32_t *out = (int32_t *)buffer;
 
740
  MYFLT buf[SBLIMIT];
 
741
 
 
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);
 
751
  }
 
752
}
 
753
 
 
754
static void synth_full32lss(mpadec_t mpadec, MYFLT *bandptr,
 
755
                            int channel, uint8_t *buffer)
 
756
{
 
757
  register int i;
 
758
  register int32_t *out = (int32_t *)buffer;
 
759
  MYFLT buf[SBLIMIT];
 
760
 
 
761
  synth_full(mpadec, bandptr, channel, buf);
 
762
  if (channel) out++;
 
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);
 
771
  }
 
772
}
 
773
 
 
774
/* 32 bit, big-endian */
 
775
 
 
776
static void synth_full32bmm(mpadec_t mpadec, MYFLT *bandptr,
 
777
                            int channel, uint8_t *buffer)
 
778
{
 
779
  register int i;
 
780
  register int32_t *out = (int32_t *)buffer;
 
781
  MYFLT buf[SBLIMIT];
 
782
 
 
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);
 
792
  }
 
793
}
 
794
 
 
795
#define synth_full32bsm synth_full32bmm
 
796
 
 
797
static void synth_full32bms(mpadec_t mpadec, MYFLT *bandptr,
 
798
                            int channel, uint8_t *buffer)
 
799
{
 
800
  register int i;
 
801
  register int32_t *out = (int32_t *)buffer;
 
802
  MYFLT buf[SBLIMIT];
 
803
 
 
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);
 
813
  }
 
814
}
 
815
 
 
816
static void synth_full32bss(mpadec_t mpadec, MYFLT *bandptr,
 
817
                            int channel, uint8_t *buffer)
 
818
{
 
819
  register int i;
 
820
  register int32_t *out = (int32_t *)buffer;
 
821
  MYFLT buf[SBLIMIT];
 
822
 
 
823
  synth_full(mpadec, bandptr, channel, buf);
 
824
  if (channel) out++;
 
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);
 
833
  }
 
834
}
 
835
 
 
836
/* 32 bit floating-point, little-endian */
 
837
 
 
838
static void synth_full32flmm(mpadec_t mpadec, MYFLT *bandptr,
 
839
                             int channel, uint8_t *buffer)
 
840
{
 
841
  register int i;
 
842
  register float *out = (float *)buffer;
 
843
  MYFLT buf[SBLIMIT];
 
844
 
 
845
  synth_full(mpadec, bandptr, channel, buf);
 
846
  for (i = 0; i < SBLIMIT; i++, out++) {
 
847
    int32_t tmp;
 
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);
 
853
  }
 
854
}
 
855
 
 
856
#define synth_full32flsm synth_full32flmm
 
857
 
 
858
static void synth_full32flms(mpadec_t mpadec, MYFLT *bandptr,
 
859
                             int channel, uint8_t *buffer)
 
860
{
 
861
  register int i;
 
862
  register float *out = (float *)buffer;
 
863
  MYFLT buf[SBLIMIT];
 
864
 
 
865
  synth_full(mpadec, bandptr, channel, buf);
 
866
  for (i = 0; i < SBLIMIT; i++, out += 2) {
 
867
    int32_t tmp;
 
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);
 
873
  }
 
874
}
 
875
 
 
876
static void synth_full32flss(mpadec_t mpadec, MYFLT *bandptr,
 
877
                             int channel, uint8_t *buffer)
 
878
{
 
879
  register int i;
 
880
  register float *out = (float *)buffer;
 
881
  MYFLT buf[SBLIMIT];
 
882
 
 
883
  synth_full(mpadec, bandptr, channel, buf);
 
884
  if (channel) out++;
 
885
  for (i = 0; i < SBLIMIT; i++, out += 2) {
 
886
    int32_t tmp;
 
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);
 
892
  }
 
893
}
 
894
 
 
895
/* 32 bit floating-point, big-endian */
 
896
 
 
897
static void synth_full32fbmm(mpadec_t mpadec, MYFLT *bandptr,
 
898
                             int channel, uint8_t *buffer)
 
899
{
 
900
  register int i;
 
901
  register float *out = (float *)buffer;
 
902
  MYFLT buf[SBLIMIT];
 
903
 
 
904
  synth_full(mpadec, bandptr, channel, buf);
 
905
  for (i = 0; i < SBLIMIT; i++, out++) {
 
906
    int32_t tmp;
 
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);
 
912
  }
 
913
}
 
914
 
 
915
#define synth_full32fbsm synth_full32fbmm
 
916
 
 
917
static void synth_full32fbms(mpadec_t mpadec, MYFLT *bandptr,
 
918
                             int channel, uint8_t *buffer)
 
919
{
 
920
  register int i;
 
921
  register float *out = (float *)buffer;
 
922
  MYFLT buf[SBLIMIT];
 
923
 
 
924
  synth_full(mpadec, bandptr, channel, buf);
 
925
  for (i = 0; i < SBLIMIT; i++, out += 2) {
 
926
    int32_t tmp;
 
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);
 
932
  }
 
933
}
 
934
 
 
935
static void synth_full32fbss(mpadec_t mpadec, MYFLT *bandptr,
 
936
                             int channel, uint8_t *buffer)
 
937
{
 
938
  register int i;
 
939
  register float *out = (float *)buffer;
 
940
  MYFLT buf[SBLIMIT];
 
941
 
 
942
  synth_full(mpadec, bandptr, channel, buf);
 
943
  if (channel) out++;
 
944
  for (i = 0; i < SBLIMIT; i++, out += 2) {
 
945
    int32_t tmp;
 
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);
 
951
  }
 
952
}
 
953
 
 
954
/* Half quality */
 
955
 
 
956
/* 16 bit, little-endian */
 
957
 
 
958
static void synth_half16lmm(mpadec_t mpadec, MYFLT *bandptr,
 
959
                            int channel, uint8_t *buffer)
 
960
{
 
961
  register int i;
 
962
  register int16_t *out = (int16_t *)buffer;
 
963
  MYFLT buf[SBLIMIT/2];
 
964
 
 
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);
 
971
  }
 
972
}
 
973
 
 
974
#define synth_half16lsm synth_half16lmm
 
975
 
 
976
static void synth_half16lms(mpadec_t mpadec, MYFLT *bandptr,
 
977
                            int channel, uint8_t *buffer)
 
978
{
 
979
  register int i;
 
980
  register int16_t *out = (int16_t *)buffer;
 
981
  MYFLT buf[SBLIMIT/2];
 
982
 
 
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);
 
989
  }
 
990
}
 
991
 
 
992
static void synth_half16lss(mpadec_t mpadec, MYFLT *bandptr,
 
993
                            int channel, uint8_t *buffer)
 
994
{
 
995
  register int i;
 
996
  register int16_t *out = (int16_t *)buffer;
 
997
  MYFLT buf[SBLIMIT/2];
 
998
 
 
999
  synth_half(mpadec, bandptr, channel, buf);
 
1000
  if (channel) out++;
 
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);
 
1006
  }
 
1007
}
 
1008
 
 
1009
/* 16 bit, big-endian */
 
1010
 
 
1011
static void synth_half16bmm(mpadec_t mpadec, MYFLT *bandptr,
 
1012
                            int channel, uint8_t *buffer)
 
1013
{
 
1014
  register int i;
 
1015
  register int16_t *out = (int16_t *)buffer;
 
1016
  MYFLT buf[SBLIMIT/2];
 
1017
 
 
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);
 
1024
  }
 
1025
}
 
1026
 
 
1027
#define synth_half16bsm synth_half16bmm
 
1028
 
 
1029
static void synth_half16bms(mpadec_t mpadec, MYFLT *bandptr,
 
1030
                            int channel, uint8_t *buffer)
 
1031
{
 
1032
  register int i;
 
1033
  register int16_t *out = (int16_t *)buffer;
 
1034
  MYFLT buf[SBLIMIT/2];
 
1035
 
 
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);
 
1042
  }
 
1043
}
 
1044
 
 
1045
static void synth_half16bss(mpadec_t mpadec, MYFLT *bandptr,
 
1046
                            int channel, uint8_t *buffer)
 
1047
{
 
1048
  register int i;
 
1049
  register int16_t *out = (int16_t *)buffer;
 
1050
  MYFLT buf[SBLIMIT/2];
 
1051
 
 
1052
  synth_half(mpadec, bandptr, channel, buf);
 
1053
  if (channel) out++;
 
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);
 
1059
  }
 
1060
}
 
1061
 
 
1062
/* 24 bit, little-endian */
 
1063
 
 
1064
static void synth_half24lmm(mpadec_t mpadec, MYFLT *bandptr,
 
1065
                            int channel, uint8_t *buffer)
 
1066
{
 
1067
  register int i;
 
1068
  register uint8_t *out = (uint8_t *)buffer;
 
1069
  MYFLT buf[SBLIMIT/2];
 
1070
 
 
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);
 
1079
  }
 
1080
}
 
1081
 
 
1082
#define synth_half24lsm synth_half24lmm
 
1083
 
 
1084
static void synth_half24lms(mpadec_t mpadec, MYFLT *bandptr,
 
1085
                            int channel, uint8_t *buffer)
 
1086
{
 
1087
  register int i;
 
1088
  register uint8_t *out = (uint8_t *)buffer;
 
1089
  MYFLT buf[SBLIMIT/2];
 
1090
 
 
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);
 
1099
  }
 
1100
}
 
1101
 
 
1102
static void synth_half24lss(mpadec_t mpadec, MYFLT *bandptr,
 
1103
                            int channel, uint8_t *buffer)
 
1104
{
 
1105
  register int i;
 
1106
  register uint8_t *out = (uint8_t *)buffer;
 
1107
  MYFLT buf[SBLIMIT/2];
 
1108
 
 
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);
 
1118
  }
 
1119
}
 
1120
 
 
1121
/* 24 bit, big-endian */
 
1122
 
 
1123
static void synth_half24bmm(mpadec_t mpadec, MYFLT *bandptr,
 
1124
                            int channel, uint8_t *buffer)
 
1125
{
 
1126
  register int i;
 
1127
  register uint8_t *out = (uint8_t *)buffer;
 
1128
  MYFLT buf[SBLIMIT/2];
 
1129
 
 
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);
 
1138
  }
 
1139
}
 
1140
 
 
1141
#define synth_half24bsm synth_half24bmm
 
1142
 
 
1143
static void synth_half24bms(mpadec_t mpadec, MYFLT *bandptr,
 
1144
                            int channel, uint8_t *buffer)
 
1145
{
 
1146
  register int i;
 
1147
  register uint8_t *out = (uint8_t *)buffer;
 
1148
  MYFLT buf[SBLIMIT/2];
 
1149
 
 
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);
 
1158
  }
 
1159
}
 
1160
 
 
1161
static void synth_half24bss(mpadec_t mpadec, MYFLT *bandptr,
 
1162
                            int channel, uint8_t *buffer)
 
1163
{
 
1164
  register int i;
 
1165
  register uint8_t *out = (uint8_t *)buffer;
 
1166
  MYFLT buf[SBLIMIT/2];
 
1167
 
 
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);
 
1177
  }
 
1178
}
 
1179
 
 
1180
/* 32 bit, little-endian */
 
1181
 
 
1182
static void synth_half32lmm(mpadec_t mpadec, MYFLT *bandptr,
 
1183
                            int channel, uint8_t *buffer)
 
1184
{
 
1185
  register int i;
 
1186
  register int32_t *out = (int32_t *)buffer;
 
1187
  MYFLT buf[SBLIMIT/2];
 
1188
 
 
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);
 
1198
  }
 
1199
}
 
1200
 
 
1201
#define synth_half32lsm synth_half32lmm
 
1202
 
 
1203
static void synth_half32lms(mpadec_t mpadec, MYFLT *bandptr,
 
1204
                            int channel, uint8_t *buffer)
 
1205
{
 
1206
  register int i;
 
1207
  register int32_t *out = (int32_t *)buffer;
 
1208
  MYFLT buf[SBLIMIT/2];
 
1209
 
 
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);
 
1219
  }
 
1220
}
 
1221
 
 
1222
static void synth_half32lss(mpadec_t mpadec, MYFLT *bandptr,
 
1223
                            int channel, uint8_t *buffer)
 
1224
{
 
1225
  register int i;
 
1226
  register int32_t *out = (int32_t *)buffer;
 
1227
  MYFLT buf[SBLIMIT/2];
 
1228
 
 
1229
  synth_half(mpadec, bandptr, channel, buf);
 
1230
  if (channel) out++;
 
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);
 
1239
  }
 
1240
}
 
1241
 
 
1242
/* 32 bit, big-endian */
 
1243
 
 
1244
static void synth_half32bmm(mpadec_t mpadec, MYFLT *bandptr,
 
1245
                            int channel, uint8_t *buffer)
 
1246
{
 
1247
  register int i;
 
1248
  register int32_t *out = (int32_t *)buffer;
 
1249
  MYFLT buf[SBLIMIT/2];
 
1250
 
 
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);
 
1260
  }
 
1261
}
 
1262
 
 
1263
#define synth_half32bsm synth_half32bmm
 
1264
 
 
1265
static void synth_half32bms(mpadec_t mpadec, MYFLT *bandptr,
 
1266
                            int channel, uint8_t *buffer)
 
1267
{
 
1268
  register int i;
 
1269
  register int32_t *out = (int32_t *)buffer;
 
1270
  MYFLT buf[SBLIMIT/2];
 
1271
 
 
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);
 
1281
  }
 
1282
}
 
1283
 
 
1284
static void synth_half32bss(mpadec_t mpadec, MYFLT *bandptr,
 
1285
                            int channel, uint8_t *buffer)
 
1286
{
 
1287
  register int i;
 
1288
  register int32_t *out = (int32_t *)buffer;
 
1289
  MYFLT buf[SBLIMIT/2];
 
1290
 
 
1291
  synth_half(mpadec, bandptr, channel, buf);
 
1292
  if (channel) out++;
 
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);
 
1301
  }
 
1302
}
 
1303
 
 
1304
/* 32 bit floating-point, little-endian */
 
1305
 
 
1306
static void synth_half32flmm(mpadec_t mpadec, MYFLT *bandptr,
 
1307
                             int channel, uint8_t *buffer)
 
1308
{
 
1309
  register int i;
 
1310
  register float *out = (float *)buffer;
 
1311
  MYFLT buf[SBLIMIT/2];
 
1312
 
 
1313
  synth_half(mpadec, bandptr, channel, buf);
 
1314
  for (i = 0; i < SBLIMIT/2; i++, out++) {
 
1315
    int32_t tmp;
 
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);
 
1321
  }
 
1322
}
 
1323
 
 
1324
#define synth_half32flsm synth_half32flmm
 
1325
 
 
1326
static void synth_half32flms(mpadec_t mpadec, MYFLT *bandptr,
 
1327
                             int channel, uint8_t *buffer)
 
1328
{
 
1329
  register int i;
 
1330
  register float *out = (float *)buffer;
 
1331
  MYFLT buf[SBLIMIT/2];
 
1332
 
 
1333
  synth_half(mpadec, bandptr, channel, buf);
 
1334
  for (i = 0; i < SBLIMIT/2; i++, out += 2) {
 
1335
    int32_t tmp;
 
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);
 
1341
  }
 
1342
}
 
1343
 
 
1344
static void synth_half32flss(mpadec_t mpadec, MYFLT *bandptr,
 
1345
                             int channel, uint8_t *buffer)
 
1346
{
 
1347
  register int i;
 
1348
  register float *out = (float *)buffer;
 
1349
  MYFLT buf[SBLIMIT/2];
 
1350
 
 
1351
  synth_half(mpadec, bandptr, channel, buf);
 
1352
  if (channel) out++;
 
1353
  for (i = 0; i < SBLIMIT/2; i++, out += 2) {
 
1354
    int32_t tmp;
 
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);
 
1360
  }
 
1361
}
 
1362
 
 
1363
/* 32 bit floating-point, big-endian */
 
1364
 
 
1365
static void synth_half32fbmm(mpadec_t mpadec, MYFLT *bandptr,
 
1366
                             int channel, uint8_t *buffer)
 
1367
{
 
1368
  register int i;
 
1369
  register float *out = (float *)buffer;
 
1370
  MYFLT buf[SBLIMIT/2];
 
1371
 
 
1372
  synth_half(mpadec, bandptr, channel, buf);
 
1373
  for (i = 0; i < SBLIMIT/2; i++, out++) {
 
1374
    int32_t tmp;
 
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);
 
1380
  }
 
1381
}
 
1382
 
 
1383
#define synth_half32fbsm synth_half32fbmm
 
1384
 
 
1385
static void synth_half32fbms(mpadec_t mpadec, MYFLT *bandptr,
 
1386
                             int channel, uint8_t *buffer)
 
1387
{
 
1388
  register int i;
 
1389
  register float *out = (float *)buffer;
 
1390
  MYFLT buf[SBLIMIT/2];
 
1391
 
 
1392
  synth_half(mpadec, bandptr, channel, buf);
 
1393
  for (i = 0; i < SBLIMIT/2; i++, out += 2) {
 
1394
    int32_t tmp;
 
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);
 
1400
  }
 
1401
}
 
1402
 
 
1403
static void synth_half32fbss(mpadec_t mpadec, MYFLT *bandptr,
 
1404
                             int channel, uint8_t *buffer)
 
1405
{
 
1406
  register int i;
 
1407
  register float *out = (float *)buffer;
 
1408
  MYFLT buf[SBLIMIT/2];
 
1409
 
 
1410
  synth_half(mpadec, bandptr, channel, buf);
 
1411
  if (channel) out++;
 
1412
  for (i = 0; i < SBLIMIT/2; i++, out += 2) {
 
1413
    int32_t tmp;
 
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);
 
1419
  }
 
1420
}
 
1421
 
 
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 } } }
 
1439
};
 
1440