Coverage Report

Created: 2026-09-01 06:57

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.8M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.18M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
4.36M
#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
36.2M
{
48
36.2M
    if (!down_matrix)
49
34.0M
        return input[internal_channel[channel]][sample];
50
51
2.18M
    if (channel == 0)
52
1.07M
    {
53
1.07M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.07M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.07M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.10M
    } else {
57
1.10M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.10M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.10M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.10M
    }
61
2.18M
}
62
63
#ifndef HAS_LRINTF
64
31.6M
#define CLIP(sample, max, min) \
65
31.6M
if (sample >= 0.0f)            \
66
27.4M
{                              \
67
27.4M
    sample += 0.5f;            \
68
27.4M
    if (sample >= max)         \
69
27.4M
        sample = max;          \
70
27.4M
} else {                       \
71
4.13M
    sample += -0.5f;           \
72
4.13M
    if (sample <= min)         \
73
4.13M
        sample = min;          \
74
4.13M
}
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
6.86k
#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.50k
{
93
1.50k
    uint8_t ch, ch1;
94
1.50k
    uint16_t i;
95
96
1.50k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.50k
    {
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
773
    case CONV(2,0):
110
773
        if (hDecoder->upMatrix)
111
51
        {
112
51
            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
722
        } else {
123
722
            ch  = hDecoder->internal_channel[0];
124
722
            ch1 = hDecoder->internal_channel[1];
125
1.12M
            for(i = 0; i < frame_len; i++)
126
1.12M
            {
127
1.12M
                real_t inp0 = input[ch ][i];
128
1.12M
                real_t inp1 = input[ch1][i];
129
130
1.12M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.12M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.12M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.12M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.12M
            }
136
722
        }
137
773
        break;
138
729
    default:
139
7.72k
        for (ch = 0; ch < channels; ch++)
140
7.00k
        {
141
10.5M
            for(i = 0; i < frame_len; i++)
142
10.5M
            {
143
10.5M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
10.5M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
10.5M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
10.5M
            }
149
7.00k
        }
150
729
        break;
151
1.50k
    }
152
1.50k
}
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.19k
{
158
1.19k
    uint8_t ch, ch1;
159
1.19k
    uint16_t i;
160
161
1.19k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.19k
    {
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
563
    case CONV(2,0):
176
563
        if (hDecoder->upMatrix)
177
41
        {
178
41
            ch = hDecoder->internal_channel[0];
179
66.4k
            for(i = 0; i < frame_len; i++)
180
66.4k
            {
181
66.4k
                real_t inp0 = input[ch][i];
182
183
66.4k
                inp0 *= 256.0f;
184
66.4k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
66.4k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
66.4k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
66.4k
            }
189
522
        } else {
190
522
            ch  = hDecoder->internal_channel[0];
191
522
            ch1 = hDecoder->internal_channel[1];
192
765k
            for(i = 0; i < frame_len; i++)
193
765k
            {
194
765k
                real_t inp0 = input[ch ][i];
195
765k
                real_t inp1 = input[ch1][i];
196
197
765k
                inp0 *= 256.0f;
198
765k
                inp1 *= 256.0f;
199
765k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
765k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
765k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
765k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
765k
            }
205
522
        }
206
563
        break;
207
634
    default:
208
6.63k
        for (ch = 0; ch < channels; ch++)
209
5.99k
        {
210
8.95M
            for(i = 0; i < frame_len; i++)
211
8.95M
            {
212
8.95M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.95M
                inp *= 256.0f;
215
8.95M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.95M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.95M
            }
219
5.99k
        }
220
634
        break;
221
1.19k
    }
222
1.19k
}
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.11k
{
228
1.11k
    uint8_t ch, ch1;
229
1.11k
    uint16_t i;
230
231
1.11k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.11k
    {
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
536
    case CONV(2,0):
246
536
        if (hDecoder->upMatrix)
247
38
        {
248
38
            ch = hDecoder->internal_channel[0];
249
60.1k
            for(i = 0; i < frame_len; i++)
250
60.1k
            {
251
60.1k
                real_t inp0 = input[ch][i];
252
253
60.1k
                inp0 *= 65536.0f;
254
60.1k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
60.1k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
60.1k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
60.1k
            }
259
498
        } else {
260
498
            ch  = hDecoder->internal_channel[0];
261
498
            ch1 = hDecoder->internal_channel[1];
262
757k
            for(i = 0; i < frame_len; i++)
263
756k
            {
264
756k
                real_t inp0 = input[ch ][i];
265
756k
                real_t inp1 = input[ch1][i];
266
267
756k
                inp0 *= 65536.0f;
268
756k
                inp1 *= 65536.0f;
269
756k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
756k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
756k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
756k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
756k
            }
275
498
        }
276
536
        break;
277
575
    default:
278
5.48k
        for (ch = 0; ch < channels; ch++)
279
4.90k
        {
280
6.59M
            for(i = 0; i < frame_len; i++)
281
6.59M
            {
282
6.59M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.59M
                inp *= 65536.0f;
285
6.59M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.59M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.59M
            }
289
4.90k
        }
290
575
        break;
291
1.11k
    }
292
1.11k
}
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
486
{
298
486
    uint8_t ch, ch1;
299
486
    uint16_t i;
300
301
486
    switch (CONV(channels,hDecoder->downMatrix))
302
486
    {
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
115
    case CONV(2,0):
312
115
        if (hDecoder->upMatrix)
313
17
        {
314
17
            ch = hDecoder->internal_channel[0];
315
27.0k
            for(i = 0; i < frame_len; i++)
316
27.0k
            {
317
27.0k
                real_t inp0 = input[ch][i];
318
27.0k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
27.0k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
27.0k
            }
321
98
        } else {
322
98
            ch  = hDecoder->internal_channel[0];
323
98
            ch1 = hDecoder->internal_channel[1];
324
144k
            for(i = 0; i < frame_len; i++)
325
144k
            {
326
144k
                real_t inp0 = input[ch ][i];
327
144k
                real_t inp1 = input[ch1][i];
328
144k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
144k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
144k
            }
331
98
        }
332
115
        break;
333
371
    default:
334
3.28k
        for (ch = 0; ch < channels; ch++)
335
2.91k
        {
336
4.23M
            for(i = 0; i < frame_len; i++)
337
4.23M
            {
338
4.23M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
4.23M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
4.23M
            }
341
2.91k
        }
342
371
        break;
343
486
    }
344
486
}
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
458
{
350
458
    uint8_t ch, ch1;
351
458
    uint16_t i;
352
353
458
    switch (CONV(channels,hDecoder->downMatrix))
354
458
    {
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
119
    case CONV(2,0):
364
119
        if (hDecoder->upMatrix)
365
20
        {
366
20
            ch = hDecoder->internal_channel[0];
367
36.5k
            for(i = 0; i < frame_len; i++)
368
36.4k
            {
369
36.4k
                real_t inp0 = input[ch][i];
370
36.4k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
36.4k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
36.4k
            }
373
99
        } else {
374
99
            ch  = hDecoder->internal_channel[0];
375
99
            ch1 = hDecoder->internal_channel[1];
376
132k
            for(i = 0; i < frame_len; i++)
377
132k
            {
378
132k
                real_t inp0 = input[ch ][i];
379
132k
                real_t inp1 = input[ch1][i];
380
132k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
132k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
132k
            }
383
99
        }
384
119
        break;
385
339
    default:
386
4.08k
        for (ch = 0; ch < channels; ch++)
387
3.74k
        {
388
5.92M
            for(i = 0; i < frame_len; i++)
389
5.92M
            {
390
5.92M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
5.92M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
5.92M
            }
393
3.74k
        }
394
339
        break;
395
458
    }
396
458
}
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.50k
{
402
9.50k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
9.50k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
9.50k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
9.50k
    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.50k
    switch (format)
413
9.50k
    {
414
3.00k
    case FAAD_FMT_16BIT:
415
3.00k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.00k
        break;
417
2.39k
    case FAAD_FMT_24BIT:
418
2.39k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.39k
        break;
420
2.22k
    case FAAD_FMT_32BIT:
421
2.22k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.22k
        break;
423
972
    case FAAD_FMT_FLOAT:
424
972
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
972
        break;
426
916
    case FAAD_FMT_DOUBLE:
427
916
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
916
        break;
429
9.50k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
9.50k
    return sample_buffer;
437
9.50k
}
output_to_PCM
Line
Count
Source
401
4.75k
{
402
4.75k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.75k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.75k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.75k
    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.75k
    switch (format)
413
4.75k
    {
414
1.50k
    case FAAD_FMT_16BIT:
415
1.50k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.50k
        break;
417
1.19k
    case FAAD_FMT_24BIT:
418
1.19k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.19k
        break;
420
1.11k
    case FAAD_FMT_32BIT:
421
1.11k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.11k
        break;
423
486
    case FAAD_FMT_FLOAT:
424
486
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
486
        break;
426
458
    case FAAD_FMT_DOUBLE:
427
458
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
458
        break;
429
4.75k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.75k
    return sample_buffer;
437
4.75k
}
output_to_PCM
Line
Count
Source
401
4.75k
{
402
4.75k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.75k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.75k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.75k
    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.75k
    switch (format)
413
4.75k
    {
414
1.50k
    case FAAD_FMT_16BIT:
415
1.50k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.50k
        break;
417
1.19k
    case FAAD_FMT_24BIT:
418
1.19k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.19k
        break;
420
1.11k
    case FAAD_FMT_32BIT:
421
1.11k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.11k
        break;
423
486
    case FAAD_FMT_FLOAT:
424
486
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
486
        break;
426
458
    case FAAD_FMT_DOUBLE:
427
458
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
458
        break;
429
4.75k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.75k
    return sample_buffer;
437
4.75k
}
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
38.1M
{
449
38.1M
    real_t C;
450
38.1M
    if (up_matrix == 1)
451
61.0k
        return input[internal_channel[0]][sample];
452
453
38.1M
    if (!down_matrix)
454
37.5M
        return input[internal_channel[channel]][sample];
455
456
617k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
617k
    if (channel == 0)
458
306k
    {
459
306k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
306k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
306k
        return core + C + L_S;
462
311k
    } else {
463
311k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
311k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
311k
        return core + C + R_S;
466
311k
    }
467
617k
}
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
7.94k
{
473
7.94k
    uint8_t ch;
474
7.94k
    uint16_t i;
475
7.94k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
7.94k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
7.94k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
59.3k
    for (ch = 0; ch < channels; ch++)
481
51.4k
    {
482
51.4k
        switch (format)
483
51.4k
        {
484
16.4k
        case FAAD_FMT_16BIT:
485
25.1M
            for(i = 0; i < frame_len; i++)
486
25.1M
            {
487
25.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
25.1M
                    hDecoder->internal_channel);
489
25.1M
                if (tmp >= 0)
490
22.6M
                {
491
22.6M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
22.6M
                        tmp += (1 << (REAL_BITS-1));
493
22.6M
                    if (tmp >= REAL_CONST(32767))
494
140k
                    {
495
140k
                        tmp = REAL_CONST(32767);
496
140k
                    }
497
22.6M
                } else {
498
2.45M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
2.45M
                        tmp += -(1 << (REAL_BITS-1));
500
2.45M
                    if (tmp <= REAL_CONST(-32768))
501
130k
                    {
502
130k
                        tmp = REAL_CONST(-32768);
503
130k
                    }
504
2.45M
                }
505
25.1M
                tmp >>= REAL_BITS;
506
25.1M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
25.1M
            }
508
16.4k
            break;
509
17.6k
        case FAAD_FMT_24BIT:
510
26.3M
            for(i = 0; i < frame_len; i++)
511
26.3M
            {
512
26.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
26.3M
                    hDecoder->internal_channel);
514
26.3M
                if (tmp >= 0)
515
23.7M
                {
516
23.7M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
23.7M
                        tmp += (1 << (REAL_BITS-9));
518
23.7M
                    tmp >>= (REAL_BITS-8);
519
23.7M
                    if (tmp >= 8388607)
520
124k
                    {
521
124k
                        tmp = 8388607;
522
124k
                    }
523
23.7M
                } else {
524
2.55M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
2.55M
                        tmp += -(1 << (REAL_BITS-9));
526
2.55M
                    tmp >>= (REAL_BITS-8);
527
2.55M
                    if (tmp <= -8388608)
528
119k
                    {
529
119k
                        tmp = -8388608;
530
119k
                    }
531
2.55M
                }
532
26.3M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
26.3M
            }
534
17.6k
            break;
535
8.99k
        case FAAD_FMT_32BIT:
536
8.99k
            exp = 16 - REAL_BITS;
537
8.99k
            half = 1 << (exp - 1);
538
8.99k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
12.6M
            for(i = 0; i < frame_len; i++)
540
12.6M
            {
541
12.6M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
12.6M
                    hDecoder->internal_channel);
543
12.6M
                if (tmp >= 0)
544
11.8M
                {
545
11.8M
                    if (tmp <= 0x7FFFFFFF - half)
546
11.8M
                        tmp += half;
547
11.8M
                } else {
548
707k
                    if (tmp >= (int32_t)0x80000000 + half)
549
707k
                        tmp += -half;
550
707k
                }
551
12.6M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
12.6M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
12.6M
            }
554
8.99k
            break;
555
8.35k
        case FAAD_FMT_FIXED:
556
12.3M
            for(i = 0; i < frame_len; i++)
557
12.3M
            {
558
12.3M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
12.3M
                    hDecoder->internal_channel);
560
12.3M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
12.3M
            }
562
8.35k
            break;
563
51.4k
        }
564
51.4k
    }
