Coverage Report

Created: 2026-04-01 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/output.c
Line
Count
Source
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**
28
** $Id: output.c,v 1.47 2009/01/26 23:51:15 menno Exp $
29
**/
30
31
#include "common.h"
32
#include "structs.h"
33
34
#include "output.h"
35
36
#ifndef FIXED_POINT
37
38
39
14.0M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.56M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.13M
#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
38.2M
{
48
38.2M
    if (!down_matrix)
49
35.6M
        return input[internal_channel[channel]][sample];
50
51
2.56M
    if (channel == 0)
52
1.27M
    {
53
1.27M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.27M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.27M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.29M
    } else {
57
1.29M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.29M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.29M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.29M
    }
61
2.56M
}
62
63
#ifndef HAS_LRINTF
64
31.4M
#define CLIP(sample, max, min) \
65
31.4M
if (sample >= 0.0f)            \
66
26.8M
{                              \
67
26.8M
    sample += 0.5f;            \
68
26.8M
    if (sample >= max)         \
69
26.8M
        sample = max;          \
70
26.8M
} else {                       \
71
4.62M
    sample += -0.5f;           \
72
4.62M
    if (sample <= min)         \
73
4.62M
        sample = min;          \
74
4.62M
}
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.82k
#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.78k
{
93
1.78k
    uint8_t ch, ch1;
94
1.78k
    uint16_t i;
95
96
1.78k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.78k
    {
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
924
    case CONV(2,0):
110
924
        if (hDecoder->upMatrix)
111
60
        {
112
60
            ch  = hDecoder->internal_channel[0];
113
101k
            for(i = 0; i < frame_len; i++)
114
101k
            {
115
101k
                real_t inp0 = input[ch][i];
116
117
101k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
101k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
101k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
101k
            }
122
864
        } else {
123
864
            ch  = hDecoder->internal_channel[0];
124
864
            ch1 = hDecoder->internal_channel[1];
125
1.32M
            for(i = 0; i < frame_len; i++)
126
1.32M
            {
127
1.32M
                real_t inp0 = input[ch ][i];
128
1.32M
                real_t inp1 = input[ch1][i];
129
130
1.32M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.32M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.32M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.32M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.32M
            }
136
864
        }
137
924
        break;
138
865
    default:
139
8.89k
        for (ch = 0; ch < channels; ch++)
140
8.03k
        {
141
11.5M
            for(i = 0; i < frame_len; i++)
142
11.5M
            {
143
11.5M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
11.5M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
11.5M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
11.5M
            }
149
8.03k
        }
150
865
        break;
151
1.78k
    }
152
1.78k
}
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
642
    case CONV(2,0):
176
642
        if (hDecoder->upMatrix)
177
36
        {
178
36
            ch = hDecoder->internal_channel[0];
179
52.1k
            for(i = 0; i < frame_len; i++)
180
52.0k
            {
181
52.0k
                real_t inp0 = input[ch][i];
182
183
52.0k
                inp0 *= 256.0f;
184
52.0k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
52.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
52.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
52.0k
            }
189
606
        } else {
190
606
            ch  = hDecoder->internal_channel[0];
191
606
            ch1 = hDecoder->internal_channel[1];
192
892k
            for(i = 0; i < frame_len; i++)
193
892k
            {
194
892k
                real_t inp0 = input[ch ][i];
195
892k
                real_t inp1 = input[ch1][i];
196
197
892k
                inp0 *= 256.0f;
198
892k
                inp1 *= 256.0f;
199
892k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
892k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
892k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
892k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
892k
            }
205
606
        }
206
642
        break;
207
589
    default:
208
6.04k
        for (ch = 0; ch < channels; ch++)
209
5.45k
        {
210
7.71M
            for(i = 0; i < frame_len; i++)
211
7.71M
            {
212
7.71M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
7.71M
                inp *= 256.0f;
215
7.71M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
7.71M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
7.71M
            }
219
5.45k
        }
