/[svn]/linuxsampler/trunk/src/engines/gig/Synthesizer.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/Synthesizer.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 424 by schoenebeck, Fri Mar 4 22:54:11 2005 UTC revision 866 by persson, Thu May 25 14:39:45 2006 UTC
# Line 29  Line 29 
29  #include "../common/Resampler.h"  #include "../common/Resampler.h"
30  #include "../common/BiquadFilter.h"  #include "../common/BiquadFilter.h"
31  #include "Filter.h"  #include "Filter.h"
32  #include "Voice.h"  #include "SynthesisParam.h"
33    
34  #define SYNTHESIS_MODE_SET_CONSTPITCH(iMode,bVal)       if (bVal) iMode |= 0x01; else iMode &= ~0x01   /* (un)set mode bit 0 */  #define SYNTHESIS_MODE_SET_INTERPOLATE(iMode,bVal)      if (bVal) iMode |= 0x01; else iMode &= ~0x01   /* (un)set mode bit 0 */
35  #define SYNTHESIS_MODE_SET_LOOP(iMode,bVal)             if (bVal) iMode |= 0x02; else iMode &= ~0x02   /* (un)set mode bit 1 */  #define SYNTHESIS_MODE_SET_FILTER(iMode,bVal)           if (bVal) iMode |= 0x02; else iMode &= ~0x02   /* (un)set mode bit 1 */
36  #define SYNTHESIS_MODE_SET_INTERPOLATE(iMode,bVal)      if (bVal) iMode |= 0x04; else iMode &= ~0x04   /* (un)set mode bit 2 */  #define SYNTHESIS_MODE_SET_LOOP(iMode,bVal)             if (bVal) iMode |= 0x04; else iMode &= ~0x04   /* (un)set mode bit 2 */
37  #define SYNTHESIS_MODE_SET_FILTER(iMode,bVal)           if (bVal) iMode |= 0x08; else iMode &= ~0x08   /* (un)set mode bit 3 */  #define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal)         if (bVal) iMode |= 0x08; else iMode &= ~0x08   /* (un)set mode bit 3 */
38  #define SYNTHESIS_MODE_SET_CHANNELS(iMode,bVal)         if (bVal) iMode |= 0x10; else iMode &= ~0x10   /* (un)set mode bit 4 */  #define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal)   if (bVal) iMode |= 0x10; else iMode &= ~0x10   /* (un)set mode bit 4 */
39  #define SYNTHESIS_MODE_SET_IMPLEMENTATION(iMode,bVal)   if (bVal) iMode |= 0x20; else iMode &= ~0x20   /* (un)set mode bit 5 */  #define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal)        if (bVal) iMode |= 0x20; else iMode &= ~0x20   /* (un)set mode bit 5 */
40  #define SYNTHESIS_MODE_SET_PROFILING(iMode,bVal)        if (bVal) iMode |= 0x40; else iMode &= ~0x40   /* (un)set mode bit 6 */  
41    #define SYNTHESIS_MODE_GET_INTERPOLATE(iMode)           iMode & 0x01
42  #define SYNTHESIS_MODE_GET_CONSTPITCH(iMode)            iMode & 0x01  #define SYNTHESIS_MODE_GET_FILTER(iMode)                iMode & 0x02
43  #define SYNTHESIS_MODE_GET_LOOP(iMode)                  iMode & 0x02  #define SYNTHESIS_MODE_GET_LOOP(iMode)                  iMode & 0x04
44  #define SYNTHESIS_MODE_GET_INTERPOLATE(iMode)           iMode & 0x04  #define SYNTHESIS_MODE_GET_CHANNELS(iMode)              iMode & 0x08
45  #define SYNTHESIS_MODE_GET_FILTER(iMode)                iMode & 0x08  #define SYNTHESIS_MODE_GET_IMPLEMENTATION(iMode)        iMode & 0x10
 #define SYNTHESIS_MODE_GET_CHANNELS(iMode)              iMode & 0x10  
 #define SYNTHESIS_MODE_GET_IMPLEMENTATION(iMode)        iMode & 0x20  
   
 // that's usually gig::Voice of course, but we make it a macro so we can  
 // include this code for our synthesis benchmark which uses fake data  
 // structures  
 #ifndef VOICE  
 # define VOICE Voice  
 #endif // VOICE  
