Coverage Report

Created: 2026-03-07 06:08

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.7M
#define FLOAT_SCALE (1.0f/(1<<15))
40
41
2.70M
#define DM_MUL REAL_CONST(0.3203772410170407) // 1/(1+sqrt(2) + 1/sqrt(2))
42
5.40M
#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
40.1M
{
48
40.1M
    if (!down_matrix)
49
37.4M
        return input[internal_channel[channel]][sample];
50
51
2.70M
    if (channel == 0)
52
1.33M
    {
53
1.33M
        return DM_MUL * (input[internal_channel[1]][sample] +
54
1.33M
            input[internal_channel[0]][sample] * RSQRT2 +
55
1.33M
            input[internal_channel[3]][sample] * RSQRT2);
56
1.36M
    } else {
57
1.36M
        return DM_MUL * (input[internal_channel[2]][sample] +
58
1.36M
            input[internal_channel[0]][sample] * RSQRT2 +
59
1.36M
            input[internal_channel[4]][sample] * RSQRT2);
60
1.36M
    }
61
2.70M
}
62
63
#ifndef HAS_LRINTF
64
33.5M
#define CLIP(sample, max, min) \
65
33.5M
if (sample >= 0.0f)            \
66
28.7M
{                              \
67
28.7M
    sample += 0.5f;            \
68
28.7M
    if (sample >= max)         \
69
28.7M
        sample = max;          \
70
28.7M
} else {                       \
71
4.87M
    sample += -0.5f;           \
72
4.87M
    if (sample <= min)         \
73
4.87M
        sample = min;          \
74
4.87M
}
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.98k
#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.79k
{
93
1.79k
    uint8_t ch, ch1;
94
1.79k
    uint16_t i;
95
96
1.79k
    switch (CONV(channels,hDecoder->downMatrix))
97
1.79k
    {
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
895
    case CONV(2,0):
110
895
        if (hDecoder->upMatrix)
111
58
        {
112
58
            ch  = hDecoder->internal_channel[0];
113
88.8k
            for(i = 0; i < frame_len; i++)
114
88.8k
            {
115
88.8k
                real_t inp0 = input[ch][i];
116
117
88.8k
                CLIP(inp0, 32767.0f, -32768.0f);
118
119
88.8k
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
120
88.8k
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp0);
121
88.8k
            }
122
837
        } else {
123
837
            ch  = hDecoder->internal_channel[0];
124
837
            ch1 = hDecoder->internal_channel[1];
125
1.28M
            for(i = 0; i < frame_len; i++)
126
1.28M
            {
127
1.28M
                real_t inp0 = input[ch ][i];
128
1.28M
                real_t inp1 = input[ch1][i];
129
130
1.28M
                CLIP(inp0, 32767.0f, -32768.0f);
131
1.28M
                CLIP(inp1, 32767.0f, -32768.0f);
132
133
1.28M
                (*sample_buffer)[(i*2)+0] = (int16_t)lrintf(inp0);
134
1.28M
                (*sample_buffer)[(i*2)+1] = (int16_t)lrintf(inp1);
135
1.28M
            }
136
837
        }
137
895
        break;
138
896
    default:
139
9.46k
        for (ch = 0; ch < channels; ch++)
140
8.56k
        {
141
12.2M
            for(i = 0; i < frame_len; i++)
142
12.1M
            {
143
12.1M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
144
145
12.1M
                CLIP(inp, 32767.0f, -32768.0f);
146
147
12.1M
                (*sample_buffer)[(i*channels)+ch] = (int16_t)lrintf(inp);
148
12.1M
            }
149
8.56k
        }
150
896
        break;
151
1.79k
    }
