Coverage Report

Created: 2026-04-12 06:11

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.4M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.55M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.11M
#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.7M
{
48
38.7M
    if (!down_matrix)
49
36.1M
        return input[internal_channel[channel]][sample];
50
51
2.55M
    if (channel == 0)
52
1.26M
    {
53
1.26M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.26M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.26M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.28M
    } else {
57
1.28M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.28M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.28M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.28M
    }
61
2.55M
}
62
63
#ifndef HAS_LRINTF
64
31.7M
#define CLIP(sample, max, min) \
65
31.7M
if (sample >= 0.0f)            \
66
27.0M
{                              \
67
27.0M
    sample += 0.5f;            \
68
27.0M
    if (sample >= max)         \
69
27.0M
        sample = max;          \
70
27.0M
} else {                       \
71
4.72M
    sample += -0.5f;           \
72
4.72M
    if (sample <= min)         \
73
4.72M
        sample = min;          \
74
4.72M
}
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.05k
#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.82k
{
93
1.82k
    uint8_t ch, ch1;
94
1.82k
    uint16_t i;
95
96
1.82k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.82k
    {
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
954
    case CONV(2,0):
110
954
        if (hDecoder->upMatrix)
111
60
        {
112
60
            ch  = hDecoder->internal_channel[0];
113
96.8k
            for(i = 0; i < frame_len; i++)
114
96.8k
            {
115
96.8k
                real_t inp0 = input[ch][i];
116
117
96.8k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
96.8k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
96.8k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
96.8k
            }
122
894
        } else {
123
894
            ch  = hDecoder->internal_channel[0];
124
894
            ch1 = hDecoder->internal_channel[1];
125
1.36M
            for(i = 0; i < frame_len; i++)
126
1.36M
            {
127
1.36M
                real_t inp0 = input[ch ][i];
128
1.36M
                real_t inp1 = input[ch1][i];
129
130
1.36M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.36M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.36M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.36M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.36M
            }
136
894
        }
137
954
        break;
138
868
    default:
139
8.90k
        for (ch = 0; ch < channels; ch++)
140
8.03k
        {
141
11.6M
            for(i = 0; i < frame_len; i++)
142
11.6M
            {
143
11.6M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
11.6M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
11.6M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
11.6M
            }
149
8.03k
        }
150
868
        break;
151
1.82k
    }
152
1.82k
}
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
648
    case CONV(2,0):
176
648
        if (hDecoder->upMatrix)
177
41
        {
178
41
            ch = hDecoder->internal_channel[0];
179
58.2k
            for(i = 0; i < frame_len; i++)
180
58.2k
            {
181
58.2k
                real_t inp0 = input[ch][i];
182
183
58.2k
                inp0 *= 256.0f;
184
58.2k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
58.2k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
58.2k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
58.2k
            }
189
607
        } else {
190
607
            ch  = hDecoder->internal_channel[0];
191
607
            ch1 = hDecoder->internal_channel[1];
192
894k
            for(i = 0; i < frame_len; i++)
193
893k
            {
194
893k
                real_t inp0 = input[ch ][i];
195
893k
                real_t inp1 = input[ch1][i];
196
197
893k
                inp0 *= 256.0f;
198
893k
                inp1 *= 256.0f;
199
893k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
893k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
893k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
893k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
893k
            }
205
607
        }
206
648
        break;
207
609
    default:
208
6.04k
        for (ch = 0; ch < channels; ch++)
209
5.43k
        {
210
7.58M
            for(i = 0; i < frame_len; i++)
211
7.57M
            {
212
7.57M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
7.57M
                inp *= 256.0f;
215
7.57M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
7.57M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
7.57M
            }
219
5.43k
        }
