Coverage Report

Created: 2026-10-17 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/output.c
Line
Count
Source
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program 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
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**
28
** $Id: output.c,v 1.47 2009/01/26 23:51:15 menno Exp $
29
**/
30
31
#include "common.h"
32
#include "structs.h"
33
34
#include "output.h"
35
36
#ifndef FIXED_POINT
37
38
39
15.1M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.89M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.78M
#define RSQRT2 REAL_CONST(0.7071067811865475244) // 1/sqrt(2)
43
44
45
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
46
                                uint8_t down_matrix, uint8_t *internal_channel)
47
43.5M
{
48
43.5M
    if (!down_matrix)
49
40.6M
        return input[internal_channel[channel]][sample];
50
51
2.89M
    if (channel == 0)
52
1.43M
    {
53
1.43M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.43M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.43M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.45M
    } else {
57
1.45M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.45M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.45M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.45M
    }
61
2.89M
}
62
63
#ifndef HAS_LRINTF
64
32.4M
#define CLIP(sample, max, min) \
65
32.4M
if (sample >= 0.0f)            \
66
28.3M
{                              \
67
28.3M
    sample += 0.5f;            \
68
28.3M
    if (sample >= max)         \
69
28.3M
        sample = max;          \
70
28.3M
} else {                       \
71
4.16M
    sample += -0.5f;           \
72
4.16M
    if (sample <= min)         \
73
4.16M
        sample = min;          \
74
4.16M
}
75
#else
76
#define CLIP(sample, max, min) \
77
if (sample >= 0.0f)            \
78
{                              \
79
    if (sample >= max)         \
80
        sample = max;          \
81
} else {                       \
82
    if (sample <= min)         \
83
        sample = min;          \
84
}
85
#endif
86
87
7.11k
#define CONV(a,b) ((a<<1)|(b&0x1))
88
89
static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
90
                         uint8_t channels, uint16_t frame_len,
91
                         int16_t **sample_buffer)
92
1.46k
{
93
1.46k
    uint8_t ch, ch1;
94
1.46k
    uint16_t i;
95
96
1.46k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.46k
    {
98
165
    case CONV(1,0):
99
166
    case CONV(1,1):
100
200k
        for(i = 0; i < frame_len; i++)
101
200k
        {
102
200k
            real_t inp = input[hDecoder->internal_channel[0]][i];
103
104
200k
            CLIP(inp, 32767.0f, -32768.0f);
105
106
200k
            (*sample_buffer)[i] = (int16_t)lrintf(inp);
107
200k
        }
108
166
        break;
109
451
    case CONV(2,0):
110
451
        if (hDecoder->upMatrix)
111
0
        {
112
0
            ch  = hDecoder->internal_channel[0];
113
0
            for(i = 0; i < frame_len; i++)
114
0
            {
115
0
                real_t inp0 = input[ch][i];
116
117
0
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
0
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
0
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
0
            }
122
451
        } else {
123
451
            ch  = hDecoder->internal_channel[0];
124
451
            ch1 = hDecoder->internal_channel[1];
125
731k
            for(i = 0; i < frame_len; i++)
126
731k
            {
127
731k
                real_t inp0 = input[ch ][i];
128
731k
                real_t inp1 = input[ch1][i];
129
130
731k
                CLIP(inp0, 32767.0f, -32768.0f);
131
731k
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
731k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
731k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
731k
            }
136
451
        }
137
451
        break;
138
851
    default:
139
8.78k
        for (ch = 0; ch < channels; ch++)
140
7.93k
        {
141
11.7M
            for(i = 0; i < frame_len; i++)
142
11.6M
            {
143
11.6M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
11.6M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
11.6M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
11.6M
            }
149
7.93k
        }
150
851
        break;
151
1.46k
    }
152
1.46k
}
153
154
static void to_PCM_24bit(NeAACDecStruct *hDecoder, real_t **input,
155
                         uint8_t channels, uint16_t frame_len,
156
                         int32_t **sample_buffer)
