Coverage Report

Created: 2026-10-28 07:04

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.86M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.72M
#define RSQRT2 REAL_CONST(0.7071067811865475244) // 1/sqrt(2)
43
44
45
static INLINE real_t get_sample(real_t **input, uint8_t channel, uint16_t sample,
46
                                uint8_t down_matrix, uint8_t *internal_channel)
47
41.9M
{
48
41.9M
    if (!down_matrix)
49
39.0M
        return input[internal_channel[channel]][sample];
50
51
2.86M
    if (channel == 0)
52
1.41M
    {
53
1.41M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.41M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.41M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.44M
    } else {
57
1.44M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.44M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.44M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.44M
    }
61
2.86M
}
62
63
#ifndef HAS_LRINTF
64
31.6M
#define CLIP(sample, max, min) \
65
31.6M
if (sample >= 0.0f)            \
66
27.3M
{                              \
67
27.3M
    sample += 0.5f;            \
68
27.3M
    if (sample >= max)         \
69
27.3M
        sample = max;          \
70
27.3M
} else {                       \
71
4.29M
    sample += -0.5f;           \
72
4.29M
    if (sample <= min)         \
73
4.29M
        sample = min;          \
74
4.29M
}
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
6.91k
#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.36k
{
93
1.36k
    uint8_t ch, ch1;
94
1.36k
    uint16_t i;
95
96
1.36k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.36k
    {
98
143
    case CONV(1,0):
99
144
    case CONV(1,1):
100
174k
        for(i = 0; i < frame_len; i++)
101
174k
        {
102
174k
            real_t inp = input[hDecoder->internal_channel[0]][i];
103
104
174k
            CLIP(inp, 32767.0f, -32768.0f);
105
106
174k
            (*sample_buffer)[i] = (int16_t)lrintf(inp);
107
174k
        }
108
144
        break;
109
438
    case CONV(2,0):
110
438
        if (hDecoder->upMatrix)
111
0
        {
112
0
            ch  = hDecoder->internal_channel[0];
113
0
            for(i = 0; i < frame_len; i++)
114
0
            {
115
0
                real_t inp0 = input[ch][i];
116
117
0
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
0
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
0
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
0
            }
122
438
        } else {
123
438
            ch  = hDecoder->internal_channel[0];
124
438
            ch1 = hDecoder->internal_channel[1];
125
714k
            for(i = 0; i < frame_len; i++)
126
714k
            {
127
714k
                real_t inp0 = input[ch ][i];
128
714k
                real_t inp1 = input[ch1][i];
129
130
714k
                CLIP(inp0, 32767.0f, -32768.0f);
131
714k
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
714k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
714k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
714k
            }
136
438
        }
137
438
        break;
138
785
    default:
139
8.12k
        for (ch = 0; ch < channels; ch++)
140
7.33k
        {
141
10.8M
            for(i = 0; i < frame_len; i++)
142
10.8M
            {
143
10.8M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
10.8M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
10.8M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
10.8M
            }
149
7.33k
        }
150
785
        break;
151
1.36k
    }
152
1.36k
}
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.11k
{
158
1.11k
    uint8_t ch, ch1;
159
1.11k
    uint16_t i;
160
161
1.11k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.11k
    {
163
149
    case CONV(1,0):
164
150
    case CONV(1,1):
165
188k
        for(i = 0; i < frame_len; i++)
166
187k
        {
167
187k
            real_t inp = input[hDecoder->internal_channel[0]][i];
168
169
187k
            inp *= 256.0f;
170
187k
            CLIP(inp, 8388607.0f, -8388608.0f);
171
172
187k
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
173
187k
        }
174
150
        break;
175
266
    case CONV(2,0):
176
266
        if (hDecoder->upMatrix)
177
0
        {
178
0
            ch = hDecoder->internal_channel[0];
179
0
            for(i = 0; i < frame_len; i++)
180
0
            {
181
0
                real_t inp0 = input[ch][i];
182
183
0
                inp0 *= 256.0f;
184
0
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
0
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
0
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
0
            }
189
266
        } else {
190
266
            ch  = hDecoder->internal_channel[0];
191
266
            ch1 = hDecoder->internal_channel[1];
192
413k
            for(i = 0; i < frame_len; i++)
193
413k
            {
194
413k
                real_t inp0 = input[ch ][i];
195
413k
                real_t inp1 = input[ch1][i];
196
197
413k
                inp0 *= 256.0f;
198
413k
                inp1 *= 256.0f;
199
413k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
413k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
413k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
413k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
413k
            }
205
266
        }
206
266
        break;
207
695
    default:
208
6.68k
        for (ch = 0; ch < channels; ch++)
209
5.99k
        {
210
8.65M
            for(i = 0; i < frame_len; i++)
211
8.65M
            {
212
8.65M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.65M
                inp *= 256.0f;
215
8.65M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.65M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.65M
            }
219
5.99k
        }
220
695
        break;
221
1.11k
    }
222
1.11k
}
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
166
    case CONV(1,0):
