/[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 332 by senkov, Sat Jan 1 03:06:06 2005 UTC revision 830 by persson, Sun Jan 15 18:23:11 2006 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 28  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                  if (IMPLEMENTATION == ASM_X86_MMX_SSE) {       */
65                      float fPos = (float) Voice.Pos;      template<channels_t CHANNELS, bool DOLOOP, bool USEFILTER, bool INTERPOLATE>
66                      SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount,      class Synthesizer : public __RTMath<CPP>, public LinuxSampler::Resampler<INTERPOLATE> {
67                                         Voice.pSample->LoopStart,  
68                                         Voice.pSample->LoopEnd,              // declarations of derived functions (see "Name lookup,
69                                         Voice.pSample->LoopSize,              // templates, and accessing members of base classes" in
70                                         Voice.LoopCyclesLeft,              // the gcc manual for an explanation of why this is
71                                         (void *)&fPos,              // needed).
72                                         Voice.PitchBase,              using __RTMath<CPP>::Mul;
73                                         Voice.PitchBend);              using __RTMath<CPP>::Float;
74                      if (INTERPOLATE) EMMS;              //using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleMonoCPP;
75                      Voice.Pos = (double) fPos;              //using LinuxSampler::Resampler<INTERPOLATE>::GetNextSampleStereoCPP;
76                  } else {              using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepMonoCPP;
77                      SynthesizeFragment(Voice, Samples, pSrc, i, Voice.pSample->LoopPlayCount,              using LinuxSampler::Resampler<INTERPOLATE>::Interpolate1StepStereoCPP;
                                        Voice.pSample->LoopStart,  
                                        Voice.pSample->LoopEnd,  
                                        Voice.pSample->LoopSize,  
                                        Voice.LoopCyclesLeft,  
                                        (void *)&Voice.Pos,  
                                        Voice.PitchBase,  
                                        Voice.PitchBend);  
                 }  
             }  
78    
79            public:
80          //protected:          //protected:
81    
82              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 loopEnd = Float(LoopEnd);  
                 const float PBbyPB = Mul(PitchBase, PitchBend);  
                 const float f_LoopStart = Float(LoopStart);  
                 const float f_LoopSize = Float(LoopSize);  
83                  if (DOLOOP) {                  if (DOLOOP) {
84                      if (LoopPlayCount) {                      const float fLoopEnd   = Float(pLoop->uiEnd);
85                        const float fLoopStart = Float(pLoop->uiStart);
86                        const float fLoopSize  = Float(pLoop->uiSize);
87                        if (pLoop->uiTotalCycles) {
88                          // render loop (loop count limited)                          // render loop (loop count limited)
89                          while (i < Samples && LoopCyclesLeft) {                          for (; pFinalParam->uiToGo > 0 && pLoop->uiCyclesLeft; pLoop->uiCyclesLeft -= WrapLoop(fLoopStart, fLoopSize, fLoopEnd, &pFinalParam->dPos)) {
90                              if (CONSTPITCH) {                              const uint uiToGo = Min(pFinalParam->uiToGo, DiffToLoopEnd(fLoopEnd, &pFinalParam->dPos, pFinalParam->fFinalPitch) + 1); //TODO: instead of +1 we could also round up
91                                  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);  
                             }  
                             else Synthesize(Voice, Pos, pSrc, i);  
                             if (WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos)) LoopCyclesLeft--;  
92                          }                          }
93                          // render on without loop                          // render on without loop
94                          while (i < Samples) Synthesize(Voice, Pos, pSrc, i);                          SynthesizeSubSubFragment(pFinalParam, pFinalParam->uiToGo);
95                      }                      } else { // render loop (endless loop)
96                      else { // render loop (endless loop)                          for (; pFinalParam->uiToGo > 0; WrapLoop(fLoopStart, fLoopSize, fLoopEnd, &pFinalParam->dPos)) {
97                          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
98                              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);  
                             }  
                             else Synthesize(Voice, Pos, pSrc, i);  
                             WrapLoop(f_LoopStart, f_LoopSize, loopEnd, Pos);  
