Coverage Report

Created: 2025-11-16 06:18

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
12.2M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.20M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
4.41M
#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.1M
{
48
38.1M
    if (!down_matrix)
49
35.9M
        return input[internal_channel[channel]][sample];
50
51
2.20M
    if (channel == 0)
52
1.08M
    {
53
1.08M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.08M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.08M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.11M
    } else {
57
1.11M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.11M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.11M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.11M
    }
61
2.20M
}
62
63
#ifndef HAS_LRINTF
64
32.6M
#define CLIP(sample, max, min) \
65
32.6M
if (sample >= 0.0f)            \
66
27.8M
{                              \
67
27.8M
    sample += 0.5f;            \
68
27.8M
    if (sample >= max)         \
69
27.8M
        sample = max;          \
70
27.8M
} else {                       \
71
4.79M
    sample += -0.5f;           \
72
4.79M
    if (sample <= min)         \
73
4.79M
        sample = min;          \
74
4.79M
}
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.07k
#define CONV(a,b) ((a<<1)|(b&0x1))
88
89
static void to_PCM_16bit(NeAACDecStruct *hDecoder, real_t **input,
90
                         uint8_t channels, uint16_t frame_len,
91
                         int16_t **sample_buffer)
92
1.69k
{
93
1.69k
    uint8_t ch, ch1;
94
1.69k
    uint16_t i;
95
96
1.69k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.69k
    {
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
860
    case CONV(2,0):
110
860
        if (hDecoder->upMatrix)
111
53
        {
112
53
            ch  = hDecoder->internal_channel[0];
113
90.0k
            for(i = 0; i < frame_len; i++)
114
89.9k
            {
115
89.9k
                real_t inp0 = input[ch][i];
116
117
89.9k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
89.9k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
89.9k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
89.9k
            }
122
807
        } else {
123
807
            ch  = hDecoder->internal_channel[0];
124
807
            ch1 = hDecoder->internal_channel[1];
125
1.26M
            for(i = 0; i < frame_len; i++)
126
1.26M
            {
127
1.26M
                real_t inp0 = input[ch ][i];
128
1.26M
                real_t inp1 = input[ch1][i];
129
130
1.26M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.26M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.26M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.26M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.26M
            }
136
807
        }
137
860
        break;
138
835
    default:
139
9.91k
        for (ch = 0; ch < channels; ch++)
140
9.07k
        {
141
12.9M
            for(i = 0; i < frame_len; i++)
142
12.8M
            {
143
12.8M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
12.8M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
12.8M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
12.8M
            }
149
9.07k
        }
150
835
        break;
151
1.69k
    }
152
1.69k
}
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.05k
{
158
1.05k
    uint8_t ch, ch1;
159
1.05k
    uint16_t i;
160
161
1.05k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.05k
    {
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
503
    case CONV(2,0):
176
503
        if (hDecoder->upMatrix)
177
32
        {
178
32
            ch = hDecoder->internal_channel[0];
179
49.5k
            for(i = 0; i < frame_len; i++)
180
49.5k
            {
181
49.5k
                real_t inp0 = input[ch][i];
182
183
49.5k
                inp0 *= 256.0f;
184
49.5k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
49.5k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
49.5k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
49.5k
            }
189
471
        } else {
190
471
            ch  = hDecoder->internal_channel[0];
191
471
            ch1 = hDecoder->internal_channel[1];
192
743k
            for(i = 0; i < frame_len; i++)
193
743k
            {
194
743k
                real_t inp0 = input[ch ][i];
195
743k
                real_t inp1 = input[ch1][i];
196
197
743k
                inp0 *= 256.0f;
198
743k
                inp1 *= 256.0f;
199
743k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
743k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
743k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
743k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
743k
            }
205
471
        }
206
503
        break;
207
551
    default:
208
5.72k
        for (ch = 0; ch < channels; ch++)
209
5.17k
        {
210
7.86M
            for(i = 0; i < frame_len; i++)
211
7.85M
            {
212
7.85M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
7.85M
                inp *= 256.0f;
215
7.85M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
7.85M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
7.85M
            }
219
5.17k
        }
220
551
        break;
221
1.05k
    }
222
1.05k
}
223
224
static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
225
                         uint8_t channels, uint16_t frame_len,
226
                         int32_t **sample_buffer)
