Coverage Report

Created: 2026-06-10 06:48

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.3M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.45M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
4.91M
#define RSQRT2 REAL_CONST(0.7071067811865475244) // 1/sqrt(2)
43
44
45
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
46
                                uint8_t down_matrix, uint8_t *internal_channel)
47
39.4M
{
48
39.4M
    if (!down_matrix)
49
37.0M
        return input[internal_channel[channel]][sample];
50
51
2.45M
    if (channel == 0)
52
1.18M
    {
53
1.18M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.18M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.18M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.27M
    } else {
57
1.27M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.27M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.27M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.27M
    }
61
2.45M
}
62
63
#ifndef HAS_LRINTF
64
32.4M
#define CLIP(sample, max, min) \
65
32.4M
if (sample >= 0.0f)            \
66
27.9M
{                              \
67
27.9M
    sample += 0.5f;            \
68
27.9M
    if (sample >= max)         \
69
27.9M
        sample = max;          \
70
27.9M
} else {                       \
71
4.49M
    sample += -0.5f;           \
72
4.49M
    if (sample <= min)         \
73
4.49M
        sample = min;          \
74
4.49M
}
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.85k
#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.74k
{
93
1.74k
    uint8_t ch, ch1;
94
1.74k
    uint16_t i;
95
96
1.74k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.74k
    {
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
898
    case CONV(2,0):
110
898
        if (hDecoder->upMatrix)
111
54
        {
112
54
            ch  = hDecoder->internal_channel[0];
113
86.5k
            for(i = 0; i < frame_len; i++)
114
86.4k
            {
115
86.4k
                real_t inp0 = input[ch][i];
116
117
86.4k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
86.4k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
86.4k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
86.4k
            }
122
844
        } else {
123
844
            ch  = hDecoder->internal_channel[0];
124
844
            ch1 = hDecoder->internal_channel[1];
125
1.29M
            for(i = 0; i < frame_len; i++)
126
1.28M
            {
127
1.28M
                real_t inp0 = input[ch ][i];
128
1.28M
                real_t inp1 = input[ch1][i];
129
130
1.28M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.28M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.28M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.28M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.28M
            }
136
844
        }
137
898
        break;
138
843
    default:
139
8.86k
        for (ch = 0; ch < channels; ch++)
140
8.01k
        {
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.01k
        }
150
843
        break;
151
1.74k
    }
152
1.74k
}
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
649
    case CONV(2,0):
176
649
        if (hDecoder->upMatrix)
177
47
        {
178
47
            ch = hDecoder->internal_channel[0];
179
64.4k
            for(i = 0; i < frame_len; i++)
180
64.3k
            {
181
64.3k
                real_t inp0 = input[ch][i];
182
183
64.3k
                inp0 *= 256.0f;
184
64.3k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
64.3k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
64.3k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
64.3k
            }
189
602
        } else {
190
602
            ch  = hDecoder->internal_channel[0];
191
602
            ch1 = hDecoder->internal_channel[1];
192
881k
            for(i = 0; i < frame_len; i++)
193
881k
            {
194
881k
                real_t inp0 = input[ch ][i];
195
881k
                real_t inp1 = input[ch1][i];
196
197
881k
                inp0 *= 256.0f;
198
881k
                inp1 *= 256.0f;
199
881k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
881k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
881k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
881k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
881k
            }
205
602
        }
206
649
        break;
207
601
    default:
208
6.24k
        for (ch = 0; ch < channels; ch++)
209
5.64k
        {
210
7.98M
            for(i = 0; i < frame_len; i++)
211
7.97M
            {
212
7.97M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
7.97M
                inp *= 256.0f;
215
7.97M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
7.97M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
7.97M
            }
219
5.64k
        }
