Coverage Report

Created: 2026-02-14 07:13

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
10.7M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
1.96M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
3.92M
#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
32.6M
{
48
32.6M
    if (!down_matrix)
49
30.6M
        return input[internal_channel[channel]][sample];
50
51
1.96M
    if (channel == 0)
52
972k
    {
53
972k
        return DM_MUL * (input[internal_channel[1]][sample] +
54
972k
            input[internal_channel[0]][sample] * RSQRT2 +
55
972k
            input[internal_channel[3]][sample] * RSQRT2);
56
991k
    } else {
57
991k
        return DM_MUL * (input[internal_channel[2]][sample] +
58
991k
            input[internal_channel[0]][sample] * RSQRT2 +
59
991k
            input[internal_channel[4]][sample] * RSQRT2);
60
991k
    }
61
1.96M
}
62
63
#ifndef HAS_LRINTF
64
27.2M
#define CLIP(sample, max, min) \
65
27.2M
if (sample >= 0.0f)            \
66
23.2M
{                              \
67
23.2M
    sample += 0.5f;            \
68
23.2M
    if (sample >= max)         \
69
23.2M
        sample = max;          \
70
23.2M
} else {                       \
71
4.08M
    sample += -0.5f;           \
72
4.08M
    if (sample <= min)         \
73
4.08M
        sample = min;          \
74
4.08M
}
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
5.94k
#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.35k
{
93
1.35k
    uint8_t ch, ch1;
94
1.35k
    uint16_t i;
95
96
1.35k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.35k
    {
98
0
    case CONV(1,0):
99
0
    case CONV(1,1):
100
0
        for(i = 0; i < frame_len; i++)
101
0
        {
102
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
103
104
0
            CLIP(inp, 32767.0f, -32768.0f);
105
106
0
            (*sample_buffer)[i] = (int16_t)lrintf(inp);
107
0
        }
108
0
        break;
109
660
    case CONV(2,0):
110
660
        if (hDecoder->upMatrix)
111
43
        {
112
43
            ch  = hDecoder->internal_channel[0];
113
66.4k
            for(i = 0; i < frame_len; i++)
114
66.4k
            {
115
66.4k
                real_t inp0 = input[ch][i];
116
117
66.4k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
66.4k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
66.4k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
66.4k
            }
122
617
        } else {
123
617
            ch  = hDecoder->internal_channel[0];
124
617
            ch1 = hDecoder->internal_channel[1];
125
987k
            for(i = 0; i < frame_len; i++)
126
986k
            {
127
986k
                real_t inp0 = input[ch ][i];
128
986k
                real_t inp1 = input[ch1][i];
129
130
986k
                CLIP(inp0, 32767.0f, -32768.0f);
131
986k
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
986k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
986k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
986k
            }
136
617
        }
137
660
        break;
138
697
    default:
139
8.02k
        for (ch = 0; ch < channels; ch++)
140
7.32k
        {
141
10.4M
            for(i = 0; i < frame_len; i++)
142
10.4M
            {
143
10.4M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
10.4M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
10.4M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
10.4M
            }
149
7.32k
        }
150
697
        break;
151
1.35k
    }
152
1.35k
}
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
923
{
158
923
    uint8_t ch, ch1;
159
923
    uint16_t i;
160
161
923
    switch (CONV(channels,hDecoder->downMatrix))
162
923
    {
163
0
    case CONV(1,0):
164
0
    case CONV(1,1):
165
0
        for(i = 0; i < frame_len; i++)
166
0
        {
167
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
168
169
0
            inp *= 256.0f;
170
0
            CLIP(inp, 8388607.0f, -8388608.0f);
171
172
0
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
173
0
        }
174
0
        break;
175
442
    case CONV(2,0):
176
442
        if (hDecoder->upMatrix)
177
29
        {
178
29
            ch = hDecoder->internal_channel[0];
179
40.9k
            for(i = 0; i < frame_len; i++)
180
40.9k
            {
181
40.9k
                real_t inp0 = input[ch][i];
182
183
40.9k
                inp0 *= 256.0f;
184
40.9k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
40.9k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
40.9k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
40.9k
            }
189
413
        } else {
190
413
            ch  = hDecoder->internal_channel[0];
191
413
            ch1 = hDecoder->internal_channel[1];
192
607k
            for(i = 0; i < frame_len; i++)
193
607k
            {
194
607k
                real_t inp0 = input[ch ][i];
195
607k
                real_t inp1 = input[ch1][i];
196
197
607k
                inp0 *= 256.0f;
198
607k
                inp1 *= 256.0f;
199
607k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
607k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
607k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
607k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
607k
            }
205
413
        }
206
442
        break;
207
481
    default:
208
5.12k
        for (ch = 0; ch < channels; ch++)
209
4.64k
        {
210
6.60M
            for(i = 0; i < frame_len; i++)
211
6.59M
            {
212
6.59M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
6.59M
                inp *= 256.0f;
215
6.59M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
6.59M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
6.59M
            }
219
4.64k
        }
220
481
        break;
221
923
    }
222
923
}
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
879
{
228
879
    uint8_t ch, ch1;
229
879
    uint16_t i;
230
231
879
    switch (CONV(channels,hDecoder->downMatrix))
232
879
    {
233
0
    case CONV(1,0):
234
0
    case CONV(1,1):
235
0
        for(i = 0; i < frame_len; i++)
236
0
        {
237
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
238
239
0
            inp *= 65536.0f;
240
0
            CLIP(inp, 2147483647.0f, -2147483648.0f);
241
242
0
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
243
0
        }
244
0
        break;
245
438
    case CONV(2,0):
246
438
        if (hDecoder->upMatrix)
247
31
        {
248
31
            ch = hDecoder->internal_channel[0];
249
50.0k
            for(i = 0; i < frame_len; i++)
250
49.9k
            {
251
49.9k
                real_t inp0 = input[ch][i];
252
253
49.9k
                inp0 *= 65536.0f;
254
49.9k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
49.9k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
49.9k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
49.9k
            }
259
407
        } else {
260
407
            ch  = hDecoder->internal_channel[0];
261
407
            ch1 = hDecoder->internal_channel[1];
262
621k
            for(i = 0; i < frame_len; i++)
263
620k
            {
264
620k
                real_t inp0 = input[ch ][i];
265
620k
                real_t inp1 = input[ch1][i];
266
267
620k
                inp0 *= 65536.0f;
268
620k
                inp1 *= 65536.0f;
269
620k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
620k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
620k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
620k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
620k
            }
275
407
        }
276
438
        break;
277
441
    default:
278
4.51k
        for (ch = 0; ch < channels; ch++)
279
4.07k
        {
280
5.64M
            for(i = 0; i < frame_len; i++)
281
5.63M
            {
282
5.63M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
5.63M
                inp *= 65536.0f;
285
5.63M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
5.63M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
5.63M
            }
289
4.07k
        }
290
441
        break;
291
879
    }
292
879
}
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
513
{
298
513
    uint8_t ch, ch1;
299
513
    uint16_t i;
300
301
513
    switch (CONV(channels,hDecoder->downMatrix))
302
513
    {
303
0
    case CONV(1,0):
304
0
    case CONV(1,1):
305
0
        for(i = 0; i < frame_len; i++)
306
0
        {
307
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
308
0
            (*sample_buffer)[i] = inp*FLOAT_SCALE;
309
0
        }
310
0
        break;
311
148
    case CONV(2,0):
312
148
        if (hDecoder->upMatrix)
313
13
        {
314
13
            ch = hDecoder->internal_channel[0];
315
23.3k
            for(i = 0; i < frame_len; i++)
316
23.3k
            {
317
23.3k
                real_t inp0 = input[ch][i];
318
23.3k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
23.3k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
23.3k
            }
321
135
        } else {
322
135
            ch  = hDecoder->internal_channel[0];
323
135
            ch1 = hDecoder->internal_channel[1];
324
207k
            for(i = 0; i < frame_len; i++)
325
207k
            {
326
207k
                real_t inp0 = input[ch ][i];
327
207k
                real_t inp1 = input[ch1][i];
328
207k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
207k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
207k
            }
331
135
        }
332
148
        break;
333
365
    default:
334
3.67k
        for (ch = 0; ch < channels; ch++)
335
3.30k
        {
336
4.69M
            for(i = 0; i < frame_len; i++)
337
4.69M
            {
338
4.69M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
4.69M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
4.69M
            }
341
3.30k
        }
342
365
        break;
343
513
    }
344
513
}
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
466
{
350
466
    uint8_t ch, ch1;
351
466
    uint16_t i;
352
353
466
    switch (CONV(channels,hDecoder->downMatrix))
354
466
    {
355
0
    case CONV(1,0):
356
0
    case CONV(1,1):
357
0
        for(i = 0; i < frame_len; i++)
358
0
        {
359
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
360
0
            (*sample_buffer)[i] = (double)inp*FLOAT_SCALE;
361
0
        }
362
0
        break;
363
116
    case CONV(2,0):
364
116
        if (hDecoder->upMatrix)
365
15
        {
366
15
            ch = hDecoder->internal_channel[0];
367
24.3k
            for(i = 0; i < frame_len; i++)
368
24.3k
            {
369
24.3k
                real_t inp0 = input[ch][i];
370
24.3k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
24.3k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
24.3k
            }
373
101
        } else {
374
101
            ch  = hDecoder->internal_channel[0];
375
101
            ch1 = hDecoder->internal_channel[1];
376
121k
            for(i = 0; i < frame_len; i++)
377
121k
            {
378
121k
                real_t inp0 = input[ch ][i];
379
121k
                real_t inp1 = input[ch1][i];
380
121k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
121k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
121k
            }
383
101
        }
384
116
        break;
385
350
    default:
386
3.72k
        for (ch = 0; ch < channels; ch++)
387
3.37k
        {
388
5.26M
            for(i = 0; i < frame_len; i++)
389
5.25M
            {
390
5.25M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
5.25M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
5.25M
            }
393
3.37k
        }
394
350
        break;
395
466
    }
396
466
}
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
8.27k
{
402
8.27k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
8.27k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
8.27k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
8.27k
    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
8.27k
    switch (format)
413
8.27k
    {
414
2.71k
    case FAAD_FMT_16BIT:
415
2.71k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
2.71k
        break;
417
1.84k
    case FAAD_FMT_24BIT:
418
1.84k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.84k
        break;
420
1.75k
    case FAAD_FMT_32BIT:
421
1.75k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.75k
        break;
423
1.02k
    case FAAD_FMT_FLOAT:
424
1.02k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.02k
        break;
426
932
    case FAAD_FMT_DOUBLE:
427
932
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
932
        break;
429
8.27k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
8.27k
    return sample_buffer;
437
8.27k
}
output_to_PCM
Line
Count
Source
401
4.13k
{
402
4.13k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.13k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.13k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.13k
    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.13k
    switch (format)
413
4.13k
    {
414
1.35k
    case FAAD_FMT_16BIT:
415
1.35k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.35k
        break;
417
923
    case FAAD_FMT_24BIT:
418
923
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
923
        break;
420
879
    case FAAD_FMT_32BIT:
421
879
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
879
        break;
423
513
    case FAAD_FMT_FLOAT:
424
513
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
513
        break;
426
466
    case FAAD_FMT_DOUBLE:
427
466
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
466
        break;
429
4.13k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.13k
    return sample_buffer;
437
4.13k
}
output_to_PCM
Line
Count
Source
401
4.13k
{
402
4.13k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.13k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.13k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.13k
    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.13k
    switch (format)
413
4.13k
    {
414
1.35k
    case FAAD_FMT_16BIT:
415
1.35k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.35k
        break;
417
923
    case FAAD_FMT_24BIT:
418
923
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
923
        break;
420
879
    case FAAD_FMT_32BIT:
421
879
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
879
        break;
423
513
    case FAAD_FMT_FLOAT:
424
513
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
513
        break;
426
466
    case FAAD_FMT_DOUBLE:
427
466
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
466
        break;
429
4.13k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.13k
    return sample_buffer;
437
4.13k
}
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
21.2M
{
449
21.2M
    real_t C;
450
21.2M
    if (up_matrix == 1)
451
242k
        return input[internal_channel[0]][sample];
452
453
21.0M
    if (!down_matrix)
454
20.6M
        return input[internal_channel[channel]][sample];
455
456
407k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
407k
    if (channel == 0)
458
191k
    {
459
191k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
191k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
191k
        return core + C + L_S;
462
216k
    } else {
463
216k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
216k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
216k
        return core + C + R_S;
466
216k
    }
467
407k
}
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
4.41k
{
473
4.41k
    uint8_t ch;
474
4.41k
    uint16_t i;
475
4.41k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
4.41k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
4.41k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
34.7k
    for (ch = 0; ch < channels; ch++)
481
30.3k
    {
482
30.3k
        switch (format)
483
30.3k
        {
484
10.4k
        case FAAD_FMT_16BIT:
485
15.0M
            for(i = 0; i < frame_len; i++)
486
15.0M
            {
487
15.0M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
15.0M
                    hDecoder->internal_channel);
489
15.0M
                if (tmp >= 0)
490
13.5M
                {
491
13.5M
                    tmp += (1 << (REAL_BITS-1));
492
13.5M
                    if (tmp >= REAL_CONST(32767))
493
21.7k
                    {
494
21.7k
                        tmp = REAL_CONST(32767);
495
21.7k
                    }
496
13.5M
                } else {
497
1.49M
                    tmp += -(1 << (REAL_BITS-1));
498
1.49M
                    if (tmp <= REAL_CONST(-32768))
499
23.6k
                    {
500
23.6k
                        tmp = REAL_CONST(-32768);
501
23.6k
                    }
502
1.49M
                }
503
15.0M
                tmp >>= REAL_BITS;
504
15.0M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
15.0M
            }
506
10.4k
            break;
507
8.54k
        case FAAD_FMT_24BIT:
508
11.8M
            for(i = 0; i < frame_len; i++)
509
11.8M
            {
510
11.8M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
11.8M
                    hDecoder->internal_channel);
512
11.8M
                if (tmp >= 0)
513
10.9M
                {
514
10.9M
                    tmp += (1 << (REAL_BITS-9));
515
10.9M
                    tmp >>= (REAL_BITS-8);
516
10.9M
                    if (tmp >= 8388607)
517
21.5k
                    {
518
21.5k
                        tmp = 8388607;
519
21.5k
                    }
520
10.9M
                } else {
521
882k
                    tmp += -(1 << (REAL_BITS-9));
522
882k
                    tmp >>= (REAL_BITS-8);
523
882k
                    if (tmp <= -8388608)
524
21.9k
                    {
525
21.9k
                        tmp = -8388608;
526
21.9k
                    }
527
882k
                }
528
11.8M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
11.8M
            }
530
8.54k
            break;
531
5.70k
        case FAAD_FMT_32BIT:
532
5.70k
            exp = 16 - REAL_BITS;
533
5.70k
            half = 1 << (exp - 1);
534
5.70k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
7.99M
            for(i = 0; i < frame_len; i++)
536
7.98M
            {
537
7.98M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
7.98M
                    hDecoder->internal_channel);
539
7.98M
                if (tmp >= 0)
540
7.23M
                {
541
7.23M
                    tmp += half;
542
7.23M
                } else {
543
747k
                    tmp += -half;
544
747k
                }
545
7.98M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
7.98M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
7.98M
            }
548
5.70k
            break;
549
5.68k
        case FAAD_FMT_FIXED:
550
7.66M
            for(i = 0; i < frame_len; i++)
551
7.66M
            {
552
7.66M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
7.66M
                    hDecoder->internal_channel);
554
7.66M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
7.66M
            }
556
5.68k
            break;
557
30.3k
        }
558
30.3k
    }