227
1.08k
{
228
1.08k
    uint8_t ch, ch1;
229
1.08k
    uint16_t i;
230
231
1.08k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.08k
    {
233
0
    case CONV(1,0):
234
0
    case CONV(1,1):
235
0
        for(i = 0; i < frame_len; i++)
236
0
        {
237
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
238
239
0
            inp *= 65536.0f;
240
0
            CLIP(inp, 2147483647.0f, -2147483648.0f);
241
242
0
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
243
0
        }
244
0
        break;
245
608
    case CONV(2,0):
246
608
        if (hDecoder->upMatrix)
247
33
        {
248
33
            ch = hDecoder->internal_channel[0];
249
55.2k
            for(i = 0; i < frame_len; i++)
250
55.1k
            {
251
55.1k
                real_t inp0 = input[ch][i];
252
253
55.1k
                inp0 *= 65536.0f;
254
55.1k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
55.1k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
55.1k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
55.1k
            }
259
575
        } else {
260
575
            ch  = hDecoder->internal_channel[0];
261
575
            ch1 = hDecoder->internal_channel[1];
262
867k
            for(i = 0; i < frame_len; i++)
263
866k
            {
264
866k
                real_t inp0 = input[ch ][i];
265
866k
                real_t inp1 = input[ch1][i];
266
267
866k
                inp0 *= 65536.0f;
268
866k
                inp1 *= 65536.0f;
269
866k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
866k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
866k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
866k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
866k
            }
275
575
        }
276
608
        break;
277
481
    default:
278
4.67k
        for (ch = 0; ch < channels; ch++)
279
4.19k
        {
280
5.94M
            for(i = 0; i < frame_len; i++)
281
5.93M
            {
282
5.93M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
5.93M
                inp *= 65536.0f;
285
5.93M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
5.93M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
5.93M
            }
289
4.19k
        }
290
481
        break;
291
1.08k
    }
292
1.08k
}
293
294
static void to_PCM_float(NeAACDecStruct *hDecoder, real_t **input,
295
                         uint8_t channels, uint16_t frame_len,
296
                         float32_t **sample_buffer)
