Coverage Report

Created: 2026-05-24 06:39

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
14.2M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.46M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
4.93M
#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
39.3M
{
48
39.3M
    if (!down_matrix)
49
36.9M
        return input[internal_channel[channel]][sample];
50
51
2.46M
    if (channel == 0)
52
1.22M
    {
53
1.22M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.22M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.22M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.24M
    } else {
57
1.24M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.24M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.24M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.24M
    }
61
2.46M
}
62
63
#ifndef HAS_LRINTF
64
32.9M
#define CLIP(sample, max, min) \
65
32.9M
if (sample >= 0.0f)            \
66
28.1M
{                              \
67
28.1M
    sample += 0.5f;            \
68
28.1M
    if (sample >= max)         \
69
28.1M
        sample = max;          \
70
28.1M
} else {                       \
71
4.80M
    sample += -0.5f;           \
72
4.80M
    if (sample <= min)         \
73
4.80M
        sample = min;          \
74
4.80M
}
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
8.30k
#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.81k
{
93
1.81k
    uint8_t ch, ch1;
94
1.81k
    uint16_t i;
95
96
1.81k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.81k
    {
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
940
    case CONV(2,0):
110
940
        if (hDecoder->upMatrix)
111
50
        {
112
50
            ch  = hDecoder->internal_channel[0];
113
81.5k
            for(i = 0; i < frame_len; i++)
114
81.4k
            {
115
81.4k
                real_t inp0 = input[ch][i];
116
117
81.4k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
81.4k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
81.4k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
81.4k
            }
122
890
        } else {
123
890
            ch  = hDecoder->internal_channel[0];
124
890
            ch1 = hDecoder->internal_channel[1];
125
1.35M
            for(i = 0; i < frame_len; i++)
126
1.35M
            {
127
1.35M
                real_t inp0 = input[ch ][i];
128
1.35M
                real_t inp1 = input[ch1][i];
129
130
1.35M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.35M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.35M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.35M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.35M
            }
136
890
        }
137
940
        break;
138
876
    default:
139
9.36k
        for (ch = 0; ch < channels; ch++)
140
8.49k
        {
141
12.0M
            for(i = 0; i < frame_len; i++)
142
12.0M
            {
143
12.0M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
12.0M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
12.0M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
12.0M
            }
149
8.49k
        }
150
876
        break;
151
1.81k
    }
152
1.81k
}
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.30k
{
158
1.30k
    uint8_t ch, ch1;
159
1.30k
    uint16_t i;
160
161
1.30k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.30k
    {
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
693
    case CONV(2,0):
176
693
        if (hDecoder->upMatrix)
177
47
        {
178
47
            ch = hDecoder->internal_channel[0];
179
67.3k
            for(i = 0; i < frame_len; i++)
180
67.3k
            {
181
67.3k
                real_t inp0 = input[ch][i];
182
183
67.3k
                inp0 *= 256.0f;
184
67.3k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
67.3k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
67.3k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
67.3k
            }
189
646
        } else {
190
646
            ch  = hDecoder->internal_channel[0];
191
646
            ch1 = hDecoder->internal_channel[1];
192
938k
            for(i = 0; i < frame_len; i++)
193
937k
            {
194
937k
                real_t inp0 = input[ch ][i];
195
937k
                real_t inp1 = input[ch1][i];
196
197
937k
                inp0 *= 256.0f;
198
937k
                inp1 *= 256.0f;
199
937k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
937k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
937k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
937k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
937k
            }
205
646
        }
206
693
        break;
207
612
    default:
208
6.09k
        for (ch = 0; ch < channels; ch++)
209
5.47k
        {
210
7.76M
            for(i = 0; i < frame_len; i++)
211
7.76M
            {
212
7.76M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
7.76M
                inp *= 256.0f;
215
7.76M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
7.76M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
7.76M
            }
219
5.47k
        }
220
612
        break;
221
1.30k
    }
222
1.30k
}
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.24k
{
228
1.24k
    uint8_t ch, ch1;
229
1.24k
    uint16_t i;
230
231
1.24k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.24k
    {
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
686
    case CONV(2,0):
246
686
        if (hDecoder->upMatrix)
247
37
        {
248
37
            ch = hDecoder->internal_channel[0];
249
56.1k
            for(i = 0; i < frame_len; i++)
250
56.0k
            {
251
56.0k
                real_t inp0 = input[ch][i];
252
253
56.0k
                inp0 *= 65536.0f;
254
56.0k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
56.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
56.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
56.0k
            }
259
649
        } else {
260
649
            ch  = hDecoder->internal_channel[0];
261
649
            ch1 = hDecoder->internal_channel[1];
262
1.01M
            for(i = 0; i < frame_len; i++)
263
1.01M
            {
264
1.01M
                real_t inp0 = input[ch ][i];
265
1.01M
                real_t inp1 = input[ch1][i];
266
267
1.01M
                inp0 *= 65536.0f;
268
1.01M
                inp1 *= 65536.0f;
269
1.01M
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
1.01M
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
1.01M
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
1.01M
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
1.01M
            }
275
649
        }
276
686
        break;
277
562
    default:
278
5.11k
        for (ch = 0; ch < channels; ch++)
279
4.55k
        {
280
6.31M
            for(i = 0; i < frame_len; i++)
281
6.30M
            {
282
6.30M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.30M
                inp *= 65536.0f;
285
6.30M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.30M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.30M
            }
289
4.55k
        }
290
562
        break;
291
1.24k
    }
292
1.24k
}
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
688
{
298
688
    uint8_t ch, ch1;
299
688
    uint16_t i;
300
301
688
    switch (CONV(channels,hDecoder->downMatrix))
302
688
    {
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
184
    case CONV(2,0):
312
184
        if (hDecoder->upMatrix)
313
20
        {
314
20
            ch = hDecoder->internal_channel[0];
315
28.5k
            for(i = 0; i < frame_len; i++)
316
28.5k
            {
317
28.5k
                real_t inp0 = input[ch][i];
318
28.5k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
28.5k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
28.5k
            }
321
164
        } else {
322
164
            ch  = hDecoder->internal_channel[0];
323
164
            ch1 = hDecoder->internal_channel[1];
324
244k
            for(i = 0; i < frame_len; i++)
325
244k
            {
326
244k
                real_t inp0 = input[ch ][i];
327
244k
                real_t inp1 = input[ch1][i];
328
244k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
244k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
244k
            }
331
164
        }
332
184
        break;
333
504
    default:
334
4.80k
        for (ch = 0; ch < channels; ch++)
335
4.29k
        {
336
6.41M
            for(i = 0; i < frame_len; i++)
337
6.40M
            {
338
6.40M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.40M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.40M
            }
341
4.29k
        }
342
504
        break;
343
688
    }
344
688
}
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
595
{
350
595
    uint8_t ch, ch1;
351
595
    uint16_t i;
352
353
595
    switch (CONV(channels,hDecoder->downMatrix))
354
595
    {
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
147
    case CONV(2,0):
364
147
        if (hDecoder->upMatrix)
365
19
        {
366
19
            ch = hDecoder->internal_channel[0];
367
31.3k
            for(i = 0; i < frame_len; i++)
368
31.3k
            {
369
31.3k
                real_t inp0 = input[ch][i];
370
31.3k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
31.3k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
31.3k
            }
373
128
        } else {
374
128
            ch  = hDecoder->internal_channel[0];
375
128
            ch1 = hDecoder->internal_channel[1];
376
161k
            for(i = 0; i < frame_len; i++)
377
161k
            {
378
161k
                real_t inp0 = input[ch ][i];
379
161k
                real_t inp1 = input[ch1][i];
380
161k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
161k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
161k
            }
383
128
        }
384
147
        break;
385
448
    default:
386
4.97k
        for (ch = 0; ch < channels; ch++)
387
4.52k
        {
388
6.87M
            for(i = 0; i < frame_len; i++)
389
6.86M
            {
390
6.86M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.86M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.86M
            }
393
4.52k
        }
394
448
        break;
395
595
    }
396
595
}
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
11.3k
{
402
11.3k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
11.3k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
11.3k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
11.3k
    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
11.3k
    switch (format)
413
11.3k
    {
414
3.63k
    case FAAD_FMT_16BIT:
415
3.63k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.63k
        break;
417
2.61k
    case FAAD_FMT_24BIT:
418
2.61k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.61k
        break;
420
2.49k
    case FAAD_FMT_32BIT:
421
2.49k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.49k
        break;
423
1.37k
    case FAAD_FMT_FLOAT:
424
1.37k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.37k
        break;
426
1.19k
    case FAAD_FMT_DOUBLE:
427
1.19k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.19k
        break;
429
11.3k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
11.3k
    return sample_buffer;
437
11.3k
}
output_to_PCM
Line
Count
Source
401
5.65k
{
402
5.65k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.65k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.65k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.65k
    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
5.65k
    switch (format)
413
5.65k
    {
414
1.81k
    case FAAD_FMT_16BIT:
415
1.81k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.81k
        break;
417
1.30k
    case FAAD_FMT_24BIT:
418
1.30k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.30k
        break;
420
1.24k
    case FAAD_FMT_32BIT:
421
1.24k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.24k
        break;
423
688
    case FAAD_FMT_FLOAT:
424
688
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
688
        break;
426
595
    case FAAD_FMT_DOUBLE:
427
595
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
595
        break;
429
5.65k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.65k
    return sample_buffer;
437
5.65k
}
output_to_PCM
Line
Count
Source
401
5.65k
{
402
5.65k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.65k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.65k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.65k
    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
5.65k
    switch (format)
413
5.65k
    {
414
1.81k
    case FAAD_FMT_16BIT:
415
1.81k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.81k
        break;
417
1.30k
    case FAAD_FMT_24BIT:
418
1.30k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.30k
        break;
420
1.24k
    case FAAD_FMT_32BIT:
421
1.24k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.24k
        break;
423
688
    case FAAD_FMT_FLOAT:
424
688
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
688
        break;
426
595
    case FAAD_FMT_DOUBLE:
427
595
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
595
        break;
429
5.65k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.65k
    return sample_buffer;
437
5.65k
}
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
28.3M
{
449
28.3M
    real_t C;
450
28.3M
    if (up_matrix == 1)
451
277k
        return input[internal_channel[0]][sample];
452
453
28.0M
    if (!down_matrix)
454
27.3M
        return input[internal_channel[channel]][sample];
455
456
683k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
683k
    if (channel == 0)
458
331k
    {
459
331k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
331k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
331k
        return core + C + L_S;
462
351k
    } else {
463
351k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
351k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
351k
        return core + C + R_S;
466
351k
    }
467
683k
}
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
6.40k
{
473
6.40k
    uint8_t ch;
474
6.40k
    uint16_t i;
475
6.40k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.40k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.40k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
46.7k
    for (ch = 0; ch < channels; ch++)
481
40.3k
    {
482
40.3k
        switch (format)
483
40.3k
        {
484
12.2k
        case FAAD_FMT_16BIT:
485
17.6M
            for(i = 0; i < frame_len; i++)
486
17.5M
            {
487
17.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
17.5M
                    hDecoder->internal_channel);
489
17.5M
                if (tmp >= 0)
490
15.9M
                {
491
15.9M
                    tmp += (1 << (REAL_BITS-1));
492
15.9M
                    if (tmp >= REAL_CONST(32767))
493
45.4k
                    {
494
45.4k
                        tmp = REAL_CONST(32767);
495
45.4k
                    }
496
15.9M
                } else {
497
1.68M
                    tmp += -(1 << (REAL_BITS-1));
498
1.68M
                    if (tmp <= REAL_CONST(-32768))
499
48.2k
                    {
500
48.2k
                        tmp = REAL_CONST(-32768);
501
48.2k
                    }
502
1.68M
                }
503
17.5M
                tmp >>= REAL_BITS;
504
17.5M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
17.5M
            }
506
12.2k
            break;
507
12.2k
        case FAAD_FMT_24BIT:
508
17.0M
            for(i = 0; i < frame_len; i++)
509
17.0M
            {
510
17.0M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
17.0M
                    hDecoder->internal_channel);
512
17.0M
                if (tmp >= 0)
513
15.8M
                {
514
15.8M
                    tmp += (1 << (REAL_BITS-9));
515
15.8M
                    tmp >>= (REAL_BITS-8);
516
15.8M
                    if (tmp >= 8388607)
517
22.5k
                    {
518
22.5k
                        tmp = 8388607;
519
22.5k
                    }
520
15.8M
                } else {
521
1.17M
                    tmp += -(1 << (REAL_BITS-9));
522
1.17M
                    tmp >>= (REAL_BITS-8);
523
1.17M
                    if (tmp <= -8388608)
524
22.7k
                    {
525
22.7k
                        tmp = -8388608;
526
22.7k
                    }
527
1.17M
                }
528
17.0M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
17.0M
            }
530
12.2k
            break;
531
8.86k
        case FAAD_FMT_32BIT:
532
8.86k
            exp = 16 - REAL_BITS;
533
8.86k
            half = 1 << (exp - 1);
534
8.86k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
12.5M
            for(i = 0; i < frame_len; i++)
536
12.5M
            {
537
12.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
12.5M
                    hDecoder->internal_channel);
539
12.5M
                if (tmp >= 0)
540
11.6M
                {
541
11.6M
                    tmp += half;
542
11.6M
                } else {
543
934k
                    tmp += -half;
544
934k
                }
545
12.5M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
12.5M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
12.5M
            }
548
8.86k
            break;
549
6.92k
        case FAAD_FMT_FIXED:
550
9.43M
            for(i = 0; i < frame_len; i++)
551
9.42M
            {
552
9.42M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
9.42M
                    hDecoder->internal_channel);
554
9.42M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
9.42M
            }
556
6.92k
            break;
557
40.3k
        }
558
40.3k
    }
