forked from mywave82/opencubicplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixclip.c
329 lines (292 loc) · 7.5 KB
/
mixclip.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/* OpenCP Module Player
* copyright (c) 1994-'10 Niklas Beisert <[email protected]>
* copyright (c) 2004-'22 Stian Skjelstad <[email protected]>
*
* assembler routines for amplifying/clipping
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* revision history: (please note changes here)
* -nb980510 Niklas Beisert <[email protected]>
* -first release
* -ss04???? Stian Skjelstad <[email protected]>
* -translated assembler to gcc
* -ss040908 Stian Skjelstad <[email protected]>
* -made assembler optimize-safe for gcc
*/
#include "config.h"
#include "types.h"
#include "mixclip.h"
#include "boot/plinkman.h"
#if 0
This was used when amplification was configured - non of the players in Linux/Unix used this
#ifdef I386_ASM
/* assembler versions uses the first 512 entries as 32bit pointers */
void mixCalcClipTab(uint16_t *ct, int32_t amp)
{
signed long i,j,a,b;
a=-amp;
for (i=0; i<256; i++)
ct[i+768]=(a+=amp)>>16;
for (i=0; i<256; i++)
ct[i+1024]=0;
b=0x800000-(amp<<7);
for (i=0; i<256; i++)
{
if (b<0x000000)
{
if ((b+amp)<0x000000)
{
((unsigned short **)ct)[i]=ct+1024;
ct[i+512]=0x0000;
} else {
a=0;
for (j=0; j<256; j++)
{
ct[j+1280]=(((a>>8)+b)<0x000000)?0x0000:(((a>>8)+b)>>8);
a+=amp;
}
((unsigned short **)ct)[i]=ct+1280;
ct[i+512]=0x0000;
}
} else if ((b+amp)>0xFFFFFF)
{
if (b>0xFFFFFF)
{
((unsigned short **)ct)[i]=ct+1024;
ct[i+512]=0xFFFF;
} else {
a=0;
for (j=0; j<256; j++)
{
ct[j+1536]=(((a>>8)+b)>0xFFFFFF)?0x0000:((((a>>8)+b)>>8)+1);
a+=amp;
}
((unsigned short **)ct)[i]=ct+1536;
ct[i+512]=0xFFFF;
}
} else {
((unsigned short **)ct)[i]=ct+768;
ct[i+512]=b>>8;
}
b+=amp;
}
}
void mixClipAlt(uint16_t *dst, const uint16_t *src, uint32_t len, const uint16_t *tab)
{
int d0, d1, d2;
__asm__ __volatile__
(
#ifdef __PIC__
"pushl %%ebx\n"
"movl %%edx, %%ebx\n"
#endif
" pushl %%ebp\n"
" xorl %%edx, %%edx\n"
" pushl %%ecx\n" /* macro, exp=4 , blocksize = (1 shl exp) = 16, blockexp=exp*/
" andl $15, %%ecx\n" /* blocksize-1 */
" subl $16, %%ecx\n" /* blocksize */
" negl %%ecx\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%edi\n"
" subl %%ecx, %%edi\n"
" movl $blockend, %%eax\n"
" subl $block, %%eax\n"
" shrl $4, %%eax\n"
" mulb %%cl\n"
" addl $block, %%eax\n"
" popl %%ecx\n"
" shrl $4, %%ecx\n"
" incl %%ecx\n"
" jmp *%%eax\n"
"block:\n"
/*
" nop\n"
" nop\n" */
".macro dummy from=0, to=30\n"
" movb 1+\\from(%%esi), %%dl\n"
" movl (%%ebx,%%edx,4), %%ebp\n"
" movl 1024(%%ebx,%%edx,2), %%eax\n"
".byte 0x8a\n.byte 0x56\n.byte \\from\n" /* since some gcc/binutils patct-sets optimze away 0 offset, we do this "movb \\from(%%esi), %%dl\n" */
" addl (%%ebp,%%edx,2), %%eax\n"
".byte 0x66\n.byte 0x89\n.byte 0x47\n.byte \\from\n" /* since some gcc/binutils patct-sets optimze away 0 offset, we do this "movw %%ax, \\from(%%edi)\n" */
".if \\to-\\from\n"
" dummy \"(\\from+2)\",\\to\n"
".endif\n"
".endm\n"
" dummy\n"
"blockend:\n"
" addl $32, %%esi\n" /* 128 ??? */
" addl $32, %%edi\n" /* 128 ??? */
" decl %%ecx\n"
" jnz block\n"
" popl %%ebp\n"
#ifdef __PIC__
"movl %%ebx, %%edx\n"
"popl %%ebx\n"
: "=&S"(d0), "=&D"(d1), "=&c"(d2)
: "0" (src), "1" (dst), "d" (tab), "2" (len)
: "memory", "eax"
#else
: "=&S"(d0), "=&D"(d1), "=&c"(d2)
: "0" (src), "1" (dst), "b" (tab), "2" (len)
: "memory", "eax", "edx"
#endif
);
}
void mixClipAlt2(uint16_t *dst, const uint16_t *src, uint32_t len, const uint16_t *tab)
{
int d0, d1, d2;
__asm__ __volatile__
(
#ifdef __PIC__
"pushl %%ebx\n"
"movl %%edx, %%ebx\n"
#endif
" pushl %%ebp\n"
" xorl %%edx, %%edx\n"
" pushl %%ecx\n" /* macro, exp=4 , blocksize = (1 shl exp) = 16, blockexp=exp*/
" andl $15, %%ecx\n" /* blocksize-1 */
" subl $16, %%ecx\n" /* blocksize */
" negl %%ecx\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%esi\n"
" subl %%ecx, %%edi\n"
" subl %%ecx, %%edi\n"
" subl %%ecx, %%edi\n"
" subl %%ecx, %%edi\n"
" movl $blockend2, %%eax\n"
" subl $block2, %%eax\n"
" shrl $4, %%eax\n"
" mulb %%cl\n"
" addl $block2, %%eax\n"
" popl %%ecx\n"
" shrl $4, %%ecx\n"
" incl %%ecx\n"
" jmp *%%eax\n"
"block2:\n"
/*
" nop\n"
" nop\n" */
".macro dummy2 from=0, to=60\n"
" movb 1+\\from(%%esi), %%dl\n"
" movl (%%ebx,%%edx,4), %%ebp\n"
" movl 1024(%%ebx,%%edx,2), %%eax\n"
".byte 0x8A\n.byte 0x56\n.byte \\from\n" /* since some gcc/binutils patch-sets optimze away 0 offset, we do this " movb \\from(%%esi), %%dl\n"*/
" addl (%%ebp,%%edx,2), %%eax\n"
".byte 0x66\n.byte 0x89\n.byte 0x47\n.byte \\from\n" /* since some gcc/binutils patct-sets optimze away 0 offset, we do this "movw %%ax, \\from(%%edi)\n" */
".if \\to-\\from\n"
" dummy2 \"(\\from+4)\",\\to\n"
".endif\n"
".endm\n"
" dummy2\n"
"blockend2:\n"
" addl $64, %%esi\n"
" addl $64, %%edi\n"
" decl %%ecx\n"
" jnz block2\n"
" popl %%ebp\n"
#ifdef __PIC__
"movl %%ebx, %%edx\n"
"popl %%ebx\n"
: "=&S"(d0), "=&D"(d1), "=&c"(d2)
: "0" (src), "1" (dst), "d" (tab), "2" (len)
: "memory", "eax"
#else
: "=&S"(d0), "=&D"(d1), "=&c"(d2)
: "0" (src), "1" (dst), "b" (tab), "2" (len)
: "memory", "eax", "edx"
#endif
);
}
#else
void mixCalcClipTab(uint16_t *ct, int32_t amp)
{
signed long i,j,a,b;
a=-amp;
for (i=0; i<256; i++)
ct[i+768]=(a+=amp)>>16;
for (i=0; i<256; i++)
ct[i+1024]=0;
b=0x800000-(amp<<7);
for (i=0; i<256; i++)
{
if (b<0x000000)
{
if ((b+amp)<0x000000)
{
ct[i]=1024;
ct[i+512]=0x0000;
} else {
a=0;
for (j=0; j<256; j++)
{
ct[j+1280]=(((a>>8)+b)<0x000000)?0x0000:(((a>>8)+b)>>8);
a+=amp;
}
ct[i]=1280;
ct[i+512]=0x0000;
}
} else if ((b+amp)>0xFFFFFF)
{
if (b>0xFFFFFF)
{
ct[i]=1024;
ct[i+512]=0xFFFF;
} else {
a=0;
for (j=0; j<256; j++)
{
ct[j+1536]=(((a>>8)+b)>0xFFFFFF)?0x0000:((((a>>8)+b)>>8)+1);
a+=amp;
}
ct[i]=1536;
ct[i+512]=0xFFFF;
}
} else {
ct[i]=768;
ct[i+512]=b>>8;
}
b+=amp;
}
}
void mixClipAlt(uint16_t *dst, const uint16_t *src, uint32_t len, const uint16_t *tab)
{
while (len)
{
const uint16_t *tabfine=tab+tab[(*src)>>8];
*dst=tab[512+((*src)>>8)]+tabfine[(*src)&0xff];
dst++;
src++;
len--;
}
}
void mixClipAlt2(uint16_t *dst, const uint16_t *src, uint32_t len, const uint16_t *tab)
{
while (len)
{
const uint16_t *tabfine=tab+tab[(*src)>>8];
*dst=tab[512+((*src)>>8)]+tabfine[(*src)&0xff];
dst+=2;
src+=2;
len--;
}
}
#endif
#endif
DLLEXTINFO_PREFIX struct linkinfostruct dllextinfo = {.name = "mixclip", .desc = "OpenCP common clipper for various streams (c) 1994-'22 Niklas Beisert, Stian Skjelstad", .ver = DLLVERSION, .size = 0};