]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/ext/lame/decode_i386.c
8ffcab36c35dd17d501c2c9eb3586cbca79bd151
[16.git] / src / lib / doslib / ext / lame / decode_i386.c
1 /*
2  * decode_i396.c: Mpeg Layer-1,2,3 audio decoder
3  *
4  * Copyright (C) 1999-2010 The L.A.M.E. project
5  *
6  * Initially written by Michael Hipp, see also AUTHORS and README.
7  *  
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  *
24  * Slighlty optimized for machines without autoincrement/decrement.
25  * The performance is highly compiler dependend. Maybe
26  * the decode.c version for 'normal' processor may be faster
27  * even for Intel processors.
28  */
29
30 /* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
31
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35
36 #ifdef STDC_HEADERS
37 # include <stdlib.h>
38 # include <string.h>
39 #else
40 # ifndef HAVE_STRCHR
41 #  define strchr index
42 #  define strrchr rindex
43 # endif
44 char   *strchr(), *strrchr();
45 # ifndef HAVE_MEMCPY
46 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
47 #  define memmove(d, s, n) bcopy ((s), (d), (n))
48 # endif
49 #endif
50
51 #if defined(__riscos__) && defined(FPA10)
52 #include "ymath.h"
53 #else
54 #include <math.h>
55 #endif
56
57 #include "decode_i386.h"
58 #include "dct64_i386.h"
59 #include "tabinit.h"
60
61 #ifdef WITH_DMALLOC
62 #include <dmalloc.h>
63 #endif
64
65
66  /* old WRITE_SAMPLE_CLIPPED */
67 #define WRITE_SAMPLE_CLIPPED(TYPE,samples,sum,clip) \
68   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
69   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
70   else { *(samples) = (TYPE)((sum)>0 ? (sum)+0.5 : (sum)-0.5) ; }
71
72 #define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
73   *samples = (TYPE)sum;
74
75   /* *INDENT-OFF* */
76
77  /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1_mono* functions */
78 #define SYNTH_1TO1_MONO_CLIPCHOICE(TYPE,SYNTH_1TO1)                    \
79   TYPE samples_tmp[64];                                                \
80   TYPE *tmp1 = samples_tmp;                                            \
81   int i,ret;                                                           \
82   int pnt1 = 0;                                                        \
83                                                                        \
84   ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
85   out += *pnt;                                                         \
86                                                                        \
87   for(i=0;i<32;i++) {                                                  \
88     *( (TYPE *) out) = *tmp1;                                          \
89     out += sizeof(TYPE);                                               \
90     tmp1 += 2;                                                         \
91   }                                                                    \
92   *pnt += 32*sizeof(TYPE);                                             \
93                                                                        \
94   return ret; 
95
96   /* *INDENT-ON* */
97
98
99 int
100 synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
101 {
102     SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
103 } int
104 synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
105 {
106     SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
107 }
108
109     /* *INDENT-OFF* */
110 /* versions: clipped (when TYPE == short) and unclipped (when TYPE == real) of synth_1to1* functions */
111 #define SYNTH_1TO1_CLIPCHOICE(TYPE,WRITE_SAMPLE)         \
112   static const int step = 2;                             \
113   int bo;                                                \
114   TYPE *samples = (TYPE *) (out + *pnt);                 \
115                                                          \
116   real *b0,(*buf)[0x110];                                \
117   int clip = 0;                                          \
118   int bo1;                                               \
119                                                          \
120   bo = mp->synth_bo;                                     \
121                                                          \
122   if(!channel) {                                         \
123     bo--;                                                \
124     bo &= 0xf;                                           \
125     buf = mp->synth_buffs[0];                            \
126   }                                                      \
127   else {                                                 \
128     samples++;                                           \
129     buf = mp->synth_buffs[1];                            \
130   }                                                      \
131                                                          \
132   if(bo & 0x1) {                                         \
133     b0 = buf[0];                                         \
134     bo1 = bo;                                            \
135     dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);        \
136   }                                                      \
137   else {                                                 \
138     b0 = buf[1];                                         \
139     bo1 = bo+1;                                          \
140     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);                \
141   }                                                      \
142                                                          \
143   mp->synth_bo = bo;                                     \
144                                                          \
145   {                                                      \
146     int j;                                               \
147     real *window = decwin + 16 - bo1;                    \
148                                                          \
149     for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
150     {                                                    \
151       real sum;                                          \
152       sum  = window[0x0] * b0[0x0];                      \
153       sum -= window[0x1] * b0[0x1];                      \
154       sum += window[0x2] * b0[0x2];                      \
155       sum -= window[0x3] * b0[0x3];                      \
156       sum += window[0x4] * b0[0x4];                      \
157       sum -= window[0x5] * b0[0x5];                      \
158       sum += window[0x6] * b0[0x6];                      \
159       sum -= window[0x7] * b0[0x7];                      \
160       sum += window[0x8] * b0[0x8];                      \
161       sum -= window[0x9] * b0[0x9];                      \
162       sum += window[0xA] * b0[0xA];                      \
163       sum -= window[0xB] * b0[0xB];                      \
164       sum += window[0xC] * b0[0xC];                      \
165       sum -= window[0xD] * b0[0xD];                      \
166       sum += window[0xE] * b0[0xE];                      \
167       sum -= window[0xF] * b0[0xF];                      \
168                                                          \
169       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
170     }                                                    \
171                                                          \
172     {                                                    \
173       real sum;                                          \
174       sum  = window[0x0] * b0[0x0];                      \
175       sum += window[0x2] * b0[0x2];                      \
176       sum += window[0x4] * b0[0x4];                      \
177       sum += window[0x6] * b0[0x6];                      \
178       sum += window[0x8] * b0[0x8];                      \
179       sum += window[0xA] * b0[0xA];                      \
180       sum += window[0xC] * b0[0xC];                      \
181       sum += window[0xE] * b0[0xE];                      \
182       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
183       b0-=0x10,window-=0x20,samples+=step;               \
184     }                                                    \
185     window += bo1<<1;                                    \
186                                                          \
187     for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
188     {                                                    \
189       real sum;                                          \
190       sum = -window[-0x1] * b0[0x0];                     \
191       sum -= window[-0x2] * b0[0x1];                     \
192       sum -= window[-0x3] * b0[0x2];                     \
193       sum -= window[-0x4] * b0[0x3];                     \
194       sum -= window[-0x5] * b0[0x4];                     \
195       sum -= window[-0x6] * b0[0x5];                     \
196       sum -= window[-0x7] * b0[0x6];                     \
197       sum -= window[-0x8] * b0[0x7];                     \
198       sum -= window[-0x9] * b0[0x8];                     \
199       sum -= window[-0xA] * b0[0x9];                     \
200       sum -= window[-0xB] * b0[0xA];                     \
201       sum -= window[-0xC] * b0[0xB];                     \
202       sum -= window[-0xD] * b0[0xC];                     \
203       sum -= window[-0xE] * b0[0xD];                     \
204       sum -= window[-0xF] * b0[0xE];                     \
205       sum -= window[-0x0] * b0[0xF];                     \
206                                                          \
207       WRITE_SAMPLE (TYPE,samples,sum,clip);              \
208     }                                                    \
209   }                                                      \
210   *pnt += 64*sizeof(TYPE);                               \
211                                                          \
212   return clip;                                           
213     /* *INDENT-ON* */
214
215
216 int
217 synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
218 {
219     SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
220 } int
221 synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
222 {
223     SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)
224 }