559
560
6.40k
    return sample_buffer;
561
6.40k
}
output_to_PCM
Line
Count
Source
472
3.20k
{
473
3.20k
    uint8_t ch;
474
3.20k
    uint16_t i;
475
3.20k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.20k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.20k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.3k
    for (ch = 0; ch < channels; ch++)
481
20.1k
    {
482
20.1k
        switch (format)
483
20.1k
        {
484
6.13k
        case FAAD_FMT_16BIT:
485
8.80M
            for(i = 0; i < frame_len; i++)
486
8.79M
            {
487
8.79M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.79M
                    hDecoder->internal_channel);
489
8.79M
                if (tmp >= 0)
490
7.95M
                {
491
7.95M
                    tmp += (1 << (REAL_BITS-1));
492
7.95M
                    if (tmp >= REAL_CONST(32767))
493
22.7k
                    {
494
22.7k
                        tmp = REAL_CONST(32767);
495
22.7k
                    }
496
7.95M
                } else {
497
844k
                    tmp += -(1 << (REAL_BITS-1));
498
844k
                    if (tmp <= REAL_CONST(-32768))
499
24.1k
                    {
500
24.1k
                        tmp = REAL_CONST(-32768);
501
24.1k
                    }
502
844k
                }
503
8.79M
                tmp >>= REAL_BITS;
504
8.79M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.79M
            }
506
6.13k
            break;
507
6.13k
        case FAAD_FMT_24BIT:
508
8.54M
            for(i = 0; i < frame_len; i++)
509
8.53M
            {
510
8.53M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.53M
                    hDecoder->internal_channel);
512
8.53M
                if (tmp >= 0)
513
7.94M
                {
514
7.94M
                    tmp += (1 << (REAL_BITS-9));
515
7.94M
                    tmp >>= (REAL_BITS-8);
516
7.94M
                    if (tmp >= 8388607)
517
11.2k
                    {
518
11.2k
                        tmp = 8388607;
519
11.2k
                    }
520
7.94M
                } else {
521
585k
                    tmp += -(1 << (REAL_BITS-9));
522
585k
                    tmp >>= (REAL_BITS-8);
523
585k
                    if (tmp <= -8388608)
524
11.3k
                    {
525
11.3k
                        tmp = -8388608;
526
11.3k
                    }
527
585k
                }
528
8.53M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.53M
            }
530
6.13k
            break;
531
4.43k
        case FAAD_FMT_32BIT:
532
4.43k
            exp = 16 - REAL_BITS;
533
4.43k
            half = 1 << (exp - 1);
534
4.43k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
6.29M
            for(i = 0; i < frame_len; i++)
536
6.29M
            {
537
6.29M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
6.29M
                    hDecoder->internal_channel);
539
6.29M
                if (tmp >= 0)
540
5.82M
                {
541
5.82M
                    tmp += half;
542
5.82M
                } else {
543
467k
                    tmp += -half;
544
467k
                }
545
6.29M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
6.29M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
6.29M
            }
