Coverage Report

Created: 2026-03-20 06:59

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
13.4M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.61M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.23M
#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.0M
{
48
39.0M
    if (!down_matrix)
49
36.4M
        return input[internal_channel[channel]][sample];
50
51
2.61M
    if (channel == 0)
52
1.29M
    {
53
1.29M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.29M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.29M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.32M
    } else {
57
1.32M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.32M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.32M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.32M
    }
61
2.61M
}
62
63
#ifndef HAS_LRINTF
64
32.9M
#define CLIP(sample, max, min) \
65
32.9M
if (sample >= 0.0f)            \
66
28.2M
{                              \
67
28.2M
    sample += 0.5f;            \
68
28.2M
    if (sample >= max)         \
69
28.2M
        sample = max;          \
70
28.2M
} else {                       \
71
4.65M
    sample += -0.5f;           \
72
4.65M
    if (sample <= min)         \
73
4.65M
        sample = min;          \
74
4.65M
}
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.94k
#define CONV(a,b) ((a<<1)|(b&0x1))
88
89
static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
90
                         uint8_t channels, uint16_t frame_len,
91
                         int16_t **sample_buffer)
92
1.84k
{
93
1.84k
    uint8_t ch, ch1;
94
1.84k
    uint16_t i;
95
96
1.84k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.84k
    {
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
935
    case CONV(2,0):
110
935
        if (hDecoder->upMatrix)
111
53
        {
112
53
            ch  = hDecoder->internal_channel[0];
113
87.8k
            for(i = 0; i < frame_len; i++)
114
87.8k
            {
115
87.8k
                real_t inp0 = input[ch][i];
116
117
87.8k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
87.8k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
87.8k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
87.8k
            }
122
882
        } else {
123
882
            ch  = hDecoder->internal_channel[0];
124
882
            ch1 = hDecoder->internal_channel[1];
125
1.34M
            for(i = 0; i < frame_len; i++)
126
1.33M
            {
127
1.33M
                real_t inp0 = input[ch ][i];
128
1.33M
                real_t inp1 = input[ch1][i];
129
130
1.33M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.33M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.33M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.33M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.33M
            }
136
882
        }
137
935
        break;
138
906
    default:
139
9.32k
        for (ch = 0; ch < channels; ch++)
140
8.42k
        {
141
11.9M
            for(i = 0; i < frame_len; i++)
142
11.9M
            {
143
11.9M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
11.9M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
11.9M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
11.9M
            }
149
8.42k
        }
150
906
        break;
151
1.84k
    }
152
1.84k
}
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.23k
{
158
1.23k
    uint8_t ch, ch1;
159
1.23k
    uint16_t i;
160
161
1.23k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.23k
    {
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
591
    case CONV(2,0):
176
591
        if (hDecoder->upMatrix)
177
36
        {
178
36
            ch = hDecoder->internal_channel[0];
179
53.0k
            for(i = 0; i < frame_len; i++)
180
52.9k
            {
181
52.9k
                real_t inp0 = input[ch][i];
182
183
52.9k
                inp0 *= 256.0f;
184
52.9k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
52.9k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
52.9k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
52.9k
            }
189
555
        } else {
190
555
            ch  = hDecoder->internal_channel[0];
191
555
            ch1 = hDecoder->internal_channel[1];
192
791k
            for(i = 0; i < frame_len; i++)
193
790k
            {
194
790k
                real_t inp0 = input[ch ][i];
195
790k
                real_t inp1 = input[ch1][i];
196
197
790k
                inp0 *= 256.0f;
198
790k
                inp1 *= 256.0f;
199
790k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
790k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
790k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
790k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
790k
            }
205
555
        }
206
591
        break;
207
645
    default:
208
6.38k
        for (ch = 0; ch < channels; ch++)
209
5.73k
        {
210
8.26M
            for(i = 0; i < frame_len; i++)
211
8.25M
            {
212
8.25M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.25M
                inp *= 256.0f;
215
8.25M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.25M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.25M
            }
219
5.73k
        }
220
645
        break;
221
1.23k
    }
222
1.23k
}
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.12k
{
228
1.12k
    uint8_t ch, ch1;
229
1.12k
    uint16_t i;
230
231
1.12k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.12k
    {
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
586
    case CONV(2,0):
246
586
        if (hDecoder->upMatrix)
247
42
        {
248
42
            ch = hDecoder->internal_channel[0];
249
67.2k
            for(i = 0; i < frame_len; i++)
250
67.2k
            {
251
67.2k
                real_t inp0 = input[ch][i];
252
253
67.2k
                inp0 *= 65536.0f;
254
67.2k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
67.2k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
67.2k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
67.2k
            }
259
544
        } else {
260
544
            ch  = hDecoder->internal_channel[0];
261
544
            ch1 = hDecoder->internal_channel[1];
262
863k
            for(i = 0; i < frame_len; i++)
263
862k
            {
264
862k
                real_t inp0 = input[ch ][i];
265
862k
                real_t inp1 = input[ch1][i];
266
267
862k
                inp0 *= 65536.0f;
268
862k
                inp1 *= 65536.0f;
269
862k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
862k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
862k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
862k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
862k
            }
275
544
        }
276
586
        break;
277
541
    default:
278
5.15k
        for (ch = 0; ch < channels; ch++)
279
4.61k
        {
280
6.50M
            for(i = 0; i < frame_len; i++)
281
6.49M
            {
282
6.49M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.49M
                inp *= 65536.0f;
285
6.49M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.49M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.49M
            }
289
4.61k
        }
290
541
        break;
291
1.12k
    }
292
1.12k
}
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
681
{
298
681
    uint8_t ch, ch1;
299
681
    uint16_t i;
300
301
681
    switch (CONV(channels,hDecoder->downMatrix))
302
681
    {
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
208
    case CONV(2,0):
312
208
        if (hDecoder->upMatrix)
313
14
        {
314
14
            ch = hDecoder->internal_channel[0];
315
20.3k
            for(i = 0; i < frame_len; i++)
316
20.3k
            {
317
20.3k
                real_t inp0 = input[ch][i];
318
20.3k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
20.3k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
20.3k
            }
321
194
        } else {
322
194
            ch  = hDecoder->internal_channel[0];
323
194
            ch1 = hDecoder->internal_channel[1];
324
294k
            for(i = 0; i < frame_len; i++)
325
294k
            {
326
294k
                real_t inp0 = input[ch ][i];
327
294k
                real_t inp1 = input[ch1][i];
328
294k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
294k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
294k
            }
331
194
        }
332
208
        break;
333
473
    default:
334
4.70k
        for (ch = 0; ch < channels; ch++)
335
4.23k
        {
336
6.04M
            for(i = 0; i < frame_len; i++)
337
6.03M
            {
338
6.03M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.03M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.03M
            }
341
4.23k
        }
342
473
        break;
343
681
    }
344
681
}
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
582
{
350
582
    uint8_t ch, ch1;
351
582
    uint16_t i;
352
353
582
    switch (CONV(channels,hDecoder->downMatrix))
354
582
    {
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
162
    case CONV(2,0):
364
162
        if (hDecoder->upMatrix)
365
13
        {
366
13
            ch = hDecoder->internal_channel[0];
367
24.3k
            for(i = 0; i < frame_len; i++)
368
24.3k
            {
369
24.3k
                real_t inp0 = input[ch][i];
370
24.3k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
24.3k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
24.3k
            }
373
149
        } else {
374
149
            ch  = hDecoder->internal_channel[0];
375
149
            ch1 = hDecoder->internal_channel[1];
376
192k
            for(i = 0; i < frame_len; i++)
377
192k
            {
378
192k
                real_t inp0 = input[ch ][i];
379
192k
                real_t inp1 = input[ch1][i];
380
192k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
192k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
192k
            }
383
149
        }
384
162
        break;
385
420
    default:
386
4.55k
        for (ch = 0; ch < channels; ch++)
387
4.13k
        {
388
6.30M
            for(i = 0; i < frame_len; i++)
389
6.29M
            {
390
6.29M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.29M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.29M
            }
393
4.13k
        }
394
420
        break;
395
582
    }
396
582
}
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.9k
{
402
10.9k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
10.9k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
10.9k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
10.9k
    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.9k
    switch (format)
413
10.9k
    {
414
3.68k
    case FAAD_FMT_16BIT:
415
3.68k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.68k
        break;
417
2.47k
    case FAAD_FMT_24BIT:
418
2.47k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.47k
        break;
420
2.25k
    case FAAD_FMT_32BIT:
421
2.25k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.25k
        break;
423
1.36k
    case FAAD_FMT_FLOAT:
424
1.36k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.36k
        break;
426
1.16k
    case FAAD_FMT_DOUBLE:
427
1.16k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.16k
        break;
429
10.9k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
10.9k
    return sample_buffer;
437
10.9k
}
output_to_PCM
Line
Count
Source
401
5.46k
{
402
5.46k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.46k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.46k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.46k
    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.46k
    switch (format)
413
5.46k
    {
414
1.84k
    case FAAD_FMT_16BIT:
415
1.84k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.84k
        break;
417
1.23k
    case FAAD_FMT_24BIT:
418
1.23k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.23k
        break;
420
1.12k
    case FAAD_FMT_32BIT:
421
1.12k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.12k
        break;
423
681
    case FAAD_FMT_FLOAT:
424
681
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
681
        break;
426
582
    case FAAD_FMT_DOUBLE:
427
582
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
582
        break;
429
5.46k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.46k
    return sample_buffer;
437
5.46k
}
output_to_PCM
Line
Count
Source
401
5.46k
{
402
5.46k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.46k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.46k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.46k
    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.46k
    switch (format)
413
5.46k
    {
414
1.84k
    case FAAD_FMT_16BIT:
415
1.84k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.84k
        break;
417
1.23k
    case FAAD_FMT_24BIT:
418
1.23k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.23k
        break;
420
1.12k
    case FAAD_FMT_32BIT:
421
1.12k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.12k
        break;
423
681
    case FAAD_FMT_FLOAT:
424
681
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
681
        break;
426
582
    case FAAD_FMT_DOUBLE:
427
582
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
582
        break;
429
5.46k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.46k
    return sample_buffer;
437
5.46k
}
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.1M
{
449
28.1M
    real_t C;
450
28.1M
    if (up_matrix == 1)
451
268k
        return input[internal_channel[0]][sample];
452
453
27.8M
    if (!down_matrix)
454
27.2M
        return input[internal_channel[channel]][sample];
455
456
596k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
596k
    if (channel == 0)
458
288k
    {
459
288k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
288k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
288k
        return core + C + L_S;
462
307k
    } else {
463
307k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
307k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
307k
        return core + C + R_S;
466
307k
    }
467
596k
}
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.25k
{
473
6.25k
    uint8_t ch;
474
6.25k
    uint16_t i;
475
6.25k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.25k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.25k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
46.0k
    for (ch = 0; ch < channels; ch++)
481
39.7k
    {
482
39.7k
        switch (format)
483
39.7k
        {
484
12.9k
        case FAAD_FMT_16BIT:
485
19.1M
            for(i = 0; i < frame_len; i++)
486
19.1M
            {
487
19.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
19.1M
                    hDecoder->internal_channel);
489
19.1M
                if (tmp >= 0)
490
17.5M
                {
491
17.5M
                    tmp += (1 << (REAL_BITS-1));
492
17.5M
                    if (tmp >= REAL_CONST(32767))
493
37.5k
                    {
494
37.5k
                        tmp = REAL_CONST(32767);
495
37.5k
                    }
496
17.5M
                } else {
497
1.56M
                    tmp += -(1 << (REAL_BITS-1));
498
1.56M
                    if (tmp <= REAL_CONST(-32768))
499
41.6k
                    {
500
41.6k
                        tmp = REAL_CONST(-32768);
501
41.6k
                    }
502
1.56M
                }
503
19.1M
                tmp >>= REAL_BITS;
504
19.1M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
19.1M
            }
506
12.9k
            break;
507
12.1k
        case FAAD_FMT_24BIT:
508
17.3M
            for(i = 0; i < frame_len; i++)
509
17.3M
            {
510
17.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
17.3M
                    hDecoder->internal_channel);
512
17.3M
                if (tmp >= 0)
513
15.9M
                {
514
15.9M
                    tmp += (1 << (REAL_BITS-9));
515
15.9M
                    tmp >>= (REAL_BITS-8);
516
15.9M
                    if (tmp >= 8388607)
517
29.4k
                    {
518
29.4k
                        tmp = 8388607;
519
29.4k
                    }
520
15.9M
                } else {
521
1.44M
                    tmp += -(1 << (REAL_BITS-9));
522
1.44M
                    tmp >>= (REAL_BITS-8);
523
1.44M
                    if (tmp <= -8388608)
524
30.4k
                    {
525
30.4k
                        tmp = -8388608;
526
30.4k
                    }
527
1.44M
                }
528
17.3M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
17.3M
            }
530
12.1k
            break;
531
8.25k
        case FAAD_FMT_32BIT:
532
8.25k
            exp = 16 - REAL_BITS;
533
8.25k
            half = 1 << (exp - 1);
534
8.25k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
11.3M
            for(i = 0; i < frame_len; i++)
536
11.2M
            {
537
11.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
11.2M
                    hDecoder->internal_channel);
539
11.2M
                if (tmp >= 0)
540
10.3M
                {
541
10.3M
                    tmp += half;
542
10.3M
                } else {
543
950k
                    tmp += -half;
544
950k
                }
545
11.2M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
11.2M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
11.2M
            }
548
8.25k
            break;
549
6.43k
        case FAAD_FMT_FIXED:
550
8.51M
            for(i = 0; i < frame_len; i++)
551
8.51M
            {
552
8.51M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
8.51M
                    hDecoder->internal_channel);
554
8.51M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
8.51M
            }
556
6.43k
            break;
557
39.7k
        }
558
39.7k
    }
