Coverage Report

Created: 2025-12-14 06:24

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
12.6M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.26M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
4.52M
#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
40.8M
{
48
40.8M
    if (!down_matrix)
49
38.6M
        return input[internal_channel[channel]][sample];
50
51
2.26M
    if (channel == 0)
52
1.12M
    {
53
1.12M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.12M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.12M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.14M
    } else {
57
1.14M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.14M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.14M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.14M
    }
61
2.26M
}
62
63
#ifndef HAS_LRINTF
64
34.9M
#define CLIP(sample, max, min) \
65
34.9M
if (sample >= 0.0f)            \
66
29.9M
{                              \
67
29.9M
    sample += 0.5f;            \
68
29.9M
    if (sample >= max)         \
69
29.9M
        sample = max;          \
70
29.9M
} else {                       \
71
5.01M
    sample += -0.5f;           \
72
5.01M
    if (sample <= min)         \
73
5.01M
        sample = min;          \
74
5.01M
}
75
#else
76
#define CLIP(sample, max, min) \
77
if (sample >= 0.0f)            \
78
{                              \
79
    if (sample >= max)         \
80
        sample = max;          \
81
} else {                       \
82
    if (sample <= min)         \
83
        sample = min;          \
84
}
85
#endif
86
87
7.38k
#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.79k
{
93
1.79k
    uint8_t ch, ch1;
94
1.79k
    uint16_t i;
95
96
1.79k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.79k
    {
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
857
    case CONV(2,0):
110
857
        if (hDecoder->upMatrix)
111
53
        {
112
53
            ch  = hDecoder->internal_channel[0];
113
84.7k
            for(i = 0; i < frame_len; i++)
114
84.6k
            {
115
84.6k
                real_t inp0 = input[ch][i];
116
117
84.6k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
84.6k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
84.6k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
84.6k
            }
122
804
        } else {
123
804
            ch  = hDecoder->internal_channel[0];
124
804
            ch1 = hDecoder->internal_channel[1];
125
1.24M
            for(i = 0; i < frame_len; i++)
126
1.24M
            {
127
1.24M
                real_t inp0 = input[ch ][i];
128
1.24M
                real_t inp1 = input[ch1][i];
129
130
1.24M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.24M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.24M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.24M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.24M
            }
136
804
        }
137
857
        break;
138
942
    default:
139
10.1k
        for (ch = 0; ch < channels; ch++)
140
9.20k
        {
141
13.5M
            for(i = 0; i < frame_len; i++)
142
13.5M
            {
143
13.5M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
13.5M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
13.5M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
13.5M
            }
149
9.20k
        }
150
942
        break;
151
1.79k
    }
152
1.79k
}
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.11k
{
158
1.11k
    uint8_t ch, ch1;
159
1.11k
    uint16_t i;
160
161
1.11k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.11k
    {
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
517
    case CONV(2,0):
176
517
        if (hDecoder->upMatrix)
177
40
        {
178
40
            ch = hDecoder->internal_channel[0];
179
59.8k
            for(i = 0; i < frame_len; i++)
180
59.7k
            {
181
59.7k
                real_t inp0 = input[ch][i];
182
183
59.7k
                inp0 *= 256.0f;
184
59.7k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
59.7k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
59.7k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
59.7k
            }
189
477
        } else {
190
477
            ch  = hDecoder->internal_channel[0];
191
477
            ch1 = hDecoder->internal_channel[1];
192
710k
            for(i = 0; i < frame_len; i++)
193
709k
            {
194
709k
                real_t inp0 = input[ch ][i];
195
709k
                real_t inp1 = input[ch1][i];
196
197
709k
                inp0 *= 256.0f;
198
709k
                inp1 *= 256.0f;
199
709k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
709k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
709k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
709k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
709k
            }
205
477
        }
206
517
        break;
207
593
    default:
208
6.16k
        for (ch = 0; ch < channels; ch++)
209
5.57k
        {
210
8.43M
            for(i = 0; i < frame_len; i++)
211
8.43M
            {
212
8.43M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.43M
                inp *= 256.0f;
215
8.43M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.43M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.43M
            }
219
5.57k
        }
220
593
        break;
221
1.11k
    }
222
1.11k
}
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.16k
{
228
1.16k
    uint8_t ch, ch1;
229
1.16k
    uint16_t i;
230
231
1.16k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.16k
    {
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
595
    case CONV(2,0):
246
595
        if (hDecoder->upMatrix)
247
29
        {
248
29
            ch = hDecoder->internal_channel[0];
249
42.9k
            for(i = 0; i < frame_len; i++)
250
42.8k
            {
251
42.8k
                real_t inp0 = input[ch][i];
252
253
42.8k
                inp0 *= 65536.0f;
254
42.8k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
42.8k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
42.8k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
42.8k
            }
259
566
        } else {
260
566
            ch  = hDecoder->internal_channel[0];
261
566
            ch1 = hDecoder->internal_channel[1];
262
854k
            for(i = 0; i < frame_len; i++)
263
854k
            {
264
854k
                real_t inp0 = input[ch ][i];
265
854k
                real_t inp1 = input[ch1][i];
266
267
854k
                inp0 *= 65536.0f;
268
854k
                inp1 *= 65536.0f;
269
854k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
854k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
854k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
854k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
854k
            }
275
566
        }
276
595
        break;
277
568
    default:
278
5.47k
        for (ch = 0; ch < channels; ch++)
279
4.90k
        {
280
7.21M
            for(i = 0; i < frame_len; i++)
281
7.20M
            {
282
7.20M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
7.20M
                inp *= 65536.0f;
285
7.20M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
7.20M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
7.20M
            }
289
4.90k
        }
290
568
        break;
291
1.16k
    }
292
1.16k
}
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
546
{
298
546
    uint8_t ch, ch1;
299
546
    uint16_t i;
300
301
546
    switch (CONV(channels,hDecoder->downMatrix))
302
546
    {
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
156
    case CONV(2,0):
312
156
        if (hDecoder->upMatrix)
313
10
        {
314
10
            ch = hDecoder->internal_channel[0];
315
15.8k
            for(i = 0; i < frame_len; i++)
316
15.8k
            {
317
15.8k
                real_t inp0 = input[ch][i];
318
15.8k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
15.8k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
15.8k
            }
321
146
        } else {
322
146
            ch  = hDecoder->internal_channel[0];
323
146
            ch1 = hDecoder->internal_channel[1];
324
241k
            for(i = 0; i < frame_len; i++)
325
241k
            {
326
241k
                real_t inp0 = input[ch ][i];
327
241k
                real_t inp1 = input[ch1][i];
328
241k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
241k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
241k
            }
331
146
        }
332
156
        break;
333
390
    default:
334
4.38k
        for (ch = 0; ch < channels; ch++)
335
3.99k
        {
336
5.86M
            for(i = 0; i < frame_len; i++)
337
5.85M
            {
338
5.85M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
5.85M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
5.85M
            }
341
3.99k
        }
342
390
        break;
343
546
    }
344
546
}
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
481
{
350
481
    uint8_t ch, ch1;
351
481
    uint16_t i;
352
353
481
    switch (CONV(channels,hDecoder->downMatrix))
354
481
    {
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
156
    case CONV(2,0):
364
156
        if (hDecoder->upMatrix)
365
21
        {
366
21
            ch = hDecoder->internal_channel[0];
367
34.5k
            for(i = 0; i < frame_len; i++)
368
34.5k
            {
369
34.5k
                real_t inp0 = input[ch][i];
370
34.5k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
34.5k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
34.5k
            }
373
135
        } else {
374
135
            ch  = hDecoder->internal_channel[0];
375
135
            ch1 = hDecoder->internal_channel[1];
376
173k
            for(i = 0; i < frame_len; i++)
377
173k
            {
378
173k
                real_t inp0 = input[ch ][i];
379
173k
                real_t inp1 = input[ch1][i];
380
173k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
173k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
173k
            }
383
135
        }
384
156
        break;
385
325
    default:
386
4.25k
        for (ch = 0; ch < channels; ch++)
387
3.93k
        {
388
5.84M
            for(i = 0; i < frame_len; i++)
389
5.84M
            {
390
5.84M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
5.84M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
5.84M
            }
393
3.93k
        }
394
325
        break;
395
481
    }
396
481
}
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
10.1k
{
402
10.1k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
10.1k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
10.1k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
10.1k
    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
10.1k
    switch (format)
413
10.1k
    {
414
3.59k
    case FAAD_FMT_16BIT:
415
3.59k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.59k
        break;
417
2.22k
    case FAAD_FMT_24BIT:
418
2.22k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.22k
        break;
420
2.32k
    case FAAD_FMT_32BIT:
421
2.32k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.32k
        break;
423
1.09k
    case FAAD_FMT_FLOAT:
424
1.09k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.09k
        break;
426
962
    case FAAD_FMT_DOUBLE:
427
962
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
962
        break;
429
10.1k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
10.1k
    return sample_buffer;
437
10.1k
}
output_to_PCM
Line
Count
Source
401
5.09k
{
402
5.09k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.09k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.09k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.09k
    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.09k
    switch (format)
413
5.09k
    {
414
1.79k
    case FAAD_FMT_16BIT:
415
1.79k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.79k
        break;
417
1.11k
    case FAAD_FMT_24BIT:
418
1.11k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.11k
        break;
420
1.16k
    case FAAD_FMT_32BIT:
421
1.16k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.16k
        break;
423
546
    case FAAD_FMT_FLOAT:
424
546
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
546
        break;
426
481
    case FAAD_FMT_DOUBLE:
427
481
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
481
        break;
429
5.09k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.09k
    return sample_buffer;
437
5.09k
}
output_to_PCM
Line
Count
Source
401
5.09k
{
402
5.09k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.09k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.09k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.09k
    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.09k
    switch (format)
413
5.09k
    {
414
1.79k
    case FAAD_FMT_16BIT:
415
1.79k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.79k
        break;
417
1.11k
    case FAAD_FMT_24BIT:
418
1.11k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.11k
        break;
420
1.16k
    case FAAD_FMT_32BIT:
421
1.16k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.16k
        break;
423
546
    case FAAD_FMT_FLOAT:
424
546
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
546
        break;
426
481
    case FAAD_FMT_DOUBLE:
427
481
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
481
        break;
429
5.09k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.09k
    return sample_buffer;
437
5.09k
}
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
29.5M
{
449
29.5M
    real_t C;
450
29.5M
    if (up_matrix == 1)
451
301k
        return input[internal_channel[0]][sample];
452
453
29.2M
    if (!down_matrix)
454
28.5M
        return input[internal_channel[channel]][sample];
455
456
738k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
738k
    if (channel == 0)
458
354k
    {
459
354k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
354k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
354k
        return core + C + L_S;
462
383k
    } else {
463
383k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
383k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
383k
        return core + C + R_S;
466
383k
    }
467
738k
}
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.75k
{
473
6.75k
    uint8_t ch;
474
6.75k
    uint16_t i;
475
6.75k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.75k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.75k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
47.1k
    for (ch = 0; ch < channels; ch++)
481
40.3k
    {
482
40.3k
        switch (format)
483
40.3k
        {
484
10.2k
        case FAAD_FMT_16BIT:
485
15.8M
            for(i = 0; i < frame_len; i++)
486
15.8M
            {
487
15.8M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
15.8M
                    hDecoder->internal_channel);
489
15.8M
                if (tmp >= 0)
490
14.9M
                {
491
14.9M
                    tmp += (1 << (REAL_BITS-1));
492
14.9M
                    if (tmp >= REAL_CONST(32767))
493
43.5k
                    {
494
43.5k
                        tmp = REAL_CONST(32767);
495
43.5k
                    }
496
14.9M
                } else {
497
936k
                    tmp += -(1 << (REAL_BITS-1));
498
936k
                    if (tmp <= REAL_CONST(-32768))
499
45.7k
                    {
500
45.7k
                        tmp = REAL_CONST(-32768);
501
45.7k
                    }
502
936k
                }
503
15.8M
                tmp >>= REAL_BITS;
504
15.8M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
15.8M
            }
506
10.2k
            break;
507
13.8k
        case FAAD_FMT_24BIT:
508
20.3M
            for(i = 0; i < frame_len; i++)
509
20.3M
            {
510
20.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
20.3M
                    hDecoder->internal_channel);
512
20.3M
                if (tmp >= 0)
513
18.6M
                {
514
18.6M
                    tmp += (1 << (REAL_BITS-9));
515
18.6M
                    tmp >>= (REAL_BITS-8);
516
18.6M
                    if (tmp >= 8388607)
517
27.4k
                    {
518
27.4k
                        tmp = 8388607;
519
27.4k
                    }
520
18.6M
                } else {
521
1.67M
                    tmp += -(1 << (REAL_BITS-9));
522
1.67M
                    tmp >>= (REAL_BITS-8);
523
1.67M
                    if (tmp <= -8388608)
524
26.7k
                    {
525
26.7k
                        tmp = -8388608;
526
26.7k
                    }
527
1.67M
                }
528
20.3M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
20.3M
            }
530
13.8k
            break;
531
9.92k
        case FAAD_FMT_32BIT:
532
9.92k
            exp = 16 - REAL_BITS;
533
9.92k
            half = 1 << (exp - 1);
534
9.92k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
13.8M
            for(i = 0; i < frame_len; i++)
536
13.8M
            {
537
13.8M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
13.8M
                    hDecoder->internal_channel);
539
13.8M
                if (tmp >= 0)
540
12.8M
                {
541
12.8M
                    tmp += half;
542
12.8M
                } else {
543
1.05M
                    tmp += -half;
544
1.05M
                }
545
13.8M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
13.8M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
13.8M
            }
548
9.92k
            break;
549
6.27k
        case FAAD_FMT_FIXED:
550
9.07M
            for(i = 0; i < frame_len; i++)
551
9.07M
            {
552
9.07M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
9.07M
                    hDecoder->internal_channel);
554
9.07M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
9.07M
            }
556
6.27k
            break;
557
40.3k
        }
558
40.3k
    }