152
1.79k
}
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.28k
{
158
1.28k
    uint8_t ch, ch1;
159
1.28k
    uint16_t i;
160
161
1.28k
    switch (CONV(channels,hDecoder->downMatrix))
162
1.28k
    {
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
617
    case CONV(2,0):
176
617
        if (hDecoder->upMatrix)
177
34
        {
178
34
            ch = hDecoder->internal_channel[0];
179
50.0k
            for(i = 0; i < frame_len; i++)
180
50.0k
            {
181
50.0k
                real_t inp0 = input[ch][i];
182
183
50.0k
                inp0 *= 256.0f;
184
50.0k
                CLIP(inp0, 8388607.0f, -8388608.0f);
185
186
50.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
187
50.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
188
50.0k
            }
189
583
        } else {
190
583
            ch  = hDecoder->internal_channel[0];
191
583
            ch1 = hDecoder->internal_channel[1];
192
839k
            for(i = 0; i < frame_len; i++)
193
838k
            {
194
838k
                real_t inp0 = input[ch ][i];
195
838k
                real_t inp1 = input[ch1][i];
196
197
838k
                inp0 *= 256.0f;
198
838k
                inp1 *= 256.0f;
199
838k
                CLIP(inp0, 8388607.0f, -8388608.0f);
200
838k
                CLIP(inp1, 8388607.0f, -8388608.0f);
201
202
838k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
203
838k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
204
838k
            }
205
583
        }
206
617
        break;
207
668
    default:
208
6.40k
        for (ch = 0; ch < channels; ch++)
209
5.73k
        {
210
8.43M
            for(i = 0; i < frame_len; i++)
211
8.42M
            {
212
8.42M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
213
214
8.42M
                inp *= 256.0f;
215
8.42M
                CLIP(inp, 8388607.0f, -8388608.0f);
216
217
8.42M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
218
8.42M
            }
219
5.73k
        }
220
668
        break;
221
1.28k
    }
222
1.28k
}
223
224
static void to_PCM_32bit(NeAACDecStruct *hDecoder, real_t **input,
225
                         uint8_t channels, uint16_t frame_len,
226
                         int32_t **sample_buffer)
227
1.14k
{
228
1.14k
    uint8_t ch, ch1;
229
1.14k
    uint16_t i;
230
231
1.14k
    switch (CONV(channels,hDecoder->downMatrix))
232
1.14k
    {
233
0
    case CONV(1,0):
234
0
    case CONV(1,1):
235
0
        for(i = 0; i < frame_len; i++)
236
0
        {
237
0
            real_t inp = input[hDecoder->internal_channel[0]][i];
238
239
0
            inp *= 65536.0f;
240
0
            CLIP(inp, 2147483647.0f, -2147483648.0f);
241
242
0
            (*sample_buffer)[i] = (int32_t)lrintf(inp);
243
0
        }
244
0
        break;
245
578
    case CONV(2,0):
246
578
        if (hDecoder->upMatrix)
247
40
        {
248
40
            ch = hDecoder->internal_channel[0];
249
65.0k
            for(i = 0; i < frame_len; i++)
250
65.0k
            {
251
65.0k
                real_t inp0 = input[ch][i];
252
253
65.0k
                inp0 *= 65536.0f;
254
65.0k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
255
256
65.0k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
257
65.0k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp0);
258
65.0k
            }
259
538
        } else {
260
538
            ch  = hDecoder->internal_channel[0];
261
538
            ch1 = hDecoder->internal_channel[1];
262
840k
            for(i = 0; i < frame_len; i++)
263
840k
            {
264
840k
                real_t inp0 = input[ch ][i];
265
840k
                real_t inp1 = input[ch1][i];
266
267
840k
                inp0 *= 65536.0f;
268
840k
                inp1 *= 65536.0f;
269
840k
                CLIP(inp0, 2147483647.0f, -2147483648.0f);
270
840k
                CLIP(inp1, 2147483647.0f, -2147483648.0f);
271
272
840k
                (*sample_buffer)[(i*2)+0] = (int32_t)lrintf(inp0);
273
840k
                (*sample_buffer)[(i*2)+1] = (int32_t)lrintf(inp1);
274
840k
            }
275
538
        }
276
578
        break;
277
563
    default:
278
5.37k
        for (ch = 0; ch < channels; ch++)
279
4.80k
        {
280
6.83M
            for(i = 0; i < frame_len; i++)
281
6.83M
            {
282
6.83M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
283
284
6.83M
                inp *= 65536.0f;
285
6.83M
                CLIP(inp, 2147483647.0f, -2147483648.0f);
286
287
6.83M
                (*sample_buffer)[(i*channels)+ch] = (int32_t)lrintf(inp);
288
6.83M
            }
289
4.80k
        }
290
563
        break;
291
1.14k
    }
