Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2007-2008 Ian Caulfield | ||
3 | * 2009 Ramiro Polla | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "libavutil/attributes.h" | ||
24 | #include "mlpdsp.h" | ||
25 | #include "mlp.h" | ||
26 | |||
27 | 73644 | static void mlp_filter_channel(int32_t *state, const int32_t *coeff, | |
28 | int firorder, int iirorder, | ||
29 | unsigned int filter_shift, int32_t mask, | ||
30 | int blocksize, int32_t *sample_buffer) | ||
31 | { | ||
32 | 73644 | int32_t *firbuf = state; | |
33 | 73644 | int32_t *iirbuf = state + MAX_BLOCKSIZE + MAX_FIR_ORDER; | |
34 | 73644 | const int32_t *fircoeff = coeff; | |
35 | 73644 | const int32_t *iircoeff = coeff + MAX_FIR_ORDER; | |
36 | int i; | ||
37 | |||
38 |
2/2✓ Branch 0 taken 2734080 times.
✓ Branch 1 taken 73644 times.
|
2807724 | for (i = 0; i < blocksize; i++) { |
39 | 2734080 | int32_t residual = *sample_buffer; | |
40 | unsigned int order; | ||
41 | 2734080 | int64_t accum = 0; | |
42 | int32_t result; | ||
43 | |||
44 |
2/2✓ Branch 0 taken 11127752 times.
✓ Branch 1 taken 2734080 times.
|
13861832 | for (order = 0; order < firorder; order++) |
45 | 11127752 | accum += (int64_t) firbuf[order] * fircoeff[order]; | |
46 |
2/2✓ Branch 0 taken 331912 times.
✓ Branch 1 taken 2734080 times.
|
3065992 | for (order = 0; order < iirorder; order++) |
47 | 331912 | accum += (int64_t) iirbuf[order] * iircoeff[order]; | |
48 | |||
49 | 2734080 | accum = accum >> filter_shift; | |
50 | 2734080 | result = (accum + residual) & mask; | |
51 | |||
52 | 2734080 | *--firbuf = result; | |
53 | 2734080 | *--iirbuf = result - accum; | |
54 | |||
55 | 2734080 | *sample_buffer = result; | |
56 | 2734080 | sample_buffer += MAX_CHANNELS; | |
57 | } | ||
58 | 73644 | } | |
59 | |||
60 | 35059 | void ff_mlp_rematrix_channel(int32_t *samples, | |
61 | const int32_t *coeffs, | ||
62 | const uint8_t *bypassed_lsbs, | ||
63 | const int8_t *noise_buffer, | ||
64 | int index, | ||
65 | unsigned int dest_ch, | ||
66 | uint16_t blockpos, | ||
67 | unsigned int maxchan, | ||
68 | int matrix_noise_shift, | ||
69 | int access_unit_size_pow2, | ||
70 | int32_t mask) | ||
71 | { | ||
72 | unsigned int src_ch, i; | ||
73 | 35059 | int index2 = 2 * index + 1; | |
74 |
2/2✓ Branch 0 taken 1402360 times.
✓ Branch 1 taken 35059 times.
|
1437419 | for (i = 0; i < blockpos; i++) { |
75 | 1402360 | int64_t accum = 0; | |
76 | |||
77 |
2/2✓ Branch 0 taken 7416960 times.
✓ Branch 1 taken 1402360 times.
|
8819320 | for (src_ch = 0; src_ch <= maxchan; src_ch++) |
78 | 7416960 | accum += (int64_t) samples[src_ch] * coeffs[src_ch]; | |
79 | |||
80 |
2/2✓ Branch 0 taken 545760 times.
✓ Branch 1 taken 856600 times.
|
1402360 | if (matrix_noise_shift) { |
81 | 545760 | index &= access_unit_size_pow2 - 1; | |
82 | 545760 | accum += noise_buffer[index] * (1 << (matrix_noise_shift + 7)); | |
83 | 545760 | index += index2; | |
84 | } | ||
85 | |||
86 | 1402360 | samples[dest_ch] = ((accum >> 14) & mask) + *bypassed_lsbs; | |
87 | 1402360 | bypassed_lsbs += MAX_CHANNELS; | |
88 | 1402360 | samples += MAX_CHANNELS; | |
89 | } | ||
90 | 35059 | } | |
91 | |||
92 | 4919 | static int32_t (*mlp_select_pack_output(uint8_t *ch_assign, | |
93 | int8_t *output_shift, | ||
94 | uint8_t max_matrix_channel, | ||
95 | int is32))(int32_t, uint16_t, int32_t (*)[], void *, uint8_t*, int8_t *, uint8_t, int) | ||
96 | { | ||
97 | 4919 | return ff_mlp_pack_output; | |
98 | } | ||
99 | |||
100 | 20139 | int32_t ff_mlp_pack_output(int32_t lossless_check_data, | |
101 | uint16_t blockpos, | ||
102 | int32_t (*sample_buffer)[MAX_CHANNELS], | ||
103 | void *data, | ||
104 | uint8_t *ch_assign, | ||
105 | int8_t *output_shift, | ||
106 | uint8_t max_matrix_channel, | ||
107 | int is32) | ||
108 | { | ||
109 | 20139 | unsigned int i, out_ch = 0; | |
110 | 20139 | int32_t *data_32 = data; | |
111 | 20139 | int16_t *data_16 = data; | |
112 | |||
113 |
2/2✓ Branch 0 taken 805560 times.
✓ Branch 1 taken 20139 times.
|
825699 | for (i = 0; i < blockpos; i++) { |
114 |
2/2✓ Branch 0 taken 2701840 times.
✓ Branch 1 taken 805560 times.
|
3507400 | for (out_ch = 0; out_ch <= max_matrix_channel; out_ch++) { |
115 | 2701840 | int mat_ch = ch_assign[out_ch]; | |
116 | 2701840 | int32_t sample = sample_buffer[i][mat_ch] * | |
117 | 2701840 | (1U << output_shift[mat_ch]); | |
118 | 2701840 | lossless_check_data ^= (sample & 0xffffff) << mat_ch; | |
119 |
2/2✓ Branch 0 taken 1984320 times.
✓ Branch 1 taken 717520 times.
|
2701840 | if (is32) |
120 | 1984320 | *data_32++ = sample * 256U; | |
121 | else | ||
122 | 717520 | *data_16++ = sample >> 8; | |
123 | } | ||
124 | } | ||
125 | 20139 | return lossless_check_data; | |
126 | } | ||
127 | |||
128 | 15 | av_cold void ff_mlpdsp_init(MLPDSPContext *c) | |
129 | { | ||
130 | 15 | c->mlp_filter_channel = mlp_filter_channel; | |
131 | 15 | c->mlp_rematrix_channel = ff_mlp_rematrix_channel; | |
132 | 15 | c->mlp_select_pack_output = mlp_select_pack_output; | |
133 | #if ARCH_ARM | ||
134 | ff_mlpdsp_init_arm(c); | ||
135 | #elif ARCH_X86 | ||
136 | 15 | ff_mlpdsp_init_x86(c); | |
137 | #endif | ||
138 | 15 | } | |
139 |