548
4.43k
            break;
549
3.46k
        case FAAD_FMT_FIXED:
550
4.71M
            for(i = 0; i < frame_len; i++)
551
4.71M
            {
552
4.71M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.71M
                    hDecoder->internal_channel);
554
4.71M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.71M
            }
556
3.46k
            break;
557
20.1k
        }
558
20.1k
    }
559
560
3.20k
    return sample_buffer;
561
3.20k
}
output_to_PCM
Line
Count
Source
472
3.20k
{
473
3.20k
    uint8_t ch;
474
3.20k
    uint16_t i;
475
3.20k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.20k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.20k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.3k
    for (ch = 0; ch < channels; ch++)
481
20.1k
    {
482
20.1k
        switch (format)
483
20.1k
        {
484
6.13k
        case FAAD_FMT_16BIT:
485
8.80M
            for(i = 0; i < frame_len; i++)
486
8.79M
            {
487
8.79M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.79M
                    hDecoder->internal_channel);
489
8.79M
                if (tmp >= 0)
490
7.95M
                {
491
7.95M
                    tmp += (1 << (REAL_BITS-1));
492
7.95M
                    if (tmp >= REAL_CONST(32767))
493
22.7k
                    {
494
22.7k
                        tmp = REAL_CONST(32767);
495
22.7k
                    }
496
7.95M
                } else {
497
844k
                    tmp += -(1 << (REAL_BITS-1));
498
844k
                    if (tmp <= REAL_CONST(-32768))
499
24.1k
                    {
500
24.1k
                        tmp = REAL_CONST(-32768);
501
24.1k
                    }
502
844k
                }
503
8.79M
                tmp >>= REAL_BITS;
504
8.79M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.79M
            }
506
6.13k
            break;
507
6.13k
        case FAAD_FMT_24BIT:
508
8.54M
            for(i = 0; i < frame_len; i++)
509
8.53M
            {
510
8.53M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.53M
                    hDecoder->internal_channel);
512
8.53M
                if (tmp >= 0)
513
7.94M
                {
514
7.94M
                    tmp += (1 << (REAL_BITS-9));
515
7.94M
                    tmp >>= (REAL_BITS-8);
516
7.94M
                    if (tmp >= 8388607)
517
11.2k
                    {
518
11.2k
                        tmp = 8388607;
519
11.2k
                    }
520
7.94M
                } else {
521
585k
                    tmp += -(1 << (REAL_BITS-9));
522
585k
                    tmp >>= (REAL_BITS-8);
523
585k
                    if (tmp <= -8388608)
524
11.3k
                    {
525
11.3k
                        tmp = -8388608;
526
11.3k
                    }
527
585k
                }
528
8.53M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.53M
            }
530
6.13k
            break;
531
4.43k
        case FAAD_FMT_32BIT:
532
4.43k
            exp = 16 - REAL_BITS;
533
4.43k
            half = 1 << (exp - 1);
534
4.43k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
6.29M
            for(i = 0; i < frame_len; i++)
536
6.29M
            {
537
6.29M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
6.29M
                    hDecoder->internal_channel);
539
6.29M
                if (tmp >= 0)
540
5.82M
                {
541
5.82M
                    tmp += half;
542
5.82M
                } else {
543
467k
                    tmp += -half;
544
467k
                }
545
6.29M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
6.29M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
6.29M
            }
548
4.43k
            break;
549
3.46k
        case FAAD_FMT_FIXED:
550
4.71M
            for(i = 0; i < frame_len; i++)
551
4.71M
            {
552
4.71M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.71M
                    hDecoder->internal_channel);
554
4.71M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.71M
            }
556
3.46k
            break;
557
20.1k
        }
558
20.1k
    }
559
560
3.20k
    return sample_buffer;
561
3.20k
}
562
563
#endif