99                          }                          }
100                      }                      }
101                  }                  } else { // no looping
102                  else { // no looping                      SynthesizeSubSubFragment(pFinalParam, pFinalParam->uiToGo);
                     while (i < Samples) { Synthesize(Voice, Pos, pSrc, i);}  
103                  }                  }
104              }              }
105    
106              template<typename VOICE_T>              /**
107              inline static void Synthesize(VOICE_T& Voice, void* Pos, sample_t* pSrc, uint& i) {               * Returns the difference to the sample's loop end.
108                  Synthesize(pSrc, Pos,               */
109                             Voice.pEngine->pSynthesisParameters[Event::destination_vco][i],              inline static int DiffToLoopEnd(const float& LoopEnd, const void* Pos, const float& Pitch) {
110                             Voice.pEngine->pOutputLeft,                  return uint((LoopEnd - *((double *)Pos)) / Pitch);
                            Voice.pEngine->pOutputRight,  
                            i,  
                            Voice.pEngine->pSynthesisParameters[Event::destination_vca],  
                            &Voice.PanLeft,  
                            &Voice.PanRight,  
                            Voice.FilterLeft,  
                            Voice.FilterRight,  
                            Voice.pEngine->pBasicFilterParameters[i],  
                            Voice.pEngine->pMainFilterParameters[i]);  
111              }              }
112    
113              inline static int DiffToLoopEnd(const float& LoopEnd, const void* Pos, const float& Pitch) {  #if 0
114                  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
115                      // pure C++ implementation (thus platform independent)              inline static int WrapLoop(const int& LoopStart, const int& LoopSize, const int& LoopEnd, int& Pos) {
116                      case CPP: {                  //TODO: we can easily eliminate the branch here
117                          return uint((LoopEnd - *((double *)Pos)) / Pitch);                  if (Pos < LoopEnd) return 0;
118                      }                  Pos = (Pos - LoopEnd) % LoopSize + LoopStart;
119                      #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  
                 }  