157
1.17k
{
158
1.17k
    uint8_t ch, ch1;
159
1.17k
    uint16_t i;
160
161
1.17k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.17k
    {
163
154
    case CONV(1,0):
164
155
    case CONV(1,1):
165
184k
        for(i = 0; i < frame_len; i++)
166
183k
        {
167
183k
            real_t inp = input[hDecoder->internal_channel[0]][i];
168
169
183k
            inp *= 256.0f;
170
183k
            CLIP(inp, 8388607.0f, -8388608.0f);
171
172
183k
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
173
183k
        }
174
155
        break;
175
262
    case CONV(2,0):
176
262
        if (hDecoder->upMatrix)
177
0
        {
178
0
            ch = hDecoder->internal_channel[0];
179
0
            for(i = 0; i < frame_len; i++)
180
0
            {
181
0
                real_t inp0 = input[ch][i];
182
183
0
                inp0 *= 256.0f;
184
0
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
0
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
0
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
0
            }
189
262
        } else {
190
262
            ch  = hDecoder->internal_channel[0];
191
262
            ch1 = hDecoder->internal_channel[1];
192
413k
            for(i = 0; i < frame_len; i++)
193
413k
            {
194
413k
                real_t inp0 = input[ch ][i];
195
413k
                real_t inp1 = input[ch1][i];
196
197
413k
                inp0 *= 256.0f;
198
413k
                inp1 *= 256.0f;
199
413k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
413k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
413k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
413k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
413k
            }
205
262
        }
206
262
        break;
207
762
    default:
208
7.08k
        for (ch = 0; ch < channels; ch++)
209
6.32k
        {
210
8.91M
            for(i = 0; i < frame_len; i++)
211
8.90M
            {
212
8.90M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.90M
                inp *= 256.0f;
215
8.90M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.90M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.90M
            }
219
6.32k
        }
220
762
        break;
221
1.17k
    }
222
1.17k
}
223
224
static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
225
                         uint8_t channels, uint16_t frame_len,
226
                         int32_t **sample_buffer)
227
1.21k
{
228
1.21k
    uint8_t ch, ch1;
229
1.21k
    uint16_t i;
230
231
1.21k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.21k
    {
233
146
    case CONV(1,0):
234
147
    case CONV(1,1):
235
157k
        for(i = 0; i < frame_len; i++)
236
157k
        {
237
157k
            real_t inp = input[hDecoder->internal_channel[0]][i];
238
239
157k
            inp *= 65536.0f;
240
157k
            CLIP(inp, 2147483647.0f, -2147483648.0f);
241
242
157k
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
243
157k
        }
244
147
        break;
245
285
    case CONV(2,0):
246
285
        if (hDecoder->upMatrix)
247
0
        {
248
0
            ch = hDecoder->internal_channel[0];
249
0
            for(i = 0; i < frame_len; i++)
250
0
            {
251
0
                real_t inp0 = input[ch][i];
252
253
0
                inp0 *= 65536.0f;
254
0
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
0
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
0
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
0
            }
259
285
        } else {
260
285
            ch  = hDecoder->internal_channel[0];
261
285
            ch1 = hDecoder->internal_channel[1];
262
431k
            for(i = 0; i < frame_len; i++)
263
431k
            {
264
431k
                real_t inp0 = input[ch ][i];
265
431k
                real_t inp1 = input[ch1][i];
266
267
431k
                inp0 *= 65536.0f;
268
431k
                inp1 *= 65536.0f;
269
431k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
431k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
431k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
431k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
431k
            }
275
285
        }
276
285
        break;
277
779
    default:
278
6.59k
        for (ch = 0; ch < channels; ch++)
279
5.81k
        {
280
8.20M
            for(i = 0; i < frame_len; i++)
281
8.20M
            {
282
8.20M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
8.20M
                inp *= 65536.0f;
285
8.20M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
8.20M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
8.20M
            }
289
5.81k
        }
290
779
        break;
291
1.21k
    }
292
1.21k
}
293
294
static void to_PCM_float(NeAACDecStruct *hDecoder, real_t **input,
295
                         uint8_t channels, uint16_t frame_len,
296
                         float32_t **sample_buffer)
