Coverage Report

Created: 2025-11-09 06:08

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.8M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.66M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.32M
#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
41.9M
{
48
41.9M
    if (!down_matrix)
49
39.2M
        return input[internal_channel[channel]][sample];
50
51
2.66M
    if (channel == 0)
52
1.25M
    {
53
1.25M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.25M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.25M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.40M
    } else {
57
1.40M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.40M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.40M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.40M
    }
61
2.66M
}
62
63
#ifndef HAS_LRINTF
64
35.6M
#define CLIP(sample, max, min) \
65
35.6M
if (sample >= 0.0f)            \
66
30.6M
{                              \
67
30.6M
    sample += 0.5f;            \
68
30.6M
    if (sample >= max)         \
69
30.6M
        sample = max;          \
70
30.6M
} else {                       \
71
5.00M
    sample += -0.5f;           \
72
5.00M
    if (sample <= min)         \
73
5.00M
        sample = min;          \
74
5.00M
}
75
#else
76
#define CLIP(sample, max, min) \
77
if (sample >= 0.0f)            \
78
{                              \
79
    if (sample >= max)         \
80
        sample = max;          \
81
} else {                       \
82
    if (sample <= min)         \
83
        sample = min;          \
84
}
85
#endif
86
87
8.07k
#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.90k
{
93
1.90k
    uint8_t ch, ch1;
94
1.90k
    uint16_t i;
95
96
1.90k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.90k
    {
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
967
    case CONV(2,0):
110
967
        if (hDecoder->upMatrix)
111
63
        {
112
63
            ch  = hDecoder->internal_channel[0];
113
107k
            for(i = 0; i < frame_len; i++)
114
107k
            {
115
107k
                real_t inp0 = input[ch][i];
116
117
107k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
107k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
107k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
107k
            }
122
904
        } else {
123
904
            ch  = hDecoder->internal_channel[0];
124
904
            ch1 = hDecoder->internal_channel[1];
125
1.41M
            for(i = 0; i < frame_len; i++)
126
1.41M
            {
127
1.41M
                real_t inp0 = input[ch ][i];
128
1.41M
                real_t inp1 = input[ch1][i];
129
130
1.41M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.41M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.41M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.41M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.41M
            }
136
904
        }
137
967
        break;
138
935
    default:
139
10.4k
        for (ch = 0; ch < channels; ch++)
140
9.53k
        {
141
13.3M
            for(i = 0; i < frame_len; i++)
142
13.3M
            {
143
13.3M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
13.3M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
13.3M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
13.3M
            }
149
9.53k
        }
150
935
        break;
151
1.90k
    }
152
1.90k
}
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.25k
{
158
1.25k
    uint8_t ch, ch1;
159
1.25k
    uint16_t i;
160
161
1.25k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.25k
    {
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
572
    case CONV(2,0):
176
572
        if (hDecoder->upMatrix)
177
35
        {
178
35
            ch = hDecoder->internal_channel[0];
179
49.9k
            for(i = 0; i < frame_len; i++)
180
49.9k
            {
181
49.9k
                real_t inp0 = input[ch][i];
182
183
49.9k
                inp0 *= 256.0f;
184
49.9k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
49.9k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
49.9k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
49.9k
            }
189
537
        } else {
190
537
            ch  = hDecoder->internal_channel[0];
191
537
            ch1 = hDecoder->internal_channel[1];
192
804k
            for(i = 0; i < frame_len; i++)
193
803k
            {
194
803k
                real_t inp0 = input[ch ][i];
195
803k
                real_t inp1 = input[ch1][i];
196
197
803k
                inp0 *= 256.0f;
198
803k
                inp1 *= 256.0f;
199
803k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
803k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
803k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
803k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
803k
            }
205
537
        }
206
572
        break;
207
679
    default:
208
6.81k
        for (ch = 0; ch < channels; ch++)
209
6.13k
        {
210
9.15M
            for(i = 0; i < frame_len; i++)
211
9.14M
            {
212
9.14M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
9.14M
                inp *= 256.0f;
215
9.14M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
9.14M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
9.14M
            }
219
6.13k
        }
220
679
        break;
221
1.25k
    }
222
1.25k
}
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.26k
{
228
1.26k
    uint8_t ch, ch1;
229
1.26k
    uint16_t i;
230
231
1.26k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.26k
    {
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
682
    case CONV(2,0):
246
682
        if (hDecoder->upMatrix)
247
31
        {
248
31
            ch = hDecoder->internal_channel[0];
249
48.0k
            for(i = 0; i < frame_len; i++)
250
48.0k
            {
251
48.0k
                real_t inp0 = input[ch][i];
252
253
48.0k
                inp0 *= 65536.0f;
254
48.0k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
48.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
48.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
48.0k
            }
259
651
        } else {
260
651
            ch  = hDecoder->internal_channel[0];
261
651
            ch1 = hDecoder->internal_channel[1];
262
988k
            for(i = 0; i < frame_len; i++)
263
987k
            {
264
987k
                real_t inp0 = input[ch ][i];
265
987k
                real_t inp1 = input[ch1][i];
266
267
987k
                inp0 *= 65536.0f;
268
987k
                inp1 *= 65536.0f;
269
987k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
987k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
987k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
987k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
987k
            }
275
651
        }
276
682
        break;
277
587
    default:
278
5.24k
        for (ch = 0; ch < channels; ch++)
279
4.66k
        {
280
6.53M
            for(i = 0; i < frame_len; i++)
281
6.53M
            {
282
6.53M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.53M
                inp *= 65536.0f;
285
6.53M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.53M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.53M
            }
289
4.66k
        }
290
587
        break;
291
1.26k
    }
292
1.26k
}
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
614
{
298
614
    uint8_t ch, ch1;
299
614
    uint16_t i;
300
301
614
    switch (CONV(channels,hDecoder->downMatrix))
302
614
    {
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
154
    case CONV(2,0):
312
154
        if (hDecoder->upMatrix)
313
17
        {
314
17
            ch = hDecoder->internal_channel[0];
315
29.3k
            for(i = 0; i < frame_len; i++)
316
29.3k
            {
317
29.3k
                real_t inp0 = input[ch][i];
318
29.3k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
29.3k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
29.3k
            }
321
137
        } else {
322
137
            ch  = hDecoder->internal_channel[0];
323
137
            ch1 = hDecoder->internal_channel[1];
324
215k
            for(i = 0; i < frame_len; i++)
325
215k
            {
326
215k
                real_t inp0 = input[ch ][i];
327
215k
                real_t inp1 = input[ch1][i];
328
215k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
215k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
215k
            }
331
137
        }
332
154
        break;
333
460
    default:
334
4.72k
        for (ch = 0; ch < channels; ch++)
335
4.26k
        {
336
6.16M
            for(i = 0; i < frame_len; i++)
337
6.16M
            {
338
6.16M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.16M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.16M
            }
341
4.26k
        }
342
460
        break;
343
614
    }
344
614
}
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
517
{
350
517
    uint8_t ch, ch1;
351
517
    uint16_t i;
352
353
517
    switch (CONV(channels,hDecoder->downMatrix))
354
517
    {
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
151
    case CONV(2,0):
364
151
        if (hDecoder->upMatrix)
365
25
        {
366
25
            ch = hDecoder->internal_channel[0];
367
38.7k
            for(i = 0; i < frame_len; i++)
368
38.7k
            {
369
38.7k
                real_t inp0 = input[ch][i];
370
38.7k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
38.7k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
38.7k
            }
373
126
        } else {
374
126
            ch  = hDecoder->internal_channel[0];
375
126
            ch1 = hDecoder->internal_channel[1];
376
161k
            for(i = 0; i < frame_len; i++)
377
161k
            {
378
161k
                real_t inp0 = input[ch ][i];
379
161k
                real_t inp1 = input[ch1][i];
380
161k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
161k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
161k
            }
383
126
        }
384
151
        break;
385
366
    default:
386
4.61k
        for (ch = 0; ch < channels; ch++)
387
4.25k
        {
388
6.77M
            for(i = 0; i < frame_len; i++)
389
6.77M
            {
390
6.77M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.77M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.77M
            }
393
4.25k
        }
394
366
        break;
395
517
    }
396
517
}
397
398
void *output_to_PCM(NeAACDecStruct *hDecoder,
399
                    real_t **input, void *sample_buffer, uint8_t channels,
400
                    uint16_t frame_len, uint8_t format)