292
1.14k
}
293
294
static void to_PCM_float(NeAACDecStruct *hDecoder, real_t **input,
295
                         uint8_t channels, uint16_t frame_len,
296
                         float32_t **sample_buffer)
297
674
{
298
674
    uint8_t ch, ch1;
299
674
    uint16_t i;
300
301
674
    switch (CONV(channels,hDecoder->downMatrix))
302
674
    {
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
201
    case CONV(2,0):
312
201
        if (hDecoder->upMatrix)
313
15
        {
314
15
            ch = hDecoder->internal_channel[0];
315
22.4k
            for(i = 0; i < frame_len; i++)
316
22.4k
            {
317
22.4k
                real_t inp0 = input[ch][i];
318
22.4k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
319
22.4k
                (*sample_buffer)[(i*2)+1] = inp0*FLOAT_SCALE;
320
22.4k
            }
321
186
        } else {
322
186
            ch  = hDecoder->internal_channel[0];
323
186
            ch1 = hDecoder->internal_channel[1];
324
277k
            for(i = 0; i < frame_len; i++)
325
277k
            {
326
277k
                real_t inp0 = input[ch ][i];
327
277k
                real_t inp1 = input[ch1][i];
328
277k
                (*sample_buffer)[(i*2)+0] = inp0*FLOAT_SCALE;
329
277k
                (*sample_buffer)[(i*2)+1] = inp1*FLOAT_SCALE;
330
277k
            }
331
186
        }
332
201
        break;
333
473
    default:
334
4.71k
        for (ch = 0; ch < channels; ch++)
335
4.23k
        {
336
6.07M
            for(i = 0; i < frame_len; i++)
337
6.07M
            {
338
6.07M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
339
6.07M
                (*sample_buffer)[(i*channels)+ch] = inp*FLOAT_SCALE;
340
6.07M
            }
341
4.23k
        }
342
473
        break;
343
674
    }
344
674
}
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
632
{
350
632
    uint8_t ch, ch1;
351
632
    uint16_t i;
352
353
632
    switch (CONV(channels,hDecoder->downMatrix))
354
632
    {
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
171
    case CONV(2,0):
364
171
        if (hDecoder->upMatrix)
365
15
        {
366
15
            ch = hDecoder->internal_channel[0];
367
26.5k
            for(i = 0; i < frame_len; i++)
368
26.4k
            {
369
26.4k
                real_t inp0 = input[ch][i];
370
26.4k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
371
26.4k
                (*sample_buffer)[(i*2)+1] = (double)inp0*FLOAT_SCALE;
372
26.4k
            }
373
156
        } else {
374
156
            ch  = hDecoder->internal_channel[0];
375
156
            ch1 = hDecoder->internal_channel[1];
376
190k
            for(i = 0; i < frame_len; i++)
377
190k
            {
378
190k
                real_t inp0 = input[ch ][i];
379
190k
                real_t inp1 = input[ch1][i];
380
190k
                (*sample_buffer)[(i*2)+0] = (double)inp0*FLOAT_SCALE;
381
190k
                (*sample_buffer)[(i*2)+1] = (double)inp1*FLOAT_SCALE;
382
190k
            }
383
156
        }
384
171
        break;
385
461
    default:
386
4.90k
        for (ch = 0; ch < channels; ch++)
387
4.44k
        {
388
6.65M
            for(i = 0; i < frame_len; i++)
389
6.65M
            {
390
6.65M
                real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
391
6.65M
                (*sample_buffer)[(i*channels)+ch] = (double)inp*FLOAT_SCALE;
392
6.65M
            }
393
4.44k
        }
394
461
        break;
395
632
    }
396
632
}
397
398
void *output_to_PCM(NeAACDecStruct *hDecoder,
399
                    real_t **input, void *sample_buffer, uint8_t channels,
400
                    uint16_t frame_len, uint8_t format)