565
566
7.94k
    return sample_buffer;
567
7.94k
}
output_to_PCM
Line
Count
Source
472
3.97k
{
473
3.97k
    uint8_t ch;
474
3.97k
    uint16_t i;
475
3.97k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.97k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.97k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
29.6k
    for (ch = 0; ch < channels; ch++)
481
25.7k
    {
482
25.7k
        switch (format)
483
25.7k
        {
484
8.20k
        case FAAD_FMT_16BIT:
485
12.5M
            for(i = 0; i < frame_len; i++)
486
12.5M
            {
487
12.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
12.5M
                    hDecoder->internal_channel);
489
12.5M
                if (tmp >= 0)
490
11.3M
                {
491
11.3M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
11.3M
                        tmp += (1 << (REAL_BITS-1));
493
11.3M
                    if (tmp >= REAL_CONST(32767))
494
70.2k
                    {
495
70.2k
                        tmp = REAL_CONST(32767);
496
70.2k
                    }
497
11.3M
                } else {
498
1.22M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
1.22M
                        tmp += -(1 << (REAL_BITS-1));
500
1.22M
                    if (tmp <= REAL_CONST(-32768))
501
65.0k
                    {
502
65.0k
                        tmp = REAL_CONST(-32768);
503
65.0k
                    }
504
1.22M
                }
505
12.5M
                tmp >>= REAL_BITS;
506
12.5M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
12.5M
            }
508
8.20k
            break;
509
8.83k
        case FAAD_FMT_24BIT:
510
13.1M
            for(i = 0; i < frame_len; i++)
511
13.1M
            {
512
13.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
13.1M
                    hDecoder->internal_channel);
514
13.1M
                if (tmp >= 0)
515
11.8M
                {
516
11.8M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
11.8M
                        tmp += (1 << (REAL_BITS-9));
518
11.8M
                    tmp >>= (REAL_BITS-8);
519
11.8M
                    if (tmp >= 8388607)
520
62.1k
                    {
521
62.1k
                        tmp = 8388607;
522
62.1k
                    }
523
11.8M
                } else {
524
1.27M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.27M
                        tmp += -(1 << (REAL_BITS-9));
526
1.27M
                    tmp >>= (REAL_BITS-8);
527
1.27M
                    if (tmp <= -8388608)
528
59.7k
                    {
529
59.7k
                        tmp = -8388608;
530
59.7k
                    }
531
1.27M
                }
532
13.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
13.1M
            }
534
8.83k
            break;
535
4.49k
        case FAAD_FMT_32BIT:
536
4.49k
            exp = 16 - REAL_BITS;
537
4.49k
            half = 1 << (exp - 1);
538
4.49k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
6.30M
            for(i = 0; i < frame_len; i++)
540
6.30M
            {
541
6.30M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
6.30M
                    hDecoder->internal_channel);
543
6.30M
                if (tmp >= 0)
544
5.94M
                {
545
5.94M
                    if (tmp <= 0x7FFFFFFF - half)
546
5.94M
                        tmp += half;
547
5.94M
                } else {
548
353k
                    if (tmp >= (int32_t)0x80000000 + half)
549
353k
                        tmp += -half;
550
353k
                }
551
6.30M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
6.30M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
6.30M
            }