220
589
        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.08k
{
228
1.08k
    uint8_t ch, ch1;
229
1.08k
    uint16_t i;
230
231
1.08k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.08k
    {
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
560
    case CONV(2,0):
246
560
        if (hDecoder->upMatrix)
247
34
        {
248
34
            ch = hDecoder->internal_channel[0];
249
54.0k
            for(i = 0; i < frame_len; i++)
250
54.0k
            {
251
54.0k
                real_t inp0 = input[ch][i];
252
253
54.0k
                inp0 *= 65536.0f;
254
54.0k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
54.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
54.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
54.0k
            }
259
526
        } else {
260
526
            ch  = hDecoder->internal_channel[0];
261
526
            ch1 = hDecoder->internal_channel[1];
262
843k
            for(i = 0; i < frame_len; i++)
263
843k
            {
264
843k
                real_t inp0 = input[ch ][i];
265
843k
                real_t inp1 = input[ch1][i];
266
267
843k
                inp0 *= 65536.0f;
268
843k
                inp1 *= 65536.0f;
269
843k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
843k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
843k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
843k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
843k
            }
275
526
        }
276
560
        break;
277
529
    default:
278
4.89k
        for (ch = 0; ch < channels; ch++)
279
4.37k
        {
280
5.94M
            for(i = 0; i < frame_len; i++)
281
5.94M
            {
282
5.94M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
5.94M
                inp *= 65536.0f;
285
5.94M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
5.94M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
5.94M
            }
289
4.37k
        }
290
529
        break;
291
1.08k
    }
292
1.08k
}
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
655
{
298
655
    uint8_t ch, ch1;
299
655
    uint16_t i;
300
301
655
    switch (CONV(channels,hDecoder->downMatrix))
302
655
    {
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
169
    case CONV(2,0):
312
169
        if (hDecoder->upMatrix)
313
15
        {
314
15
            ch = hDecoder->internal_channel[0];
315
24.4k
            for(i = 0; i < frame_len; i++)
316
24.4k
            {
317
24.4k
                real_t inp0 = input[ch][i];
318
24.4k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
24.4k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
24.4k
            }
321
154
        } else {
322
154
            ch  = hDecoder->internal_channel[0];
323
154
            ch1 = hDecoder->internal_channel[1];
324
232k
            for(i = 0; i < frame_len; i++)
325
232k
            {
326
232k
                real_t inp0 = input[ch ][i];
327
232k
                real_t inp1 = input[ch1][i];
328
232k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
232k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
232k
            }
331
154
        }
332
169
        break;
333
486
    default:
334
4.90k
        for (ch = 0; ch < channels; ch++)
335
4.41k
        {
336
6.21M
            for(i = 0; i < frame_len; i++)
337
6.20M
            {
338
6.20M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.20M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.20M
            }
341
4.41k
        }
342
486
        break;
343
655
    }
344
655
}
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
600
{
350
600
    uint8_t ch, ch1;
351
600
    uint16_t i;
352
353
600
    switch (CONV(channels,hDecoder->downMatrix))
354
600
    {
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
166
    case CONV(2,0):
364
166
        if (hDecoder->upMatrix)
365
20
        {
366
20
            ch = hDecoder->internal_channel[0];
367
38.5k
            for(i = 0; i < frame_len; i++)
368
38.5k
            {
369
38.5k
                real_t inp0 = input[ch][i];
370
38.5k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
38.5k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
38.5k
            }
373
146
        } else {
374
146
            ch  = hDecoder->internal_channel[0];
375
146
            ch1 = hDecoder->internal_channel[1];
376
196k
            for(i = 0; i < frame_len; i++)
377
196k
            {
378
196k
                real_t inp0 = input[ch ][i];
379
196k
                real_t inp1 = input[ch1][i];
380
196k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
196k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
196k
            }
383
146
        }
384
166
        break;
385
434
    default:
386
4.86k
        for (ch = 0; ch < channels; ch++)
387
4.43k
        {
388
6.84M
            for(i = 0; i < frame_len; i++)
389
6.84M
            {
390
6.84M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.84M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.84M
            }
393
4.43k
        }
394
434
        break;
395
600
    }
396
600
}
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.7k
{
402
10.7k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
10.7k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
10.7k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
10.7k
    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.7k
    switch (format)
413
10.7k
    {
414
3.57k
    case FAAD_FMT_16BIT:
415
3.57k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.57k
        break;
417
2.46k
    case FAAD_FMT_24BIT:
418
2.46k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.46k
        break;
420
2.17k
    case FAAD_FMT_32BIT:
421
2.17k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.17k
        break;
423
1.31k
    case FAAD_FMT_FLOAT:
424
1.31k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.31k
        break;
426
1.20k
    case FAAD_FMT_DOUBLE:
427
1.20k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.20k
        break;
429
10.7k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
10.7k
    return sample_buffer;
437
10.7k
}
output_to_PCM
Line
Count
Source
401
5.36k
{
402
5.36k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.36k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.36k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.36k
    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.36k
    switch (format)
413
5.36k
    {
414
1.78k
    case FAAD_FMT_16BIT:
415
1.78k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.78k
        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.08k
    case FAAD_FMT_32BIT:
421
1.08k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.08k
        break;
423
655
    case FAAD_FMT_FLOAT:
424
655
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
655
        break;
426
600
    case FAAD_FMT_DOUBLE:
427
600
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
600
        break;
429
5.36k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.36k
    return sample_buffer;
437
5.36k
}
output_to_PCM
Line
Count
Source
401
5.36k
{
402
5.36k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.36k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.36k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.36k
    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.36k
    switch (format)
413
5.36k
    {
414
1.78k
    case FAAD_FMT_16BIT:
415
1.78k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.78k
        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.08k
    case FAAD_FMT_32BIT:
421
1.08k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.08k
        break;
423
655
    case FAAD_FMT_FLOAT:
424
655
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
655
        break;
426
600
    case FAAD_FMT_DOUBLE:
427
600
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
600
        break;
429
5.36k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.36k
    return sample_buffer;
437
5.36k
}
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
26.9M
{
449
26.9M
    real_t C;
450
26.9M
    if (up_matrix == 1)
451
305k
        return input[internal_channel[0]][sample];
452
453
26.6M
    if (!down_matrix)
454
26.0M
        return input[internal_channel[channel]][sample];
455
456
587k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
587k
    if (channel == 0)
458
284k
    {
459
284k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
284k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
284k
        return core + C + L_S;
462
303k
    } else {
463
303k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
303k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
303k
        return core + C + R_S;
466
303k
    }
467
587k
}
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
5.86k
{
473
5.86k
    uint8_t ch;
474
5.86k
    uint16_t i;
475
5.86k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.86k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.86k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
43.4k
    for (ch = 0; ch < channels; ch++)
481
37.6k
    {
482
37.6k
        switch (format)
483
37.6k
        {
484
11.8k
        case FAAD_FMT_16BIT:
485
17.9M
            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.4M
                {
491
16.4M
                    tmp += (1 << (REAL_BITS-1));
492
16.4M
                    if (tmp >= REAL_CONST(32767))
493
33.5k
                    {
494
33.5k
                        tmp = REAL_CONST(32767);
495
33.5k
                    }
496
16.4M
                } else {
497
1.43M
                    tmp += -(1 << (REAL_BITS-1));
498
1.43M
                    if (tmp <= REAL_CONST(-32768))
499
36.2k
                    {
500
36.2k
                        tmp = REAL_CONST(-32768);
501
36.2k
                    }
502
1.43M
                }
503
17.8M
                tmp >>= REAL_BITS;
504
17.8M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
17.8M
            }
506
11.8k
            break;
507
11.0k
        case FAAD_FMT_24BIT:
508
15.6M
            for(i = 0; i < frame_len; i++)
509
15.6M
            {
510
15.6M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
15.6M
                    hDecoder->internal_channel);
512
15.6M
                if (tmp >= 0)
513
14.4M
                {
514
14.4M
                    tmp += (1 << (REAL_BITS-9));
515
14.4M
                    tmp >>= (REAL_BITS-8);
516
14.4M
                    if (tmp >= 8388607)
517
28.5k
                    {
518
28.5k
                        tmp = 8388607;
519
28.5k
                    }
520
14.4M
                } else {
521
1.21M
                    tmp += -(1 << (REAL_BITS-9));
522
1.21M
                    tmp >>= (REAL_BITS-8);
523
1.21M
                    if (tmp <= -8388608)
524
28.5k
                    {
525
28.5k
                        tmp = -8388608;
526
28.5k
                    }
527
1.21M
                }
528
15.6M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
15.6M
            }
530
11.0k
            break;
531
8.02k
        case FAAD_FMT_32BIT:
532
8.02k
            exp = 16 - REAL_BITS;
533
8.02k
            half = 1 << (exp - 1);
534
8.02k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
11.3M
            for(i = 0; i < frame_len; i++)
536
11.3M
            {
537
11.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
11.3M
                    hDecoder->internal_channel);
539
11.3M
                if (tmp >= 0)
540
10.4M
                {
541
10.4M
                    tmp += half;
542
10.4M
                } else {
543
932k
                    tmp += -half;
544
932k
                }
545
11.3M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
11.3M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
11.3M
            }
548
8.02k
            break;
549
6.64k
        case FAAD_FMT_FIXED:
550
8.96M
            for(i = 0; i < frame_len; i++)
551
8.95M
            {
552
8.95M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
8.95M
                    hDecoder->internal_channel);
554
8.95M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
8.95M
            }
556
6.64k
            break;
557
37.6k
        }
558
37.6k
    }
