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

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

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

revision 617 by schoenebeck, Wed Jun 8 21:00:06 2005 UTC revision 1424 by schoenebeck, Sun Oct 14 22:00:17 2007 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                              *   *   Copyright (C) 2005 - 2007 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 21  Line 21 
21   *   MA  02111-1307  USA                                                   *   *   MA  02111-1307  USA                                                   *
22   ***************************************************************************/   ***************************************************************************/
23    
24    // Note: the assembly code is currently disabled, as it doesn't fit into
25    // the new synthesis core introduced by LS 0.4.0
26    
27  #ifndef __LS_RESAMPLER_H__  #ifndef __LS_RESAMPLER_H__
28  #define __LS_RESAMPLER_H__  #define __LS_RESAMPLER_H__
29    
30  #include "../../common/global.h"  #include "../../common/global_private.h"
31    
32  // TODO: cubic interpolation is not yet supported by the MMX/SSE(1) version though  // TODO: cubic interpolation is not yet supported by the MMX/SSE(1) version though
33    // TODO: cubic interpolation is not supported for 24 bit samples
34  #ifndef USE_LINEAR_INTERPOLATION  #ifndef USE_LINEAR_INTERPOLATION
35  # define USE_LINEAR_INTERPOLATION   1  ///< set to 0 if you prefer cubic interpolation (slower, better quality)  # define USE_LINEAR_INTERPOLATION   1  ///< set to 0 if you prefer cubic interpolation (slower, better quality)
36  #endif  #endif
# Line 49  namespace LinuxSampler { Line 53  namespace LinuxSampler {
53       * for linear and cubic interpolation for pitching a mono or stereo       * for linear and cubic interpolation for pitching a mono or stereo
54       * input signal.       * input signal.
55       */       */
56      template<bool INTERPOLATE>      template<bool INTERPOLATE,bool BITDEPTH24>
57      class Resampler {      class Resampler {
58          public:          public:
59              inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) {              inline static float GetNextSampleMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) {
# Line 74  namespace LinuxSampler { Line 78  namespace LinuxSampler {
78                  }                  }
79              }              }
80    
81  #if CONFIG_ASM && ARCH_X86  #if 0 // CONFIG_ASM && ARCH_X86
82              inline static void GetNext4SamplesMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {              inline static void GetNext4SamplesMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
83                  if (INTERPOLATE) Interpolate4StepsMonoMMXSSE(pSrc, Pos, Pitch);                  if (INTERPOLATE) Interpolate4StepsMonoMMXSSE(pSrc, Pos, Pitch);
84                  else { // no pitch, so no interpolation necessary                  else { // no pitch, so no interpolation necessary
# Line 146  namespace LinuxSampler { Line 150  namespace LinuxSampler {
150    
151          protected:          protected:
152    
153                static int getSample(sample_t* src, int pos) {
154                    if (BITDEPTH24) {
155                        pos *= 3;
156                        unsigned char* p = (unsigned char*)src;
157                        return p[pos] << 8 | p[pos + 1] << 16 | p[pos + 2] << 24;
158                    } else {
159                        return src[pos];
160                    }
161                }
162    
163              inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) {              inline static float Interpolate1StepMonoCPP(sample_t* pSrc, double* Pos, float& Pitch) {
164                  int   pos_int   = (int) *Pos;     // integer position                  int   pos_int   = (int) *Pos;     // integer position
165                  float pos_fract = *Pos - pos_int; // fractional part of position                  float pos_fract = *Pos - pos_int; // fractional part of position
166    
167                  #if USE_LINEAR_INTERPOLATION                  #if USE_LINEAR_INTERPOLATION
168                      float samplePoint  = pSrc[pos_int] + pos_fract * (pSrc[pos_int+1] - pSrc[pos_int]);                      int x1 = getSample(pSrc, pos_int);
169                        int x2 = getSample(pSrc, pos_int + 1);
170                        float samplePoint  = (x1 + pos_fract * (x2 - x1));
171                  #else // polynomial interpolation                  #else // polynomial interpolation
172                      float xm1 = pSrc[pos_int];                      float xm1 = pSrc[pos_int];
173                      float x0  = pSrc[pos_int+1];                      float x0  = pSrc[pos_int+1];
# Line 176  namespace LinuxSampler { Line 192  namespace LinuxSampler {
192    
193                  #if USE_LINEAR_INTERPOLATION                  #if USE_LINEAR_INTERPOLATION
194                      // left channel                      // left channel
195                      samplePoint.left = pSrc[pos_int]   + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]);                      int x1 = getSample(pSrc, pos_int);
196                        int x2 = getSample(pSrc, pos_int + 2);
197                        samplePoint.left  = (x1 + pos_fract * (x2 - x1));
198                      // right channel                      // right channel
199                      samplePoint.right = pSrc[pos_int+1] + pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1]);                      x1 = getSample(pSrc, pos_int + 1);
200                        x2 = getSample(pSrc, pos_int + 3);
201                        samplePoint.right = (x1 + pos_fract * (x2 - x1));
202                  #else // polynomial interpolation                  #else // polynomial interpolation
203                      // calculate left channel                      // calculate left channel
204                      float xm1 = pSrc[pos_int];                      float xm1 = pSrc[pos_int];
# Line 205  namespace LinuxSampler { Line 225  namespace LinuxSampler {
225                  return samplePoint;                  return samplePoint;
226              }              }
227    
228  #if CONFIG_ASM && ARCH_X86  #if 0 // CONFIG_ASM && ARCH_X86
229              // TODO: no support for cubic interpolation yet              // TODO: no support for cubic interpolation yet
230              inline static void Interpolate4StepsMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {              inline static void Interpolate4StepsMonoMMXSSE(sample_t* pSrc, void* Pos, float& Pitch) {
231                  /* calculate playback position of each of the 4 samples by adding the associated pitch */                  /* calculate playback position of each of the 4 samples by adding the associated pitch */

Legend:
Removed from v.617  
changed lines
  Added in v.1424

  ViewVC Help
Powered by ViewVC