297
623
{
298
623
    uint8_t ch, ch1;
299
623
    uint16_t i;
300
301
623
    switch (CONV(channels,hDecoder->downMatrix))
302
623
    {
303
21
    case CONV(1,0):
304
22
    case CONV(1,1):
305
40.5k
        for(i = 0; i < frame_len; i++)
306
40.5k
        {
307
40.5k
            real_t inp = input[hDecoder->internal_channel[0]][i];
308
40.5k
            (*sample_buffer)[i] = inp*FLOAT_SCALE;
309
40.5k
        }
310
22
        break;
311
72
    case CONV(2,0):
312
72
        if (hDecoder->upMatrix)
313
0
        {
314
0
            ch = hDecoder->internal_channel[0];
315
0
            for(i = 0; i < frame_len; i++)
316
0
            {
317
0
                real_t inp0 = input[ch][i];
318
0
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
0
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
0
            }
321
72
        } else {
322
72
            ch  = hDecoder->internal_channel[0];
323
72
            ch1 = hDecoder->internal_channel[1];
324
109k
            for(i = 0; i < frame_len; i++)
325
109k
            {
326
109k
                real_t inp0 = input[ch ][i];
327
109k
                real_t inp1 = input[ch1][i];
328
109k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
109k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
109k
            }
331
72
        }
332
72
        break;
333
529
    default:
334
5.55k
        for (ch = 0; ch < channels; ch++)
335
5.02k
        {
336
7.72M
            for(i = 0; i < frame_len; i++)
337
7.72M
            {
338
7.72M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
7.72M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
7.72M
            }
341
5.02k
        }
342
529
        break;
343
623
    }
344
623
}
345
346
static void to_PCM_double(NeAACDecStruct *hDecoder, real_t **input,
347
                          uint8_t channels, uint16_t frame_len,
348
                          double **sample_buffer)
349
499
{
350
499
    uint8_t ch, ch1;
351
499
    uint16_t i;
352
353
499
    switch (CONV(channels,hDecoder->downMatrix))
354
499
    {
355
20
    case CONV(1,0):
356
21
    case CONV(1,1):
357
31.3k
        for(i = 0; i < frame_len; i++)
358
31.2k
        {
359
31.2k
            real_t inp = input[hDecoder->internal_channel[0]][i];
360
31.2k
            (*sample_buffer)[i] = (double)inp*FLOAT_SCALE;
361
31.2k
        }
362
21
        break;
363
51
    case CONV(2,0):
364
51
        if (hDecoder->upMatrix)
365
0
        {
366
0
            ch = hDecoder->internal_channel[0];
367
0
            for(i = 0; i < frame_len; i++)
368
0
            {
369
0
                real_t inp0 = input[ch][i];
370
0
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
0
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
0
            }
373
51
        } else {
374
51
            ch  = hDecoder->internal_channel[0];
375
51
            ch1 = hDecoder->internal_channel[1];
376
65.7k
            for(i = 0; i < frame_len; i++)
377
65.6k
            {
378
65.6k
                real_t inp0 = input[ch ][i];
379
65.6k
                real_t inp1 = input[ch1][i];
380
65.6k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
65.6k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
65.6k
            }
383
51
        }
384
51
        break;
385
427
    default:
386
4.82k
        for (ch = 0; ch < channels; ch++)
387
4.40k
        {
388
7.01M
            for(i = 0; i < frame_len; i++)
389
7.01M
            {
390
7.01M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
7.01M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
7.01M
            }
393
4.40k
        }
394
427
        break;
395
499
    }
396
499
}
397
398
void *output_to_PCM(NeAACDecStruct *hDecoder,
399
                    real_t **input, void *sample_buffer, uint8_t channels,
400
                    uint16_t frame_len, uint8_t format)