46    
47  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
48    
49      typedef void SynthesizeFragment_Fn(VOICE&, uint, sample_t*, uint);      typedef void SynthesizeFragment_Fn(SynthesisParam* pFinalParam, Loop* pLoop);
50    
51      void* GetSynthesisFunction(const int SynthesisMode);      void* GetSynthesisFunction(const int SynthesisMode);
52      void RunSynthesisFunction(const int SynthesisMode, VOICE& voice, uint Samples, sample_t* pSrc, uint Skip);      void RunSynthesisFunction(const int SynthesisMode, SynthesisParam* pFinalParam, Loop* pLoop);
53    
54      enum channels_t {      enum channels_t {
55          MONO,          MONO,
56          STEREO          STEREO
57      };      };
58    
59      template<implementation_t IMPLEMENTATION, channels_t CHANNELS, bool USEFILTER, bool INTERPOLATE, bool DOLOOP, bool CONSTPITCH>      /** @brief Main Synthesis algorithms for the gig::Engine
60      class Synthesizer : public __RTMath<IMPLEMENTATION>, public LinuxSampler::Resampler<INTERPOLATE> {       *
61          public:       * Implementation of the main synthesis algorithms of the Gigasampler
62              template<typename VOICE_T>       * format capable sampler engine. This means resampling / interpolation
63              inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint i) {       * for pitching the audio signal, looping, filter and amplification.
64                  const float panLeft  = Mul(Voice.PanLeft,  Voice.pEngineChannel->GlobalPanLeft);       */
65                  const float panRight = Mul(Voice.PanRight, Voice.pEngineChannel->GlobalPanRight);      template<channels_t CHANNELS, bool DOLOOP, bool USEFILTER, bool INTERPOLATE>
66                  if (IMPLEMENTATION == ASM_X86_MMX_SSE) {      class Synthesizer : public __RTMath<CPP>, public LinuxSampler::Resampler<INTERPOLATE> {
67                      float fPos = (float) Voice.Pos;  
68                      SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount,              // declarations of derived functions (see "Name lookup,
69                                         Voice.pSample->LoopStart,              // templates, and accessing members of base classes" in
70                                         Voice.pSample->LoopEnd,              // the gcc manual for an explanation of why this is
71                                         Voice.pSample->LoopSize,              // needed).
72                                         Voice.LoopCyclesLeft,              //using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleMonoCPP;
73                                         (void *)&fPos,              //using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleStereoCPP;
74                                         Voice.PitchBase,              using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepMonoCPP;
75                                         Voice.PitchBend,              using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepStereoCPP;
                                        &panLeft, &panRight);  
                     #if  ARCH_X86  
                     if (INTERPOLATE) EMMS;  
                     #endif  
                     Voice.Pos = (double) fPos;  
                 } else {  
                     SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount,  
                                        Voice.pSample->LoopStart,  
                                        Voice.pSample->LoopEnd,  
                                        Voice.pSample->LoopSize,  
                                        Voice.LoopCyclesLeft,  
                                        (void *)&Voice.Pos,  
                                        Voice.PitchBase,  
                                        Voice.PitchBend,  
                                        &panLeft, &panRight);  
                 }  
             }  