234
167
    case CONV(1,1):
235
189k
        for(i = 0; i < frame_len; i++)
236
189k
        {
237
189k
            real_t inp = input[hDecoder->internal_channel[0]][i];
238
239
189k
            inp *= 65536.0f;
240
189k
            CLIP(inp, 2147483647.0f, -2147483648.0f);
241
242
189k
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
243
189k
        }
244
167
        break;
245
290
    case CONV(2,0):
246
290
        if (hDecoder->upMatrix)
247
0
        {
248
0
            ch = hDecoder->internal_channel[0];
249
0
            for(i = 0; i < frame_len; i++)
250
0
            {
251
0
                real_t inp0 = input[ch][i];
252
253
0
                inp0 *= 65536.0f;
254
0
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
0
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
0
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
0
            }
259
290
        } else {
260
290
            ch  = hDecoder->internal_channel[0];
261
290
            ch1 = hDecoder->internal_channel[1];
262
461k
            for(i = 0; i < frame_len; i++)
263
460k
            {
264
460k
                real_t inp0 = input[ch ][i];
265
460k
                real_t inp1 = input[ch1][i];
266
267
460k
                inp0 *= 65536.0f;
268
460k
                inp1 *= 65536.0f;
269
460k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
460k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
460k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
460k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
460k
            }
275
290
        }
276
290
        break;
277
722
    default:
278
6.60k
        for (ch = 0; ch < channels; ch++)
279
5.87k
        {
280
8.45M
            for(i = 0; i < frame_len; i++)
281
8.45M
            {
282
8.45M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
8.45M
                inp *= 65536.0f;
285
8.45M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
8.45M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
8.45M
            }
289
5.87k
        }
290
722
        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