401
11.0k
{
402
11.0k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
11.0k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
11.0k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
11.0k
    double    *double_sample_buffer = (double*)sample_buffer;
406
407
#ifdef PROFILE
408
    int64_t count = faad_get_ts();
409
#endif
410
411
    /* Copy output to a standard PCM buffer */
412
11.0k
    switch (format)
413
11.0k
    {
414
3.58k
    case FAAD_FMT_16BIT:
415
3.58k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
3.58k
        break;
417
2.57k
    case FAAD_FMT_24BIT:
418
2.57k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
2.57k
        break;
420
2.28k
    case FAAD_FMT_32BIT:
421
2.28k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
2.28k
        break;
423
1.34k
    case FAAD_FMT_FLOAT:
424
1.34k
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
1.34k
        break;
426
1.26k
    case FAAD_FMT_DOUBLE:
427
1.26k
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
1.26k
        break;
429
11.0k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
11.0k
    return sample_buffer;
437
11.0k
}
output_to_PCM
Line
Count
Source
401
5.52k
{
402
5.52k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.52k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.52k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.52k
    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.52k
    switch (format)
413
5.52k
    {
414
1.79k
    case FAAD_FMT_16BIT:
415
1.79k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.79k
        break;
417
1.28k
    case FAAD_FMT_24BIT:
418
1.28k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.28k
        break;
420
1.14k
    case FAAD_FMT_32BIT:
421
1.14k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.14k
        break;
423
674
    case FAAD_FMT_FLOAT:
424
674
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
674
        break;
426
632
    case FAAD_FMT_DOUBLE:
427
632
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
632
        break;
429
5.52k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.52k
    return sample_buffer;
437
5.52k
}
output_to_PCM
Line
Count
Source
401
5.52k
{
402
5.52k
    int16_t   *short_sample_buffer = (int16_t*)sample_buffer;
403
5.52k
    int32_t   *int_sample_buffer = (int32_t*)sample_buffer;
404
5.52k
    float32_t *float_sample_buffer = (float32_t*)sample_buffer;
405
5.52k
    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.52k
    switch (format)
413
5.52k
    {
414
1.79k
    case FAAD_FMT_16BIT:
415
1.79k
        to_PCM_16bit(hDecoder, input, channels, frame_len, &short_sample_buffer);
416
1.79k
        break;
417
1.28k
    case FAAD_FMT_24BIT:
418
1.28k
        to_PCM_24bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
419
1.28k
        break;
420
1.14k
    case FAAD_FMT_32BIT:
421
1.14k
        to_PCM_32bit(hDecoder, input, channels, frame_len, &int_sample_buffer);
422
1.14k
        break;
423
674
    case FAAD_FMT_FLOAT:
424
674
        to_PCM_float(hDecoder, input, channels, frame_len, &float_sample_buffer);
425
674
        break;
426
632
    case FAAD_FMT_DOUBLE:
427
632
        to_PCM_double(hDecoder, input, channels, frame_len, &double_sample_buffer);
428
632
        break;
429
5.52k
    }
430
431
#ifdef PROFILE
432
    count = faad_get_ts() - count;
433
    hDecoder->output_cycles += count;
434
#endif
435
436
5.52k
    return sample_buffer;
437
5.52k
}
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.8M
{
449
23.8M
    real_t C;
450
23.8M
    if (up_matrix == 1)
451
289k
        return input[internal_channel[0]][sample];
452
453
23.5M
    if (!down_matrix)
454
23.0M
        return input[internal_channel[channel]][sample];
455
456
527k
    C = MUL_F(input[internal_channel[0]][sample], BOTH);
457
527k
    if (channel == 0)
458
254k
    {
459
254k
        real_t L_S = MUL_F(input[internal_channel[3]][sample], BOTH);
460
254k
        real_t core = MUL_F(input[internal_channel[1]][sample], DM_MUL);
461
254k
        return core + C + L_S;
462
273k
    } else {
463
273k
        real_t R_S = MUL_F(input[internal_channel[4]][sample], BOTH);
464
273k
        real_t core = MUL_F(input[internal_channel[2]][sample], DM_MUL);
465
273k
        return core + C + R_S;
466
273k
    }
467
527k
}
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.22k
{
473
5.22k
    uint8_t ch;
474
5.22k
    uint16_t i;
475
5.22k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
5.22k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
5.22k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
39.1k
    for (ch = 0; ch < channels; ch++)
481
33.9k
    {
482
33.9k
        switch (format)
483
33.9k
        {
484
11.1k
        case FAAD_FMT_16BIT:
485
16.3M
            for(i = 0; i < frame_len; i++)
486
16.3M
            {
487
16.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
16.3M
                    hDecoder->internal_channel);
489
16.3M
                if (tmp >= 0)
490
14.8M
                {
491
14.8M
                    tmp += (1 << (REAL_BITS-1));
492
14.8M
                    if (tmp >= REAL_CONST(32767))
493
30.4k
                    {
494
30.4k
                        tmp = REAL_CONST(32767);
495
30.4k
                    }
496
14.8M
                } else {
497
1.50M
                    tmp += -(1 << (REAL_BITS-1));
498
1.50M
                    if (tmp <= REAL_CONST(-32768))
499
32.0k
                    {
500
32.0k
                        tmp = REAL_CONST(-32768);
501
32.0k
                    }
502
1.50M
                }
503
16.3M
                tmp >>= REAL_BITS;
504
16.3M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
16.3M
            }
506
11.1k
            break;
507
9.48k
        case FAAD_FMT_24BIT:
508
13.3M
            for(i = 0; i < frame_len; i++)
509
13.3M
            {
510
13.3M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
13.3M
                    hDecoder->internal_channel);
512
13.3M
                if (tmp >= 0)
513
12.2M
                {
514
12.2M
                    tmp += (1 << (REAL_BITS-9));
515
12.2M
                    tmp >>= (REAL_BITS-8);
516
12.2M
                    if (tmp >= 8388607)
517
30.2k
                    {
518
30.2k
                        tmp = 8388607;
519
30.2k
                    }
520
12.2M
                } else {
521
1.06M
                    tmp += -(1 << (REAL_BITS-9));
522
1.06M
                    tmp >>= (REAL_BITS-8);
523
1.06M
                    if (tmp <= -8388608)
524
30.0k
                    {
525
30.0k
                        tmp = -8388608;
526
30.0k
                    }
527
1.06M
                }
528
13.3M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
13.3M
            }
530
9.48k
            break;
531
7.07k
        case FAAD_FMT_32BIT:
532
7.07k
            exp = 16 - REAL_BITS;
533
7.07k
            half = 1 << (exp - 1);
534
7.07k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
9.47M
            for(i = 0; i < frame_len; i++)
536
9.46M
            {
537
9.46M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
9.46M
                    hDecoder->internal_channel);
539
9.46M
                if (tmp >= 0)
540
8.65M
                {
541
8.65M
                    tmp += half;
542
8.65M
                } else {
543
815k
                    tmp += -half;
544
815k
                }
545
9.46M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
9.46M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
9.46M
            }
548
7.07k
            break;
549
6.20k
        case FAAD_FMT_FIXED:
550
8.59M
            for(i = 0; i < frame_len; i++)
551
8.59M
            {
552
8.59M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
8.59M
                    hDecoder->internal_channel);
554
8.59M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
8.59M
            }
556
6.20k
            break;
557
33.9k
        }