220
601
        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.17k
{
228
1.17k
    uint8_t ch, ch1;
229
1.17k
    uint16_t i;
230
231
1.17k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.17k
    {
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
628
    case CONV(2,0):
246
628
        if (hDecoder->upMatrix)
247
38
        {
248
38
            ch = hDecoder->internal_channel[0];
249
57.1k
            for(i = 0; i < frame_len; i++)
250
57.0k
            {
251
57.0k
                real_t inp0 = input[ch][i];
252
253
57.0k
                inp0 *= 65536.0f;
254
57.0k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
57.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
57.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
57.0k
            }
259
590
        } else {
260
590
            ch  = hDecoder->internal_channel[0];
261
590
            ch1 = hDecoder->internal_channel[1];
262
925k
            for(i = 0; i < frame_len; i++)
263
924k
            {
264
924k
                real_t inp0 = input[ch ][i];
265
924k
                real_t inp1 = input[ch1][i];
266
267
924k
                inp0 *= 65536.0f;
268
924k
                inp1 *= 65536.0f;
269
924k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
924k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
924k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
924k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
924k
            }
275
590
        }
276
628
        break;
277
549
    default:
278
5.28k
        for (ch = 0; ch < channels; ch++)
279
4.73k
        {
280
6.54M
            for(i = 0; i < frame_len; i++)
281
6.54M
            {
282
6.54M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.54M
                inp *= 65536.0f;
285
6.54M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.54M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.54M
            }
289
4.73k
        }
290
549
        break;
291
1.17k
    }
292
1.17k
}
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
639
{
298
639
    uint8_t ch, ch1;
299
639
    uint16_t i;
300
301
639
    switch (CONV(channels,hDecoder->downMatrix))
302
639
    {
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
165
    case CONV(2,0):
312
165
        if (hDecoder->upMatrix)
313
18
        {
314
18
            ch = hDecoder->internal_channel[0];
315
26.5k
            for(i = 0; i < frame_len; i++)
316
26.4k
            {
317
26.4k
                real_t inp0 = input[ch][i];
318
26.4k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
26.4k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
26.4k
            }
321
147
        } else {
322
147
            ch  = hDecoder->internal_channel[0];
323
147
            ch1 = hDecoder->internal_channel[1];
324
220k
            for(i = 0; i < frame_len; i++)
325
220k
            {
326
220k
                real_t inp0 = input[ch ][i];
327
220k
                real_t inp1 = input[ch1][i];
328
220k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
220k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
220k
            }
331
147
        }
332
165
        break;
333
474
    default:
334
4.76k
        for (ch = 0; ch < channels; ch++)
335
4.29k
        {
336
6.26M
            for(i = 0; i < frame_len; i++)
337
6.25M
            {
338
6.25M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.25M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.25M
            }
341
4.29k
        }
342
474
        break;
343
639
    }
344
639
}
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
568
{
350
568
    uint8_t ch, ch1;
351
568
    uint16_t i;
352
353
568
    switch (CONV(channels,hDecoder->downMatrix))
354
568
    {
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
139
    case CONV(2,0):
364
139
        if (hDecoder->upMatrix)
365
29
        {
366
29
            ch = hDecoder->internal_channel[0];
367
51.9k
            for(i = 0; i < frame_len; i++)
368
51.9k
            {
369
51.9k
                real_t inp0 = input[ch][i];
370
51.9k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
51.9k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
51.9k
            }
373
110
        } else {
374
110
            ch  = hDecoder->internal_channel[0];
375
110
            ch1 = hDecoder->internal_channel[1];
376
144k
            for(i = 0; i < frame_len; i++)
377
144k
            {
378
144k
                real_t inp0 = input[ch ][i];
379
144k
                real_t inp1 = input[ch1][i];
380
144k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
144k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
144k
            }
383
110
        }
384
139
        break;
385
429
    default:
386
5.13k
        for (ch = 0; ch < channels; ch++)
387
4.70k
        {
388
7.18M
            for(i = 0; i < frame_len; i++)
389
7.18M
            {
390
7.18M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
7.18M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
7.18M
            }
393
4.70k
        }
394
429
        break;
395
568
    }
396
568
}
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.48k
    case FAAD_FMT_16BIT:
415
3.48k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.48k
        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.35k
    case FAAD_FMT_32BIT:
421
2.35k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.35k
        break;
423
1.27k
    case FAAD_FMT_FLOAT:
424
1.27k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.27k
        break;
426
1.13k
    case FAAD_FMT_DOUBLE:
427
1.13k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.13k
        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.37k
{
402
5.37k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.37k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.37k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.37k
    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.37k
    switch (format)
413
5.37k
    {
414
1.74k
    case FAAD_FMT_16BIT:
415
1.74k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.74k
        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.17k
    case FAAD_FMT_32BIT:
421
1.17k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.17k
        break;
423
639
    case FAAD_FMT_FLOAT:
424
639
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
639
        break;
426
568
    case FAAD_FMT_DOUBLE:
427
568
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
568
        break;
429
5.37k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.37k
    return sample_buffer;
437
5.37k
}
output_to_PCM
Line
Count
Source
401
5.37k
{
402
5.37k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.37k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.37k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.37k
    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.37k
    switch (format)
413
5.37k
    {
414
1.74k
    case FAAD_FMT_16BIT:
415
1.74k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.74k
        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.17k
    case FAAD_FMT_32BIT:
421
1.17k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.17k
        break;
423
639
    case FAAD_FMT_FLOAT:
424
639
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
639
        break;
426
568
    case FAAD_FMT_DOUBLE:
427
568
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
568
        break;
429
5.37k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.37k
    return sample_buffer;
437
5.37k
}
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.2M
{
449
27.2M
    real_t C;
450
27.2M
    if (up_matrix == 1)
451
271k
        return input[internal_channel[0]][sample];
452
453
26.9M
    if (!down_matrix)
454
26.3M
        return input[internal_channel[channel]][sample];
455
456
648k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
648k
    if (channel == 0)
458
314k
    {
459
314k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
314k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
314k
        return core + C + L_S;
462
333k
    } else {
463
333k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
333k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
333k
        return core + C + R_S;
466
333k
    }
467
648k
}
468
469
void* output_to_PCM(NeAACDecStruct *hDecoder,
470
                    real_t **input, void *sample_buffer, uint8_t channels,
471
                    uint16_t frame_len, uint8_t format)
472
6.25k
{
473
6.25k
    uint8_t ch;
474
6.25k
    uint16_t i;
475
6.25k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.25k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.25k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
44.9k
    for (ch = 0; ch < channels; ch++)
481
38.7k
    {
482
38.7k
        switch (format)
483
38.7k
        {
484
11.8k
        case FAAD_FMT_16BIT:
485
17.1M
            for(i = 0; i < frame_len; i++)
486
17.1M
            {
487
17.1M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
17.1M
                    hDecoder->internal_channel);
489
17.1M
                if (tmp >= 0)
490
15.5M
                {
491
15.5M
                    tmp += (1 << (REAL_BITS-1));
492
15.5M
                    if (tmp >= REAL_CONST(32767))
493
39.2k
                    {
494
39.2k
                        tmp = REAL_CONST(32767);
495
39.2k
                    }
496
15.5M
                } else {
497
1.60M
                    tmp += -(1 << (REAL_BITS-1));
498
1.60M
                    if (tmp <= REAL_CONST(-32768))
499
41.3k
                    {
500
41.3k
                        tmp = REAL_CONST(-32768);
501
41.3k
                    }
502
1.60M
                }
503
17.1M
                tmp >>= REAL_BITS;
504
17.1M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
17.1M
            }
506
11.8k
            break;
507
11.5k
        case FAAD_FMT_24BIT:
508
16.4M
            for(i = 0; i < frame_len; i++)
509
16.4M
            {
510
16.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
16.4M
                    hDecoder->internal_channel);
512
16.4M
                if (tmp >= 0)
513
15.1M
                {
514
15.1M
                    tmp += (1 << (REAL_BITS-9));
515
15.1M
                    tmp >>= (REAL_BITS-8);
516
15.1M
                    if (tmp >= 8388607)
517
22.2k
                    {
518
22.2k
                        tmp = 8388607;
519
22.2k
                    }
520
15.1M
                } else {
521
1.25M
                    tmp += -(1 << (REAL_BITS-9));
522
1.25M
                    tmp >>= (REAL_BITS-8);
523
1.25M
                    if (tmp <= -8388608)
524
22.0k
                    {
525
22.0k
                        tmp = -8388608;
526
22.0k
                    }
527
1.25M
                }
528
16.4M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
16.4M
            }
530
11.5k
            break;
531
8.58k
        case FAAD_FMT_32BIT:
532
8.58k
            exp = 16 - REAL_BITS;
533
8.58k
            half = 1 << (exp - 1);
534
8.58k
            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
883k
                    tmp += -half;
544
883k
                }
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
8.58k
            break;
549
6.73k
        case FAAD_FMT_FIXED:
550
9.26M
            for(i = 0; i < frame_len; i++)
551
9.25M
            {
552
9.25M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
9.25M
                    hDecoder->internal_channel);
554
9.25M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
9.25M
            }
556
6.73k
            break;
557
38.7k
        }
558
38.7k
    }
559
560
6.25k
    return sample_buffer;