559
560
6.25k
    return sample_buffer;
561
6.25k
}
output_to_PCM
Line
Count
Source
472
3.12k
{
473
3.12k
    uint8_t ch;
474
3.12k
    uint16_t i;
475
3.12k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.12k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.12k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.0k
    for (ch = 0; ch < channels; ch++)
481
19.8k
    {
482
19.8k
        switch (format)
483
19.8k
        {
484
6.49k
        case FAAD_FMT_16BIT:
485
9.57M
            for(i = 0; i < frame_len; i++)
486
9.57M
            {
487
9.57M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.57M
                    hDecoder->internal_channel);
489
9.57M
                if (tmp >= 0)
490
8.78M
                {
491
8.78M
                    tmp += (1 << (REAL_BITS-1));
492
8.78M
                    if (tmp >= REAL_CONST(32767))
493
18.7k
                    {
494
18.7k
                        tmp = REAL_CONST(32767);
495
18.7k
                    }
496
8.78M
                } else {
497
782k
                    tmp += -(1 << (REAL_BITS-1));
498
782k
                    if (tmp <= REAL_CONST(-32768))
499
20.8k
                    {
500
20.8k
                        tmp = REAL_CONST(-32768);
501
20.8k
                    }
502
782k
                }
503
9.57M
                tmp >>= REAL_BITS;
504
9.57M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.57M
            }
506
6.49k
            break;
507
6.06k
        case FAAD_FMT_24BIT:
508
8.68M
            for(i = 0; i < frame_len; i++)
509
8.68M
            {
510
8.68M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.68M
                    hDecoder->internal_channel);
512
8.68M
                if (tmp >= 0)
513
7.96M
                {
514
7.96M
                    tmp += (1 << (REAL_BITS-9));
515
7.96M
                    tmp >>= (REAL_BITS-8);
516
7.96M
                    if (tmp >= 8388607)
517
14.7k
                    {
518
14.7k
                        tmp = 8388607;
519
14.7k
                    }
520
7.96M
                } else {
521
721k
                    tmp += -(1 << (REAL_BITS-9));
522
721k
                    tmp >>= (REAL_BITS-8);
523
721k
                    if (tmp <= -8388608)
524
15.2k
                    {
525
15.2k
                        tmp = -8388608;
526
15.2k
                    }
527
721k
                }
528
8.68M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.68M
            }
530
6.06k
            break;
531
4.12k
        case FAAD_FMT_32BIT:
532
4.12k
            exp = 16 - REAL_BITS;
533
4.12k
            half = 1 << (exp - 1);
534
4.12k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.65M
            for(i = 0; i < frame_len; i++)
536
5.64M
            {
537
5.64M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.64M
                    hDecoder->internal_channel);
539
5.64M
                if (tmp >= 0)
540
5.17M
                {
541
5.17M
                    tmp += half;
542
5.17M
                } else {
543
475k
                    tmp += -half;
544
475k
                }
545
5.64M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.64M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.64M
            }