120              }              }
121    #endif
122    
123                /**
124                 * This method handles looping of the RAM playback part of the
125                 * sample, thus repositioning the playback position once the
126                 * loop limit was reached. Note: looping of the disk streaming
127                 * part is handled by libgig (ReadAndLoop() method which will
128                 * be called by the DiskThread).
129                 */
130              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) {
131                  switch (IMPLEMENTATION) {                  double * Pos = (double *)vPos;
132                      // pure C++ implementation (thus platform independent)                  if (*Pos < LoopEnd) return 0;
133                      case CPP: {                  *Pos = fmod(*Pos - LoopEnd, LoopSize) + LoopStart;
134                          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;  
                         __asm__ __volatile__ (  
                             "movss  (%2), %%xmm0          # load LoopEnd\n\t"  
                             "movss  (%1), %%xmm1          # load Pos\n\t"  
                             "comiss %%xmm0, %%xmm1      # LoopEnd <> Pos\n\t"  
                             "movl    $0,%%eax            # result = 0\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,%%eax            # result = 1\n\t"  
                             ".balign 16 \n\t"  
                             "1:\n\t"  
                             : "=a" (result)     /* %0 */  
                             : "r"  (vPos),      /* %1 */  
                               "r"  (&LoopEnd),  /* %2 */  
                               "r"  (&LoopSize), /* %3 */  
                               "r"  (&LoopStart) /* %4 */  
                         );  
                         return result;  
                     }  
                     #endif // ARCH_X86  
                 }  
135              }              }
136    
137              inline static void Synthesize(sample_t* pSrc, void* Pos, float& Pitch, float* pOutL, float* pOutR, uint& i, float* Volume, float* PanL, float* PanR, Filter& FilterL, Filter& FilterR, biquad_param_t& bqBase, biquad_param_t& bqMain) {              static void SynthesizeSubSubFragment(SynthesisParam* pFinalParam, uint uiToGo) {
138                  switch (IMPLEMENTATION) {                  float fVolumeL = pFinalParam->fFinalVolumeLeft;
139                      // pure C++ implementation (thus platform independent)                  float fVolumeR = pFinalParam->fFinalVolumeRight;
140                      case CPP: {                  sample_t* pSrc = pFinalParam->pSrc;
141                          switch (CHANNELS) {                  float* pOutL   = pFinalParam->pOutLeft;
142                              case MONO: {                  float* pOutR   = pFinalParam->pOutRight;
143                                  float samplePoint = GetNextSampleMonoCPP(pSrc, (double *)Pos, Pitch);  #ifdef CONFIG_INTERPOLATE_VOLUME
144                                  if (USEFILTER) samplePoint = FilterL.Apply(&bqBase, &bqMain, samplePoint);                  float fDeltaL  = pFinalParam->fFinalVolumeDeltaLeft;
145                                  pOutL[i] += samplePoint * Volume[i] * *PanL;                  float fDeltaR  = pFinalParam->fFinalVolumeDeltaRight;
146                                  pOutR[i] += samplePoint * Volume[i] * *PanR;  #endif
147                                  i++;                  switch (CHANNELS) {
148                                  break;                      case MONO: {
149                            float samplePoint;
150                            if (INTERPOLATE) {
151                                double dPos    = pFinalParam->dPos;
152                                float fPitch   = pFinalParam->fFinalPitch;
153                                if (USEFILTER) {
154                                    Filter filterL = pFinalParam->filterLeft;
155                                    for (int i = 0; i < uiToGo; ++i) {
156                                        samplePoint = Interpolate1StepMonoCPP(pSrc, &dPos, fPitch);
157                                        samplePoint = filterL.Apply(samplePoint);
158    #ifdef CONFIG_INTERPOLATE_VOLUME
159                                        fVolumeL += fDeltaL;
160                                        fVolumeR += fDeltaR;
161    #endif
162                                        pOutL[i] += samplePoint * fVolumeL;
163                                        pOutR[i] += samplePoint * fVolumeR;
164                                    }
165                                } else { // no filter needed
166                                    for (int i = 0; i < uiToGo; ++i) {
167                                        samplePoint = Interpolate1StepMonoCPP(pSrc, &dPos, fPitch);
168    #ifdef CONFIG_INTERPOLATE_VOLUME
169                                        fVolumeL += fDeltaL;
170                                        fVolumeR += fDeltaR;
171    #endif
172                                        pOutL[i] += samplePoint * fVolumeL;
173                                        pOutR[i] += samplePoint * fVolumeR;
174                                    }
175                              }                              }
176                              case STEREO: {                              pFinalParam->dPos = dPos;
177                                  stereo_sample_t samplePoint = GetNextSampleStereoCPP(pSrc, (double *)Pos, Pitch);                          } else { // no interpolation
178                                  if (USEFILTER) {                              int pos_offset = (int) pFinalParam->dPos;
179                                      samplePoint.left  = FilterL.Apply(&bqBase, &bqMain, samplePoint.left);                              if (USEFILTER) {
180                                      samplePoint.right = FilterR.Apply(&bqBase, &bqMain, samplePoint.right);                                  Filter filterL = pFinalParam->filterLeft;
181                                    for (int i = 0; i < uiToGo; ++i) {
182                                        samplePoint = pSrc[i + pos_offset];
183                                        samplePoint = filterL.Apply(samplePoint);
184    #ifdef CONFIG_INTERPOLATE_VOLUME
185                                        fVolumeL += fDeltaL;
186                                        fVolumeR += fDeltaR;
187    #endif
188                                        pOutL[i] += samplePoint * fVolumeL;
189                                        pOutR[i] += samplePoint * fVolumeR;
190                                    }
191                                } else { // no filter needed
192                                    for (int i = 0; i < uiToGo; ++i) {
193                                        samplePoint = pSrc[i + pos_offset];
194    #ifdef CONFIG_INTERPOLATE_VOLUME
195                                        fVolumeL += fDeltaL;
196                                        fVolumeR += fDeltaR;
197    #endif
198                                        pOutL[i] += samplePoint * fVolumeL;
199                                        pOutR[i] += samplePoint * fVolumeR;
200                                  }                                  }
                                 pOutL[i] += samplePoint.left  * Volume[i] * *PanL;  
                                 pOutR[i] += samplePoint.right * Volume[i] * *PanR;  
                                 i++;  
                                 break;  
201                              }                              }
202                                pFinalParam->dPos += uiToGo;
203                          }                          }
204                          break;                          break;
205                      }                      }
206                      #if ARCH_X86                      case STEREO: {
207                      // Assembly optimization using the MMX & SSE(1) instruction set (thus only for x86)                          stereo_sample_t samplePoint;
208                      case ASM_X86_MMX_SSE: {                          if (INTERPOLATE) {
209                          const int ii = i & 0xfffffffc;                              double dPos    = pFinalParam->dPos;
210                          i += 4;                              float fPitch   = pFinalParam->fFinalPitch;
211                          switch (CHANNELS) {                              if (USEFILTER) {
212                              case MONO: {                                  Filter filterL = pFinalParam->filterLeft;
213                                  GetNext4SamplesMonoMMXSSE(pSrc, (float *)Pos, Pitch); // outputs samples in xmm2                                  Filter filterR = pFinalParam->filterRight;
214                                  if (USEFILTER) {                                  for (int i = 0; i < uiToGo; ++i) {
215                                      /* prepare filter input */                                      samplePoint = Interpolate1StepStereoCPP(pSrc, &dPos, fPitch);
216                                      __asm__ __volatile__ (                                      samplePoint.left  = filterL.Apply(samplePoint.left);
217                                          "movaps %xmm2,%xmm0"                                      samplePoint.right = filterR.Apply(samplePoint.right);
218                                      );  #ifdef CONFIG_INTERPOLATE_VOLUME
219                                      FilterL.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      fVolumeL += fDeltaL;
220                                      __asm__ __volatile__ (                                      fVolumeR += fDeltaR;
221                                          "movaps %xmm7,%xmm2       # mono filter result -> xmm2"  #endif
222                                      );                                      pOutL[i] += samplePoint.left  * fVolumeL;
223                                        pOutR[i] += samplePoint.right * fVolumeR;
224                                    }
225                                } else { // no filter needed
226                                    for (int i = 0; i < uiToGo; ++i) {
227                                        samplePoint = Interpolate1StepStereoCPP(pSrc, &dPos, fPitch);
228    #ifdef CONFIG_INTERPOLATE_VOLUME
229                                        fVolumeL += fDeltaL;
230                                        fVolumeR += fDeltaR;
231    #endif
232                                        pOutL[i] += samplePoint.left  * fVolumeL;
233                                        pOutR[i] += samplePoint.right * fVolumeR;
234                                  }                                  }
                                 /* 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;  
235                              }                              }
236                              case STEREO: {                              pFinalParam->dPos = dPos;
237                                  GetNext4SamplesStereoMMXSSE(pSrc, (float *)Pos, Pitch); // outputs samples in xmm2 (left channel) and xmm3 (right channel)                          } else { // no interpolation
238                                  if (USEFILTER) {                              int pos_offset = ((int) pFinalParam->dPos) << 1;
239                                      __asm__ __volatile__ (                              if (USEFILTER) {
240                                          "movaps %xmm2,%xmm0     # prepare left channel for filter\n\t"                                  Filter filterL = pFinalParam->filterLeft;
241                                          "movaps %xmm3,%xmm1     # save right channel not to get overwritten by filter algorithms\n\t"                                  Filter filterR = pFinalParam->filterRight;
242                                      );                                  for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) {
243                                      FilterL.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      samplePoint.left  = pSrc[ii + pos_offset];
244                                      __asm__ __volatile__ (                                      samplePoint.right = pSrc[ii + pos_offset + 1];
245                                          "movaps %xmm1,%xmm0     # prepare right channel for filter\n\t"                                      samplePoint.left  = filterL.Apply(samplePoint.left);
246                                          "movaps %xmm7,%xmm1     # save filter output for left channel\n\t"                                      samplePoint.right = filterR.Apply(samplePoint.right);
247                                      );  #ifdef CONFIG_INTERPOLATE_VOLUME
248                                      FilterR.Apply4StepsSSE(&bqBase, &bqMain); // xmm0 input, xmm7 output                                      fVolumeL += fDeltaL;
249                                      __asm__ __volatile__ (                                      fVolumeR += fDeltaR;
250                                          "movaps %xmm1,%xmm2     # result left channel -> xmm2\n\t"  #endif
251                                          "movaps %xmm7,%xmm3     # result right channel -> xmm3\n\t"                                      pOutL[i] += samplePoint.left  * fVolumeL;
252                                      );                                      pOutR[i] += samplePoint.right * fVolumeR;
253                                    }
254                                } else { // no filter needed
255                                    for (int i = 0, ii = 0; i < uiToGo; ++i, ii+=2) {
256                                        samplePoint.left  = pSrc[ii + pos_offset];
257                                        samplePoint.right = pSrc[ii + pos_offset + 1];
258    #ifdef CONFIG_INTERPOLATE_VOLUME
259                                        fVolumeL += fDeltaL;
260                                        fVolumeR += fDeltaR;
261    #endif
262                                        pOutL[i] += samplePoint.left  * fVolumeL;
263                                        pOutR[i] += samplePoint.right * fVolumeR;
264                                  }                                  }
                                 /* 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;  
265                              }                              }
266                                pFinalParam->dPos += uiToGo;
267                          }                          }
268                          /* 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 ! */  
                         );  
269                      }                      }
                     #endif // ARCH_X86  
270                  }                  }
271                    pFinalParam->fFinalVolumeLeft = fVolumeL;
272                    pFinalParam->fFinalVolumeRight = fVolumeR;
273                    pFinalParam->pOutRight += uiToGo;
274                    pFinalParam->pOutLeft  += uiToGo;
275                    pFinalParam->uiToGo    -= uiToGo;
276              }              }
277      };      };
278    

Legend:
Removed from v.332  
changed lines
  Added in v.830

  ViewVC Help
Powered by ViewVC