617
{
298
617
    uint8_t ch, ch1;
299
617
    uint16_t i;
300
301
617
    switch (CONV(channels,hDecoder->downMatrix))
302
617
    {
303
25
    case CONV(1,0):
304
26
    case CONV(1,1):
305
37.7k
        for(i = 0; i < frame_len; i++)
306
37.7k
        {
307
37.7k
            real_t inp = input[hDecoder->internal_channel[0]][i];
308
37.7k
            (*sample_buffer)[i] = inp*FLOAT_SCALE;
309
37.7k
        }
310
26
        break;
311
66
    case CONV(2,0):
312
66
        if (hDecoder->upMatrix)
313
0
        {
314
0
            ch = hDecoder->internal_channel[0];
315
0
            for(i = 0; i < frame_len; i++)
316
0
            {
317
0
                real_t inp0 = input[ch][i];
318
0
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
0
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
0
            }
321
66
        } else {
322
66
            ch  = hDecoder->internal_channel[0];
323
66
            ch1 = hDecoder->internal_channel[1];
324
98.0k
            for(i = 0; i < frame_len; i++)
325
97.9k
            {
326
97.9k
                real_t inp0 = input[ch ][i];
327
97.9k
                real_t inp1 = input[ch1][i];
328
97.9k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
97.9k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
97.9k
            }
331
66
        }
332
66
        break;
333
525
    default:
334
5.43k
        for (ch = 0; ch < channels; ch++)
335
4.90k
        {
336
7.05M
            for(i = 0; i < frame_len; i++)
337
7.04M
            {
338
7.04M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
7.04M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
7.04M
            }
341
4.90k
        }
342
525
        break;
343
617
    }
344
617
}
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
508
{
350
508
    uint8_t ch, ch1;
351
508
    uint16_t i;
352
353
508
    switch (CONV(channels,hDecoder->downMatrix))
354
508
    {
355
28
    case CONV(1,0):
356
29
    case CONV(1,1):
357
50.9k
        for(i = 0; i < frame_len; i++)
358
50.8k
        {
359
50.8k
            real_t inp = input[hDecoder->internal_channel[0]][i];
360
50.8k
            (*sample_buffer)[i] = (double)inp*FLOAT_SCALE;
361
50.8k
        }
362
29
        break;
363
50
    case CONV(2,0):
364
50
        if (hDecoder->upMatrix)
365
0
        {
366
0
            ch = hDecoder->internal_channel[0];
367
0
            for(i = 0; i < frame_len; i++)
368
0
            {
369
0
                real_t inp0 = input[ch][i];
370
0
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
0
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
0
            }
373
50
        } else {
374
50
            ch  = hDecoder->internal_channel[0];
375
50
            ch1 = hDecoder->internal_channel[1];
376
69.3k
            for(i = 0; i < frame_len; i++)
377
69.3k
            {
378
69.3k
                real_t inp0 = input[ch ][i];
379
69.3k
                real_t inp1 = input[ch1][i];
380
69.3k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
69.3k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
69.3k
            }
383
50
        }
384
50
        break;
385
429
    default:
386
5.10k
        for (ch = 0; ch < channels; ch++)
387
4.68k
        {
388
6.96M
            for(i = 0; i < frame_len; i++)
389
6.96M
            {
390
6.96M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.96M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.96M
            }
393
4.68k
        }
394
429
        break;
395
508
    }
396
508
}
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
9.56k
{
402
9.56k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
9.56k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
9.56k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
9.56k
    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
9.56k
    switch (format)
413
9.56k
    {
414
2.73k
    case FAAD_FMT_16BIT:
415
2.73k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
2.73k
        break;
417
2.22k
    case FAAD_FMT_24BIT:
418
2.22k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.22k
        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.23k
    case FAAD_FMT_FLOAT:
424
1.23k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.23k
        break;
426
1.01k
    case FAAD_FMT_DOUBLE:
427
1.01k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.01k
        break;
429
9.56k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
9.56k
    return sample_buffer;
437
9.56k
}
output_to_PCM
Line
Count
Source
401
4.78k
{
402
4.78k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.78k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.78k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.78k
    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
4.78k
    switch (format)
413
4.78k
    {
414
1.36k
    case FAAD_FMT_16BIT:
415
1.36k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.36k
        break;
417
1.11k
    case FAAD_FMT_24BIT:
418
1.11k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.11k
        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
617
    case FAAD_FMT_FLOAT:
424
617
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
617
        break;
426
508
    case FAAD_FMT_DOUBLE:
427
508
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
508
        break;
429
4.78k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.78k
    return sample_buffer;
437
4.78k
}
output_to_PCM
Line
Count
Source
401
4.78k
{
402
4.78k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.78k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.78k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.78k
    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
4.78k
    switch (format)
413
4.78k
    {
414
1.36k
    case FAAD_FMT_16BIT:
415
1.36k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.36k
        break;
417
1.11k
    case FAAD_FMT_24BIT:
418
1.11k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.11k
        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
617
    case FAAD_FMT_FLOAT:
424
617
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
617
        break;
426
508
    case FAAD_FMT_DOUBLE:
427
508
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
508
        break;
429
4.78k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.78k
    return sample_buffer;
437
4.78k
}
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
47.0M
{
449
47.0M
    real_t C;
450
47.0M
    if (up_matrix == 1)
451
0
        return input[internal_channel[0]][sample];
452
453
47.0M
    if (!down_matrix)
454
45.3M
        return input[internal_channel[channel]][sample];
455
456
1.69M
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
1.69M
    if (channel == 0)
458
833k
    {
459
833k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
833k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
833k
        return core + C + L_S;
462
858k
    } else {
463
858k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
858k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
858k
        return core + C + R_S;
466
858k
    }
467
1.69M
}
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
10.2k
{
473
10.2k
    uint8_t ch;
474
10.2k
    uint16_t i;
475
10.2k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
10.2k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
10.2k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
75.8k
    for (ch = 0; ch < channels; ch++)
481
65.6k
    {
482
65.6k
        switch (format)
483
65.6k
        {
484
16.2k
        case FAAD_FMT_16BIT:
485
24.1M
            for(i = 0; i < frame_len; i++)
486
24.0M
            {
487
24.0M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
24.0M
                    hDecoder->internal_channel);
489
24.0M
                if (tmp >= 0)
490
22.1M
                {
491
22.1M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
22.1M
                        tmp += (1 << (REAL_BITS-1));
493
22.1M
                    if (tmp >= REAL_CONST(32767))
494
110k
                    {
495
110k
                        tmp = REAL_CONST(32767);
496
110k
                    }
497
22.1M
                } else {
498
1.92M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
1.92M
                        tmp += -(1 << (REAL_BITS-1));
500
1.92M
                    if (tmp <= REAL_CONST(-32768))
501
99.1k
                    {
502
99.1k
                        tmp = REAL_CONST(-32768);
503
99.1k
                    }
504
1.92M
                }
505
24.0M
                tmp >>= REAL_BITS;
506
24.0M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
24.0M
            }
508
16.2k
            break;
509
23.1k
        case FAAD_FMT_24BIT:
510
33.8M
            for(i = 0; i < frame_len; i++)
511
33.8M
            {
512
33.8M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
33.8M
                    hDecoder->internal_channel);
514
33.8M
                if (tmp >= 0)
515
31.2M
                {
516
31.2M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
31.2M
                        tmp += (1 << (REAL_BITS-9));
518
31.2M
                    tmp >>= (REAL_BITS-8);
519
31.2M
                    if (tmp >= 8388607)
520
87.5k
                    {
521
87.5k
                        tmp = 8388607;
522
87.5k
                    }
523
31.2M
                } else {
524
2.59M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
2.59M
                        tmp += -(1 << (REAL_BITS-9));
526
2.59M
                    tmp >>= (REAL_BITS-8);
527
2.59M
                    if (tmp <= -8388608)
528
91.0k
                    {
529
91.0k
                        tmp = -8388608;
530
91.0k
                    }
531
2.59M
                }
532
33.8M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
33.8M
            }
534
23.1k
            break;
535
15.2k
        case FAAD_FMT_32BIT:
536
15.2k
            exp = 16 - REAL_BITS;
537
15.2k
            half = 1 << (exp - 1);
538
15.2k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
20.6M
            for(i = 0; i < frame_len; i++)
540
20.5M
            {
541
20.5M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
20.5M
                    hDecoder->internal_channel);
543
20.5M
                if (tmp >= 0)
544
19.4M
                {
545
19.4M
                    if (tmp <= 0x7FFFFFFF - half)
546
19.4M
                        tmp += half;
547
19.4M
                } else {
548
1.10M
                    if (tmp >= (int32_t)0x80000000 + half)
549
1.10M
                        tmp += -half;
550
1.10M
                }
551
20.5M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
20.5M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
20.5M
            }
554
15.2k
            break;
555
10.9k
        case FAAD_FMT_FIXED:
556
15.5M
            for(i = 0; i < frame_len; i++)
557
15.5M
            {
558
15.5M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
15.5M
                    hDecoder->internal_channel);
560
15.5M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
15.5M
            }
562
10.9k
            break;
563
65.6k
        }
564
65.6k
    }