559
560
5.86k
    return sample_buffer;
561
5.86k
}
output_to_PCM
Line
Count
Source
472
2.93k
{
473
2.93k
    uint8_t ch;
474
2.93k
    uint16_t i;
475
2.93k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.93k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.93k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
21.7k
    for (ch = 0; ch < channels; ch++)
481
18.8k
    {
482
18.8k
        switch (format)
483
18.8k
        {
484
5.94k
        case FAAD_FMT_16BIT:
485
8.95M
            for(i = 0; i < frame_len; i++)
486
8.94M
            {
487
8.94M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.94M
                    hDecoder->internal_channel);
489
8.94M
                if (tmp >= 0)
490
8.22M
                {
491
8.22M
                    tmp += (1 << (REAL_BITS-1));
492
8.22M
                    if (tmp >= REAL_CONST(32767))
493
16.7k
                    {
494
16.7k
                        tmp = REAL_CONST(32767);
495
16.7k
                    }
496
8.22M
                } else {
497
718k
                    tmp += -(1 << (REAL_BITS-1));
498
718k
                    if (tmp <= REAL_CONST(-32768))
499
18.1k
                    {
500
18.1k
                        tmp = REAL_CONST(-32768);
501
18.1k
                    }
502
718k
                }
503
8.94M
                tmp >>= REAL_BITS;
504
8.94M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.94M
            }
506
5.94k
            break;
507
5.54k
        case FAAD_FMT_24BIT:
508
7.84M
            for(i = 0; i < frame_len; i++)
509
7.83M
            {
510
7.83M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
7.83M
                    hDecoder->internal_channel);
512
7.83M
                if (tmp >= 0)
513
7.23M
                {
514
7.23M
                    tmp += (1 << (REAL_BITS-9));
515
7.23M
                    tmp >>= (REAL_BITS-8);
516
7.23M
                    if (tmp >= 8388607)
517
14.2k
                    {
518
14.2k
                        tmp = 8388607;
519
14.2k
                    }
520
7.23M
                } else {
521
605k
                    tmp += -(1 << (REAL_BITS-9));
522
605k
                    tmp >>= (REAL_BITS-8);
523
605k
                    if (tmp <= -8388608)
524
14.2k
                    {
525
14.2k
                        tmp = -8388608;
526
14.2k
                    }
527
605k
                }
528
7.83M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
7.83M
            }
530
5.54k
            break;
531
4.01k
        case FAAD_FMT_32BIT:
532
4.01k
            exp = 16 - REAL_BITS;
533
4.01k
            half = 1 << (exp - 1);
534
4.01k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.69M
            for(i = 0; i < frame_len; i++)
536
5.69M
            {
537
5.69M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.69M
                    hDecoder->internal_channel);
539
5.69M
                if (tmp >= 0)
540
5.22M
                {
541
5.22M
                    tmp += half;
542
5.22M
                } else {
543
466k
                    tmp += -half;
544
466k
                }
545
5.69M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.69M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.69M
            }