559
560
4.41k
    return sample_buffer;
561
4.41k
}
output_to_PCM
Line
Count
Source
472
2.20k
{
473
2.20k
    uint8_t ch;
474
2.20k
    uint16_t i;
475
2.20k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.20k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.20k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
17.3k
    for (ch = 0; ch < channels; ch++)
481
15.1k
    {
482
15.1k
        switch (format)
483
15.1k
        {
484
5.20k
        case FAAD_FMT_16BIT:
485
7.53M
            for(i = 0; i < frame_len; i++)
486
7.52M
            {
487
7.52M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.52M
                    hDecoder->internal_channel);
489
7.52M
                if (tmp >= 0)
490
6.77M
                {
491
6.77M
                    tmp += (1 << (REAL_BITS-1));
492
6.77M
                    if (tmp >= REAL_CONST(32767))
493
10.8k
                    {
494
10.8k
                        tmp = REAL_CONST(32767);
495
10.8k
                    }
496
6.77M
                } else {
497
747k
                    tmp += -(1 << (REAL_BITS-1));
498
747k
                    if (tmp <= REAL_CONST(-32768))
499
11.8k
                    {
500
11.8k
                        tmp = REAL_CONST(-32768);
501
11.8k
                    }
502
747k
                }
503
7.52M
                tmp >>= REAL_BITS;
504
7.52M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.52M
            }
506
5.20k
            break;
507
4.27k
        case FAAD_FMT_24BIT:
508
5.92M
            for(i = 0; i < frame_len; i++)
509
5.91M
            {
510
5.91M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
5.91M
                    hDecoder->internal_channel);
512
5.91M
                if (tmp >= 0)
513
5.47M
                {
514
5.47M
                    tmp += (1 << (REAL_BITS-9));
515
5.47M
                    tmp >>= (REAL_BITS-8);
516
5.47M
                    if (tmp >= 8388607)
517
10.7k
                    {
518
10.7k
                        tmp = 8388607;
519
10.7k
                    }
520
5.47M
                } else {
521
441k
                    tmp += -(1 << (REAL_BITS-9));
522
441k
                    tmp >>= (REAL_BITS-8);
523
441k
                    if (tmp <= -8388608)
524
10.9k
                    {
525
10.9k
                        tmp = -8388608;
526
10.9k
                    }
527
441k
                }
528
5.91M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
5.91M
            }
530
4.27k
            break;
531
2.85k
        case FAAD_FMT_32BIT:
532
2.85k
            exp = 16 - REAL_BITS;
533
2.85k
            half = 1 << (exp - 1);
534
2.85k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
3.99M
            for(i = 0; i < frame_len; i++)
536
3.99M
            {
537
3.99M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
3.99M
                    hDecoder->internal_channel);
539
3.99M
                if (tmp >= 0)
540
3.61M
                {
541
3.61M
                    tmp += half;
542
3.61M
                } else {
543
373k
                    tmp += -half;
544
373k
                }
545
3.99M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
3.99M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
3.99M
            }