401
9.96k
{
402
9.96k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
9.96k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
9.96k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
9.96k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
9.96k
    switch (format)
413
9.96k
    {
414
2.93k
    case FAAD_FMT_16BIT:
415
2.93k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
2.93k
        break;
417
2.35k
    case FAAD_FMT_24BIT:
418
2.35k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.35k
        break;
420
2.42k
    case FAAD_FMT_32BIT:
421
2.42k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.42k
        break;
423
1.24k
    case FAAD_FMT_FLOAT:
424
1.24k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.24k
        break;
426
998
    case FAAD_FMT_DOUBLE:
427
998
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
998
        break;
429
9.96k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
9.96k
    return sample_buffer;
437
9.96k
}
output_to_PCM
Line
Count
Source
401
4.98k
{
402
4.98k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.98k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.98k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.98k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
4.98k
    switch (format)
413
4.98k
    {
414
1.46k
    case FAAD_FMT_16BIT:
415
1.46k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.46k
        break;
417
1.17k
    case FAAD_FMT_24BIT:
418
1.17k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.17k
        break;
420
1.21k
    case FAAD_FMT_32BIT:
421
1.21k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.21k
        break;
423
623
    case FAAD_FMT_FLOAT:
424
623
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
623
        break;
426
499
    case FAAD_FMT_DOUBLE:
427
499
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
499
        break;
429
4.98k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.98k
    return sample_buffer;
437
4.98k
}
output_to_PCM
Line
Count
Source
401
4.98k
{
402
4.98k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.98k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.98k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.98k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
4.98k
    switch (format)
413
4.98k
    {
414
1.46k
    case FAAD_FMT_16BIT:
415
1.46k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.46k
        break;
417
1.17k
    case FAAD_FMT_24BIT:
418
1.17k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.17k
        break;
420
1.21k
    case FAAD_FMT_32BIT:
421
1.21k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.21k
        break;
423
623
    case FAAD_FMT_FLOAT:
424
623
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
623
        break;
426
499
    case FAAD_FMT_DOUBLE:
427
499
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
499
        break;
429
4.98k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.98k
    return sample_buffer;
437
4.98k
}
438
439
#else
440
441
#define DM_MUL FRAC_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
442
#define RSQRT2 FRAC_CONST(0.7071067811865475244) // 1/sqrt(2)
443
#define BOTH FRAC_CONST(0.2265409196609864215998) // 1/(sqrt(2) + 2 + 1)
444
445
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
446
                                uint8_t down_matrix, uint8_t up_matrix,
447
                                uint8_t *internal_channel)
448
50.4M
{
449
50.4M
    real_t C;
450
50.4M
    if (up_matrix == 1)
451
0
        return input[internal_channel[0]][sample];
452
453
50.4M
    if (!down_matrix)
454
48.7M
        return input[internal_channel[channel]][sample];
455
456
1.67M
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
1.67M
    if (channel == 0)
458
829k
    {
459
829k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
829k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
829k
        return core + C + L_S;
462
848k
    } else {
463
848k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
848k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
848k
        return core + C + R_S;
466
848k
    }
467
1.67M
}
468
469
void* output_to_PCM(NeAACDecStruct *hDecoder,
470
                    real_t **input, void *sample_buffer, uint8_t channels,
471
                    uint16_t frame_len, uint8_t format)
472
11.0k
{
473
11.0k
    uint8_t ch;
474
11.0k
    uint16_t i;
475
11.0k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
11.0k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
11.0k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
83.0k
    for (ch = 0; ch < channels; ch++)
481
71.9k
    {
482
71.9k
        switch (format)
483
71.9k
        {
484
20.2k
        case FAAD_FMT_16BIT:
485
28.5M
            for(i = 0; i < frame_len; i++)
486
28.5M
            {
487
28.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
28.5M
                    hDecoder->internal_channel);
489
28.5M
                if (tmp >= 0)
490
26.4M
                {
491
26.4M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
26.4M
                        tmp += (1 << (REAL_BITS-1));
493
26.4M
                    if (tmp >= REAL_CONST(32767))
494
122k
                    {
495
122k
                        tmp = REAL_CONST(32767);
496
122k
                    }
497
26.4M
                } else {
498
2.05M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
2.05M
                        tmp += -(1 << (REAL_BITS-1));
500
2.05M
                    if (tmp <= REAL_CONST(-32768))
501
106k
                    {
502
106k
                        tmp = REAL_CONST(-32768);
503
106k
                    }
504
2.05M
                }
505
28.5M
                tmp >>= REAL_BITS;
506
28.5M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
28.5M
            }
508
20.2k
            break;
509
23.6k
        case FAAD_FMT_24BIT:
510
32.9M
            for(i = 0; i < frame_len; i++)
511
32.9M
            {
512
32.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
32.9M
                    hDecoder->internal_channel);
514
32.9M
                if (tmp >= 0)
515
30.4M
                {
516
30.4M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
30.4M
                        tmp += (1 << (REAL_BITS-9));
518
30.4M
                    tmp >>= (REAL_BITS-8);
519
30.4M
                    if (tmp >= 8388607)
520
98.7k
                    {
521
98.7k
                        tmp = 8388607;
522
98.7k
                    }
523
30.4M
                } else {
524
2.49M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
2.49M
                        tmp += -(1 << (REAL_BITS-9));
526
2.49M
                    tmp >>= (REAL_BITS-8);
527
2.49M
                    if (tmp <= -8388608)
528
100k
                    {
529
100k
                        tmp = -8388608;
530
100k
                    }
531
2.49M
                }
532
32.9M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
32.9M
            }
534
23.6k
            break;
535
16.5k
        case FAAD_FMT_32BIT:
536
16.5k
            exp = 16 - REAL_BITS;
537
16.5k
            half = 1 << (exp - 1);
538
16.5k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
22.9M
            for(i = 0; i < frame_len; i++)
540
22.9M
            {
541
22.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
22.9M
                    hDecoder->internal_channel);
543
22.9M
                if (tmp >= 0)
544
21.5M
                {
545
21.5M
                    if (tmp <= 0x7FFFFFFF - half)
546
21.5M
                        tmp += half;
547
21.5M
                } else {
548
1.36M
                    if (tmp >= (int32_t)0x80000000 + half)
549
1.36M
                        tmp += -half;
550
1.36M
                }
551
22.9M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
22.9M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
22.9M
            }
554
16.5k
            break;
555
11.5k
        case FAAD_FMT_FIXED:
556
16.5M
            for(i = 0; i < frame_len; i++)
557
16.5M
            {
558
16.5M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
16.5M
                    hDecoder->internal_channel);
560
16.5M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
16.5M
            }
562
11.5k
            break;
563
71.9k
        }