220
609
        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.14k
{
228
1.14k
    uint8_t ch, ch1;
229
1.14k
    uint16_t i;
230
231
1.14k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.14k
    {
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
598
    case CONV(2,0):
246
598
        if (hDecoder->upMatrix)
247
42
        {
248
42
            ch = hDecoder->internal_channel[0];
249
63.1k
            for(i = 0; i < frame_len; i++)
250
63.1k
            {
251
63.1k
                real_t inp0 = input[ch][i];
252
253
63.1k
                inp0 *= 65536.0f;
254
63.1k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
63.1k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
63.1k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
63.1k
            }
259
556
        } else {
260
556
            ch  = hDecoder->internal_channel[0];
261
556
            ch1 = hDecoder->internal_channel[1];
262
873k
            for(i = 0; i < frame_len; i++)
263
873k
            {
264
873k
                real_t inp0 = input[ch ][i];
265
873k
                real_t inp1 = input[ch1][i];
266
267
873k
                inp0 *= 65536.0f;
268
873k
                inp1 *= 65536.0f;
269
873k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
873k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
873k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
873k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
873k
            }
275
556
        }
276
598
        break;
277
546
    default:
278
4.97k
        for (ch = 0; ch < channels; ch++)
279
4.43k
        {
280
6.09M
            for(i = 0; i < frame_len; i++)
281
6.09M
            {
282
6.09M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.09M
                inp *= 65536.0f;
285
6.09M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.09M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.09M
            }
289
4.43k
        }
290
546
        break;
291
1.14k
    }
292
1.14k
}
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
662
{
298
662
    uint8_t ch, ch1;
299
662
    uint16_t i;
300
301
662
    switch (CONV(channels,hDecoder->downMatrix))
302
662
    {
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
173
    case CONV(2,0):
312
173
        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
159
        } else {
322
159
            ch  = hDecoder->internal_channel[0];
323
159
            ch1 = hDecoder->internal_channel[1];
324
241k
            for(i = 0; i < frame_len; i++)
325
241k
            {
326
241k
                real_t inp0 = input[ch ][i];
327
241k
                real_t inp1 = input[ch1][i];
328
241k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
241k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
241k
            }
331
159
        }
332
173
        break;
333
489
    default:
334
5.08k
        for (ch = 0; ch < channels; ch++)
335
4.59k
        {
336
6.75M
            for(i = 0; i < frame_len; i++)
337
6.74M
            {
338
6.74M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.74M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.74M
            }
341
4.59k
        }
342
489
        break;
343
662
    }
