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

Legend:
Removed from v.497  
changed lines
  Added in v.877

  ViewVC Help
Powered by ViewVC