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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  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 
dct64(MYFLT * outptr0,MYFLT * outptr1,MYFLT * samples)47 static void dct64(MYFLT *outptr0, MYFLT *outptr1, MYFLT *samples)
48 {
49   MYFLT tmp1[32], tmp2[32];
50 
51   {
52     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     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 
synth_full(mpadec_t mpadec,MYFLT * bandptr,int channel,MYFLT * buffer)322 static void synth_full(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
323 {
324   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     int i;
345     MYFLT *out = buffer;
346     MYFLT *win = mpa->tables.decwin + (16 - bo);
347 
348     for (i = 16; i; i--, win += 32, b0 += 16) {
349       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       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       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 
synth_half(mpadec_t mpadec,MYFLT * bandptr,int channel,MYFLT * buffer)403 static void synth_half(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer)
404 {
405   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     int i;
427     MYFLT *out = buffer;
428     MYFLT *win = mpa->tables.decwin + (16 - bo);
429 
430     for (i = 8; i; i--, win += 64, b0 += 32) {
431       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       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       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 
synth_full16lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)489 static void synth_full16lmm(mpadec_t mpadec, MYFLT *bandptr,
490                             int channel, uint8_t *buffer)
491 {
492   int i;
493   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     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 
synth_full16lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)507 static void synth_full16lms(mpadec_t mpadec, MYFLT *bandptr,
508                             int channel, uint8_t *buffer)
509 {
510   int i;
511   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     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 
synth_full16lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)523 static void synth_full16lss(mpadec_t mpadec, MYFLT *bandptr,
524                             int channel, uint8_t *buffer)
525 {
526   int i;
527   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     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 
synth_full16bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)542 static void synth_full16bmm(mpadec_t mpadec, MYFLT *bandptr,
543                             int channel, uint8_t *buffer)
544 {
545   int i;
546   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     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 
synth_full16bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)561 static void synth_full16bms(mpadec_t mpadec, MYFLT *bandptr,
562                             int channel, uint8_t *buffer)
563 {
564   int i;
565   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     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 
synth_full16bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)577 static void synth_full16bss(mpadec_t mpadec, MYFLT *bandptr,
578                             int channel, uint8_t *buffer)
579 {
580   int i;
581   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     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 
synth_full24lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)596 static void synth_full24lmm(mpadec_t mpadec, MYFLT *bandptr,
597                             int channel, uint8_t *buffer)
598 {
599   int i;
600   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     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 
synth_full24lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)616 static void synth_full24lms(mpadec_t mpadec, MYFLT *bandptr,
617                             int channel, uint8_t *buffer)
618 {
619   int i;
620   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     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 
synth_full24lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)634 static void synth_full24lss(mpadec_t mpadec, MYFLT *bandptr,
635                             int channel, uint8_t *buffer)
636 {
637   int i;
638   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     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 
synth_full24bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)655 static void synth_full24bmm(mpadec_t mpadec, MYFLT *bandptr,
656                             int channel, uint8_t *buffer)
657 {
658   int i;
659   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     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 
synth_full24bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)675 static void synth_full24bms(mpadec_t mpadec, MYFLT *bandptr,
676                             int channel, uint8_t *buffer)
677 {
678   int i;
679   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     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 
synth_full24bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)693 static void synth_full24bss(mpadec_t mpadec, MYFLT *bandptr,
694                             int channel, uint8_t *buffer)
695 {
696   int i;
697   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     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 
synth_full32lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)714 static void synth_full32lmm(mpadec_t mpadec, MYFLT *bandptr,
715                             int channel, uint8_t *buffer)
716 {
717   int i;
718   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     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 
synth_full32lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)735 static void synth_full32lms(mpadec_t mpadec, MYFLT *bandptr,
736                             int channel, uint8_t *buffer)
737 {
738   int i;
739   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     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 
synth_full32lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)754 static void synth_full32lss(mpadec_t mpadec, MYFLT *bandptr,
755                             int channel, uint8_t *buffer)
756 {
757   int i;
758   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     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 
synth_full32bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)776 static void synth_full32bmm(mpadec_t mpadec, MYFLT *bandptr,
777                             int channel, uint8_t *buffer)
778 {
779   int i;
780   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     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 
synth_full32bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)797 static void synth_full32bms(mpadec_t mpadec, MYFLT *bandptr,
798                             int channel, uint8_t *buffer)
799 {
800   int i;
801   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     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 
synth_full32bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)816 static void synth_full32bss(mpadec_t mpadec, MYFLT *bandptr,
817                             int channel, uint8_t *buffer)
818 {
819   int i;
820   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     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 
synth_full32flmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)838 static void synth_full32flmm(mpadec_t mpadec, MYFLT *bandptr,
839                              int channel, uint8_t *buffer)
840 {
841   int i;
842   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     union tmp__ {
848       int32_t i;
849       float   f;
850     } tmp;
851     tmp.f = (float)buf[i];
852     ((uint8_t *)out)[0] = (uint8_t)tmp.i;
853     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8);
854     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16);
855     ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24);
856   }
857 }
858 
859 #define synth_full32flsm synth_full32flmm
860 
synth_full32flms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)861 static void synth_full32flms(mpadec_t mpadec, MYFLT *bandptr,
862                              int channel, uint8_t *buffer)
863 {
864   int i;
865   float *out = (float *)buffer;
866   MYFLT buf[SBLIMIT];
867 
868   synth_full(mpadec, bandptr, channel, buf);
869   for (i = 0; i < SBLIMIT; i++, out += 2) {
870     union tmp__ {
871       int32_t i;
872       float   f;
873     } tmp;
874     tmp.f = (float)buf[i];
875     ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp.i;
876     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 8);
877     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 16);
878     ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp.i >> 24);
879   }
880 }
881 
synth_full32flss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)882 static void synth_full32flss(mpadec_t mpadec, MYFLT *bandptr,
883                              int channel, uint8_t *buffer)
884 {
885   int i;
886   float *out = (float *)buffer;
887   MYFLT buf[SBLIMIT];
888 
889   synth_full(mpadec, bandptr, channel, buf);
890   if (channel) out++;
891   for (i = 0; i < SBLIMIT; i++, out += 2) {
892     union tmp__ {
893       int32_t i;
894       float   f;
895     } tmp;
896     tmp.f = (float)buf[i];
897     ((uint8_t *)out)[0] = (uint8_t)tmp.i;
898     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8);
899     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16);
900     ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24);
901   }
902 }
903 
904 /* 32 bit floating-point, big-endian */
905 
synth_full32fbmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)906 static void synth_full32fbmm(mpadec_t mpadec, MYFLT *bandptr,
907                              int channel, uint8_t *buffer)
908 {
909   int i;
910   float *out = (float *)buffer;
911   MYFLT buf[SBLIMIT];
912 
913   synth_full(mpadec, bandptr, channel, buf);
914   for (i = 0; i < SBLIMIT; i++, out++) {
915     union tmp__ {
916       int32_t i;
917       float   f;
918     } tmp;
919     tmp.f = (float)buf[i];
920     ((uint8_t *)out)[3] = (uint8_t)tmp.i;
921     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8);
922     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16);
923     ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24);
924   }
925 }
926 
927 #define synth_full32fbsm synth_full32fbmm
928 
synth_full32fbms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)929 static void synth_full32fbms(mpadec_t mpadec, MYFLT *bandptr,
930                              int channel, uint8_t *buffer)
931 {
932   int i;
933   float *out = (float *)buffer;
934   MYFLT buf[SBLIMIT];
935 
936   synth_full(mpadec, bandptr, channel, buf);
937   for (i = 0; i < SBLIMIT; i++, out += 2) {
938     union tmp__ {
939       int32_t i;
940       float   f;
941     } tmp;
942     tmp.f = (float)buf[i];
943     ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp.i;
944     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 8);
945     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 16);
946     ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp.i >> 24);
947   }
948 }
949 
synth_full32fbss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)950 static void synth_full32fbss(mpadec_t mpadec, MYFLT *bandptr,
951                              int channel, uint8_t *buffer)
952 {
953   int i;
954   float *out = (float *)buffer;
955   MYFLT buf[SBLIMIT];
956 
957   synth_full(mpadec, bandptr, channel, buf);
958   if (channel) out++;
959   for (i = 0; i < SBLIMIT; i++, out += 2) {
960     union tmp__ {
961       int32_t i;
962       float   f;
963     } tmp;
964     tmp.f = (float)buf[i];
965     ((uint8_t *)out)[3] = (uint8_t)tmp.i;
966     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8);
967     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16);
968     ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24);
969   }
970 }
971 
972 /* Half quality */
973 
974 /* 16 bit, little-endian */
975 
synth_half16lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)976 static void synth_half16lmm(mpadec_t mpadec, MYFLT *bandptr,
977                             int channel, uint8_t *buffer)
978 {
979   int i;
980   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++) {
985     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)tmp;
988     ((int8_t *)out)[1] = (int8_t)(tmp >> 8);
989   }
990 }
991 
992 #define synth_half16lsm synth_half16lmm
993 
synth_half16lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)994 static void synth_half16lms(mpadec_t mpadec, MYFLT *bandptr,
995                             int channel, uint8_t *buffer)
996 {
997   int i;
998   int16_t *out = (int16_t *)buffer;
999   MYFLT buf[SBLIMIT/2];
1000 
1001   synth_half(mpadec, bandptr, channel, buf);
1002   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1003     int32_t tmp = LROUND(buf[i]);
1004     if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1005     ((uint8_t *)out)[0] = ((uint8_t *)out)[2] = (uint8_t)tmp;
1006     ((int8_t *)out)[1] = ((int8_t *)out)[3] = (int8_t)(tmp >> 8);
1007   }
1008 }
1009 
synth_half16lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1010 static void synth_half16lss(mpadec_t mpadec, MYFLT *bandptr,
1011                             int channel, uint8_t *buffer)
1012 {
1013   int i;
1014   int16_t *out = (int16_t *)buffer;
1015   MYFLT buf[SBLIMIT/2];
1016 
1017   synth_half(mpadec, bandptr, channel, buf);
1018   if (channel) out++;
1019   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1020     int32_t tmp = LROUND(buf[i]);
1021     if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1022     ((uint8_t *)out)[0] = (uint8_t)tmp;
1023     ((int8_t *)out)[1] = (int8_t)(tmp >> 8);
1024   }
1025 }
1026 
1027 /* 16 bit, big-endian */
1028 
synth_half16bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1029 static void synth_half16bmm(mpadec_t mpadec, MYFLT *bandptr,
1030                             int channel, uint8_t *buffer)
1031 {
1032   int i;
1033   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++) {
1038     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)tmp;
1041     ((int8_t *)out)[0] = (int8_t)(tmp >> 8);
1042   }
1043 }
1044 
1045 #define synth_half16bsm synth_half16bmm
1046 
synth_half16bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1047 static void synth_half16bms(mpadec_t mpadec, MYFLT *bandptr,
1048                             int channel, uint8_t *buffer)
1049 {
1050   int i;
1051   int16_t *out = (int16_t *)buffer;
1052   MYFLT buf[SBLIMIT/2];
1053 
1054   synth_half(mpadec, bandptr, channel, buf);
1055   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1056     int32_t tmp = LROUND(buf[i]);
1057     if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1058     ((uint8_t *)out)[1] = ((uint8_t *)out)[3] = (uint8_t)tmp;
1059     ((int8_t *)out)[0] = ((int8_t *)out)[2] = (int8_t)(tmp >> 8);
1060   }
1061 }
1062 
synth_half16bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1063 static void synth_half16bss(mpadec_t mpadec, MYFLT *bandptr,
1064                             int channel, uint8_t *buffer)
1065 {
1066   int i;
1067   int16_t *out = (int16_t *)buffer;
1068   MYFLT buf[SBLIMIT/2];
1069 
1070   synth_half(mpadec, bandptr, channel, buf);
1071   if (channel) out++;
1072   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1073     int32_t tmp = LROUND(buf[i]);
1074     if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768;
1075     ((uint8_t *)out)[1] = (uint8_t)tmp;
1076     ((int8_t *)out)[0] = (int8_t)(tmp >> 8);
1077   }
1078 }
1079 
1080 /* 24 bit, little-endian */
1081 
synth_half24lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1082 static void synth_half24lmm(mpadec_t mpadec, MYFLT *bandptr,
1083                             int channel, uint8_t *buffer)
1084 {
1085   int i;
1086   uint8_t *out = (uint8_t *)buffer;
1087   MYFLT buf[SBLIMIT/2];
1088 
1089   synth_half(mpadec, bandptr, channel, buf);
1090   for (i = 0; i < SBLIMIT/2; i++, out += 3) {
1091     int32_t tmp = LROUND(buf[i]);
1092     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1093     else if (tmp < -0x800000) tmp = -0x800000;
1094     ((uint8_t *)out)[0] = (uint8_t)tmp;
1095     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1096     ((int8_t *)out)[2] = (int8_t)(tmp >> 16);
1097   }
1098 }
1099 
1100 #define synth_half24lsm synth_half24lmm
1101 
synth_half24lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1102 static void synth_half24lms(mpadec_t mpadec, MYFLT *bandptr,
1103                             int channel, uint8_t *buffer)
1104 {
1105   int i;
1106   uint8_t *out = (uint8_t *)buffer;
1107   MYFLT buf[SBLIMIT/2];
1108 
1109   synth_half(mpadec, bandptr, channel, buf);
1110   for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1111     int32_t tmp = LROUND(buf[i]);
1112     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1113     else if (tmp < -0x800000) tmp = -0x800000;
1114     ((uint8_t *)out)[0] = ((uint8_t *)out)[3] = (uint8_t)tmp;
1115     ((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
1116     ((int8_t *)out)[2] = ((int8_t *)out)[5] = (int8_t)(tmp >> 16);
1117   }
1118 }
1119 
synth_half24lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1120 static void synth_half24lss(mpadec_t mpadec, MYFLT *bandptr,
1121                             int channel, uint8_t *buffer)
1122 {
1123   int i;
1124   uint8_t *out = (uint8_t *)buffer;
1125   MYFLT buf[SBLIMIT/2];
1126 
1127   synth_half(mpadec, bandptr, channel, buf);
1128   if (channel) out += 3;
1129   for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1130     int32_t tmp = LROUND(buf[i]);
1131     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1132     else if (tmp < -0x800000) tmp = -0x800000;
1133     ((uint8_t *)out)[0] = (uint8_t)tmp;
1134     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1135     ((int8_t *)out)[2] = (int8_t)(tmp >> 16);
1136   }
1137 }
1138 
1139 /* 24 bit, big-endian */
1140 
synth_half24bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1141 static void synth_half24bmm(mpadec_t mpadec, MYFLT *bandptr,
1142                             int channel, uint8_t *buffer)
1143 {
1144   int i;
1145   uint8_t *out = (uint8_t *)buffer;
1146   MYFLT buf[SBLIMIT/2];
1147 
1148   synth_half(mpadec, bandptr, channel, buf);
1149   for (i = 0; i < SBLIMIT/2; i++, out += 3) {
1150     int32_t tmp = LROUND(buf[i]);
1151     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1152     else if (tmp < -0x800000) tmp = -0x800000;
1153     ((uint8_t *)out)[2] = (uint8_t)tmp;
1154     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1155     ((int8_t *)out)[0] = (int8_t)(tmp >> 16);
1156   }
1157 }
1158 
1159 #define synth_half24bsm synth_half24bmm
1160 
synth_half24bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1161 static void synth_half24bms(mpadec_t mpadec, MYFLT *bandptr,
1162                             int channel, uint8_t *buffer)
1163 {
1164   int i;
1165   uint8_t *out = (uint8_t *)buffer;
1166   MYFLT buf[SBLIMIT/2];
1167 
1168   synth_half(mpadec, bandptr, channel, buf);
1169   for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1170     int32_t tmp = LROUND(buf[i]);
1171     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1172     else if (tmp < -0x800000) tmp = -0x800000;
1173     ((uint8_t *)out)[2] = ((uint8_t *)out)[5] = (uint8_t)tmp;
1174     ((uint8_t *)out)[1] = ((uint8_t *)out)[4] = (uint8_t)(tmp >> 8);
1175     ((int8_t *)out)[0] = ((int8_t *)out)[3] = (int8_t)(tmp >> 16);
1176   }
1177 }
1178 
synth_half24bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1179 static void synth_half24bss(mpadec_t mpadec, MYFLT *bandptr,
1180                             int channel, uint8_t *buffer)
1181 {
1182   int i;
1183   uint8_t *out = (uint8_t *)buffer;
1184   MYFLT buf[SBLIMIT/2];
1185 
1186   synth_half(mpadec, bandptr, channel, buf);
1187   if (channel) out += 3;
1188   for (i = 0; i < SBLIMIT/2; i++, out += 6) {
1189     int32_t tmp = LROUND(buf[i]);
1190     if (tmp > 0x7FFFFF) tmp = 0x7FFFFF;
1191     else if (tmp < -0x800000) tmp = -0x800000;
1192     ((uint8_t *)out)[2] = (uint8_t)tmp;
1193     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1194     ((int8_t *)out)[0] = (int8_t)(tmp >> 16);
1195   }
1196 }
1197 
1198 /* 32 bit, little-endian */
1199 
synth_half32lmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1200 static void synth_half32lmm(mpadec_t mpadec, MYFLT *bandptr,
1201                             int channel, uint8_t *buffer)
1202 {
1203   int i;
1204   int32_t *out = (int32_t *)buffer;
1205   MYFLT buf[SBLIMIT/2];
1206 
1207   synth_half(mpadec, bandptr, channel, buf);
1208   for (i = 0; i < SBLIMIT/2; i++, out++) {
1209     int64_t tmp = LLROUND(buf[i]);
1210     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1211     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1212     ((uint8_t *)out)[0] = (uint8_t)tmp;
1213     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1214     ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1215     ((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1216   }
1217 }
1218 
1219 #define synth_half32lsm synth_half32lmm
1220 
synth_half32lms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1221 static void synth_half32lms(mpadec_t mpadec, MYFLT *bandptr,
1222                             int channel, uint8_t *buffer)
1223 {
1224   int i;
1225   int32_t *out = (int32_t *)buffer;
1226   MYFLT buf[SBLIMIT/2];
1227 
1228   synth_half(mpadec, bandptr, channel, buf);
1229   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1230     int64_t tmp = LLROUND(buf[i]);
1231     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1232     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1233     ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp;
1234     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8);
1235     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16);
1236     ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24);
1237   }
1238 }
1239 
synth_half32lss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1240 static void synth_half32lss(mpadec_t mpadec, MYFLT *bandptr,
1241                             int channel, uint8_t *buffer)
1242 {
1243   int i;
1244   int32_t *out = (int32_t *)buffer;
1245   MYFLT buf[SBLIMIT/2];
1246 
1247   synth_half(mpadec, bandptr, channel, buf);
1248   if (channel) out++;
1249   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1250     int64_t tmp = LLROUND(buf[i]);
1251     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1252     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1253     ((uint8_t *)out)[0] = (uint8_t)tmp;
1254     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8);
1255     ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16);
1256     ((int8_t *)out)[3] = (int8_t)(tmp >> 24);
1257   }
1258 }
1259 
1260 /* 32 bit, big-endian */
1261 
synth_half32bmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1262 static void synth_half32bmm(mpadec_t mpadec, MYFLT *bandptr,
1263                             int channel, uint8_t *buffer)
1264 {
1265   int i;
1266   int32_t *out = (int32_t *)buffer;
1267   MYFLT buf[SBLIMIT/2];
1268 
1269   synth_half(mpadec, bandptr, channel, buf);
1270   for (i = 0; i < SBLIMIT/2; i++, out++) {
1271     int64_t tmp = LLROUND(buf[i]);
1272     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1273     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1274     ((uint8_t *)out)[3] = (uint8_t)tmp;
1275     ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1276     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1277     ((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1278   }
1279 }
1280 
1281 #define synth_half32bsm synth_half32bmm
1282 
synth_half32bms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1283 static void synth_half32bms(mpadec_t mpadec, MYFLT *bandptr,
1284                             int channel, uint8_t *buffer)
1285 {
1286   int i;
1287   int32_t *out = (int32_t *)buffer;
1288   MYFLT buf[SBLIMIT/2];
1289 
1290   synth_half(mpadec, bandptr, channel, buf);
1291   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1292     int64_t tmp = LLROUND(buf[i]);
1293     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1294     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1295     ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp;
1296     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8);
1297     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16);
1298     ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24);
1299   }
1300 }
1301 
synth_half32bss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1302 static void synth_half32bss(mpadec_t mpadec, MYFLT *bandptr,
1303                             int channel, uint8_t *buffer)
1304 {
1305   int i;
1306   int32_t *out = (int32_t *)buffer;
1307   MYFLT buf[SBLIMIT/2];
1308 
1309   synth_half(mpadec, bandptr, channel, buf);
1310   if (channel) out++;
1311   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1312     int64_t tmp = LLROUND(buf[i]);
1313     if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF;
1314     else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1);
1315     ((uint8_t *)out)[3] = (uint8_t)tmp;
1316     ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8);
1317     ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16);
1318     ((int8_t *)out)[0] = (int8_t)(tmp >> 24);
1319   }
1320 }
1321 
1322 /* 32 bit floating-point, little-endian */
1323 
synth_half32flmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1324 static void synth_half32flmm(mpadec_t mpadec, MYFLT *bandptr,
1325                              int channel, uint8_t *buffer)
1326 {
1327   int i;
1328   float *out = (float *)buffer;
1329   MYFLT buf[SBLIMIT/2];
1330 
1331   synth_half(mpadec, bandptr, channel, buf);
1332   for (i = 0; i < SBLIMIT/2; i++, out++) {
1333     union tmp__ {
1334       int32_t i;
1335       float f;
1336     } tmp;
1337     tmp.f = (float)buf[i];
1338     ((uint8_t *)out)[0] = (uint8_t)tmp.i;
1339     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8);
1340     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16);
1341     ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24);
1342   }
1343 }
1344 
1345 #define synth_half32flsm synth_half32flmm
1346 
synth_half32flms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1347 static void synth_half32flms(mpadec_t mpadec, MYFLT *bandptr,
1348                              int channel, uint8_t *buffer)
1349 {
1350   int i;
1351   float *out = (float *)buffer;
1352   MYFLT buf[SBLIMIT/2];
1353 
1354   synth_half(mpadec, bandptr, channel, buf);
1355   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1356     union tmp__ {
1357       int32_t i;
1358       float   f;
1359     } tmp;
1360     tmp.f = (float)buf[i];
1361     ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp.i;
1362     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 8);
1363     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 16);
1364     ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp.i >> 24);
1365   }
1366 }
1367 
synth_half32flss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1368 static void synth_half32flss(mpadec_t mpadec, MYFLT *bandptr,
1369                              int channel, uint8_t *buffer)
1370 {
1371   int i;
1372   float *out = (float *)buffer;
1373   MYFLT buf[SBLIMIT/2];
1374 
1375   synth_half(mpadec, bandptr, channel, buf);
1376   if (channel) out++;
1377   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1378     union tmp__ {
1379       int32_t i;
1380       float   f;
1381     } tmp;
1382     tmp.f = (float)buf[i];
1383     ((uint8_t *)out)[0] = (uint8_t)tmp.i;
1384     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8);
1385     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16);
1386     ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24);
1387   }
1388 }
1389 
1390 /* 32 bit floating-point, big-endian */
1391 
synth_half32fbmm(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1392 static void synth_half32fbmm(mpadec_t mpadec, MYFLT *bandptr,
1393                              int channel, uint8_t *buffer)
1394 {
1395   int i;
1396   float *out = (float *)buffer;
1397   MYFLT buf[SBLIMIT/2];
1398 
1399   synth_half(mpadec, bandptr, channel, buf);
1400   for (i = 0; i < SBLIMIT/2; i++, out++) {
1401     union tmp__ {
1402       int32_t i;
1403       float   f;
1404     } tmp;
1405     tmp.f = (float)buf[i];
1406     ((uint8_t *)out)[3] = (uint8_t)tmp.i;
1407     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8);
1408     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16);
1409     ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24);
1410   }
1411 }
1412 
1413 #define synth_half32fbsm synth_half32fbmm
1414 
synth_half32fbms(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1415 static void synth_half32fbms(mpadec_t mpadec, MYFLT *bandptr,
1416                              int channel, uint8_t *buffer)
1417 {
1418   int i;
1419   float *out = (float *)buffer;
1420   MYFLT buf[SBLIMIT/2];
1421 
1422   synth_half(mpadec, bandptr, channel, buf);
1423   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1424     union tmp__ {
1425       int32_t i;
1426       float   f;
1427     } tmp;
1428     tmp.f = (float)buf[i];
1429     ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp.i;
1430     ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 8);
1431     ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 16);
1432     ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp.i >> 24);
1433   }
1434 }
1435 
synth_half32fbss(mpadec_t mpadec,MYFLT * bandptr,int channel,uint8_t * buffer)1436 static void synth_half32fbss(mpadec_t mpadec, MYFLT *bandptr,
1437                              int channel, uint8_t *buffer)
1438 {
1439   int i;
1440   float *out = (float *)buffer;
1441   MYFLT buf[SBLIMIT/2];
1442 
1443   synth_half(mpadec, bandptr, channel, buf);
1444   if (channel) out++;
1445   for (i = 0; i < SBLIMIT/2; i++, out += 2) {
1446     union tmp__ {
1447       int32 i;
1448       float f;
1449     } tmp;
1450     tmp.f = (float)buf[i];
1451     ((uint8_t *)out)[3] = (uint8_t)tmp.i;
1452     ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8);
1453     ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16);
1454     ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24);
1455   }
1456 }
1457 
1458 void *synth_table[2][2][4][4] = {
1459   { { { synth_full16lmm,  synth_full16lms,  synth_full16lsm,  synth_full16lss  },
1460       { synth_full24lmm,  synth_full24lms,  synth_full24lsm,  synth_full24lss  },
1461       { synth_full32lmm,  synth_full32lms,  synth_full32lsm,  synth_full32lss  },
1462       { synth_full32flmm, synth_full32flms, synth_full32flsm, synth_full32flss } },
1463     { { synth_full16bmm,  synth_full16bms,  synth_full16bsm,  synth_full16bss  },
1464       { synth_full24bmm,  synth_full24bms,  synth_full24bsm,  synth_full24bss  },
1465       { synth_full32bmm,  synth_full32bms,  synth_full32bsm,  synth_full32bss  },
1466       { synth_full32fbmm, synth_full32fbms, synth_full32fbsm, synth_full32fbss } } },
1467   { { { synth_half16lmm,  synth_half16lms,  synth_half16lsm,  synth_half16lss  },
1468       { synth_half24lmm,  synth_half24lms,  synth_half24lsm,  synth_half24lss  },
1469       { synth_half32lmm,  synth_half32lms,  synth_half32lsm,  synth_half32lss  },
1470       { synth_half32flmm, synth_half32flms, synth_half32flsm, synth_half32flss } },
1471     { { synth_half16bmm,  synth_half16bms,  synth_half16bsm,  synth_half16bss  },
1472       { synth_half24bmm,  synth_half24bms,  synth_half24bsm,  synth_half24bss  },
1473       { synth_half32bmm,  synth_half32bms,  synth_half32bsm,  synth_half32bss  },
1474       { synth_half32fbmm, synth_half32fbms, synth_half32fbsm, synth_half32fbss } } }
1475 };
1476