344
662
}
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
619
{
350
619
    uint8_t ch, ch1;
351
619
    uint16_t i;
352
353
619
    switch (CONV(channels,hDecoder->downMatrix))
354
619
    {
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
177
    case CONV(2,0):
364
177
        if (hDecoder->upMatrix)
365
28
        {
366
28
            ch = hDecoder->internal_channel[0];
367
53.7k
            for(i = 0; i < frame_len; i++)
368
53.7k
            {
369
53.7k
                real_t inp0 = input[ch][i];
370
53.7k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
53.7k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
53.7k
            }
373
149
        } else {
374
149
            ch  = hDecoder->internal_channel[0];
375
149
            ch1 = hDecoder->internal_channel[1];
376
194k
            for(i = 0; i < frame_len; i++)
377
194k
            {
378
194k
                real_t inp0 = input[ch ][i];
379
194k
                real_t inp1 = input[ch1][i];
380
194k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
194k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
194k
            }
383
149
        }
384
177
        break;
385
442
    default:
386
4.84k
        for (ch = 0; ch < channels; ch++)
387
4.39k
        {
388
6.70M
            for(i = 0; i < frame_len; i++)
389
6.69M
            {
390
6.69M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.69M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.69M
            }
393
4.39k
        }
394
442
        break;
395
619
    }
396
619
}
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.0k
{
402
11.0k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
11.0k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
11.0k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
11.0k
    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.0k
    switch (format)
413
11.0k
    {
414
3.64k
    case FAAD_FMT_16BIT:
415
3.64k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.64k
        break;
417
2.51k
    case FAAD_FMT_24BIT:
418
2.51k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.51k
        break;
420
2.28k
    case FAAD_FMT_32BIT:
421
2.28k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.28k
        break;
423
1.32k
    case FAAD_FMT_FLOAT:
424
1.32k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.32k
        break;
426
1.23k
    case FAAD_FMT_DOUBLE:
427
1.23k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.23k
        break;
429
11.0k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
11.0k
    return sample_buffer;
437
11.0k
}
output_to_PCM
Line
Count
Source
401
5.50k
{
402
5.50k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.50k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.50k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.50k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
5.50k
    switch (format)
413
5.50k
    {
414
1.82k
    case FAAD_FMT_16BIT:
415
1.82k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.82k
        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.14k
    case FAAD_FMT_32BIT:
421
1.14k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.14k
        break;
423
662
    case FAAD_FMT_FLOAT:
424
662
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
662
        break;
426
619
    case FAAD_FMT_DOUBLE:
427
619
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
619
        break;
429
5.50k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.50k
    return sample_buffer;
437
5.50k
}
output_to_PCM
Line
Count
Source
401
5.50k
{
402
5.50k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.50k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.50k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.50k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
5.50k
    switch (format)
413
5.50k
    {
414
1.82k
    case FAAD_FMT_16BIT:
415
1.82k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.82k
        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.14k
    case FAAD_FMT_32BIT:
421
1.14k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.14k
        break;
423
662
    case FAAD_FMT_FLOAT:
424
662
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
662
        break;
426
619
    case FAAD_FMT_DOUBLE:
427
619
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
619
        break;
429
5.50k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.50k
    return sample_buffer;
437
5.50k
}
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
27.6M
{
449
27.6M
    real_t C;
450
27.6M
    if (up_matrix == 1)
451
291k
        return input[internal_channel[0]][sample];
452
453
27.4M
    if (!down_matrix)
454
26.7M
        return input[internal_channel[channel]][sample];
455
456
674k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
674k
    if (channel == 0)
458
327k
    {
459
327k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
327k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
327k
        return core + C + L_S;
462
346k
    } else {
463
346k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
346k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
346k
        return core + C + R_S;
466
346k
    }
467
674k
}
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.21k
{
473
6.21k
    uint8_t ch;
474
6.21k
    uint16_t i;
475
6.21k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.21k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.21k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
45.3k
    for (ch = 0; ch < channels; ch++)
481
39.0k
    {
482
39.0k
        switch (format)
483
39.0k
        {
484
12.5k
        case FAAD_FMT_16BIT:
485
18.7M
            for(i = 0; i < frame_len; i++)
486
18.7M
            {
487
18.7M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
18.7M
                    hDecoder->internal_channel);
489
18.7M
                if (tmp >= 0)
490
16.9M
                {
491
16.9M
                    tmp += (1 << (REAL_BITS-1));
492
16.9M
                    if (tmp >= REAL_CONST(32767))
493
37.1k
                    {
494
37.1k
                        tmp = REAL_CONST(32767);
495
37.1k
                    }
496
16.9M
                } else {
497
1.72M
                    tmp += -(1 << (REAL_BITS-1));
498
1.72M
                    if (tmp <= REAL_CONST(-32768))
499
40.0k
                    {
500
40.0k
                        tmp = REAL_CONST(-32768);
501
40.0k
                    }
502
1.72M
                }
503
18.7M
                tmp >>= REAL_BITS;
504
18.7M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
18.7M
            }
506
12.5k
            break;
507
11.9k
        case FAAD_FMT_24BIT:
508
16.6M
            for(i = 0; i < frame_len; i++)
509
16.5M
            {
510
16.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
16.5M
                    hDecoder->internal_channel);
512
16.5M
                if (tmp >= 0)
513
15.3M
                {
514
15.3M
                    tmp += (1 << (REAL_BITS-9));
515
15.3M
                    tmp >>= (REAL_BITS-8);
516
15.3M
                    if (tmp >= 8388607)
517
27.7k
                    {
518
27.7k
                        tmp = 8388607;
519
27.7k
                    }
520
15.3M
                } else {
521
1.27M
                    tmp += -(1 << (REAL_BITS-9));
522
1.27M
                    tmp >>= (REAL_BITS-8);
523
1.27M
                    if (tmp <= -8388608)
524
28.0k
                    {
525
28.0k
                        tmp = -8388608;
526
28.0k
                    }
527
1.27M
                }
528
16.5M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
16.5M
            }
530
11.9k
            break;
531
8.04k
        case FAAD_FMT_32BIT:
532
8.04k
            exp = 16 - REAL_BITS;
533
8.04k
            half = 1 << (exp - 1);
534
8.04k
            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.3M
                {
541
10.3M
                    tmp += half;
542
10.3M
                } else {
543
922k
                    tmp += -half;
544
922k
                }
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.04k
            break;
549
6.50k
        case FAAD_FMT_FIXED:
550
8.78M
            for(i = 0; i < frame_len; i++)
551
8.77M
            {
552
8.77M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
8.77M
                    hDecoder->internal_channel);
554
8.77M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
8.77M
            }
556
6.50k
            break;
557
39.0k
        }
558
39.0k
    }
559
560
6.21k
    return sample_buffer;
561
6.21k
}
output_to_PCM
Line
Count
Source
472
3.10k
{
473
3.10k
    uint8_t ch;
474
3.10k
    uint16_t i;
475
3.10k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.10k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.10k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
22.6k
    for (ch = 0; ch < channels; ch++)
481
19.5k
    {
482
19.5k
        switch (format)
483
19.5k
        {
484
6.29k
        case FAAD_FMT_16BIT:
485
9.36M
            for(i = 0; i < frame_len; i++)
486
9.35M
            {
487
9.35M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.35M
                    hDecoder->internal_channel);
489
9.35M
                if (tmp >= 0)
490
8.49M
                {
491
8.49M
                    tmp += (1 << (REAL_BITS-1));
492
8.49M
                    if (tmp >= REAL_CONST(32767))
493
18.5k
                    {
494
18.5k
                        tmp = REAL_CONST(32767);
495
18.5k
                    }
496
8.49M
                } else {
497
863k
                    tmp += -(1 << (REAL_BITS-1));
498
863k
                    if (tmp <= REAL_CONST(-32768))
499
20.0k
                    {
500
20.0k
                        tmp = REAL_CONST(-32768);
501
20.0k
                    }
502
863k
                }
503
9.35M
                tmp >>= REAL_BITS;
504
9.35M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.35M
            }
506
6.29k
            break;
507
5.97k
        case FAAD_FMT_24BIT:
508
8.30M
            for(i = 0; i < frame_len; i++)
509
8.29M
            {
510
8.29M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.29M
                    hDecoder->internal_channel);
512
8.29M
                if (tmp >= 0)
513
7.66M
                {
514
7.66M
                    tmp += (1 << (REAL_BITS-9));
515
7.66M
                    tmp >>= (REAL_BITS-8);
516
7.66M
                    if (tmp >= 8388607)
517
13.8k
                    {
518
13.8k
                        tmp = 8388607;
519
13.8k
                    }
520
7.66M
                } else {
521
638k
                    tmp += -(1 << (REAL_BITS-9));
522
638k
                    tmp >>= (REAL_BITS-8);
523
638k
                    if (tmp <= -8388608)
524
14.0k
                    {
525
14.0k
                        tmp = -8388608;
526
14.0k
                    }
527
638k
                }
528
8.29M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.29M
            }
530
5.97k
            break;
531
4.02k
        case FAAD_FMT_32BIT:
532
4.02k
            exp = 16 - REAL_BITS;
533
4.02k
            half = 1 << (exp - 1);
534
4.02k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.65M
            for(i = 0; i < frame_len; i++)
536
5.65M
            {
537
5.65M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.65M
                    hDecoder->internal_channel);
539
5.65M
                if (tmp >= 0)
540
5.19M
                {
541
5.19M
                    tmp += half;
542
5.19M
                } else {
543
461k
                    tmp += -half;
544
461k
                }
545
5.65M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.65M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.65M
            }