564
71.9k
    }
565
566
11.0k
    return sample_buffer;
567
11.0k
}
output_to_PCM
Line
Count
Source
472
5.53k
{
473
5.53k
    uint8_t ch;
474
5.53k
    uint16_t i;
475
5.53k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.53k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.53k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
41.5k
    for (ch = 0; ch < channels; ch++)
481
35.9k
    {
482
35.9k
        switch (format)
483
35.9k
        {
484
10.1k
        case FAAD_FMT_16BIT:
485
14.2M
            for(i = 0; i < frame_len; i++)
486
14.2M
            {
487
14.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
14.2M
                    hDecoder->internal_channel);
489
14.2M
                if (tmp >= 0)
490
13.2M
                {
491
13.2M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
13.2M
                        tmp += (1 << (REAL_BITS-1));
493
13.2M
                    if (tmp >= REAL_CONST(32767))
494
61.0k
                    {
495
61.0k
                        tmp = REAL_CONST(32767);
496
61.0k
                    }
497
13.2M
                } else {
498
1.02M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
1.02M
                        tmp += -(1 << (REAL_BITS-1));
500
1.02M
                    if (tmp <= REAL_CONST(-32768))
501
53.4k
                    {
502
53.4k
                        tmp = REAL_CONST(-32768);
503
53.4k
                    }
504
1.02M
                }
505
14.2M
                tmp >>= REAL_BITS;
506
14.2M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
14.2M
            }
508
10.1k
            break;
509
11.8k
        case FAAD_FMT_24BIT:
510
16.4M
            for(i = 0; i < frame_len; i++)
511
16.4M
            {
512
16.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
16.4M
                    hDecoder->internal_channel);
514
16.4M
                if (tmp >= 0)
515
15.2M
                {
516
15.2M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
15.2M
                        tmp += (1 << (REAL_BITS-9));
518
15.2M
                    tmp >>= (REAL_BITS-8);
519
15.2M
                    if (tmp >= 8388607)
520
49.3k
                    {
521
49.3k
                        tmp = 8388607;
522
49.3k
                    }
523
15.2M
                } else {
524
1.24M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.24M
                        tmp += -(1 << (REAL_BITS-9));
526
1.24M
                    tmp >>= (REAL_BITS-8);
527
1.24M
                    if (tmp <= -8388608)
528
50.3k
                    {
529
50.3k
                        tmp = -8388608;
530
50.3k
                    }
531
1.24M
                }
532
16.4M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
16.4M
            }
534
11.8k
            break;
535
8.25k
        case FAAD_FMT_32BIT:
536
8.25k
            exp = 16 - REAL_BITS;
537
8.25k
            half = 1 << (exp - 1);
538
8.25k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
11.4M
            for(i = 0; i < frame_len; i++)
540
11.4M
            {
541
11.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
11.4M
                    hDecoder->internal_channel);
543
11.4M
                if (tmp >= 0)
544
10.7M
                {
545
10.7M
                    if (tmp <= 0x7FFFFFFF - half)
546
10.7M
                        tmp += half;
547
10.7M
                } else {
548
681k
                    if (tmp >= (int32_t)0x80000000 + half)
549
681k
                        tmp += -half;
550
681k
                }
551
11.4M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
11.4M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
11.4M
            }