558
33.9k
    }
559
560
5.22k
    return sample_buffer;
561
5.22k
}
output_to_PCM
Line
Count
Source
472
2.61k
{
473
2.61k
    uint8_t ch;
474
2.61k
    uint16_t i;
475
2.61k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.61k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.61k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
19.5k
    for (ch = 0; ch < channels; ch++)
481
16.9k
    {
482
16.9k
        switch (format)
483
16.9k
        {
484
5.58k
        case FAAD_FMT_16BIT:
485
8.17M
            for(i = 0; i < frame_len; i++)
486
8.17M
            {
487
8.17M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.17M
                    hDecoder->internal_channel);
489
8.17M
                if (tmp >= 0)
490
7.42M
                {
491
7.42M
                    tmp += (1 << (REAL_BITS-1));
492
7.42M
                    if (tmp >= REAL_CONST(32767))
493
15.2k
                    {
494
15.2k
                        tmp = REAL_CONST(32767);
495
15.2k
                    }
496
7.42M
                } else {
497
750k
                    tmp += -(1 << (REAL_BITS-1));
498
750k
                    if (tmp <= REAL_CONST(-32768))
499
16.0k
                    {
500
16.0k
                        tmp = REAL_CONST(-32768);
501
16.0k
                    }
502
750k
                }
503
8.17M
                tmp >>= REAL_BITS;
504
8.17M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.17M
            }
506
5.58k
            break;
507
4.74k
        case FAAD_FMT_24BIT:
508
6.67M
            for(i = 0; i < frame_len; i++)
509
6.67M
            {
510
6.67M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
6.67M
                    hDecoder->internal_channel);
512
6.67M
                if (tmp >= 0)
513
6.13M
                {
514
6.13M
                    tmp += (1 << (REAL_BITS-9));
515
6.13M
                    tmp >>= (REAL_BITS-8);
516
6.13M
                    if (tmp >= 8388607)
517
15.1k
                    {
518
15.1k
                        tmp = 8388607;
519
15.1k
                    }
520
6.13M
                } else {
521
533k
                    tmp += -(1 << (REAL_BITS-9));
522
533k
                    tmp >>= (REAL_BITS-8);
523
533k
                    if (tmp <= -8388608)
524
15.0k
                    {
525
15.0k
                        tmp = -8388608;
526
15.0k
                    }
527
533k
                }
528
6.67M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
6.67M
            }
530
4.74k
            break;
531
3.53k
        case FAAD_FMT_32BIT:
532
3.53k
            exp = 16 - REAL_BITS;
533
3.53k
            half = 1 << (exp - 1);
534
3.53k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
4.73M
            for(i = 0; i < frame_len; i++)
536
4.73M
            {
537
4.73M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
4.73M
                    hDecoder->internal_channel);
539
4.73M
                if (tmp >= 0)
540
4.32M
                {
541
4.32M
                    tmp += half;
542
4.32M
                } else {
543
407k
                    tmp += -half;
544
407k
                }
545
4.73M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
4.73M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
4.73M
            }
