/[svn]/linuxsampler/trunk/src/engines/common/Resampler.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/Resampler.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3639 - (hide annotations) (download) (as text)
Fri Oct 25 18:46:58 2019 UTC (4 years, 5 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 28849 byte(s)
* Using now cubic interpolation as resampling algorithm by default; and
  linear interpolation is deprecated now.

* Bumped version (2.1.1.svn23).

1 schoenebeck 320 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 3639 * Copyright (C) 2005 - 2019 Christian Schoenebeck *
7 schoenebeck 320 * *
8     * This program is free software; you can redistribute it and/or modify *
9     * it under the terms of the GNU General Public License as published by *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program 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 *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24 schoenebeck 1259 // Note: the assembly code is currently disabled, as it doesn't fit into
25     // the new synthesis core introduced by LS 0.4.0
26    
27 schoenebeck 320 #ifndef __LS_RESAMPLER_H__
28     #define __LS_RESAMPLER_H__
29    
30 schoenebeck 1424 #include "../../common/global_private.h"
31 schoenebeck 320
32     #ifndef USE_LINEAR_INTERPOLATION
33 schoenebeck 3639 # define USE_LINEAR_INTERPOLATION 0 ///< we set this to 0 by default for using cubic interpolation instead (slightly slower, but much better audio quality than linear interpolation)
34 schoenebeck 320 #endif
35 schoenebeck 3639 #if USE_LINEAR_INTERPOLATION
36     # warning Linear interpolation was configured as resampling algorithm, which is deprecated!
37     #endif
38 schoenebeck 320
39     namespace LinuxSampler {
40    
41 schoenebeck 563 /** @brief Stereo sample point
42     *
43     * Encapsulates one stereo sample point, thus signal value for one
44     * sample point for left and right channel.
45     */
46 schoenebeck 320 struct stereo_sample_t {
47     float left;
48     float right;
49     };
50    
51 schoenebeck 563 /** @brief Resampler Template
52     *
53     * This template provides pure C++ and MMX/SSE assembly implementations
54     * for linear and cubic interpolation for pitching a mono or stereo
55     * input signal.
56     */
57 persson 903 template<bool INTERPOLATE,bool BITDEPTH24>
58 schoenebeck 320 class Resampler {
59     public:
60 schoenebeck 2377 inline static float GetNextSampleMonoCPP(sample_t* __restrict pSrc, double* __restrict Pos, float& Pitch) {
61 schoenebeck 320 if (INTERPOLATE) return Interpolate1StepMonoCPP(pSrc, Pos, Pitch);
62     else { // no pitch, so no interpolation necessary
63     int pos_int = (int) *Pos;
64     *Pos += 1.0;
65     return pSrc [pos_int];
66     }
67     }
68    
69 schoenebeck 2377 inline static stereo_sample_t GetNextSampleStereoCPP(sample_t* __restrict pSrc, double* __restrict Pos, float& Pitch) {
70 schoenebeck 320 if (INTERPOLATE) return Interpolate1StepStereoCPP(pSrc, Pos, Pitch);
71     else { // no pitch, so no interpolation necessary
72     int pos_int = (int) *Pos;
73     pos_int <<= 1;
74     *Pos += 1.0;
75     stereo_sample_t samplePoint;
76     samplePoint.left = pSrc[pos_int];
77     samplePoint.right = pSrc[pos_int+1];
78     return samplePoint;
79     }
80     }
81    
82 schoenebeck 1259 #if 0 // CONFIG_ASM && ARCH_X86
83 schoenebeck 320 inline static void GetNext4SamplesMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
84     if (INTERPOLATE) Interpolate4StepsMonoMMXSSE(pSrc, Pos, Pitch);
85     else { // no pitch, so no interpolation necessary
86     const float __4f = 4.0f;
87     __asm__ __volatile__ (
88     "movss (%1), %%xmm5 # load Pos\n\t"
89     "cvtss2si %%xmm5, %%edi # int(Pos)\n\t"
90     "addss %2, %%xmm5 # Pos += 4.0f\n\t"
91     "movswl (%0,%%edi,2), %%eax # load sample 0\n\t"
92     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
93     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
94     "movswl 2(%0,%%edi,2), %%edx # load sample 1\n\t"
95     "cvtsi2ss %%edx, %%xmm2 # convert to float\n\t"
96     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
97     "movss %%xmm5, (%1) # update Pos\n\t"
98     "movswl 4(%0,%%edi,2), %%eax # load sample 2\n\t"
99     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
100     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
101     "movswl 6(%0,%%edi,2), %%edx # load sample 3\n\t"
102     "cvtsi2ss %%edx, %%xmm2 # convert to float\n\t"
103     "shufps $0x1b, %%xmm2, %%xmm2 # swap to correct order\n\t"
104     :: "r" (pSrc), "r" (Pos), "m" (__4f)
105     : "%eax", "%edx", "%edi"
106     );
107     }
108     }
109    
110     inline static void GetNext4SamplesStereoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
111     if (INTERPOLATE) {
112     Interpolate4StepsStereoMMXSSE(pSrc, Pos, Pitch);
113     //EMMS;
114     } else { // no pitch, so no interpolation necessary
115     const float __4f = 4.0f;
116     __asm__ __volatile__ (
117     "movss (%1), %%xmm5 # load Pos\n\t"
118     "cvtss2si %%xmm5, %%edi # int(Pos)\n\t"
119     "addss %2, %%xmm5 # Pos += 4.0f\n\t"
120     "movswl (%0, %%edi,4), %%eax # load sample 0 (left)\n\t"
121     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
122     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
123     "movss %%xmm5, (%1) # update Pos\n\t"
124     "movswl 2(%0, %%edi,4), %%edx # load sample 0 (left)\n\t"
125     "cvtsi2ss %%edx, %%xmm3 # convert to float\n\t"
126     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
127     "movswl 4(%0, %%edi,4), %%eax # load sample 1 (left)\n\t"
128     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
129     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
130     "movswl 6(%0, %%edi,4), %%edx # load sample 1 (right)\n\t"
131     "cvtsi2ss %%edx, %%xmm3 # convert to float\n\t"
132     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
133     "movswl 8(%0, %%edi,4), %%eax # load sample 2 (left)\n\t"
134     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
135     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
136     "movswl 10(%0, %%edi,4), %%edx # load sample 2 (right)\n\t"
137     "cvtsi2ss %%edx, %%xmm3 # convert to float\n\t"
138     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
139     "movswl 12(%0, %%edi,4), %%eax # load sample 3 (left)\n\t"
140     "cvtsi2ss %%eax, %%xmm2 # convert to float\n\t"
141     "shufps $0x1b, %%xmm2, %%xmm2 # swap to correct order\n\t"
142     "movswl 14(%0, %%edi,4), %%edx # load sample 3 (right)\n\t"
143     "cvtsi2ss %%edx, %%xmm3 # convert to float\n\t"
144     "shufps $0x1b, %%xmm3, %%xmm3 # swap to correct order\n\t"
145     :: "r" (pSrc), "r" (Pos), "m" (__4f)
146     : "%eax", "%edx", "%edi"
147     );
148     }
149     }
150 schoenebeck 617 #endif // CONFIG_ASM && ARCH_X86
151 schoenebeck 320
152     protected:
153    
154 schoenebeck 2377 inline static int32_t getSample(sample_t* __restrict src, int pos) {
155 persson 903 if (BITDEPTH24) {
156     pos *= 3;
157 senoner 1484 #if WORDS_BIGENDIAN
158 persson 903 unsigned char* p = (unsigned char*)src;
159     return p[pos] << 8 | p[pos + 1] << 16 | p[pos + 2] << 24;
160 senoner 1484 #else
161     // 24bit read optimization:
162     // a misaligned 32bit read and subquent 8 bit shift is faster (on x86) than reading 3 single bytes and shifting them
163 senoner 1485 return (*((int32_t *)(&((char *)(src))[pos])))<<8;
164 senoner 1484 #endif
165 persson 903 } else {
166     return src[pos];
167     }
168     }
169    
170 schoenebeck 2377 inline static float Interpolate1StepMonoCPP(sample_t* __restrict pSrc, double* __restrict Pos, float& Pitch) {
171 schoenebeck 320 int pos_int = (int) *Pos; // integer position
172     float pos_fract = *Pos - pos_int; // fractional part of position
173    
174     #if USE_LINEAR_INTERPOLATION
175 persson 903 int x1 = getSample(pSrc, pos_int);
176     int x2 = getSample(pSrc, pos_int + 1);
177     float samplePoint = (x1 + pos_fract * (x2 - x1));
178 schoenebeck 320 #else // polynomial interpolation
179 senoner 1484 float xm1 = getSample(pSrc, pos_int);
180     float x0 = getSample(pSrc, pos_int + 1);
181     float x1 = getSample(pSrc, pos_int + 2);
182     float x2 = getSample(pSrc, pos_int + 3);
183 schoenebeck 320 float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f;
184     float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f;
185     float c = (x1 - xm1) * 0.5f;
186     float samplePoint = (((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0;
187     #endif // USE_LINEAR_INTERPOLATION
188    
189     *Pos += Pitch;
190     return samplePoint;
191     }
192    
193 schoenebeck 2377 inline static stereo_sample_t Interpolate1StepStereoCPP(sample_t* __restrict pSrc, double* __restrict Pos, float& Pitch) {
194 schoenebeck 320 int pos_int = (int) *Pos; // integer position
195     float pos_fract = *Pos - pos_int; // fractional part of position
196     pos_int <<= 1;
197    
198     stereo_sample_t samplePoint;
199    
200     #if USE_LINEAR_INTERPOLATION
201     // left channel
202 persson 903 int x1 = getSample(pSrc, pos_int);
203     int x2 = getSample(pSrc, pos_int + 2);
204     samplePoint.left = (x1 + pos_fract * (x2 - x1));
205 schoenebeck 320 // right channel
206 persson 903 x1 = getSample(pSrc, pos_int + 1);
207     x2 = getSample(pSrc, pos_int + 3);
208     samplePoint.right = (x1 + pos_fract * (x2 - x1));
209 schoenebeck 320 #else // polynomial interpolation
210     // calculate left channel
211 senoner 1484 float xm1 = getSample(pSrc, pos_int);
212     float x0 = getSample(pSrc, pos_int + 2);
213     float x1 = getSample(pSrc, pos_int + 4);
214     float x2 = getSample(pSrc, pos_int + 6);
215 schoenebeck 320 float a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f;
216     float b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f;
217     float c = (x1 - xm1) * 0.5f;
218     samplePoint.left = (((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0;
219    
220     //calculate right channel
221 senoner 1484 xm1 = getSample(pSrc, pos_int + 1);
222     x0 = getSample(pSrc, pos_int + 3);
223     x1 = getSample(pSrc, pos_int + 5);
224     x2 = getSample(pSrc, pos_int + 7);
225 schoenebeck 320 a = (3.0f * (x0 - x1) - xm1 + x2) * 0.5f;
226     b = 2.0f * x1 + xm1 - (5.0f * x0 + x2) * 0.5f;
227     c = (x1 - xm1) * 0.5f;
228     samplePoint.right = (((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0;
229     #endif // USE_LINEAR_INTERPOLATION
230    
231     *Pos += Pitch;
232     return samplePoint;
233     }
234    
235 schoenebeck 1259 #if 0 // CONFIG_ASM && ARCH_X86
236 schoenebeck 320 // TODO: no support for cubic interpolation yet
237     inline static void Interpolate4StepsMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
238     /* calculate playback position of each of the 4 samples by adding the associated pitch */
239     __asm__ __volatile__ (
240     "movss (%0),%%xmm0 # sample position of sample[0] -> xmm0[0]\n\t"
241     "movss %1,%%xmm1 # copy pitch -> xmm1[0]\n\t"
242     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
243     "addss %%xmm1,%%xmm0 # calculate sample position of sample[1]\n\t"
244     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
245     "addss %%xmm1,%%xmm0 # calculate sample position of sample[2]\n\t"
246     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
247     "addss %%xmm1,%%xmm0 # calculate sample position of sample[3]\n\t"
248     "movss %%xmm0,%%xmm2 # xmm0[0] -> xmm2[0]\n\t"
249     "addss %%xmm1,%%xmm2 # calculate initial sample position for the next 4-sample cycle\n\t"
250     "movss %%xmm2,(%0) # update 'Pos'\n\t"
251     "shufps $0x1b,%%xmm0,%%xmm0 # swap, so that xmm0[0]=sample pos 0, xmm0[1]=sample pos 1,...\n\t"
252     "cvttps2pi %%xmm0,%%mm4 # int(xmm0[0-1]) -> mm4\n\t"
253     "shufps $0xe4,%%xmm0,%%xmm1 # xmm0[2-3] -> xmm1[2-3]\n\t"
254     "shufps $0x0e,%%xmm1,%%xmm1 # xmm1[2-3] -> xmm1[0-1]\n\t"
255     "cvttps2pi %%xmm1,%%mm5 # int(xmm1[0-1]) -> mm5\n\t"
256     "cvtpi2ps %%mm5,%%xmm1 # double(mm5) -> xmm1[0-1]\n\t"
257     "shufps $0x44,%%xmm1,%%xmm1 # shift lower 2 FPs up to the upper 2 cells\n\t"
258     "cvtpi2ps %%mm4,%%xmm1 # double(mm4) -> xmm1[0-1]\n\t"
259     "subps %%xmm1,%%xmm0 # xmm0[1-3] = xmm0[1-3] - xmm1[1-3]\n\t"
260     :
261     : "r" (Pos), /* %0 */
262     "m" (Pitch) /* %1 */
263     : "%xmm0", /* holds fractional position (0.0 <= x < 1.0) of sample 0-3 at the end */
264     "%xmm1", /* holds integer position (back converted to SPFP) of sample 0-3 at the end */
265     "mm4", /* holds integer position of sample 0-1 at the end */
266     "mm5", /* holds integer position of sample 2-3 at the end */
267     "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"
268     );
269     /* get sample values of pSrc[pos_int] and pSrc[pos_int+1] of the 4 samples */
270     __asm__ __volatile__ (
271     "movd %%mm4,%%edi # sample position of sample 0\n\t"
272     "psrlq $32,%%mm4 # mm4 >> 32\n\t"
273     "movswl (%0,%%edi,2),%%eax # pSrc[pos_int] (sample 0)\n\t"
274     "movswl 2(%0,%%edi,2),%%ecx # pSrc[pos_int] (sample 0+1)\n\t"
275     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
276     "cvtsi2ss %%ecx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
277     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
278     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
279     "movd %%mm4,%%edi # sample position of sample 1\n\t"
280     "movswl (%0,%%edi,2),%%eax # pSrc[pos_int] (sample 1)\n\t"
281     "movswl 2(%0,%%edi,2),%%ecx # pSrc[pos_int] (sample 1+1)\n\t"
282     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
283     "cvtsi2ss %%ecx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
284     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
285     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
286     "movd %%mm5,%%edi # sample position of sample 2\n\t"
287     "psrlq $32,%%mm5 # mm5 >> 32\n\t"
288     "movswl (%0,%%edi,2),%%eax # pSrc[pos_int] (sample 2)\n\t"
289     "movswl 2(%0,%%edi,2),%%ecx # pSrc[pos_int] (sample 2+1)\n\t"
290     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
291     "cvtsi2ss %%ecx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
292     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
293     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
294     "movd %%mm5,%%edi # sample position of sample 2\n\t"
295     "movswl (%0,%%edi,2),%%eax # pSrc[pos_int] (sample 3)\n\t"
296     "movswl 2(%0,%%edi,2),%%ecx # pSrc[pos_int] (sample 3+1)\n\t"
297     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
298     "cvtsi2ss %%ecx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
299     "shufps $0x1b, %%xmm2, %%xmm2 # swap to correct order\n\t"
300     "shufps $0x1b, %%xmm3, %%xmm3 # swap to correct order\n\t"
301     : /* no output */
302     : "S" (pSrc) /* %0 - sample read position */
303     : "%eax", "%ecx", /*"%edx",*/ "%edi",
304     "%xmm2", /* holds pSrc[int_pos] of the 4 samples at the end */
305     "%xmm3", /* holds pSrc[int_pos+1] of the 4 samples at the end */
306     "mm4", /* holds integer position of sample 0-1 at the end */
307     "mm5", /* holds integer position of sample 2-3 at the end */
308     "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"
309     );
310     /* linear interpolation of the 4 samples simultaniously */
311     __asm__ __volatile__ (
312     "subps %%xmm2,%%xmm3 # xmm3 = pSrc[pos_int+1] - pSrc[pos_int]\n\t"
313     "mulps %%xmm0,%%xmm3 # xmm3 = pos_fract * (pSrc[pos_int+1] - pSrc[pos_int])\n\t"
314     "addps %%xmm3,%%xmm2 # xmm2 = pSrc[pos_int] + (pos_fract * (pSrc[pos_int+1] - pSrc[pos_int]))\n\t"
315     : /* no output */
316     : /* no input */
317     : "%xmm2" /* holds linear interpolated sample point (of all 4 samples) at the end */
318     );
319     }
320    
321     // TODO: no support for cubic interpolation yet
322     inline static void Interpolate4StepsStereoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
323     /* calculate playback position of each of the 4 samples by adding the associated pitch */
324     __asm__ __volatile__ (
325     "movss (%0),%%xmm0 # sample position of sample[0] -> xmm0[0]\n\t"
326     "movss %1,%%xmm1 # copy pitch -> xmm1[0]\n\t"
327     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
328     "addss %%xmm1,%%xmm0 # calculate sample position of sample[1]\n\t"
329     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
330     "addss %%xmm1,%%xmm0 # calculate sample position of sample[2]\n\t"
331     "shufps $0x90,%%xmm0,%%xmm0 # shift up, but keep xmm0[0]\n\t"
332     "addss %%xmm1,%%xmm0 # calculate sample position of sample[3]\n\t"
333     "movss %%xmm0,%%xmm2 # xmm0[0] -> xmm2[0]\n\t"
334     "addss %%xmm1,%%xmm2 # calculate initial sample position for the next 4-sample cycle\n\t"
335     "movss %%xmm2,(%0) # update 'Pos'\n\t"
336     "shufps $0x1b,%%xmm0,%%xmm0 # swap, so that xmm0[0]=sample pos 0, xmm0[1]=sample pos 1,...\n\t"
337     "cvttps2pi %%xmm0,%%mm4 # int(xmm0[0-1]) -> mm4\n\t"
338     "shufps $0xe4,%%xmm0,%%xmm1 # xmm0[2-3] -> xmm1[2-3]\n\t"
339     "shufps $0x0e,%%xmm1,%%xmm1 # xmm1[2-3] -> xmm1[0-1]\n\t"
340     "cvttps2pi %%xmm1,%%mm5 # int(xmm1[0-1]) -> mm5\n\t"
341     "cvtpi2ps %%mm5,%%xmm1 # double(mm5) -> xmm1[0-1]\n\t"
342     "shufps $0x44,%%xmm1,%%xmm1 # shift lower 2 FPs up to the upper 2 cells\n\t"
343     "cvtpi2ps %%mm4,%%xmm1 # double(mm4) -> xmm1[0-1]\n\t"
344     "subps %%xmm1,%%xmm0 # xmm0[1-3] = xmm0[1-3] - xmm1[1-3]\n\t"
345     :
346     : "r" (Pos), /* %0 */
347     "m" (Pitch) /* %1 */
348     : "%xmm0", /* holds fractional position (0.0 <= x < 1.0) of sample 0-3 at the end */
349     "%xmm1", /* holds integer position (back converted to SPFP) of sample 0-3 at the end */
350     "mm4", /* holds integer position of sample 0-1 at the end */
351     "mm5", /* holds integer position of sample 2-3 at the end */
352     "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"
353     );
354    
355     /* get sample values of pSrc[pos_int], pSrc[pos_int+1], pSrc[pos_int+2] and pSrc[pos_int+3] of the 4 samples */
356     __asm__ __volatile__ (
357     "xorl %%eax,%%eax # clear eax\n\t"
358     "xorl %%edx,%%edx # clear edx\n\t"
359     "movd %%mm4,%%edi # sample position of sample 0\n\t"
360     "psrlq $32,%%mm4 # mm4 >> 32\n\t"
361     "movswl (%0,%%edi,4),%%eax # pSrc[pos_int] (sample 0)\n\t"
362     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
363     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
364     "movswl 2(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 0+1)\n\t"
365     "cvtsi2ss %%edx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
366     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
367     "movswl 4(%0,%%edi,4),%%eax # pSrc[pos_int] (sample 0+2)\n\t"
368     "cvtsi2ss %%eax, %%xmm4 # pSrc[pos_int] -> xmm4[0]\n\t"
369     "shufps $0x93, %%xmm4, %%xmm4 # shift up\n\t"
370     "movswl 6(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 0+3)\n\t"
371     "cvtsi2ss %%edx, %%xmm5 # pSrc[pos_int] -> xmm5[0]\n\t"
372     "movd %%mm4,%%edi # sample position of sample 1\n\t"
373     "shufps $0x93, %%xmm5, %%xmm5 # shift up\n\t"
374     "movswl (%0,%%edi,4),%%eax # pSrc[pos_int] (sample 1)\n\t"
375     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
376     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
377     "movswl 2(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 1+1)\n\t"
378     "cvtsi2ss %%edx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
379     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
380     "movswl 4(%0,%%edi,4),%%eax # pSrc[pos_int] (sample 1+2)\n\t"
381     "cvtsi2ss %%eax, %%xmm4 # pSrc[pos_int] -> xmm4[0]\n\t"
382     "shufps $0x93, %%xmm4, %%xmm4 # shift up\n\t"
383     "movswl 6(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 1+3)\n\t"
384     "cvtsi2ss %%edx, %%xmm5 # pSrc[pos_int] -> xmm5[0]\n\t"
385     "movd %%mm5,%%edi # sample position of sample 2\n\t"
386     "shufps $0x93, %%xmm5, %%xmm5 # shift up\n\t"
387     "psrlq $32,%%mm5 # mm5 >> 32\n\t"
388     "movswl (%0,%%edi,4),%%eax # pSrc[pos_int] (sample 2)\n\t"
389     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
390     "shufps $0x93, %%xmm2, %%xmm2 # shift up\n\t"
391     "movswl 2(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 2+1)\n\t"
392     "cvtsi2ss %%edx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
393     "shufps $0x93, %%xmm3, %%xmm3 # shift up\n\t"
394     "movswl 4(%0,%%edi,4),%%eax # pSrc[pos_int] (sample 2+2)\n\t"
395     "cvtsi2ss %%eax, %%xmm4 # pSrc[pos_int] -> xmm4[0]\n\t"
396     "shufps $0x93, %%xmm4, %%xmm4 # shift up\n\t"
397     "movswl 6(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 2+3)\n\t"
398     "cvtsi2ss %%edx, %%xmm5 # pSrc[pos_int] -> xmm5[0]\n\t"
399     "movd %%mm5,%%edi # sample position of sample 3\n\t"
400     "shufps $0x93, %%xmm5, %%xmm5 # shift up\n\t"
401     "movswl (%0,%%edi,4),%%eax # pSrc[pos_int] (sample 3)\n\t"
402     "cvtsi2ss %%eax, %%xmm2 # pSrc[pos_int] -> xmm2[0]\n\t"
403     "shufps $0x1b, %%xmm2, %%xmm2 # shift up\n\t"
404     "movswl 2(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 3+1)\n\t"
405     "cvtsi2ss %%edx, %%xmm3 # pSrc[pos_int] -> xmm3[0]\n\t"
406     "shufps $0x1b, %%xmm3, %%xmm3 # shift up\n\t"
407     "movswl 4(%0,%%edi,4),%%eax # pSrc[pos_int] (sample 3+2)\n\t"
408     "cvtsi2ss %%eax, %%xmm4 # pSrc[pos_int] -> xmm4[0]\n\t"
409     "shufps $0x1b, %%xmm4, %%xmm4 # swap to correct order\n\t"
410     "movswl 6(%0,%%edi,4),%%edx # pSrc[pos_int] (sample 3+3)\n\t"
411     "cvtsi2ss %%edx, %%xmm5 # pSrc[pos_int] -> xmm5[0]\n\t"
412     "shufps $0x1b, %%xmm5, %%xmm5 # swap to correct order\n\t"
413     : /* no output */
414     : "S" (pSrc) /* %0 - sample read position */
415     : "%eax", "%edx", "%edi",
416     "xmm2", /* holds pSrc[int_pos] of the 4 samples at the end */
417     "xmm3", /* holds pSrc[int_pos+1] of the 4 samples at the end */
418     "xmm4", /* holds pSrc[int_pos+2] of the 4 samples at the end */
419     "xmm5", /* holds pSrc[int_pos+3] of the 4 samples at the end */
420     "mm4", /* holds integer position of sample 0-1 at the end */
421     "mm5", /* holds integer position of sample 2-3 at the end */
422     "st", "st(1)", "st(2)", "st(3)", "st(4)", "st(5)", "st(6)", "st(7)"
423     );
424     /* linear interpolation of the 4 samples (left & right channel) simultaniously */
425     __asm__ __volatile__ (
426     "subps %%xmm2,%%xmm4 # xmm4 = pSrc[pos_int+2] - pSrc[pos_int] (left channel)\n\t"
427     "mulps %%xmm0,%%xmm4 # xmm4 = pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]) (left channel)\n\t"
428     "addps %%xmm4,%%xmm2 # xmm2 = pSrc[pos_int] + (pos_fract * (pSrc[pos_int+2] - pSrc[pos_int])) (left channel)\n\t"
429     "subps %%xmm3,%%xmm5 # xmm5 = pSrc[pos_int+3] - pSrc[pos_int+1] (right channel)\n\t"
430     "mulps %%xmm0,%%xmm5 # xmm5 = pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1]) (right channel)\n\t"
431     "addps %%xmm5,%%xmm3 # xmm3 = pSrc[pos_int+1] + (pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1])) (right channel)\n\t"
432     : /* no output */
433     : /* no input */
434     : "%xmm2", /* holds linear interpolated sample of left channel (of all 4 samples) at the end */
435     "%xmm3" /* holds linear interpolated sample of right channel (of all 4 samples) at the end */
436     );
437     }
438 schoenebeck 617 #endif // CONFIG_ASM && ARCH_X86
439 schoenebeck 320 };
440    
441     } // namespace LinuxSampler
442    
443     #endif // __LS_RESAMPLER_H__

  ViewVC Help
Powered by ViewVC