76    
77            public:
78          //protected:          //protected:
79    
80              template<typename VOICE_T>              static void SynthesizeSubFragment(SynthesisParam* pFinalParam, Loop* pLoop) {
             inline static void SynthesizeFragment(VOICE_T& Voice, uint Samples, sample_t* pSrc, uint& i, uint& LoopPlayCount, uint LoopStart, uint LoopEnd, uint LoopSize, uint& LoopCyclesLeft, void* Pos, float& PitchBase, float& PitchBend, const float* PanLeft, const float* PanRight) {  
                 const float loopEnd = Float(LoopEnd);  
                 const float PBbyPB = Mul(PitchBase, PitchBend);  
                 const float f_LoopStart = Float(LoopStart);  
                 const float f_LoopSize = Float(LoopSize);  
81                  if (DOLOOP) {                  if (DOLOOP) {
82                      if (LoopPlayCount) {                      const float fLoopEnd   = Float(pLoop->uiEnd);
83                        const float fLoopStart = Float(pLoop->uiStart);
84                        const float fLoopSize  = Float(pLoop->uiSize);
85                        if (pLoop->uiTotalCycles) {
86                          // render loop (loop count limited)                          // render loop (loop count limited)
87                          while (i < Samples && LoopCyclesLeft) {                          for (; pFinalParam->uiToGo > 0 && pLoop->uiCyclesLeft; pLoop->uiCyclesLeft -= WrapLoop(fLoopStart, fLoopSize, fLoopEnd, &pFinalParam->dPos)) {
88                              if (CONSTPITCH) {                              const uint uiToGo = Min(pFinalParam->uiToGo, DiffToLoopEnd(fLoopEnd, &pFinalParam->dPos, pFinalParam->fFinalPitch) + 1); //TODO: instead of +1 we could also round up
89                                  const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd,Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up                              SynthesizeSubSubFragment(pFinalParam, uiToGo);
                                 while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);  
                             }  
                             else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);  
                             if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--;  
90                          }                          }
91                          // render on without loop                          // render on without loop
92                          while (i < Samples) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);                          SynthesizeSubSubFragment(pFinalParam, pFinalParam->uiToGo);
93                      }                      } else { // render loop (endless loop)
94                      else { // render loop (endless loop)                          for (; pFinalParam->uiToGo > 0; WrapLoop(fLoopStart, fLoopSize, fLoopEnd, &pFinalParam->dPos)) {
95                          while (i < Samples) {                              const uint uiToGo = Min(pFinalParam->uiToGo, DiffToLoopEnd(fLoopEnd, &pFinalParam->dPos, pFinalParam->fFinalPitch) + 1); //TODO: instead of +1 we could also round up
96                              if (CONSTPITCH) {                              SynthesizeSubSubFragment(pFinalParam, uiToGo);
                                 const uint processEnd = Min(Samples, i + DiffToLoopEnd(loopEnd, Pos, PBbyPB) + 1); //TODO: instead of +1 we could also round up  
                                 while (i < processEnd) Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);  
                             }  
                             else Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);  
                             WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos);  
97                          }                          }
98                      }                      }
99                    } else { // no looping
100                        SynthesizeSubSubFragment(pFinalParam, pFinalParam->uiToGo);
101                  }                  }
                 else { // no looping  
                     while (i < Samples) { Synthesize(Voice, Pos, pSrc, i, PanLeft, PanRight);}  
                 }  
             }  
   
             template<typename VOICE_T>  
             inline static void Synthesize(VOICE_T& Voice, void* Pos, sample_t* pSrc, uint& i, const float* PanLeft, const float* PanRight) {  
                 Synthesize(pSrc, Pos,  
                            Voice.pEngine->pSynthesisParameters[Event::destination_vco][i],  
                            Voice.pEngineChannel->pOutputLeft,  
                            Voice.pEngineChannel->pOutputRight,  
                            i,  
                            Voice.pEngine->pSynthesisParameters[Event::destination_vca],  
                            PanLeft,  
                            PanRight,  
                            Voice.FilterLeft,  
                            Voice.FilterRight,  
                            Voice.pEngine->pBasicFilterParameters[i],  
                            Voice.pEngine->pMainFilterParameters[i]);  
102              }              }
103    
104                /**
105                 * Returns the difference to the sample's loop end.
106                 */
107              inline static int DiffToLoopEnd(const float& LoopEnd, const void* Pos, const float& Pitch) {              inline static int DiffToLoopEnd(const float& LoopEnd, const void* Pos, const float& Pitch) {
108                  switch (IMPLEMENTATION) {                  return uint((LoopEnd - *((double *)Pos)) / Pitch);
                     // pure C++ implementation (thus platform independent)  
                     case CPP: {  
                         return uint((LoopEnd - *((double *)Pos)) / Pitch);  
                     }  
                     #if ARCH_X86  
                     case ASM_X86_MMX_SSE: {  
                         int result;  
                         __asm__ __volatile__ (  
                             "movss    (%1), %%xmm0  #read loopend\n\t"  
                             "subss    (%2), %%xmm0  #sub  pos\n\t"  
                             "divss    (%3), %%xmm0  #div  by pitch\n\t"  
                             "cvtss2si %%xmm0, %0    #convert to int\n\t"  
                             : "=r" (result)   /* %0 */  
                             : "r" (&LoopEnd), /* %1 */  
                               "r" (Pos),      /* %2 */  
                               "r" (&Pitch)    /* %3 */  
                         );  
                         return result;  
                     }  
                     #endif // ARCH_X86  
                 }  
109              }              }
110    
111    #if 0
112                //TODO: this method is not in use yet, it's intended to be used for pitch=x.0f where we could use integer instead of float as playback position variable
113                inline static int WrapLoop(const int& LoopStart, const int& LoopSize, const int& LoopEnd, int& Pos) {
114                    //TODO: we can easily eliminate the branch here
115                    if (Pos < LoopEnd) return 0;
116                    Pos = (Pos - LoopEnd) % LoopSize + LoopStart;
117                    return 1;
118                }
119    #endif
120    
121                /**
122                 * This method handles looping of the RAM playback part of the
123                 * sample, thus repositioning the playback position once the
124                 * loop limit was reached. Note: looping of the disk streaming
125                 * part is handled by libgig (ReadAndLoop() method which will
126                 * be called by the DiskThread).
127                 */
128              inline static int WrapLoop(const float& LoopStart, const float& LoopSize, const float& LoopEnd, void* vPos) {              inline static int WrapLoop(const float& LoopStart, const float& LoopSize, const float& LoopEnd, void* vPos) {
129                  switch (IMPLEMENTATION) {                  double * Pos = (double *)vPos;
130                      // pure C++ implementation (thus platform independent)                  if (*Pos < LoopEnd) return 0;
131                      case CPP: {                  *Pos = fmod(*Pos - LoopEnd, LoopSize) + LoopStart;
132                          double * Pos = (double *)vPos;                  return 1;
133                          if (*Pos < LoopEnd) return 0;              }
134                          *Pos = fmod(*Pos - LoopEnd, LoopSize) + LoopStart;  
135                          return 1;              static void SynthesizeSubSubFragment(SynthesisParam* pFinalParam, uint uiToGo) {
136                      }                  float fVolumeL = pFinalParam->fFinalVolumeLeft;
137                      #if ARCH_X86                  float fVolumeR = pFinalParam->fFinalVolumeRight;
138                      case ASM_X86_MMX_SSE: {                  sample_t* pSrc = pFinalParam->pSrc;
139                          int result = 0;                  float* pOutL   = pFinalParam->pOutLeft;
140                          __asm__ __volatile__ (                  float* pOutR   = pFinalParam->pOutRight;
141                              "movss  (%2), %%xmm0          # load LoopEnd\n\t"  #ifdef CONFIG_INTERPOLATE_VOLUME
142                              "movss  (%1), %%xmm1          # load Pos\n\t"                  float fDeltaL  = pFinalParam->fFinalVolumeDeltaLeft;
143                              "comiss %%xmm0, %%xmm1      # LoopEnd <> Pos\n\t"                  float fDeltaR  = pFinalParam->fFinalVolumeDeltaRight;
144                              "jb     1f                  # jump if no work needs to be done\n\t"  #endif
145                              "movss    (%3), %%xmm2        # load LoopSize\n\t"                  switch (CHANNELS) {
146                              "subss    %%xmm0, %%xmm1    # Pos - LoopEnd\n\t"                      case MONO: {
147                              //now the fmodf                          float samplePoint;
148                              "movss    %%xmm1, %%xmm3    # xmm3 = (Pos - LoopEnd)\n\t"                          if (INTERPOLATE) {
149                              "divss    %%xmm2, %%xmm1    # (Pos - LoopEnd) / LoopSize\n\t"                              double dPos    = pFinalParam->dPos;
150                              "cvttss2si %%xmm1, %%eax    # convert to int\n\t"                              float fPitch   = pFinalParam->fFinalPitch;
151                              "cvtsi2ss  %%eax, %%xmm1    # convert back to float\n\t"                              if (USEFILTER) {
152                              "movss    (%4), %%xmm0      # load LoopStart\n\t"                                  Filter filterL = pFinalParam->filterLeft;
153                              "mulss    %%xmm2, %%xmm1    # LoopSize * int((Pos-LoopEnd)/LoopSize)\n\t"                                  for (int i = 0; i < uiToGo; ++i) {
154                              "subss    %%xmm1, %%xmm3    # xmm2 = fmodf(Pos - LoopEnd, LoopSize)\n\t"                                      samplePoint = Interpolate1StepMonoCPP(pSrc, &dPos, fPitch);
155                              //done with fmodf                                      samplePoint = filterL.Apply(samplePoint);
156                              "addss    %%xmm0, %%xmm3      # add LoopStart\n\t"  #ifdef CONFIG_INTERPOLATE_VOLUME
157                              "movss    %%xmm3, (%1)        # update Pos\n\t"                                      fVolumeL += fDeltaL;
158                              "movl    $1, (%0)             # result = 1\n\t"                                      fVolumeR += fDeltaR;
159                              ".balign 16 \n\t"  #endif
160                              "1:\n\t"                                      pOutL[i] += samplePoint * fVolumeL;
161                              :: "r" (&result),   /* %0 */                                      pOutR[i] += samplePoint * fVolumeR;
162                                "r"  (vPos),      /* %1 */                                  }
163                                "r"  (&LoopEnd),  /* %2 */                              } else { // no filter needed
164                                "r"  (&LoopSize), /* %3 */                                  for (int i = 0; i < uiToGo; ++i) {
165                                "r"  (&LoopStart) /* %4 */                                      samplePoint = Interpolate1StepMonoCPP(pSrc, &dPos, fPitch);
166                          );  #ifdef CONFIG_INTERPOLATE_VOLUME
167                          return result;                                      fVolumeL += fDeltaL;
168                      }                                      fVolumeR += fDeltaR;
169                      #endif // ARCH_X86  #endif
170                  }                                      pOutL[i] += samplePoint * fVolumeL;
171              }                                      pOutR[i] += samplePoint * fVolumeR;
172                                    }
             inline static void Synthesize(sample_t* pSrc, void* Pos, float& Pitch, float* pOutL, float* pOutR, uint& i, float* Volume, const float* PanL, const float* PanR, Filter& FilterL, Filter& FilterR, biquad_param_t& bqBase, biquad_param_t& bqMain) {  
                 switch (IMPLEMENTATION) {  
                     // pure C++ implementation (thus platform independent)  
                     case CPP: {  
                         switch (CHANNELS) {  
                             case MONO: {  
                                 float samplePoint = GetNextSampleMonoCPP(pSrc, (double *)Pos, Pitch);  
                                 if (USEFILTER) samplePoint = FilterL.Apply(&bqBase, &bqMain, samplePoint);  
                                 pOutL[i] += samplePoint * Volume[i] * *PanL;  
                                 pOutR[i] += samplePoint * Volume[i] * *PanR;  
                                 i++;  
                                 break;  
173                              }                              }
174                              case STEREO: {                              pFinalParam->dPos = dPos;
175                                  stereo_sample_t samplePoint = GetNextSampleStereoCPP(pSrc, (double *)Pos, Pitch);                          } else { // no interpolation
176                                  if (USEFILTER) {                              int pos_offset = (int) pFinalParam->dPos;
177                                      samplePoint.left  = FilterL.Apply(&bqBase, &bqMain, samplePoint.left);                              if (USEFILTER) {
178                                      samplePoint.right = FilterR.Apply(&bqBase, &bqMain, samplePoint.right);                                  Filter filterL = pFinalParam->filterLeft;
179                                    for (int i = 0; i < uiToGo; ++i) {
180                                        samplePoint = pSrc[i + pos_offset];
181                                        samplePoint = filterL.Apply(samplePoint);
182    #ifdef CONFIG_INTERPOLATE_VOLUME
183                                        fVolumeL += fDeltaL;
184                                        fVolumeR += fDeltaR;
185    #endif
186                                        pOutL[i] += samplePoint * fVolumeL;
187                                        pOutR[i] += samplePoint * fVolumeR;
188                                    }
189                                } else { // no filter needed
190                                    for (int i = 0; i < uiToGo; ++i) {
191                                        samplePoint = pSrc[i + pos_offset];
192    #ifdef CONFIG_INTERPOLATE_VOLUME
193                                        fVolumeL += fDeltaL;
194                                        fVolumeR += fDeltaR;
195    #endif
196                                        pOutL[i] += samplePoint * fVolumeL;
197                                        pOutR[i] += samplePoint * fVolumeR;
198                                  }                                  }
                                 pOutL[i] += samplePoint.left  * Volume[i] * *PanL;  
                                 pOutR[i] += samplePoint.right * Volume[i] * *PanR;  
                                 i++;  
                                 break;  
199                              }                              }
200                                pFinalParam->dPos += uiToGo;
201                          }                          }
202                          break;                          break;
203                      }                      }
204                      #if ARCH_X86                      case STEREO: {
205                      // Assembly optimization using the MMX & SSE(1) instruction set (thus only for x86)                          stereo_sample_t samplePoint;
206                      case ASM_X86_MMX_SSE: {                          if (INTERPOLATE) {
207                          const int ii = i & 0xfffffffc;                              double dPos    = pFinalParam->dPos;
208                          i += 4;                              float fPitch   = pFinalParam->fFinalPitch;
209                          switch (CHANNELS) {                              if (USEFILTER) {
210                              case MONO: {                                  Filter filterL = pFinalParam->filterLeft;
211                                  GetNext4SamplesMonoMMXSSE(pSrc, (float *)Pos, Pitch); // outputs samples in xmm2                                  Filter filterR = pFinalParam->filterRight;
212                                  if (USEFILTER) {                                  for (int i = 0; i < uiToGo; ++i) {
213                                      /* prepare filter input */                                      samplePoint = Interpolate1StepStereoCPP(pSrc, &dPos, fPitch);
214                                      __asm__ __volatile__ (                                      samplePoint.left  = filterL.Apply(samplePoint.left);
215                                          "movaps %xmm2,%xmm0"                                      samplePoint.right = filterR.Apply(samplePoint.right);
216                                      );  #ifdef CONFIG_INTERPOLATE_VOLUME
217                                      FilterL.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      fVolumeL += fDeltaL;
218                                      __asm__ __volatile__ (                                      fVolumeR += fDeltaR;
219                                          "movaps %xmm7,%xmm2       # mono filter result -> xmm2"  #endif
220                                      );                                      pOutL[i] += samplePoint.left  * fVolumeL;
221                                        pOutR[i] += samplePoint.right * fVolumeR;
222                                    }
223                                } else { // no filter needed
224                                    for (int i = 0; i < uiToGo; ++i) {
225                                        samplePoint = Interpolate1StepStereoCPP(pSrc, &dPos, fPitch);
226    #ifdef CONFIG_INTERPOLATE_VOLUME
227                                        fVolumeL += fDeltaL;
228                                        fVolumeR += fDeltaR;
229    #endif
230                                        pOutL[i] += samplePoint.left  * fVolumeL;
231                                        pOutR[i] += samplePoint.right * fVolumeR;
232                                  }                                  }
                                 /* apply panorama and volume factors */  
                                 __asm__ __volatile__ (  
                                     "movss    (%1),%%xmm0             # load pan left\n\t"  
                                     "movss    (%2),%%xmm1             # load pan right\n\t"  
                                     "movaps   (%0),%%xmm4             # load vca\n\t"  
                                     "shufps   $0x00,%%xmm0,%%xmm0     # copy pan left to the other 3 cells\n\t"  
                                     "shufps   $0x00,%%xmm1,%%xmm1     # copy pan right to the other 3 cells\n\t"  
                                     "mulps    %%xmm2,%%xmm0           # left  = sample * pan_left\n\t"  
                                     "mulps    %%xmm2,%%xmm1           # right = sample * pan_right\n\t"  
                                     "mulps    %%xmm4,%%xmm0           # left  = vca * (sample * pan_left)\n\t"  
                                     "mulps    %%xmm4,%%xmm1           # right = vca * (sample * pan_right)\n\t"  
                                     : /* no output */  
                                     : "r" (&Volume[ii]), /* %0 */  
                                       "r" (PanL),   /* %1 */  
                                       "r" (PanR)    /* %2 */  
                                     : "xmm0", /* holds final left  sample (for the 4 samples) at the end */  
                                       "xmm1"  /* holds final right sample (for the 4 samples) at the end */  
                                 );  
                                 break;  
233                              }                              }
234                              case STEREO: {                              pFinalParam->dPos = dPos;
235                                  GetNext4SamplesStereoMMXSSE(pSrc, (float *)Pos, Pitch); // outputs samples in xmm2 (left channel) and xmm3 (right channel)                          } else { // no interpolation
236                                  if (USEFILTER) {                              int pos_offset = ((int) pFinalParam->dPos) << 1;
237                                      __asm__ __volatile__ (                              if (USEFILTER) {
238                                          "movaps %xmm2,%xmm0     # prepare left channel for filter\n\t"                                  Filter filterL = pFinalParam->filterLeft;
239                                          "movaps %xmm3,%xmm1     # save right channel not to get overwritten by filter algorithms\n\t"                                  Filter filterR = pFinalParam->filterRight;
240                                      );                                  for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) {
241                                      FilterL.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      samplePoint.left  = pSrc[ii + pos_offset];
242                                      __asm__ __volatile__ (                                      samplePoint.right = pSrc[ii + pos_offset + 1];
243                                          "movaps %xmm1,%xmm0     # prepare right channel for filter\n\t"                                      samplePoint.left  = filterL.Apply(samplePoint.left);
244                                          "movaps %xmm7,%xmm1     # save filter output for left channel\n\t"                                      samplePoint.right = filterR.Apply(samplePoint.right);
245                                      );  #ifdef CONFIG_INTERPOLATE_VOLUME
246                                      FilterR.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      fVolumeL += fDeltaL;
247                                      __asm__ __volatile__ (                                      fVolumeR += fDeltaR;
248                                          "movaps %xmm1,%xmm2     # result left channel -> xmm2\n\t"  #endif
249                                          "movaps %xmm7,%xmm3     # result right channel -> xmm3\n\t"                                      pOutL[i] += samplePoint.left  * fVolumeL;
250                                      );                                      pOutR[i] += samplePoint.right * fVolumeR;
251                                    }
252                                } else { // no filter needed
253                                    for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) {
254                                        samplePoint.left  = pSrc[ii + pos_offset];
255                                        samplePoint.right = pSrc[ii + pos_offset + 1];
256    #ifdef CONFIG_INTERPOLATE_VOLUME
257                                        fVolumeL += fDeltaL;
258                                        fVolumeR += fDeltaR;
259    #endif
260                                        pOutL[i] += samplePoint.left  * fVolumeL;
261                                        pOutR[i] += samplePoint.right * fVolumeR;
262                                  }                                  }
                                 /* apply panorama and volume factors */  
                                 __asm__ __volatile__ (  
                                     "movss    (%1),%%xmm0             # load pan left\n\t"  
                                     "movss    (%2),%%xmm1             # load pan right\n\t"  
                                     "movaps   (%0),%%xmm4             # load vca\n\t"  
                                     "shufps   $0x00,%%xmm0,%%xmm0     # copy pan left to the other 3 cells\n\t"  
                                     "shufps   $0x00,%%xmm1,%%xmm1     # copy pan right to the other 3 cells\n\t"  
                                     "mulps    %%xmm2,%%xmm0           # left  = sample_left  * pan_left\n\t"  
                                     "mulps    %%xmm3,%%xmm1           # right = sample_right * pan_right\n\t"  
                                     "mulps    %%xmm4,%%xmm0           # left  = vca * (sample_left  * pan_left)\n\t"  
                                     "mulps    %%xmm4,%%xmm1           # right = vca * (sample_right * pan_right)\n\t"  
                                     : /* no output */  
                                     : "r" (&Volume[ii]), /* %0 */  
                                       "r" (PanL),   /* %1 */  
                                       "r" (PanR)    /* %2 */  
                                 );  
                                 break;  
263                              }                              }
264                                pFinalParam->dPos += uiToGo;
265                          }                          }
266                          /* mix the 4 samples to the output channels */                          break;
                         __asm__ __volatile__ (  
                             "addps  (%0),%%xmm0       # mix calculated sample(s) to output left\n\t"  
                             "movaps %%xmm0,(%0)       # output to left channel\n\t"  
                             "addps  (%1),%%xmm1       # mix calculated sample(s) to output right\n\t"  
                             "movaps %%xmm1,(%1)       # output to right channel\n\t"  
                             : /* no output */  
                             : "r" (&pOutL[ii]), /* %0 - must be 16 byte aligned ! */  
                               "r" (&pOutR[ii])  /* %1 - must be 16 byte aligned ! */  
                         );  
267                      }                      }
                     #endif // ARCH_X86  
268                  }                  }
269                    pFinalParam->fFinalVolumeLeft = fVolumeL;
270                    pFinalParam->fFinalVolumeRight = fVolumeR;
271                    pFinalParam->pOutRight += uiToGo;
272                    pFinalParam->pOutLeft  += uiToGo;
273                    pFinalParam->uiToGo    -= uiToGo;
274              }              }
275      };      };
276    

Legend:
Removed from v.424  
changed lines
  Added in v.866

  ViewVC Help
Powered by ViewVC