Coverage Report

Created: 2025-10-10 06:50

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
13.8M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.52M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.04M
#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
43.9M
{
48
43.9M
    if (!down_matrix)
49
41.4M
        return input[internal_channel[channel]][sample];
50
51
2.52M
    if (channel == 0)
52
1.24M
    {
53
1.24M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.24M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.24M
            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.52M
}
62
63
#ifndef HAS_LRINTF
64
37.7M
#define CLIP(sample, max, min) \
65
37.7M
if (sample >= 0.0f)            \
66
32.4M
{                              \
67
32.4M
    sample += 0.5f;            \
68
32.4M
    if (sample >= max)         \
69
32.4M
        sample = max;          \
70
32.4M
} else {                       \
71
5.23M
    sample += -0.5f;           \
72
5.23M
    if (sample <= min)         \
73
5.23M
        sample = min;          \
74
5.23M
}
75
#else
76
#define CLIP(sample, max, min) \
77
if (sample >= 0.0f)            \
78
{                              \
79
    if (sample >= max)         \
80
        sample = max;          \
81
} else {                       \
82
    if (sample <= min)         \
83
        sample = min;          \
84
}
85
#endif
86
87
8.29k
#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.94k
{
93
1.94k
    uint8_t ch, ch1;
94
1.94k
    uint16_t i;
95
96
1.94k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.94k
    {
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
972
    case CONV(2,0):
110
972
        if (hDecoder->upMatrix)
111
69
        {
112
69
            ch  = hDecoder->internal_channel[0];
113
119k
            for(i = 0; i < frame_len; i++)
114
119k
            {
115
119k
                real_t inp0 = input[ch][i];
116
117
119k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
119k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
119k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
119k
            }
122
903
        } else {
123
903
            ch  = hDecoder->internal_channel[0];
124
903
            ch1 = hDecoder->internal_channel[1];
125
1.43M
            for(i = 0; i < frame_len; i++)
126
1.43M
            {
127
1.43M
                real_t inp0 = input[ch ][i];
128
1.43M
                real_t inp1 = input[ch1][i];
129
130
1.43M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.43M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.43M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.43M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.43M
            }
136
903
        }
137
972
        break;
138
976
    default:
139
10.8k
        for (ch = 0; ch < channels; ch++)
140
9.82k
        {
141
14.3M
            for(i = 0; i < frame_len; i++)
142
14.3M
            {
143
14.3M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
14.3M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
14.3M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
14.3M
            }
149
9.82k
        }
150
976
        break;
151
1.94k
    }
152
1.94k
}
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
572
    case CONV(2,0):
176
572
        if (hDecoder->upMatrix)
177
37
        {
178
37
            ch = hDecoder->internal_channel[0];
179
57.1k
            for(i = 0; i < frame_len; i++)
180
57.0k
            {
181
57.0k
                real_t inp0 = input[ch][i];
182
183
57.0k
                inp0 *= 256.0f;
184
57.0k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
57.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
57.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
57.0k
            }
189
535
        } else {
190
535
            ch  = hDecoder->internal_channel[0];
191
535
            ch1 = hDecoder->internal_channel[1];
192
774k
            for(i = 0; i < frame_len; i++)
193
774k
            {
194
774k
                real_t inp0 = input[ch ][i];
195
774k
                real_t inp1 = input[ch1][i];
196
197
774k
                inp0 *= 256.0f;
198
774k
                inp1 *= 256.0f;
199
774k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
774k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
774k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
774k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
774k
            }
205
535
        }
206
572
        break;
207
679
    default:
208
6.97k
        for (ch = 0; ch < channels; ch++)
209
6.29k
        {
210
9.30M
            for(i = 0; i < frame_len; i++)
211
9.29M
            {
212
9.29M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
9.29M
                inp *= 256.0f;
215
9.29M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
9.29M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
9.29M
            }
219
6.29k
        }
220
679
        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.27k
{
228
1.27k
    uint8_t ch, ch1;
229
1.27k
    uint16_t i;
230
231
1.27k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.27k
    {
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
687
    case CONV(2,0):
246
687
        if (hDecoder->upMatrix)
247
36
        {
248
36
            ch = hDecoder->internal_channel[0];
249
56.2k
            for(i = 0; i < frame_len; i++)
250
56.1k
            {
251
56.1k
                real_t inp0 = input[ch][i];
252
253
56.1k
                inp0 *= 65536.0f;
254
56.1k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
56.1k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
56.1k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
56.1k
            }
259
651
        } else {
260
651
            ch  = hDecoder->internal_channel[0];
261
651
            ch1 = hDecoder->internal_channel[1];
262
1.00M
            for(i = 0; i < frame_len; i++)
263
1.00M
            {
264
1.00M
                real_t inp0 = input[ch ][i];
265
1.00M
                real_t inp1 = input[ch1][i];
266
267
1.00M
                inp0 *= 65536.0f;
268
1.00M
                inp1 *= 65536.0f;
269
1.00M
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
1.00M
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
1.00M
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
1.00M
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
1.00M
            }
275
651
        }
276
687
        break;
277
584
    default:
278
5.53k
        for (ch = 0; ch < channels; ch++)
279
4.95k
        {
280
7.45M
            for(i = 0; i < frame_len; i++)
281
7.44M
            {
282
7.44M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
7.44M
                inp *= 65536.0f;
285
7.44M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
7.44M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
7.44M
            }
289
4.95k
        }
290
584
        break;
291
1.27k
    }
292
1.27k
}
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
716
{
298
716
    uint8_t ch, ch1;
299
716
    uint16_t i;
300
301
716
    switch (CONV(channels,hDecoder->downMatrix))
302
716
    {
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
171
    case CONV(2,0):
312
171
        if (hDecoder->upMatrix)
313
19
        {
314
19
            ch = hDecoder->internal_channel[0];
315
30.4k
            for(i = 0; i < frame_len; i++)
316
30.4k
            {
317
30.4k
                real_t inp0 = input[ch][i];
318
30.4k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
30.4k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
30.4k
            }
321
152
        } else {
322
152
            ch  = hDecoder->internal_channel[0];
323
152
            ch1 = hDecoder->internal_channel[1];
324
248k
            for(i = 0; i < frame_len; i++)
325
248k
            {
326
248k
                real_t inp0 = input[ch ][i];
327
248k
                real_t inp1 = input[ch1][i];
328
248k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
248k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
248k
            }
331
152
        }
332
171
        break;
333
545
    default:
334
5.19k
        for (ch = 0; ch < channels; ch++)
335
4.65k
        {
336
6.85M
            for(i = 0; i < frame_len; i++)
337
6.85M
            {
338
6.85M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.85M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.85M
            }
341
4.65k
        }
342
545
        break;
343
716
    }
344
716
}
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
530
{
350
530
    uint8_t ch, ch1;
351
530
    uint16_t i;
352
353
530
    switch (CONV(channels,hDecoder->downMatrix))
354
530
    {
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
175
    case CONV(2,0):
364
175
        if (hDecoder->upMatrix)
365
34
        {
366
34
            ch = hDecoder->internal_channel[0];
367
47.9k
            for(i = 0; i < frame_len; i++)
368
47.8k
            {
369
47.8k
                real_t inp0 = input[ch][i];
370
47.8k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
47.8k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
47.8k
            }
373
141
        } else {
374
141
            ch  = hDecoder->internal_channel[0];
375
141
            ch1 = hDecoder->internal_channel[1];
376
169k
            for(i = 0; i < frame_len; i++)
377
169k
            {
378
169k
                real_t inp0 = input[ch ][i];
379
169k
                real_t inp1 = input[ch1][i];
380
169k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
169k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
169k
            }
383
141
        }
384
175
        break;
385
355
    default:
386
4.27k
        for (ch = 0; ch < channels; ch++)
387
3.92k
        {
388
6.01M
            for(i = 0; i < frame_len; i++)
389
6.01M
            {
390
6.01M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.01M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.01M
            }
393
3.92k
        }
394
355
        break;
395
530
    }
396
530
}
397
398
void *output_to_PCM(NeAACDecStruct *hDecoder,
399
                    real_t **input, void *sample_buffer, uint8_t channels,
400
                    uint16_t frame_len, uint8_t format)
401
11.4k
{
402
11.4k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
11.4k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
11.4k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
11.4k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
11.4k
    switch (format)
413
11.4k
    {
414
3.89k
    case FAAD_FMT_16BIT:
415
3.89k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.89k
        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.54k
    case FAAD_FMT_32BIT:
421
2.54k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.54k
        break;
423
1.43k
    case FAAD_FMT_FLOAT:
424
1.43k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.43k
        break;
426
1.06k
    case FAAD_FMT_DOUBLE:
427
1.06k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.06k
        break;
429
11.4k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
11.4k
    return sample_buffer;
437
11.4k
}
output_to_PCM
Line
Count
Source
401
5.71k
{
402
5.71k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.71k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.71k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.71k
    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.71k
    switch (format)
413
5.71k
    {
414
1.94k
    case FAAD_FMT_16BIT:
415
1.94k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.94k
        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.27k
    case FAAD_FMT_32BIT:
421
1.27k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.27k
        break;
423
716
    case FAAD_FMT_FLOAT:
424
716
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
716
        break;
426
530
    case FAAD_FMT_DOUBLE:
427
530
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
530
        break;
429
5.71k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.71k
    return sample_buffer;
437
5.71k
}
output_to_PCM
Line
Count
Source
401
5.71k
{
402
5.71k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.71k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.71k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.71k
    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.71k
    switch (format)
413
5.71k
    {
414
1.94k
    case FAAD_FMT_16BIT:
415
1.94k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.94k
        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.27k
    case FAAD_FMT_32BIT:
421
1.27k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.27k
        break;
423
716
    case FAAD_FMT_FLOAT:
424
716
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
716
        break;
426
530
    case FAAD_FMT_DOUBLE:
427
530
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
530
        break;
429
5.71k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.71k
    return sample_buffer;
437
5.71k
}
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
30.5M
{
449
30.5M
    real_t C;
450
30.5M
    if (up_matrix == 1)
451
293k
        return input[internal_channel[0]][sample];
452
453
30.2M
    if (!down_matrix)
454
29.4M
        return input[internal_channel[channel]][sample];
455
456
768k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
768k
    if (channel == 0)
458
374k
    {
459
374k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
374k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
374k
        return core + C + L_S;
462
393k
    } else {
463
393k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
393k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
393k
        return core + C + R_S;
466
393k
    }
467
768k
}
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.74k
{
473
6.74k
    uint8_t ch;
474
6.74k
    uint16_t i;
475
6.74k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
6.74k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
6.74k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
48.4k
    for (ch = 0; ch < channels; ch++)
481
41.7k
    {
482
41.7k
        switch (format)
483
41.7k
        {
484
12.5k
        case FAAD_FMT_16BIT:
485
18.4M
            for(i = 0; i < frame_len; i++)
486
18.4M
            {
487
18.4M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
18.4M
                    hDecoder->internal_channel);
489
18.4M
                if (tmp >= 0)
490
17.3M
                {
491
17.3M
                    tmp += (1 << (REAL_BITS-1));
492
17.3M
                    if (tmp >= REAL_CONST(32767))
493
44.2k
                    {
494
44.2k
                        tmp = REAL_CONST(32767);
495
44.2k
                    }
496
17.3M
                } else {
497
1.09M
                    tmp += -(1 << (REAL_BITS-1));
498
1.09M
                    if (tmp <= REAL_CONST(-32768))
499
41.0k
                    {
500
41.0k
                        tmp = REAL_CONST(-32768);
501
41.0k
                    }
502
1.09M
                }
503
18.4M
                tmp >>= REAL_BITS;
504
18.4M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
18.4M
            }
506
12.5k
            break;
507
11.8k
        case FAAD_FMT_24BIT:
508
17.3M
            for(i = 0; i < frame_len; i++)
509
17.2M
            {
510
17.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
17.2M
                    hDecoder->internal_channel);
512
17.2M
                if (tmp >= 0)
513
15.8M
                {
514
15.8M
                    tmp += (1 << (REAL_BITS-9));
515
15.8M
                    tmp >>= (REAL_BITS-8);
516
15.8M
                    if (tmp >= 8388607)
517
25.6k
                    {
518
25.6k
                        tmp = 8388607;
519
25.6k
                    }
520
15.8M
                } else {
521
1.42M
                    tmp += -(1 << (REAL_BITS-9));
522
1.42M
                    tmp >>= (REAL_BITS-8);
523
1.42M
                    if (tmp <= -8388608)
524
24.5k
                    {
525
24.5k
                        tmp = -8388608;
526
24.5k
                    }
527
1.42M
                }
528
17.2M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
17.2M
            }
530
11.8k
            break;
531
9.95k
        case FAAD_FMT_32BIT:
532
9.95k
            exp = 16 - REAL_BITS;
533
9.95k
            half = 1 << (exp - 1);
534
9.95k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
14.2M
            for(i = 0; i < frame_len; i++)
536
14.2M
            {
537
14.2M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
14.2M
                    hDecoder->internal_channel);
539
14.2M
                if (tmp >= 0)
540
12.8M
                {
541
12.8M
                    tmp += half;
542
12.8M
                } else {
543
1.45M
                    tmp += -half;
544
1.45M
                }
545
14.2M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
14.2M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
14.2M
            }
548
9.95k
            break;
549
7.40k
        case FAAD_FMT_FIXED:
550
11.1M
            for(i = 0; i < frame_len; i++)
551
11.1M
            {
552
11.1M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
11.1M
                    hDecoder->internal_channel);
554
11.1M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
11.1M
            }
556
7.40k
            break;
557
41.7k
        }
558
41.7k
    }
559
560
6.74k
    return sample_buffer;
561
6.74k
}
output_to_PCM
Line
Count
Source
472
3.37k
{
473
3.37k
    uint8_t ch;
474
3.37k
    uint16_t i;
475
3.37k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.37k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.37k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
24.2k
    for (ch = 0; ch < channels; ch++)
481
20.8k
    {
482
20.8k
        switch (format)
483
20.8k
        {
484
6.25k
        case FAAD_FMT_16BIT:
485
9.23M
            for(i = 0; i < frame_len; i++)
486
9.23M
            {
487
9.23M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.23M
                    hDecoder->internal_channel);
489
9.23M
                if (tmp >= 0)
490
8.68M
                {
491
8.68M
                    tmp += (1 << (REAL_BITS-1));
492
8.68M
                    if (tmp >= REAL_CONST(32767))
493
22.1k
                    {
494
22.1k
                        tmp = REAL_CONST(32767);
495
22.1k
                    }
496
8.68M
                } else {
497
546k
                    tmp += -(1 << (REAL_BITS-1));
498
546k
                    if (tmp <= REAL_CONST(-32768))
499
20.5k
                    {
500
20.5k
                        tmp = REAL_CONST(-32768);
501
20.5k
                    }
502
546k
                }
503
9.23M
                tmp >>= REAL_BITS;
504
9.23M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.23M
            }
506
6.25k
            break;
507
5.93k
        case FAAD_FMT_24BIT:
508
8.65M
            for(i = 0; i < frame_len; i++)
509
8.64M
            {
510
8.64M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.64M
                    hDecoder->internal_channel);
512
8.64M
                if (tmp >= 0)
513
7.93M
                {
514
7.93M
                    tmp += (1 << (REAL_BITS-9));
515
7.93M
                    tmp >>= (REAL_BITS-8);
516
7.93M
                    if (tmp >= 8388607)
517
12.8k
                    {
518
12.8k
                        tmp = 8388607;
519
12.8k
                    }
520
7.93M
                } else {
521
710k
                    tmp += -(1 << (REAL_BITS-9));
522
710k
                    tmp >>= (REAL_BITS-8);
523
710k
                    if (tmp <= -8388608)
524
12.2k
                    {
525
12.2k
                        tmp = -8388608;
526
12.2k
                    }
527
710k
                }
528
8.64M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.64M
            }
530
5.93k
            break;
531
4.97k
        case FAAD_FMT_32BIT:
532
4.97k
            exp = 16 - REAL_BITS;
533
4.97k
            half = 1 << (exp - 1);
534
4.97k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
7.13M
            for(i = 0; i < frame_len; i++)
536
7.13M
            {
537
7.13M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
7.13M
                    hDecoder->internal_channel);
539
7.13M
                if (tmp >= 0)
540
6.40M
                {
541
6.40M
                    tmp += half;
542
6.40M
                } else {
543
728k
                    tmp += -half;
544
728k
                }
545
7.13M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
7.13M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
7.13M
            }