554
4.49k
            break;
555
4.17k
        case FAAD_FMT_FIXED:
556
6.15M
            for(i = 0; i < frame_len; i++)
557
6.15M
            {
558
6.15M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
6.15M
                    hDecoder->internal_channel);
560
6.15M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
6.15M
            }
562
4.17k
            break;
563
25.7k
        }
564
25.7k
    }
565
566
3.97k
    return sample_buffer;
567
3.97k
}
output_to_PCM
Line
Count
Source
472
3.97k
{
473
3.97k
    uint8_t ch;
474
3.97k
    uint16_t i;
475
3.97k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.97k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.97k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
29.6k
    for (ch = 0; ch < channels; ch++)
481
25.7k
    {
482
25.7k
        switch (format)
483
25.7k
        {
484
8.20k
        case FAAD_FMT_16BIT:
485
12.5M
            for(i = 0; i < frame_len; i++)
486
12.5M
            {
487
12.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
12.5M
                    hDecoder->internal_channel);
489
12.5M
                if (tmp >= 0)
490
11.3M
                {
491
11.3M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
11.3M
                        tmp += (1 << (REAL_BITS-1));
493
11.3M
                    if (tmp >= REAL_CONST(32767))
494
70.2k
                    {
495
70.2k
                        tmp = REAL_CONST(32767);
496
70.2k
                    }
497
11.3M
                } else {
498
1.22M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
1.22M
                        tmp += -(1 << (REAL_BITS-1));
500
1.22M
                    if (tmp <= REAL_CONST(-32768))
501
65.0k
                    {
502
65.0k
                        tmp = REAL_CONST(-32768);
503
65.0k
                    }
504
1.22M
                }
505
12.5M
                tmp >>= REAL_BITS;
506
12.5M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
12.5M
            }
508
8.20k
            break;
509
8.83k
        case FAAD_FMT_24BIT:
510
13.1M
            for(i = 0; i < frame_len; i++)
511
13.1M
            {
512
13.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
13.1M
                    hDecoder->internal_channel);
514
13.1M
                if (tmp >= 0)
515
11.8M
                {
516
11.8M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
11.8M
                        tmp += (1 << (REAL_BITS-9));
518
11.8M
                    tmp >>= (REAL_BITS-8);
519
11.8M
                    if (tmp >= 8388607)
520
62.1k
                    {
521
62.1k
                        tmp = 8388607;
522
62.1k
                    }
523
11.8M
                } else {
524
1.27M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.27M
                        tmp += -(1 << (REAL_BITS-9));
526
1.27M
                    tmp >>= (REAL_BITS-8);
527
1.27M
                    if (tmp <= -8388608)
528
59.7k
                    {
529
59.7k
                        tmp = -8388608;
530
59.7k
                    }
531
1.27M
                }
532
13.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
13.1M
            }
534
8.83k
            break;
535
4.49k
        case FAAD_FMT_32BIT:
536
4.49k
            exp = 16 - REAL_BITS;
537
4.49k
            half = 1 << (exp - 1);
538
4.49k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
6.30M
            for(i = 0; i < frame_len; i++)
540
6.30M
            {
541
6.30M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
6.30M
                    hDecoder->internal_channel);
543
6.30M
                if (tmp >= 0)
544
5.94M
                {
545
5.94M
                    if (tmp <= 0x7FFFFFFF - half)
546
5.94M
                        tmp += half;
547
5.94M
                } else {
548
353k
                    if (tmp >= (int32_t)0x80000000 + half)
549
353k
                        tmp += -half;
550
353k
                }
551
6.30M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
6.30M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
6.30M
            }
554
4.49k
            break;
555
4.17k
        case FAAD_FMT_FIXED:
556
6.15M
            for(i = 0; i < frame_len; i++)
557
6.15M
            {
558
6.15M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
6.15M
                    hDecoder->internal_channel);
560
6.15M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
6.15M
            }
562
4.17k
            break;
563
25.7k
        }
564
25.7k
    }
565
566
3.97k
    return sample_buffer;
567
3.97k
}
568
569
#endif