559
560
6.75k
    return sample_buffer;
561
6.75k
}
output_to_PCM
Line
Count
Source
472
3.37k
{
473
3.37k
    uint8_t ch;
474
3.37k
    uint16_t i;
475
3.37k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.37k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.37k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.5k
    for (ch = 0; ch < channels; ch++)
481
20.1k
    {
482
20.1k
        switch (format)
483
20.1k
        {
484
5.14k
        case FAAD_FMT_16BIT:
485
7.93M
            for(i = 0; i < frame_len; i++)
486
7.93M
            {
487
7.93M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.93M
                    hDecoder->internal_channel);
489
7.93M
                if (tmp >= 0)
490
7.46M
                {
491
7.46M
                    tmp += (1 << (REAL_BITS-1));
492
7.46M
                    if (tmp >= REAL_CONST(32767))
493
21.7k
                    {
494
21.7k
                        tmp = REAL_CONST(32767);
495
21.7k
                    }
496
7.46M
                } else {
497
468k
                    tmp += -(1 << (REAL_BITS-1));
498
468k
                    if (tmp <= REAL_CONST(-32768))
499
22.8k
                    {
500
22.8k
                        tmp = REAL_CONST(-32768);
501
22.8k
                    }
502
468k
                }
503
7.93M
                tmp >>= REAL_BITS;
504
7.93M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.93M
            }
506
5.14k
            break;
507
6.93k
        case FAAD_FMT_24BIT:
508
10.1M
            for(i = 0; i < frame_len; i++)
509
10.1M
            {
510
10.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
10.1M
                    hDecoder->internal_channel);
512
10.1M
                if (tmp >= 0)
513
9.31M
                {
514
9.31M
                    tmp += (1 << (REAL_BITS-9));
515
9.31M
                    tmp >>= (REAL_BITS-8);
516
9.31M
                    if (tmp >= 8388607)
517
13.7k
                    {
518
13.7k
                        tmp = 8388607;
519
13.7k
                    }
520
9.31M
                } else {
521
835k
                    tmp += -(1 << (REAL_BITS-9));
522
835k
                    tmp >>= (REAL_BITS-8);
523
835k
                    if (tmp <= -8388608)
524
13.3k
                    {
525
13.3k
                        tmp = -8388608;
526
13.3k
                    }
527
835k
                }
528
10.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
10.1M
            }
530
6.93k
            break;
531
4.96k
        case FAAD_FMT_32BIT:
532
4.96k
            exp = 16 - REAL_BITS;
533
4.96k
            half = 1 << (exp - 1);
534
4.96k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
6.93M
            for(i = 0; i < frame_len; i++)
536
6.92M
            {
537
6.92M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
6.92M
                    hDecoder->internal_channel);
539
6.92M
                if (tmp >= 0)
540
6.40M
                {
541
6.40M
                    tmp += half;
542
6.40M
                } else {
543
525k
                    tmp += -half;
544
525k
                }
545
6.92M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
6.92M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
6.92M
            }