548
4.97k
            break;
549
3.70k
        case FAAD_FMT_FIXED:
550
5.55M
            for(i = 0; i < frame_len; i++)
551
5.55M
            {
552
5.55M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
5.55M
                    hDecoder->internal_channel);
554
5.55M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
5.55M
            }
556
3.70k
            break;
557
20.8k
        }
558
20.8k
    }
559
560
3.37k
    return sample_buffer;
561
3.37k
}
output_to_PCM
Line
Count
Source
472
3.37k
{
473
3.37k
    uint8_t ch;
474
3.37k
    uint16_t i;
475
3.37k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
3.37k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
3.37k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
24.2k
    for (ch = 0; ch < channels; ch++)
481
20.8k
    {
482
20.8k
        switch (format)
483
20.8k
        {
484
6.25k
        case FAAD_FMT_16BIT:
485
9.23M
            for(i = 0; i < frame_len; i++)
486
9.23M
            {
487
9.23M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
9.23M
                    hDecoder->internal_channel);
489
9.23M
                if (tmp >= 0)
490
8.68M
                {
491
8.68M
                    tmp += (1 << (REAL_BITS-1));
492
8.68M
                    if (tmp >= REAL_CONST(32767))
493
22.1k
                    {
494
22.1k
                        tmp = REAL_CONST(32767);
495
22.1k
                    }
496
8.68M
                } else {
497
546k
                    tmp += -(1 << (REAL_BITS-1));
498
546k
                    if (tmp <= REAL_CONST(-32768))
499
20.5k
                    {
500
20.5k
                        tmp = REAL_CONST(-32768);
501
20.5k
                    }
502
546k
                }
503
9.23M
                tmp >>= REAL_BITS;
504
9.23M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
9.23M
            }
506
6.25k
            break;
507
5.93k
        case FAAD_FMT_24BIT:
508
8.65M
            for(i = 0; i < frame_len; i++)
509
8.64M
            {
510
8.64M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
8.64M
                    hDecoder->internal_channel);
512
8.64M
                if (tmp >= 0)
513
7.93M
                {
514
7.93M
                    tmp += (1 << (REAL_BITS-9));
515
7.93M
                    tmp >>= (REAL_BITS-8);
516
7.93M
                    if (tmp >= 8388607)
517
12.8k
                    {
518
12.8k
                        tmp = 8388607;
519
12.8k
                    }
520
7.93M
                } else {
521
710k
                    tmp += -(1 << (REAL_BITS-9));
522
710k
                    tmp >>= (REAL_BITS-8);
523
710k
                    if (tmp <= -8388608)
524
12.2k
                    {
525
12.2k
                        tmp = -8388608;
526
12.2k
                    }
527
710k
                }
528
8.64M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
8.64M
            }
530
5.93k
            break;
531
4.97k
        case FAAD_FMT_32BIT:
532
4.97k
            exp = 16 - REAL_BITS;
533
4.97k
            half = 1 << (exp - 1);
534
4.97k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
7.13M
            for(i = 0; i < frame_len; i++)
536
7.13M
            {
537
7.13M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
7.13M
                    hDecoder->internal_channel);
539
7.13M
                if (tmp >= 0)
540
6.40M
                {
541
6.40M
                    tmp += half;
542
6.40M
                } else {
543
728k
                    tmp += -half;
544
728k
                }
545
7.13M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
7.13M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
7.13M
            }
548
4.97k
            break;
549
3.70k
        case FAAD_FMT_FIXED:
550
5.55M
            for(i = 0; i < frame_len; i++)
551
5.55M
            {
552
5.55M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
5.55M
                    hDecoder->internal_channel);
554
5.55M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
5.55M
            }
556
3.70k
            break;
557
20.8k
        }
558
20.8k
    }
559
560
3.37k
    return sample_buffer;
561
3.37k
}
562
563
#endif