401
11.1k
{
402
11.1k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
11.1k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
11.1k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
11.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
11.1k
    switch (format)
413
11.1k
    {
414
3.80k
    case FAAD_FMT_16BIT:
415
3.80k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.80k
        break;
417
2.50k
    case FAAD_FMT_24BIT:
418
2.50k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.50k
        break;
420
2.53k
    case FAAD_FMT_32BIT:
421
2.53k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.53k
        break;
423
1.22k
    case FAAD_FMT_FLOAT:
424
1.22k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.22k
        break;
426
1.03k
    case FAAD_FMT_DOUBLE:
427
1.03k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.03k
        break;
429
11.1k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
11.1k
    return sample_buffer;
437
11.1k
}
output_to_PCM
Line
Count
Source
401
5.55k
{
402
5.55k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.55k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.55k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.55k
    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.55k
    switch (format)
413
5.55k
    {
414
1.90k
    case FAAD_FMT_16BIT:
415
1.90k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.90k
        break;
417
1.25k
    case FAAD_FMT_24BIT:
418
1.25k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.25k
        break;
420
1.26k
    case FAAD_FMT_32BIT:
421
1.26k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.26k
        break;
423
614
    case FAAD_FMT_FLOAT:
424
614
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
614
        break;
426
517
    case FAAD_FMT_DOUBLE:
427
517
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
517
        break;
429
5.55k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.55k
    return sample_buffer;
437
5.55k
}
output_to_PCM
Line
Count
Source
401
5.55k
{
402
5.55k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.55k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.55k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.55k
    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.55k
    switch (format)
413
5.55k
    {
414
1.90k
    case FAAD_FMT_16BIT:
415
1.90k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.90k
        break;
417
1.25k
    case FAAD_FMT_24BIT:
418
1.25k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.25k
        break;
420
1.26k
    case FAAD_FMT_32BIT:
421
1.26k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.26k
        break;
423
614
    case FAAD_FMT_FLOAT:
424
614
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
614
        break;
426
517
    case FAAD_FMT_DOUBLE:
427
517
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
517
        break;
429
5.55k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.55k
    return sample_buffer;
437
5.55k
}
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.2M
{
449
29.2M
    real_t C;
450
29.2M
    if (up_matrix == 1)
451
287k
        return input[internal_channel[0]][sample];
452
453
28.9M
    if (!down_matrix)
454
28.2M
        return input[internal_channel[channel]][sample];
455
456
641k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
641k
    if (channel == 0)
458
308k
    {
459
308k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
308k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
308k
        return core + C + L_S;
462
332k
    } else {
463
332k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
332k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
332k
        return core + C + R_S;
466
332k
    }
467
641k
}
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.64k
{
473
6.64k
    uint8_t ch;
474
6.64k
    uint16_t i;
475
6.64k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.64k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.64k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
47.7k
    for (ch = 0; ch < channels; ch++)
481
41.0k
    {
482
41.0k
        switch (format)
483
41.0k
        {
484
12.2k
        case FAAD_FMT_16BIT:
485
17.8M
            for(i = 0; i < frame_len; i++)
486
17.8M
            {
487
17.8M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
17.8M
                    hDecoder->internal_channel);
489
17.8M
                if (tmp >= 0)
490
16.7M
                {
491
16.7M
                    tmp += (1 << (REAL_BITS-1));
492
16.7M
                    if (tmp >= REAL_CONST(32767))
493
61.0k
                    {
494
61.0k
                        tmp = REAL_CONST(32767);
495
61.0k
                    }
496
16.7M
                } else {
497
1.10M
                    tmp += -(1 << (REAL_BITS-1));
498
1.10M
                    if (tmp <= REAL_CONST(-32768))
499
62.5k
                    {
500
62.5k
                        tmp = REAL_CONST(-32768);
501
62.5k
                    }
502
1.10M
                }
503
17.8M
                tmp >>= REAL_BITS;
504
17.8M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
17.8M
            }
506
12.2k
            break;
507
13.0k
        case FAAD_FMT_24BIT:
508
19.1M
            for(i = 0; i < frame_len; i++)
509
19.1M
            {
510
19.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
19.1M
                    hDecoder->internal_channel);
512
19.1M
                if (tmp >= 0)
513
17.6M
                {
514
17.6M
                    tmp += (1 << (REAL_BITS-9));
515
17.6M
                    tmp >>= (REAL_BITS-8);
516
17.6M
                    if (tmp >= 8388607)
517
24.0k
                    {
518
24.0k
                        tmp = 8388607;
519
24.0k
                    }
520
17.6M
                } else {
521
1.49M
                    tmp += -(1 << (REAL_BITS-9));
522
1.49M
                    tmp >>= (REAL_BITS-8);
523
1.49M
                    if (tmp <= -8388608)
524
24.5k
                    {
525
24.5k
                        tmp = -8388608;
526
24.5k
                    }
527
1.49M
                }
528
19.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
19.1M
            }
530
13.0k
            break;
531
9.20k
        case FAAD_FMT_32BIT:
532
9.20k
            exp = 16 - REAL_BITS;
533
9.20k
            half = 1 << (exp - 1);
534
9.20k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
11.7M
            for(i = 0; i < frame_len; i++)
536
11.7M
            {
537
11.7M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
11.7M
                    hDecoder->internal_channel);
539
11.7M
                if (tmp >= 0)
540
10.8M
                {
541
10.8M
                    tmp += half;
542
10.8M
                } else {
543
877k
                    tmp += -half;
544
877k
                }
545
11.7M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
11.7M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
11.7M
            }
548
9.20k
            break;
549
6.55k
        case FAAD_FMT_FIXED:
550
9.71M
            for(i = 0; i < frame_len; i++)
551
9.70M
            {
552
9.70M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
9.70M
                    hDecoder->internal_channel);
554
9.70M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
9.70M
            }
556
6.55k
            break;
557
41.0k
        }
558
41.0k
    }