548
4.02k
            break;
549
3.25k
        case FAAD_FMT_FIXED:
550
4.39M
            for(i = 0; i < frame_len; i++)
551
4.38M
            {
552
4.38M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.38M
                    hDecoder->internal_channel);
554
4.38M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.38M
            }
556
3.25k
            break;
557
19.5k
        }
558
19.5k
    }
559
560
3.10k
    return sample_buffer;
561
3.10k
}
output_to_PCM
Line
Count
Source
472
3.10k
{
473
3.10k
    uint8_t ch;
474
3.10k
    uint16_t i;
475
3.10k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.10k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.10k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
22.6k
    for (ch = 0; ch < channels; ch++)
481
19.5k
    {
482
19.5k
        switch (format)
483
19.5k
        {
484
6.29k
        case FAAD_FMT_16BIT:
485
9.36M
            for(i = 0; i < frame_len; i++)
486
9.35M
            {
487
9.35M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.35M
                    hDecoder->internal_channel);
489
9.35M
                if (tmp >= 0)
490
8.49M
                {
491
8.49M
                    tmp += (1 << (REAL_BITS-1));
492
8.49M
                    if (tmp >= REAL_CONST(32767))
493
18.5k
                    {
494
18.5k
                        tmp = REAL_CONST(32767);
495
18.5k
                    }
496
8.49M
                } else {
497
863k
                    tmp += -(1 << (REAL_BITS-1));
498
863k
                    if (tmp <= REAL_CONST(-32768))
499
20.0k
                    {
500
20.0k
                        tmp = REAL_CONST(-32768);
501
20.0k
                    }
502
863k
                }
503
9.35M
                tmp >>= REAL_BITS;
504
9.35M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.35M
            }
506
6.29k
            break;
507
5.97k
        case FAAD_FMT_24BIT:
508
8.30M
            for(i = 0; i < frame_len; i++)
509
8.29M
            {
510
8.29M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.29M
                    hDecoder->internal_channel);
512
8.29M
                if (tmp >= 0)
513
7.66M
                {
514
7.66M
                    tmp += (1 << (REAL_BITS-9));
515
7.66M
                    tmp >>= (REAL_BITS-8);
516
7.66M
                    if (tmp >= 8388607)
517
13.8k
                    {
518
13.8k
                        tmp = 8388607;
519
13.8k
                    }
520
7.66M
                } else {
521
638k
                    tmp += -(1 << (REAL_BITS-9));
522
638k
                    tmp >>= (REAL_BITS-8);
523
638k
                    if (tmp <= -8388608)
524
14.0k
                    {
525
14.0k
                        tmp = -8388608;
526
14.0k
                    }
527
638k
                }
528
8.29M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.29M
            }
530
5.97k
            break;
531
4.02k
        case FAAD_FMT_32BIT:
532
4.02k
            exp = 16 - REAL_BITS;
533
4.02k
            half = 1 << (exp - 1);
534
4.02k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.65M
            for(i = 0; i < frame_len; i++)
536
5.65M
            {
537
5.65M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
5.65M
                    hDecoder->internal_channel);
539
5.65M
                if (tmp >= 0)
540
5.19M
                {
541
5.19M
                    tmp += half;
542
5.19M
                } else {
543
461k
                    tmp += -half;
544
461k
                }
545
5.65M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
5.65M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
5.65M
            }
548
4.02k
            break;
549
3.25k
        case FAAD_FMT_FIXED:
550
4.39M
            for(i = 0; i < frame_len; i++)
551
4.38M
            {
552
4.38M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.38M
                    hDecoder->internal_channel);
554
4.38M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.38M
            }
556
3.25k
            break;
557
19.5k
        }
558
19.5k
    }
559
560
3.10k
    return sample_buffer;
561
3.10k
}
562
563
#endif