554
8.25k
            break;
555
5.75k
        case FAAD_FMT_FIXED:
556
8.27M
            for(i = 0; i < frame_len; i++)
557
8.26M
            {
558
8.26M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
8.26M
                    hDecoder->internal_channel);
560
8.26M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
8.26M
            }
562
5.75k
            break;
563
35.9k
        }
564
35.9k
    }
565
566
5.53k
    return sample_buffer;
567
5.53k
}
output_to_PCM
Line
Count
Source
472
5.53k
{
473
5.53k
    uint8_t ch;
474
5.53k
    uint16_t i;
475
5.53k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.53k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.53k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
41.5k
    for (ch = 0; ch < channels; ch++)
481
35.9k
    {
482
35.9k
        switch (format)
483
35.9k
        {
484
10.1k
        case FAAD_FMT_16BIT:
485
14.2M
            for(i = 0; i < frame_len; i++)
486
14.2M
            {
487
14.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
14.2M
                    hDecoder->internal_channel);
489
14.2M
                if (tmp >= 0)
490
13.2M
                {
491
13.2M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
13.2M
                        tmp += (1 << (REAL_BITS-1));
493
13.2M
                    if (tmp >= REAL_CONST(32767))
494
61.0k
                    {
495
61.0k
                        tmp = REAL_CONST(32767);
496
61.0k
                    }
497
13.2M
                } else {
498
1.02M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
1.02M
                        tmp += -(1 << (REAL_BITS-1));
500
1.02M
                    if (tmp <= REAL_CONST(-32768))
501
53.4k
                    {
502
53.4k
                        tmp = REAL_CONST(-32768);
503
53.4k
                    }
504
1.02M
                }
505
14.2M
                tmp >>= REAL_BITS;
506
14.2M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
14.2M
            }
508
10.1k
            break;
509
11.8k
        case FAAD_FMT_24BIT:
510
16.4M
            for(i = 0; i < frame_len; i++)
511
16.4M
            {
512
16.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
16.4M
                    hDecoder->internal_channel);
514
16.4M
                if (tmp >= 0)
515
15.2M
                {
516
15.2M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
15.2M
                        tmp += (1 << (REAL_BITS-9));
518
15.2M
                    tmp >>= (REAL_BITS-8);
519
15.2M
                    if (tmp >= 8388607)
520
49.3k
                    {
521
49.3k
                        tmp = 8388607;
522
49.3k
                    }
523
15.2M
                } else {
524
1.24M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.24M
                        tmp += -(1 << (REAL_BITS-9));
526
1.24M
                    tmp >>= (REAL_BITS-8);
527
1.24M
                    if (tmp <= -8388608)
528
50.3k
                    {
529
50.3k
                        tmp = -8388608;
530
50.3k
                    }
531
1.24M
                }
532
16.4M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
16.4M
            }
534
11.8k
            break;
535
8.25k
        case FAAD_FMT_32BIT:
536
8.25k
            exp = 16 - REAL_BITS;
537
8.25k
            half = 1 << (exp - 1);
538
8.25k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
11.4M
            for(i = 0; i < frame_len; i++)
540
11.4M
            {
541
11.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
11.4M
                    hDecoder->internal_channel);
543
11.4M
                if (tmp >= 0)
544
10.7M
                {
545
10.7M
                    if (tmp <= 0x7FFFFFFF - half)
546
10.7M
                        tmp += half;
547
10.7M
                } else {
548
681k
                    if (tmp >= (int32_t)0x80000000 + half)
549
681k
                        tmp += -half;
550
681k
                }
551
11.4M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
11.4M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
11.4M
            }
554
8.25k
            break;
555
5.75k
        case FAAD_FMT_FIXED:
556
8.27M
            for(i = 0; i < frame_len; i++)
557
8.26M
            {
558
8.26M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
8.26M
                    hDecoder->internal_channel);
560
8.26M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
8.26M
            }
562
5.75k
            break;
563
35.9k
        }
564
35.9k
    }
565
566
5.53k
    return sample_buffer;
567
5.53k
}
568
569
#endif