559
560
6.64k
    return sample_buffer;
561
6.64k
}
output_to_PCM
Line
Count
Source
472
3.32k
{
473
3.32k
    uint8_t ch;
474
3.32k
    uint16_t i;
475
3.32k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.32k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.32k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.8k
    for (ch = 0; ch < channels; ch++)
481
20.5k
    {
482
20.5k
        switch (format)
483
20.5k
        {
484
6.13k
        case FAAD_FMT_16BIT:
485
8.91M
            for(i = 0; i < frame_len; i++)
486
8.90M
            {
487
8.90M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.90M
                    hDecoder->internal_channel);
489
8.90M
                if (tmp >= 0)
490
8.35M
                {
491
8.35M
                    tmp += (1 << (REAL_BITS-1));
492
8.35M
                    if (tmp >= REAL_CONST(32767))
493
30.5k
                    {
494
30.5k
                        tmp = REAL_CONST(32767);
495
30.5k
                    }
496
8.35M
                } else {
497
550k
                    tmp += -(1 << (REAL_BITS-1));
498
550k
                    if (tmp <= REAL_CONST(-32768))
499
31.2k
                    {
500
31.2k
                        tmp = REAL_CONST(-32768);
501
31.2k
                    }
502
550k
                }
503
8.90M
                tmp >>= REAL_BITS;
504
8.90M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.90M
            }
506
6.13k
            break;
507
6.53k
        case FAAD_FMT_24BIT:
508
9.57M
            for(i = 0; i < frame_len; i++)
509
9.57M
            {
510
9.57M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
9.57M
                    hDecoder->internal_channel);
512
9.57M
                if (tmp >= 0)
513
8.82M
                {
514
8.82M
                    tmp += (1 << (REAL_BITS-9));
515
8.82M
                    tmp >>= (REAL_BITS-8);
516
8.82M
                    if (tmp >= 8388607)
517
12.0k
                    {
518
12.0k
                        tmp = 8388607;
519
12.0k
                    }
520
8.82M
                } else {
521
748k
                    tmp += -(1 << (REAL_BITS-9));
522
748k
                    tmp >>= (REAL_BITS-8);
523
748k
                    if (tmp <= -8388608)
524
12.2k
                    {
525
12.2k
                        tmp = -8388608;
526
12.2k
                    }
527
748k
                }
528
9.57M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
9.57M
            }
530
6.53k
            break;
531
4.60k
        case FAAD_FMT_32BIT:
532
4.60k
            exp = 16 - REAL_BITS;
533
4.60k
            half = 1 << (exp - 1);
534
4.60k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.88M
            for(i = 0; i < frame_len; i++)
536
5.87M
            {
537
5.87M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.87M
                    hDecoder->internal_channel);
539
5.87M
                if (tmp >= 0)
540
5.43M
                {
541
5.43M
                    tmp += half;
542
5.43M
                } else {
543
438k
                    tmp += -half;
544
438k
                }
545
5.87M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.87M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.87M
            }