297
522
{
298
522
    uint8_t ch, ch1;
299
522
    uint16_t i;
300
301
522
    switch (CONV(channels,hDecoder->downMatrix))
302
522
    {
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
150
    case CONV(2,0):
312
150
        if (hDecoder->upMatrix)
313
11
        {
314
11
            ch = hDecoder->internal_channel[0];
315
15.1k
            for(i = 0; i < frame_len; i++)
316
15.1k
            {
317
15.1k
                real_t inp0 = input[ch][i];
318
15.1k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
15.1k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
15.1k
            }
321
139
        } else {
322
139
            ch  = hDecoder->internal_channel[0];
323
139
            ch1 = hDecoder->internal_channel[1];
324
217k
            for(i = 0; i < frame_len; i++)
325
217k
            {
326
217k
                real_t inp0 = input[ch ][i];
327
217k
                real_t inp1 = input[ch1][i];
328
217k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
217k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
217k
            }
331
139
        }
332
150
        break;
333
372
    default:
334
4.13k
        for (ch = 0; ch < channels; ch++)
335
3.75k
        {
336
5.52M
            for(i = 0; i < frame_len; i++)
337
5.52M
            {
338
5.52M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
5.52M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
5.52M
            }
341
3.75k
        }
342
372
        break;
343
522
    }
344
522
}
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
468
{
350
468
    uint8_t ch, ch1;
351
468
    uint16_t i;
352
353
468
    switch (CONV(channels,hDecoder->downMatrix))
354
468
    {
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
129
    case CONV(2,0):
364
129
        if (hDecoder->upMatrix)
365
22
        {
366
22
            ch = hDecoder->internal_channel[0];
367
37.7k
            for(i = 0; i < frame_len; i++)
368
37.7k
            {
369
37.7k
                real_t inp0 = input[ch][i];
370
37.7k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
37.7k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
37.7k
            }
373
107
        } else {
374
107
            ch  = hDecoder->internal_channel[0];
375
107
            ch1 = hDecoder->internal_channel[1];
376
128k
            for(i = 0; i < frame_len; i++)
377
128k
            {
378
128k
                real_t inp0 = input[ch ][i];
379
128k
                real_t inp1 = input[ch1][i];
380
128k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
128k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
128k
            }
383
107
        }
384
129
        break;
385
339
    default:
386
4.25k
        for (ch = 0; ch < channels; ch++)
387
3.91k
        {
388
5.91M
            for(i = 0; i < frame_len; i++)
389
5.91M
            {
390
5.91M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
5.91M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
5.91M
            }
393
3.91k
        }
394
339
        break;
395
468
    }
396
468
}
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.65k
{
402
9.65k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
9.65k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
9.65k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
9.65k
    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.65k
    switch (format)
413
9.65k
    {
414
3.39k
    case FAAD_FMT_16BIT:
415
3.39k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.39k
        break;
417
2.10k
    case FAAD_FMT_24BIT:
418
2.10k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.10k
        break;
420
2.17k
    case FAAD_FMT_32BIT:
421
2.17k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.17k
        break;
423
1.04k
    case FAAD_FMT_FLOAT:
424
1.04k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.04k
        break;
426
936
    case FAAD_FMT_DOUBLE:
427
936
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
936
        break;
429
9.65k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
9.65k
    return sample_buffer;
437
9.65k
}
output_to_PCM
Line
Count
Source
401
4.82k
{
402
4.82k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.82k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.82k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.82k
    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.82k
    switch (format)
413
4.82k
    {
414
1.69k
    case FAAD_FMT_16BIT:
415
1.69k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.69k
        break;
417
1.05k
    case FAAD_FMT_24BIT:
418
1.05k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.05k
        break;
420
1.08k
    case FAAD_FMT_32BIT:
421
1.08k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.08k
        break;
423
522
    case FAAD_FMT_FLOAT:
424
522
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
522
        break;
426
468
    case FAAD_FMT_DOUBLE:
427
468
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
468
        break;
429
4.82k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.82k
    return sample_buffer;
437
4.82k
}
output_to_PCM
Line
Count
Source
401
4.82k
{
402
4.82k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
4.82k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
4.82k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
4.82k
    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.82k
    switch (format)
413
4.82k
    {
414
1.69k
    case FAAD_FMT_16BIT:
415
1.69k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.69k
        break;
417
1.05k
    case FAAD_FMT_24BIT:
418
1.05k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.05k
        break;
420
1.08k
    case FAAD_FMT_32BIT:
421
1.08k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.08k
        break;
423
522
    case FAAD_FMT_FLOAT:
424
522
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
522
        break;
426
468
    case FAAD_FMT_DOUBLE:
427
468
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
468
        break;
429
4.82k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
4.82k
    return sample_buffer;
437
4.82k
}
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
23.5M
{
449
23.5M
    real_t C;
450
23.5M
    if (up_matrix == 1)
451
181k
        return input[internal_channel[0]][sample];
452
453
23.3M
    if (!down_matrix)
454
22.9M
        return input[internal_channel[channel]][sample];
455
456
370k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
370k
    if (channel == 0)
458
173k
    {
459
173k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
173k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
173k
        return core + C + L_S;
462
197k
    } else {
463
197k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
197k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
197k
        return core + C + R_S;
466
197k
    }
467
370k
}
468
469
void* output_to_PCM(NeAACDecStruct *hDecoder,
470
                    real_t **input, void *sample_buffer, uint8_t channels,
471
                    uint16_t frame_len, uint8_t format)
472
5.00k
{
473
5.00k
    uint8_t ch;
474
5.00k
    uint16_t i;
475
5.00k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.00k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.00k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
37.2k
    for (ch = 0; ch < channels; ch++)
481
32.2k
    {
482
32.2k
        switch (format)
483
32.2k
        {
484
9.99k
        case FAAD_FMT_16BIT:
485
14.9M
            for(i = 0; i < frame_len; i++)
486
14.9M
            {
487
14.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
14.9M
                    hDecoder->internal_channel);
489
14.9M
                if (tmp >= 0)
490
13.9M
                {
491
13.9M
                    tmp += (1 << (REAL_BITS-1));
492
13.9M
                    if (tmp >= REAL_CONST(32767))
493
50.1k
                    {
494
50.1k
                        tmp = REAL_CONST(32767);
495
50.1k
                    }
496
13.9M
                } else {
497
978k
                    tmp += -(1 << (REAL_BITS-1));
498
978k
                    if (tmp <= REAL_CONST(-32768))
499
51.6k
                    {
500
51.6k
                        tmp = REAL_CONST(-32768);
501
51.6k
                    }
502
978k
                }
503
14.9M
                tmp >>= REAL_BITS;
504
14.9M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
14.9M
            }
506
9.99k
            break;
507
10.4k
        case FAAD_FMT_24BIT:
508
14.9M
            for(i = 0; i < frame_len; i++)
509
14.9M
            {
510
14.9M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
14.9M
                    hDecoder->internal_channel);
512
14.9M
                if (tmp >= 0)
513
13.5M
                {
514
13.5M
                    tmp += (1 << (REAL_BITS-9));
515
13.5M
                    tmp >>= (REAL_BITS-8);
516
13.5M
                    if (tmp >= 8388607)
517
31.6k
                    {
518
31.6k
                        tmp = 8388607;
519
31.6k
                    }
520
13.5M
                } else {
521
1.38M
                    tmp += -(1 << (REAL_BITS-9));
522
1.38M
                    tmp >>= (REAL_BITS-8);
523
1.38M
                    if (tmp <= -8388608)
524
31.9k
                    {
525
31.9k
                        tmp = -8388608;
526
31.9k
                    }
527
1.38M
                }
528
14.9M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
14.9M
            }
530
10.4k
            break;
531
6.44k
        case FAAD_FMT_32BIT:
532
6.44k
            exp = 16 - REAL_BITS;
533
6.44k
            half = 1 << (exp - 1);
534
6.44k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
8.92M
            for(i = 0; i < frame_len; i++)
536
8.91M
            {
537
8.91M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
8.91M
                    hDecoder->internal_channel);
539
8.91M
                if (tmp >= 0)
540
8.05M
                {
541
8.05M
                    tmp += half;
542
8.05M
                } else {
543
865k
                    tmp += -half;
544
865k
                }
545
8.91M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
8.91M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
8.91M
            }
548
6.44k
            break;
549
5.30k
        case FAAD_FMT_FIXED:
550
8.24M
            for(i = 0; i < frame_len; i++)
551
8.24M
            {
552
8.24M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
8.24M
                    hDecoder->internal_channel);
554
8.24M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
8.24M
            }
556
5.30k
            break;
557
32.2k
        }
558
32.2k
    }