565
566
10.2k
    return sample_buffer;
567
10.2k
}
output_to_PCM
Line
Count
Source
472
5.10k
{
473
5.10k
    uint8_t ch;
474
5.10k
    uint16_t i;
475
5.10k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.10k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.10k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
37.9k
    for (ch = 0; ch < channels; ch++)
481
32.8k
    {
482
32.8k
        switch (format)
483
32.8k
        {
484
8.13k
        case FAAD_FMT_16BIT:
485
12.0M
            for(i = 0; i < frame_len; i++)
486
12.0M
            {
487
12.0M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
12.0M
                    hDecoder->internal_channel);
489
12.0M
                if (tmp >= 0)
490
11.0M
                {
491
11.0M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
11.0M
                        tmp += (1 << (REAL_BITS-1));
493
11.0M
                    if (tmp >= REAL_CONST(32767))
494
55.2k
                    {
495
55.2k
                        tmp = REAL_CONST(32767);
496
55.2k
                    }
497
11.0M
                } else {
498
964k
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
964k
                        tmp += -(1 << (REAL_BITS-1));
500
964k
                    if (tmp <= REAL_CONST(-32768))
501
49.5k
                    {
502
49.5k
                        tmp = REAL_CONST(-32768);
503
49.5k
                    }
504
964k
                }
505
12.0M
                tmp >>= REAL_BITS;
506
12.0M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
12.0M
            }
508
8.13k
            break;
509
11.5k
        case FAAD_FMT_24BIT:
510
16.9M
            for(i = 0; i < frame_len; i++)
511
16.9M
            {
512
16.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
16.9M
                    hDecoder->internal_channel);
514
16.9M
                if (tmp >= 0)
515
15.6M
                {
516
15.6M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
15.6M
                        tmp += (1 << (REAL_BITS-9));
518
15.6M
                    tmp >>= (REAL_BITS-8);
519
15.6M
                    if (tmp >= 8388607)
520
43.7k
                    {
521
43.7k
                        tmp = 8388607;
522
43.7k
                    }
523
15.6M
                } else {
524
1.29M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.29M
                        tmp += -(1 << (REAL_BITS-9));
526
1.29M
                    tmp >>= (REAL_BITS-8);
527
1.29M
                    if (tmp <= -8388608)
528
45.5k
                    {
529
45.5k
                        tmp = -8388608;
530
45.5k
                    }
531
1.29M
                }
532
16.9M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
16.9M
            }
534
11.5k
            break;
535
7.62k
        case FAAD_FMT_32BIT:
536
7.62k
            exp = 16 - REAL_BITS;
537
7.62k
            half = 1 << (exp - 1);
538
7.62k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
10.3M
            for(i = 0; i < frame_len; i++)
540
10.2M
            {
541
10.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
10.2M
                    hDecoder->internal_channel);
543
10.2M
                if (tmp >= 0)
544
9.74M
                {
545
9.74M
                    if (tmp <= 0x7FFFFFFF - half)
546
9.74M
                        tmp += half;
547
9.74M
                } else {
548
550k
                    if (tmp >= (int32_t)0x80000000 + half)
549
550k
                        tmp += -half;
550
550k
                }
551
10.2M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
10.2M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
10.2M
            }