548
4.60k
            break;
549
3.27k
        case FAAD_FMT_FIXED:
550
4.85M
            for(i = 0; i < frame_len; i++)
551
4.85M
            {
552
4.85M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.85M
                    hDecoder->internal_channel);
554
4.85M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.85M
            }
556
3.27k
            break;
557
20.5k
        }
558
20.5k
    }
559
560
3.32k
    return sample_buffer;
561
3.32k
}
output_to_PCM
Line
Count
Source
472
3.32k
{
473
3.32k
    uint8_t ch;
474
3.32k
    uint16_t i;
475
3.32k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.32k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.32k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
23.8k
    for (ch = 0; ch < channels; ch++)
481
20.5k
    {
482
20.5k
        switch (format)
483
20.5k
        {
484
6.13k
        case FAAD_FMT_16BIT:
485
8.91M
            for(i = 0; i < frame_len; i++)
486
8.90M
            {
487
8.90M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.90M
                    hDecoder->internal_channel);
489
8.90M
                if (tmp >= 0)
490
8.35M
                {
491
8.35M
                    tmp += (1 << (REAL_BITS-1));
492
8.35M
                    if (tmp >= REAL_CONST(32767))
493
30.5k
                    {
494
30.5k
                        tmp = REAL_CONST(32767);
495
30.5k
                    }
496
8.35M
                } else {
497
550k
                    tmp += -(1 << (REAL_BITS-1));
498
550k
                    if (tmp <= REAL_CONST(-32768))
499
31.2k
                    {
500
31.2k
                        tmp = REAL_CONST(-32768);
501
31.2k
                    }
502
550k
                }
503
8.90M
                tmp >>= REAL_BITS;
504
8.90M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.90M
            }
506
6.13k
            break;
507
6.53k
        case FAAD_FMT_24BIT:
508
9.57M
            for(i = 0; i < frame_len; i++)
509
9.57M
            {
510
9.57M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
9.57M
                    hDecoder->internal_channel);
512
9.57M
                if (tmp >= 0)
513
8.82M
                {
514
8.82M
                    tmp += (1 << (REAL_BITS-9));
515
8.82M
                    tmp >>= (REAL_BITS-8);
516
8.82M
                    if (tmp >= 8388607)
517
12.0k
                    {
518
12.0k
                        tmp = 8388607;
519
12.0k
                    }
520
8.82M
                } else {
521
748k
                    tmp += -(1 << (REAL_BITS-9));
522
748k
                    tmp >>= (REAL_BITS-8);
523
748k
                    if (tmp <= -8388608)
524
12.2k
                    {
525
12.2k
                        tmp = -8388608;
526
12.2k
                    }
527
748k
                }
528
9.57M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
9.57M
            }
530
6.53k
            break;
531
4.60k
        case FAAD_FMT_32BIT:
532
4.60k
            exp = 16 - REAL_BITS;
533
4.60k
            half = 1 << (exp - 1);
534
4.60k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.88M
            for(i = 0; i < frame_len; i++)
536
5.87M
            {
537
5.87M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.87M
                    hDecoder->internal_channel);
539
5.87M
                if (tmp >= 0)
540
5.43M
                {
541
5.43M
                    tmp += half;
542
5.43M
                } else {
543
438k
                    tmp += -half;
544
438k
                }
545
5.87M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.87M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.87M
            }
548
4.60k
            break;
549
3.27k
        case FAAD_FMT_FIXED:
550
4.85M
            for(i = 0; i < frame_len; i++)
551
4.85M
            {
552
4.85M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.85M
                    hDecoder->internal_channel);
554
4.85M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.85M
            }
556
3.27k
            break;
557
20.5k
        }
558
20.5k
    }
559
560
3.32k
    return sample_buffer;
561
3.32k
}
562
563
#endif