559
560
5.00k
    return sample_buffer;
561
5.00k
}
output_to_PCM
Line
Count
Source
472
2.50k
{
473
2.50k
    uint8_t ch;
474
2.50k
    uint16_t i;
475
2.50k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.50k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.50k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
18.6k
    for (ch = 0; ch < channels; ch++)
481
16.1k
    {
482
16.1k
        switch (format)
483
16.1k
        {
484
4.99k
        case FAAD_FMT_16BIT:
485
7.47M
            for(i = 0; i < frame_len; i++)
486
7.47M
            {
487
7.47M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.47M
                    hDecoder->internal_channel);
489
7.47M
                if (tmp >= 0)
490
6.98M
                {
491
6.98M
                    tmp += (1 << (REAL_BITS-1));
492
6.98M
                    if (tmp >= REAL_CONST(32767))
493
25.0k
                    {
494
25.0k
                        tmp = REAL_CONST(32767);
495
25.0k
                    }
496
6.98M
                } else {
497
489k
                    tmp += -(1 << (REAL_BITS-1));
498
489k
                    if (tmp <= REAL_CONST(-32768))
499
25.8k
                    {
500
25.8k
                        tmp = REAL_CONST(-32768);
501
25.8k
                    }
502
489k
                }
503
7.47M
                tmp >>= REAL_BITS;
504
7.47M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.47M
            }
506
4.99k
            break;
507
5.23k
        case FAAD_FMT_24BIT:
508
7.48M
            for(i = 0; i < frame_len; i++)
509
7.48M
            {
510
7.48M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
7.48M
                    hDecoder->internal_channel);
512
7.48M
                if (tmp >= 0)
513
6.78M
                {
514
6.78M
                    tmp += (1 << (REAL_BITS-9));
515
6.78M
                    tmp >>= (REAL_BITS-8);
516
6.78M
                    if (tmp >= 8388607)
517
15.8k
                    {
518
15.8k
                        tmp = 8388607;
519
15.8k
                    }
520
6.78M
                } else {
521
694k
                    tmp += -(1 << (REAL_BITS-9));
522
694k
                    tmp >>= (REAL_BITS-8);
523
694k
                    if (tmp <= -8388608)
524
15.9k
                    {
525
15.9k
                        tmp = -8388608;
526
15.9k
                    }
527
694k
                }
528
7.48M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
7.48M
            }
530
5.23k
            break;
531
3.22k
        case FAAD_FMT_32BIT:
532
3.22k
            exp = 16 - REAL_BITS;
533
3.22k
            half = 1 << (exp - 1);
534
3.22k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
4.46M
            for(i = 0; i < frame_len; i++)
536
4.45M
            {
537
4.45M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
4.45M
                    hDecoder->internal_channel);
539
4.45M
                if (tmp >= 0)
540
4.02M
                {
541
4.02M
                    tmp += half;
542
4.02M
                } else {
543
432k
                    tmp += -half;
544
432k
                }
545
4.45M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
4.45M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
4.45M
            }