554
7.62k
            break;
555
5.47k
        case FAAD_FMT_FIXED:
556
7.76M
            for(i = 0; i < frame_len; i++)
557
7.76M
            {
558
7.76M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
7.76M
                    hDecoder->internal_channel);
560
7.76M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
7.76M
            }
562
5.47k
            break;
563
32.8k
        }
564
32.8k
    }
565
566
5.10k
    return sample_buffer;
567
5.10k
}
output_to_PCM
Line
Count
Source
472
5.10k
{
473
5.10k
    uint8_t ch;
474
5.10k
    uint16_t i;
475
5.10k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.10k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.10k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
37.9k
    for (ch = 0; ch < channels; ch++)
481
32.8k
    {
482
32.8k
        switch (format)
483
32.8k
        {
484
8.13k
        case FAAD_FMT_16BIT:
485
12.0M
            for(i = 0; i < frame_len; i++)
486
12.0M
            {
487
12.0M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
12.0M
                    hDecoder->internal_channel);
489
12.0M
                if (tmp >= 0)
490
11.0M
                {
491
11.0M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-1)))
492
11.0M
                        tmp += (1 << (REAL_BITS-1));
493
11.0M
                    if (tmp >= REAL_CONST(32767))
494
55.2k
                    {
495
55.2k
                        tmp = REAL_CONST(32767);
496
55.2k
                    }
497
11.0M
                } else {
498
964k
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-1)))
499
964k
                        tmp += -(1 << (REAL_BITS-1));