548
2.85k
            break;
549
2.84k
        case FAAD_FMT_FIXED:
550
3.83M
            for(i = 0; i < frame_len; i++)
551
3.83M
            {
552
3.83M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
3.83M
                    hDecoder->internal_channel);
554
3.83M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
3.83M
            }
556
2.84k
            break;
557
15.1k
        }
558
15.1k
    }
559
560
2.20k
    return sample_buffer;
561
2.20k
}
output_to_PCM
Line
Count
Source
472
2.20k
{
473
2.20k
    uint8_t ch;
474
2.20k
    uint16_t i;
475
2.20k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.20k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.20k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
17.3k
    for (ch = 0; ch < channels; ch++)
481
15.1k
    {
482
15.1k
        switch (format)
483
15.1k
        {
484
5.20k
        case FAAD_FMT_16BIT:
485
7.53M
            for(i = 0; i < frame_len; i++)
486
7.52M
            {
487
7.52M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.52M
                    hDecoder->internal_channel);
489
7.52M
                if (tmp >= 0)
490
6.77M
                {
491
6.77M
                    tmp += (1 << (REAL_BITS-1));
492
6.77M
                    if (tmp >= REAL_CONST(32767))
493
10.8k
                    {
494
10.8k
                        tmp = REAL_CONST(32767);
495
10.8k
                    }
496
6.77M
                } else {
497
747k
                    tmp += -(1 << (REAL_BITS-1));
498
747k
                    if (tmp <= REAL_CONST(-32768))
499
11.8k
                    {
500
11.8k
                        tmp = REAL_CONST(-32768);
501
11.8k
                    }
502
747k
                }
503
7.52M
                tmp >>= REAL_BITS;
504
7.52M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.52M
            }
506
5.20k
            break;
507
4.27k
        case FAAD_FMT_24BIT:
508
5.92M
            for(i = 0; i < frame_len; i++)
509
5.91M
            {
510
5.91M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
5.91M
                    hDecoder->internal_channel);
512
5.91M
                if (tmp >= 0)
513
5.47M
                {
514
5.47M
                    tmp += (1 << (REAL_BITS-9));
515
5.47M
                    tmp >>= (REAL_BITS-8);
516
5.47M
                    if (tmp >= 8388607)
517
10.7k
                    {
518
10.7k
                        tmp = 8388607;
519
10.7k
                    }
520
5.47M
                } else {
521
441k
                    tmp += -(1 << (REAL_BITS-9));
522
441k
                    tmp >>= (REAL_BITS-8);
523
441k
                    if (tmp <= -8388608)
524
10.9k
                    {
525
10.9k
                        tmp = -8388608;
526
10.9k
                    }
527
441k
                }
528
5.91M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
5.91M
            }
530
4.27k
            break;
531
2.85k
        case FAAD_FMT_32BIT:
532
2.85k
            exp = 16 - REAL_BITS;
533
2.85k
            half = 1 << (exp - 1);
534
2.85k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
3.99M
            for(i = 0; i < frame_len; i++)
536
3.99M
            {
537
3.99M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
3.99M
                    hDecoder->internal_channel);
539
3.99M
                if (tmp >= 0)
540
3.61M
                {
541
3.61M
                    tmp += half;
542
3.61M
                } else {
543
373k
                    tmp += -half;
544
373k
                }
545
3.99M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
3.99M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
3.99M
            }
548
2.85k
            break;
549
2.84k
        case FAAD_FMT_FIXED:
550
3.83M
            for(i = 0; i < frame_len; i++)
551
3.83M
            {
552
3.83M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
3.83M
                    hDecoder->internal_channel);
554
3.83M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
3.83M
            }
556
2.84k
            break;
557
15.1k
        }
558
15.1k
    }
559
560
2.20k
    return sample_buffer;
561
2.20k
}
562
563
#endif