561
6.25k
}
output_to_PCM
Line
Count
Source
472
3.12k
{
473
3.12k
    uint8_t ch;
474
3.12k
    uint16_t i;
475
3.12k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.12k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.12k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
22.4k
    for (ch = 0; ch < channels; ch++)
481
19.3k
    {
482
19.3k
        switch (format)
483
19.3k
        {
484
5.91k
        case FAAD_FMT_16BIT:
485
8.56M
            for(i = 0; i < frame_len; i++)
486
8.55M
            {
487
8.55M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.55M
                    hDecoder->internal_channel);
489
8.55M
                if (tmp >= 0)
490
7.75M
                {
491
7.75M
                    tmp += (1 << (REAL_BITS-1));
492
7.75M
                    if (tmp >= REAL_CONST(32767))
493
19.6k
                    {
494
19.6k
                        tmp = REAL_CONST(32767);
495
19.6k
                    }
496
7.75M
                } else {
497
800k
                    tmp += -(1 << (REAL_BITS-1));
498
800k
                    if (tmp <= REAL_CONST(-32768))
499
20.6k
                    {
500
20.6k
                        tmp = REAL_CONST(-32768);
501
20.6k
                    }
502
800k
                }
503
8.55M
                tmp >>= REAL_BITS;
504
8.55M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.55M
            }
506
5.91k
            break;
507
5.79k
        case FAAD_FMT_24BIT:
508
8.21M
            for(i = 0; i < frame_len; i++)
509
8.20M
            {
510
8.20M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.20M
                    hDecoder->internal_channel);
512
8.20M
                if (tmp >= 0)
513
7.57M
                {
514
7.57M
                    tmp += (1 << (REAL_BITS-9));
515
7.57M
                    tmp >>= (REAL_BITS-8);
516
7.57M
                    if (tmp >= 8388607)
517
11.1k
                    {
518
11.1k
                        tmp = 8388607;
519
11.1k
                    }
520
7.57M
                } else {
521
626k
                    tmp += -(1 << (REAL_BITS-9));
522
626k
                    tmp >>= (REAL_BITS-8);
523
626k
                    if (tmp <= -8388608)
524
11.0k
                    {
525
11.0k
                        tmp = -8388608;
526
11.0k
                    }
527
626k
                }
528
8.20M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.20M
            }
530
5.79k
            break;
531
4.29k
        case FAAD_FMT_32BIT:
532
4.29k
            exp = 16 - REAL_BITS;
533
4.29k
            half = 1 << (exp - 1);
534
4.29k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.87M
            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
441k
                    tmp += -half;
544
441k
                }
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.29k
            break;
549
3.36k
        case FAAD_FMT_FIXED:
550
4.63M
            for(i = 0; i < frame_len; i++)
551
4.62M
            {
552
4.62M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.62M
                    hDecoder->internal_channel);
554
4.62M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.62M
            }
556
3.36k
            break;
557
19.3k
        }
558
19.3k
    }
559
560
3.12k
    return sample_buffer;
561
3.12k
}
output_to_PCM
Line
Count
Source
472
3.12k
{
473
3.12k
    uint8_t ch;
474
3.12k
    uint16_t i;
475
3.12k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.12k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.12k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
22.4k
    for (ch = 0; ch < channels; ch++)
481
19.3k
    {
482
19.3k
        switch (format)
483
19.3k
        {
484
5.91k
        case FAAD_FMT_16BIT:
485
8.56M
            for(i = 0; i < frame_len; i++)
486
8.55M
            {
487
8.55M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.55M
                    hDecoder->internal_channel);
489
8.55M
                if (tmp >= 0)
490
7.75M
                {
491
7.75M
                    tmp += (1 << (REAL_BITS-1));
492
7.75M
                    if (tmp >= REAL_CONST(32767))
493
19.6k
                    {
494
19.6k
                        tmp = REAL_CONST(32767);
495
19.6k
                    }
496
7.75M
                } else {
497
800k
                    tmp += -(1 << (REAL_BITS-1));
498
800k
                    if (tmp <= REAL_CONST(-32768))
499
20.6k
                    {
500
20.6k
                        tmp = REAL_CONST(-32768);
501
20.6k
                    }
502
800k
                }
503
8.55M
                tmp >>= REAL_BITS;
504
8.55M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.55M
            }
506
5.91k
            break;
507
5.79k
        case FAAD_FMT_24BIT:
508
8.21M
            for(i = 0; i < frame_len; i++)
509
8.20M
            {
510
8.20M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.20M
                    hDecoder->internal_channel);
512
8.20M
                if (tmp >= 0)
513
7.57M
                {
514
7.57M
                    tmp += (1 << (REAL_BITS-9));
515
7.57M
                    tmp >>= (REAL_BITS-8);
516
7.57M
                    if (tmp >= 8388607)
517
11.1k
                    {
518
11.1k
                        tmp = 8388607;
519
11.1k
                    }
520
7.57M
                } else {
521
626k
                    tmp += -(1 << (REAL_BITS-9));
522
626k
                    tmp >>= (REAL_BITS-8);
523
626k
                    if (tmp <= -8388608)
524
11.0k
                    {
525
11.0k
                        tmp = -8388608;
526
11.0k
                    }
527
626k
                }
528
8.20M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.20M
            }
530
5.79k
            break;
531
4.29k
        case FAAD_FMT_32BIT:
532
4.29k
            exp = 16 - REAL_BITS;
533
4.29k
            half = 1 << (exp - 1);
534
4.29k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
5.87M
            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
441k
                    tmp += -half;
544
441k
                }
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.29k
            break;
549
3.36k
        case FAAD_FMT_FIXED:
550
4.63M
            for(i = 0; i < frame_len; i++)
551
4.62M
            {
552
4.62M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.62M
                    hDecoder->internal_channel);
554
4.62M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.62M
            }
556
3.36k
            break;
557
19.3k
        }
558
19.3k
    }
559
560
3.12k
    return sample_buffer;
561
3.12k
}
562
563
#endif