548
4.12k
            break;
549
3.21k
        case FAAD_FMT_FIXED:
550
4.25M
            for(i = 0; i < frame_len; i++)
551
4.25M
            {
552
4.25M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.25M
                    hDecoder->internal_channel);
554
4.25M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.25M
            }
556
3.21k
            break;
557
19.8k
        }
558
19.8k
    }
559
560
3.12k
    return sample_buffer;
561
3.12k
}
output_to_PCM
Line
Count
Source
472
3.12k
{
473
3.12k
    uint8_t ch;
474
3.12k
    uint16_t i;
475
3.12k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.12k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.12k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.0k
    for (ch = 0; ch < channels; ch++)
481
19.8k
    {
482
19.8k
        switch (format)
483
19.8k
        {
484
6.49k
        case FAAD_FMT_16BIT:
485
9.57M
            for(i = 0; i < frame_len; i++)
486
9.57M
            {
487
9.57M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.57M
                    hDecoder->internal_channel);
489
9.57M
                if (tmp >= 0)
490
8.78M
                {
491
8.78M
                    tmp += (1 << (REAL_BITS-1));
492
8.78M
                    if (tmp >= REAL_CONST(32767))
493
18.7k
                    {
494
18.7k
                        tmp = REAL_CONST(32767);
495
18.7k
                    }
496
8.78M
                } else {
497
782k
                    tmp += -(1 << (REAL_BITS-1));
498
782k
                    if (tmp <= REAL_CONST(-32768))
499
20.8k
                    {
500
20.8k
                        tmp = REAL_CONST(-32768);
501
20.8k
                    }
502
782k
                }
503
9.57M
                tmp >>= REAL_BITS;
504
9.57M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.57M
            }
506
6.49k
            break;
507
6.06k
        case FAAD_FMT_24BIT:
508
8.68M
            for(i = 0; i < frame_len; i++)
509
8.68M
            {
510
8.68M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.68M
                    hDecoder->internal_channel);
512
8.68M
                if (tmp >= 0)
513
7.96M
                {
514
7.96M
                    tmp += (1 << (REAL_BITS-9));
515
7.96M
                    tmp >>= (REAL_BITS-8);
516
7.96M
                    if (tmp >= 8388607)
517
14.7k
                    {
518
14.7k
                        tmp = 8388607;
519
14.7k
                    }
520
7.96M
                } else {
521
721k
                    tmp += -(1 << (REAL_BITS-9));
522
721k
                    tmp >>= (REAL_BITS-8);
523
721k
                    if (tmp <= -8388608)
524
15.2k
                    {
525
15.2k
                        tmp = -8388608;
526
15.2k
                    }
527
721k
                }
528
8.68M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.68M
            }
530
6.06k
            break;
531
4.12k
        case FAAD_FMT_32BIT:
532
4.12k
            exp = 16 - REAL_BITS;
533
4.12k
            half = 1 << (exp - 1);
534
4.12k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.65M
            for(i = 0; i < frame_len; i++)
536
5.64M
            {
537
5.64M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.64M
                    hDecoder->internal_channel);
539
5.64M
                if (tmp >= 0)
540
5.17M
                {
541
5.17M
                    tmp += half;
542
5.17M
                } else {
543
475k
                    tmp += -half;
544
475k
                }
545
5.64M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.64M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.64M
            }
548
4.12k
            break;
549
3.21k
        case FAAD_FMT_FIXED:
550
4.25M
            for(i = 0; i < frame_len; i++)
551
4.25M
            {
552
4.25M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.25M
                    hDecoder->internal_channel);
554
4.25M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.25M
            }
556
3.21k
            break;
557
19.8k
        }
558
19.8k
    }
559
560
3.12k
    return sample_buffer;
561
3.12k
}
562
563
#endif