548
3.53k
            break;
549
3.10k
        case FAAD_FMT_FIXED:
550
4.29M
            for(i = 0; i < frame_len; i++)
551
4.29M
            {
552
4.29M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.29M
                    hDecoder->internal_channel);
554
4.29M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.29M
            }
556
3.10k
            break;
557
16.9k
        }
558
16.9k
    }
559
560
2.61k
    return sample_buffer;
561
2.61k
}
output_to_PCM
Line
Count
Source
472
2.61k
{
473
2.61k
    uint8_t ch;
474
2.61k
    uint16_t i;
475
2.61k
    int16_t *short_sample_buffer = (int16_t*)sample_buffer;
476
2.61k
    int32_t *int_sample_buffer = (int32_t*)sample_buffer;
477
2.61k
    int32_t exp, half, sat_shift_mask;
478
479
    /* Copy output to a standard PCM buffer */
480
19.5k
    for (ch = 0; ch < channels; ch++)
481
16.9k
    {
482
16.9k
        switch (format)
483
16.9k
        {
484
5.58k
        case FAAD_FMT_16BIT:
485
8.17M
            for(i = 0; i < frame_len; i++)
486
8.17M
            {
487
8.17M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
488
8.17M
                    hDecoder->internal_channel);
489
8.17M
                if (tmp >= 0)
490
7.42M
                {
491
7.42M
                    tmp += (1 << (REAL_BITS-1));
492
7.42M
                    if (tmp >= REAL_CONST(32767))
493
15.2k
                    {
494
15.2k
                        tmp = REAL_CONST(32767);
495
15.2k
                    }
496
7.42M
                } else {
497
750k
                    tmp += -(1 << (REAL_BITS-1));
498
750k
                    if (tmp <= REAL_CONST(-32768))
499
16.0k
                    {
500
16.0k
                        tmp = REAL_CONST(-32768);
501
16.0k
                    }
502
750k
                }
503
8.17M
                tmp >>= REAL_BITS;
504
8.17M
                short_sample_buffer[(i*channels)+ch] = (int16_t)tmp;
505
8.17M
            }
506
5.58k
            break;
507
4.74k
        case FAAD_FMT_24BIT:
508
6.67M
            for(i = 0; i < frame_len; i++)
509
6.67M
            {
510
6.67M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
511
6.67M
                    hDecoder->internal_channel);
512
6.67M
                if (tmp >= 0)
513
6.13M
                {
514
6.13M
                    tmp += (1 << (REAL_BITS-9));
515
6.13M
                    tmp >>= (REAL_BITS-8);
516
6.13M
                    if (tmp >= 8388607)
517
15.1k
                    {
518
15.1k
                        tmp = 8388607;
519
15.1k
                    }
520
6.13M
                } else {
521
533k
                    tmp += -(1 << (REAL_BITS-9));
522
533k
                    tmp >>= (REAL_BITS-8);
523
533k
                    if (tmp <= -8388608)
524
15.0k
                    {
525
15.0k
                        tmp = -8388608;
526
15.0k
                    }
527
533k
                }
528
6.67M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
529
6.67M
            }
530
4.74k
            break;
531
3.53k
        case FAAD_FMT_32BIT:
532
3.53k
            exp = 16 - REAL_BITS;
533
3.53k
            half = 1 << (exp - 1);
534
3.53k
            sat_shift_mask = SAT_SHIFT_MASK(exp);
535
4.73M
            for(i = 0; i < frame_len; i++)
536
4.73M
            {
537
4.73M
                int32_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
538
4.73M
                    hDecoder->internal_channel);
539
4.73M
                if (tmp >= 0)
540
4.32M
                {
541
4.32M
                    tmp += half;
542
4.32M
                } else {
543
407k
                    tmp += -half;
544
407k
                }
545
4.73M
                tmp = SAT_SHIFT(tmp, exp, sat_shift_mask);
546
4.73M
                int_sample_buffer[(i*channels)+ch] = tmp;
547
4.73M
            }
548
3.53k
            break;
549
3.10k
        case FAAD_FMT_FIXED:
550
4.29M
            for(i = 0; i < frame_len; i++)
551
4.29M
            {
552
4.29M
                real_t tmp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->upMatrix,
553
4.29M
                    hDecoder->internal_channel);
554
4.29M
                int_sample_buffer[(i*channels)+ch] = (int32_t)tmp;
555
4.29M
            }
556
3.10k
            break;
557
16.9k
        }
558
16.9k
    }
559
560
2.61k
    return sample_buffer;
561
2.61k
}
562
563
#endif