548
4.01k
            break;
549
3.32k
        case FAAD_FMT_FIXED:
550
4.48M
            for(i = 0; i < frame_len; i++)
551
4.47M
            {
552
4.47M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.47M
                    hDecoder->internal_channel);
554
4.47M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.47M
            }
556
3.32k
            break;
557
18.8k
        }
558
18.8k
    }
559
560
2.93k
    return sample_buffer;
561
2.93k
}
output_to_PCM
Line
Count
Source
472
2.93k
{
473
2.93k
    uint8_t ch;
474
2.93k
    uint16_t i;
475
2.93k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.93k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.93k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
21.7k
    for (ch = 0; ch < channels; ch++)
481
18.8k
    {
482
18.8k
        switch (format)
483
18.8k
        {
484
5.94k
        case FAAD_FMT_16BIT:
485
8.95M
            for(i = 0; i < frame_len; i++)
486
8.94M
            {
487
8.94M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.94M
                    hDecoder->internal_channel);
489
8.94M
                if (tmp >= 0)
490
8.22M
                {
491
8.22M
                    tmp += (1 << (REAL_BITS-1));
492
8.22M
                    if (tmp >= REAL_CONST(32767))
493
16.7k
                    {
494
16.7k
                        tmp = REAL_CONST(32767);
495
16.7k
                    }
496
8.22M
                } else {
497
718k
                    tmp += -(1 << (REAL_BITS-1));
498
718k
                    if (tmp <= REAL_CONST(-32768))
499
18.1k
                    {
500
18.1k
                        tmp = REAL_CONST(-32768);
501
18.1k
                    }
502
718k
                }
503
8.94M
                tmp >>= REAL_BITS;
504
8.94M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.94M
            }
506
5.94k
            break;
507
5.54k
        case FAAD_FMT_24BIT:
508
7.84M
            for(i = 0; i < frame_len; i++)
509
7.83M
            {
510
7.83M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
7.83M
                    hDecoder->internal_channel);
512
7.83M
                if (tmp >= 0)
513
7.23M
                {
514
7.23M
                    tmp += (1 << (REAL_BITS-9));
515
7.23M
                    tmp >>= (REAL_BITS-8);
516
7.23M
                    if (tmp >= 8388607)
517
14.2k
                    {
518
14.2k
                        tmp = 8388607;
519
14.2k
                    }
520
7.23M
                } else {
521
605k
                    tmp += -(1 << (REAL_BITS-9));
522
605k
                    tmp >>= (REAL_BITS-8);
523
605k
                    if (tmp <= -8388608)
524
14.2k
                    {
525
14.2k
                        tmp = -8388608;
526
14.2k
                    }
527
605k
                }
528
7.83M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
7.83M
            }
530
5.54k
            break;
531
4.01k
        case FAAD_FMT_32BIT:
532
4.01k
            exp = 16 - REAL_BITS;
533
4.01k
            half = 1 << (exp - 1);
534
4.01k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.69M
            for(i = 0; i < frame_len; i++)
536
5.69M
            {
537
5.69M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.69M
                    hDecoder->internal_channel);
539
5.69M
                if (tmp >= 0)
540
5.22M
                {
541
5.22M
                    tmp += half;
542
5.22M
                } else {
543
466k
                    tmp += -half;
544
466k
                }
545
5.69M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.69M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.69M
            }
548
4.01k
            break;
549
3.32k
        case FAAD_FMT_FIXED:
550
4.48M
            for(i = 0; i < frame_len; i++)
551
4.47M
            {
552
4.47M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.47M
                    hDecoder->internal_channel);
554
4.47M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.47M
            }
556
3.32k
            break;
557
18.8k
        }
558
18.8k
    }
559
560
2.93k
    return sample_buffer;
561
2.93k
}
562
563
#endif