2 * decode_i396.c: Mpeg Layer-1,2,3 audio decoder
4 * Copyright (C) 1999-2010 The L.A.M.E. project
6 * Initially written by Michael Hipp, see also AUTHORS and README.
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.
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.
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.
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.
30 /* $Id: decode_i386.c,v 1.22 2010/03/22 14:30:19 robert Exp $ */
42 # define strrchr rindex
44 char *strchr(), *strrchr();
46 # define memcpy(d, s, n) bcopy ((s), (d), (n))
47 # define memmove(d, s, n) bcopy ((s), (d), (n))
51 #if defined(__riscos__) && defined(FPA10)
57 #include "decode_i386.h"
58 #include "dct64_i386.h"
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) ; }
72 #define WRITE_SAMPLE_UNCLIPPED(TYPE,samples,sum,clip) \
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; \
84 ret = SYNTH_1TO1 (mp,bandPtr,0,(unsigned char *) samples_tmp,&pnt1); \
88 *( (TYPE *) out) = *tmp1; \
89 out += sizeof(TYPE); \
92 *pnt += 32*sizeof(TYPE); \
100 synth_1to1_mono(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
102 SYNTH_1TO1_MONO_CLIPCHOICE(short, synth_1to1)
104 synth_1to1_mono_unclipped(PMPSTR mp, real * bandPtr, unsigned char *out, int *pnt)
106 SYNTH_1TO1_MONO_CLIPCHOICE(real, synth_1to1_unclipped)
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; \
114 TYPE *samples = (TYPE *) (out + *pnt); \
116 real *b0,(*buf)[0x110]; \
125 buf = mp->synth_buffs[0]; \
129 buf = mp->synth_buffs[1]; \
135 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); \
140 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); \
147 real *window = decwin + 16 - bo1; \
149 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) \
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]; \
169 WRITE_SAMPLE (TYPE,samples,sum,clip); \
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; \
187 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) \
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]; \
207 WRITE_SAMPLE (TYPE,samples,sum,clip); \
210 *pnt += 64*sizeof(TYPE); \
217 synth_1to1(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
219 SYNTH_1TO1_CLIPCHOICE(short, WRITE_SAMPLE_CLIPPED)
221 synth_1to1_unclipped(PMPSTR mp, real * bandPtr, int channel, unsigned char *out, int *pnt)
223 SYNTH_1TO1_CLIPCHOICE(real, WRITE_SAMPLE_UNCLIPPED)