500
964k
                    if (tmp <= REAL_CONST(-32768))
501
49.5k
                    {
502
49.5k
                        tmp = REAL_CONST(-32768);
503
49.5k
                    }
504
964k
                }
505
12.0M
                tmp >>= REAL_BITS;
506
12.0M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
507
12.0M
            }
508
8.13k
            break;
509
11.5k
        case FAAD_FMT_24BIT:
510
16.9M
            for(i = 0; i < frame_len; i++)
511
16.9M
            {
512
16.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
513
16.9M
                    hDecoder->internal_channel);
514
16.9M
                if (tmp >= 0)
515
15.6M
                {
516
15.6M
                    if (tmp <= 0x7FFFFFFF - (1 << (REAL_BITS-9)))
517
15.6M
                        tmp += (1 << (REAL_BITS-9));
518
15.6M
                    tmp >>= (REAL_BITS-8);
519
15.6M
                    if (tmp >= 8388607)
520
43.7k
                    {
521
43.7k
                        tmp = 8388607;
522
43.7k
                    }
523
15.6M
                } else {
524
1.29M
                    if (tmp >= (int32_t)0x80000000 + (1 << (REAL_BITS-9)))
525
1.29M
                        tmp += -(1 << (REAL_BITS-9));
526
1.29M
                    tmp >>= (REAL_BITS-8);
527
1.29M
                    if (tmp <= -8388608)
528
45.5k
                    {
529
45.5k
                        tmp = -8388608;
530
45.5k
                    }
531
1.29M
                }
532
16.9M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
533
16.9M
            }
534
11.5k
            break;
535
7.62k
        case FAAD_FMT_32BIT:
536
7.62k
            exp = 16 - REAL_BITS;
537
7.62k
            half = 1 << (exp - 1);
538
7.62k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
539
10.3M
            for(i = 0; i < frame_len; i++)
540
10.2M
            {
541
10.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
542
10.2M
                    hDecoder->internal_channel);
543
10.2M
                if (tmp >= 0)
544
9.74M
                {
545
9.74M
                    if (tmp <= 0x7FFFFFFF - half)
546
9.74M
                        tmp += half;
547
9.74M
                } else {
548
550k
                    if (tmp >= (int32_t)0x80000000 + half)
549
550k
                        tmp += -half;
550
550k
                }
551
10.2M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
552
10.2M
                int_sample_buffer[(i*channels)+ch] = tmp;
553
10.2M
            }
554
7.62k
            break;
555
5.47k
        case FAAD_FMT_FIXED:
556
7.76M
            for(i = 0; i < frame_len; i++)
557
7.76M
            {
558
7.76M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
559
7.76M
                    hDecoder->internal_channel);
560
7.76M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
561
7.76M
            }
562
5.47k
            break;
563
32.8k
        }
564
32.8k
    }
565
566
5.10k
    return sample_buffer;
567
5.10k
}
568
569
#endif