548
4.96k
            break;
549
3.13k
        case FAAD_FMT_FIXED:
550
4.53M
            for(i = 0; i < frame_len; i++)
551
4.53M
            {
552
4.53M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.53M
                    hDecoder->internal_channel);
554
4.53M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.53M
            }
556
3.13k
            break;
557
20.1k
        }
558
20.1k
    }
559
560
3.37k
    return sample_buffer;
561
3.37k
}
output_to_PCM
Line
Count
Source
472
3.37k
{
473
3.37k
    uint8_t ch;
474
3.37k
    uint16_t i;
475
3.37k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.37k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.37k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.5k
    for (ch = 0; ch < channels; ch++)
481
20.1k
    {
482
20.1k
        switch (format)
483
20.1k
        {
484
5.14k
        case FAAD_FMT_16BIT:
485
7.93M
            for(i = 0; i < frame_len; i++)
486
7.93M
            {
487
7.93M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.93M
                    hDecoder->internal_channel);
489
7.93M
                if (tmp >= 0)
490
7.46M
                {
491
7.46M
                    tmp += (1 << (REAL_BITS-1));
492
7.46M
                    if (tmp >= REAL_CONST(32767))
493
21.7k
                    {
494
21.7k
                        tmp = REAL_CONST(32767);
495
21.7k
                    }
496
7.46M
                } else {
497
468k
                    tmp += -(1 << (REAL_BITS-1));
498
468k
                    if (tmp <= REAL_CONST(-32768))
499
22.8k
                    {
500
22.8k
                        tmp = REAL_CONST(-32768);
501
22.8k
                    }
502
468k
                }
503
7.93M
                tmp >>= REAL_BITS;
504
7.93M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.93M
            }
506
5.14k
            break;
507
6.93k
        case FAAD_FMT_24BIT:
508
10.1M
            for(i = 0; i < frame_len; i++)
509
10.1M
            {
510
10.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
10.1M
                    hDecoder->internal_channel);
512
10.1M
                if (tmp >= 0)
513
9.31M
                {
514
9.31M
                    tmp += (1 << (REAL_BITS-9));
515
9.31M
                    tmp >>= (REAL_BITS-8);
516
9.31M
                    if (tmp >= 8388607)
517
13.7k
                    {
518
13.7k
                        tmp = 8388607;
519
13.7k
                    }
520
9.31M
                } else {
521
835k
                    tmp += -(1 << (REAL_BITS-9));
522
835k
                    tmp >>= (REAL_BITS-8);
523
835k
                    if (tmp <= -8388608)
524
13.3k
                    {
525
13.3k
                        tmp = -8388608;
526
13.3k
                    }
527
835k
                }
528
10.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
10.1M
            }
530
6.93k
            break;
531
4.96k
        case FAAD_FMT_32BIT:
532
4.96k
            exp = 16 - REAL_BITS;
533
4.96k
            half = 1 << (exp - 1);
534
4.96k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
6.93M
            for(i = 0; i < frame_len; i++)
536
6.92M
            {
537
6.92M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
6.92M
                    hDecoder->internal_channel);
539
6.92M
                if (tmp >= 0)
540
6.40M
                {
541
6.40M
                    tmp += half;
542
6.40M
                } else {
543
525k
                    tmp += -half;
544
525k
                }
545
6.92M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
6.92M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
6.92M
            }
548
4.96k
            break;
549
3.13k
        case FAAD_FMT_FIXED:
550
4.53M
            for(i = 0; i < frame_len; i++)
551
4.53M
            {
552
4.53M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.53M
                    hDecoder->internal_channel);
554
4.53M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.53M
            }
556
3.13k
            break;
557
20.1k
        }
558
20.1k
    }
559
560
3.37k
    return sample_buffer;
561
3.37k
}
562
563
#endif