548
3.22k
            break;
549
2.65k
        case FAAD_FMT_FIXED:
550
4.12M
            for(i = 0; i < frame_len; i++)
551
4.12M
            {
552
4.12M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.12M
                    hDecoder->internal_channel);
554
4.12M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.12M
            }
556
2.65k
            break;
557
16.1k
        }
558
16.1k
    }
559
560
2.50k
    return sample_buffer;
561
2.50k
}
output_to_PCM
Line
Count
Source
472
2.50k
{
473
2.50k
    uint8_t ch;
474
2.50k
    uint16_t i;
475
2.50k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.50k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.50k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
18.6k
    for (ch = 0; ch < channels; ch++)
481
16.1k
    {
482
16.1k
        switch (format)
483
16.1k
        {
484
4.99k
        case FAAD_FMT_16BIT:
485
7.47M
            for(i = 0; i < frame_len; i++)
486
7.47M
            {
487
7.47M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
7.47M
                    hDecoder->internal_channel);
489
7.47M
                if (tmp >= 0)
490
6.98M
                {
491
6.98M
                    tmp += (1 << (REAL_BITS-1));
492
6.98M
                    if (tmp >= REAL_CONST(32767))
493
25.0k
                    {
494
25.0k
                        tmp = REAL_CONST(32767);
495
25.0k
                    }
496
6.98M
                } else {
497
489k
                    tmp += -(1 << (REAL_BITS-1));
498
489k
                    if (tmp <= REAL_CONST(-32768))
499
25.8k
                    {
500
25.8k
                        tmp = REAL_CONST(-32768);
501
25.8k
                    }
502
489k
                }
503
7.47M
                tmp >>= REAL_BITS;
504
7.47M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
7.47M
            }
506
4.99k
            break;
507
5.23k
        case FAAD_FMT_24BIT:
508
7.48M
            for(i = 0; i < frame_len; i++)
509
7.48M
            {
510
7.48M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
7.48M
                    hDecoder->internal_channel);
512
7.48M
                if (tmp >= 0)
513
6.78M
                {
514
6.78M
                    tmp += (1 << (REAL_BITS-9));
515
6.78M
                    tmp >>= (REAL_BITS-8);
516
6.78M
                    if (tmp >= 8388607)
517
15.8k
                    {
518
15.8k
                        tmp = 8388607;
519
15.8k
                    }
520
6.78M
                } else {
521
694k
                    tmp += -(1 << (REAL_BITS-9));
522
694k
                    tmp >>= (REAL_BITS-8);
523
694k
                    if (tmp <= -8388608)
524
15.9k
                    {
525
15.9k
                        tmp = -8388608;
526
15.9k
                    }
527
694k
                }
528
7.48M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
7.48M
            }
530
5.23k
            break;
531
3.22k
        case FAAD_FMT_32BIT:
532
3.22k
            exp = 16 - REAL_BITS;
533
3.22k
            half = 1 << (exp - 1);
534
3.22k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
4.46M
            for(i = 0; i < frame_len; i++)
536
4.45M
            {
537
4.45M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
4.45M
                    hDecoder->internal_channel);
539
4.45M
                if (tmp >= 0)
540
4.02M
                {
541
4.02M
                    tmp += half;
542
4.02M
                } else {
543
432k
                    tmp += -half;
544
432k
                }
545
4.45M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
4.45M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
4.45M
            }
548
3.22k
            break;
549
2.65k
        case FAAD_FMT_FIXED:
550
4.12M
            for(i = 0; i < frame_len; i++)
551
4.12M
            {
552
4.12M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.12M
                    hDecoder->internal_channel);
554
4.12M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.12M
            }
556
2.65k
            break;
557
16.1k
        }
558
16.1k
    }
559
560
2.50k
    return sample_buffer;
561
2.50k
}
562
563
#endif