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

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

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

revision 56 by schoenebeck, Tue Apr 27 09:21:58 2004 UTC revision 80 by schoenebeck, Sun May 23 19:16:33 2004 UTC
# Line 34  Line 34 
34  #include "../../common/RTELMemoryPool.h"  #include "../../common/RTELMemoryPool.h"
35  #include "../../audiodriver/AudioOutputDevice.h"  #include "../../audiodriver/AudioOutputDevice.h"
36  #include "../../lib/fileloader/libgig/gig.h"  #include "../../lib/fileloader/libgig/gig.h"
37    #include "../common/BiquadFilter.h"
38  #include "Engine.h"  #include "Engine.h"
39  #include "Stream.h"  #include "Stream.h"
40  #include "DiskThread.h"  #include "DiskThread.h"
# Line 42  Line 43 
43  #include "Filter.h"  #include "Filter.h"
44  #include "../common/LFO.h"  #include "../common/LFO.h"
45    
46  #define USE_LINEAR_INTERPOLATION        1  ///< set to 0 if you prefer cubic interpolation (slower, better quality)  #define USE_LINEAR_INTERPOLATION        0  ///< set to 0 if you prefer cubic interpolation (slower, better quality)
47  #define ENABLE_FILTER                   0  ///< if set to 0 then filter (VCF) code is ignored on compile time  #define ENABLE_FILTER                   1  ///< if set to 0 then filter (VCF) code is ignored on compile time
48  #define FILTER_UPDATE_PERIOD            64 ///< amount of sample points after which filter parameters (cutoff, resonance) are going to be updated (higher value means less CPU load, but also worse parameter resolution)  #define FILTER_UPDATE_PERIOD            64 ///< amount of sample points after which filter parameters (cutoff, resonance) are going to be updated (higher value means less CPU load, but also worse parameter resolution, this value will be aligned to a power of two)
49  #define FORCE_FILTER_USAGE              0  ///< if set to 1 then filter is always used, if set to 0 filter is used only in case the instrument file defined one  #define FORCE_FILTER_USAGE              0  ///< if set to 1 then filter is always used, if set to 0 filter is used only in case the instrument file defined one
50  #define FILTER_CUTOFF_MAX               10000.0f ///< maximum cutoff frequency (10kHz)  #define FILTER_CUTOFF_MAX               10000.0f ///< maximum cutoff frequency (10kHz)
51  #define FILTER_CUTOFF_MIN               100.0f   ///< minimum cutoff frequency (100Hz)  #define FILTER_CUTOFF_MIN               100.0f   ///< minimum cutoff frequency (100Hz)
# Line 130  namespace LinuxSampler { namespace gig { Line 131  namespace LinuxSampler { namespace gig {
131              midi_ctrl                   VCFResonanceCtrl;              midi_ctrl                   VCFResonanceCtrl;
132              int                         FilterUpdateCounter; ///< Used to update filter parameters all FILTER_UPDATE_PERIOD samples              int                         FilterUpdateCounter; ///< Used to update filter parameters all FILTER_UPDATE_PERIOD samples
133              static const float          FILTER_CUTOFF_COEFF;              static const float          FILTER_CUTOFF_COEFF;
134                static const int            FILTER_UPDATE_MASK;
135              VCAManipulator*             pVCAManipulator;              VCAManipulator*             pVCAManipulator;
136              VCFCManipulator*            pVCFCManipulator;              VCFCManipulator*            pVCFCManipulator;
137              VCOManipulator*             pVCOManipulator;              VCOManipulator*             pVCOManipulator;
# Line 140  namespace LinuxSampler { namespace gig { Line 142  namespace LinuxSampler { namespace gig {
142    
143              // Static Methods              // Static Methods
144              static float CalculateFilterCutoffCoeff();              static float CalculateFilterCutoffCoeff();
145                static int   CalculateFilterUpdateMask();
146    
147              // Methods              // Methods
148              void        ProcessEvents(uint Samples);              void        ProcessEvents(uint Samples);
149                #if ENABLE_FILTER
150                void        CalculateBiquadParameters(uint Samples);
151                #endif // ENABLE_FILTER
152              void        Interpolate(uint Samples, sample_t* pSrc, uint Skip);              void        Interpolate(uint Samples, sample_t* pSrc, uint Skip);
153              void        InterpolateAndLoop(uint Samples, sample_t* pSrc, uint Skip);              void        InterpolateAndLoop(uint Samples, sample_t* pSrc, uint Skip);
154              inline void InterpolateOneStep_Stereo(sample_t* pSrc, int& i, float& effective_volume, float& pitch, float& cutoff, float& resonance) {              inline void InterpolateOneStep_Stereo(sample_t* pSrc, int& i, float& effective_volume, float& pitch, biquad_param_t& bq_base, biquad_param_t& bq_main) {
155                  int   pos_int   = RTMath::DoubleToInt(this->Pos);  // integer position                  int   pos_int   = RTMath::DoubleToInt(this->Pos);  // integer position
156                  float pos_fract = this->Pos - pos_int;             // fractional part of position                  float pos_fract = this->Pos - pos_int;             // fractional part of position
157                  pos_int <<= 1;                  pos_int <<= 1;
158    
159                  #if ENABLE_FILTER                  #if 0 //ENABLE_FILTER
160                      UpdateFilter_Stereo(cutoff + FILTER_CUTOFF_MIN, resonance);                      UpdateFilter_Stereo(cutoff + FILTER_CUTOFF_MIN, resonance);
161                  #endif // ENABLE_FILTER                  #endif // ENABLE_FILTER
162    
163                  #if USE_LINEAR_INTERPOLATION                  #if USE_LINEAR_INTERPOLATION
164                      #if ENABLE_FILTER                      #if ENABLE_FILTER
165                          // left channel                          // left channel
166                          pOutputLeft[i]    += this->FilterLeft.Apply(effective_volume * (pSrc[pos_int]   + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int])));                          pOutputLeft[i]    += this->FilterLeft.Apply(&bq_base, &bq_main, effective_volume * (pSrc[pos_int]   + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int])));
167                          // right channel                          // right channel
168                          pOutputRight[i++] += this->FilterRight.Apply(effective_volume * (pSrc[pos_int+1] + pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1])));                          pOutputRight[i++] += this->FilterRight.Apply(&bq_base, &bq_main, effective_volume * (pSrc[pos_int+1] + pos_fract * (pSrc[pos_int+3] - pSrc[pos_int+1])));
169                      #else // no filter                      #else // no filter
170                          // left channel                          // left channel
171                          pOutputLeft[i]    += effective_volume * (pSrc[pos_int]   + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]));                          pOutputLeft[i]    += effective_volume * (pSrc[pos_int]   + pos_fract * (pSrc[pos_int+2] - pSrc[pos_int]));
# Line 176  namespace LinuxSampler { namespace gig { Line 182  namespace LinuxSampler { namespace gig {
182                      float b   = 2 * x1 + xm1 - (5 * x0 + x2) / 2;                      float b   = 2 * x1 + xm1 - (5 * x0 + x2) / 2;
183                      float c   = (x1 - xm1) / 2;                      float c   = (x1 - xm1) / 2;
184                      #if ENABLE_FILTER                      #if ENABLE_FILTER
185                          pOutputLeft[i] += this->FilterLeft.Apply(effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0));                          pOutputLeft[i] += this->FilterLeft.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0));
186                      #else // no filter                      #else // no filter
187                          pOutputRight[i] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0);                          pOutputRight[i] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0);
188                      #endif // ENABLE_FILTER                      #endif // ENABLE_FILTER
# Line 190  namespace LinuxSampler { namespace gig { Line 196  namespace LinuxSampler { namespace gig {
196                      b   = 2 * x1 + xm1 - (5 * x0 + x2) / 2;                      b   = 2 * x1 + xm1 - (5 * x0 + x2) / 2;
197                      c   = (x1 - xm1) / 2;                      c   = (x1 - xm1) / 2;
198                      #if ENABLE_FILTER                      #if ENABLE_FILTER
199                          pOutputLeft[i++] += this->FilterRight.Apply(effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0));                          pOutputLeft[i++] += this->FilterRight.Apply(&bq_base, &bq_main, effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0));
200                      #else // no filter                      #else // no filter
201                          pOutputRight[i++] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0);                          pOutputRight[i++] += effective_volume * ((((a * pos_fract) + b) * pos_fract + c) * pos_fract + x0);
202                      #endif // ENABLE_FILTER                      #endif // ENABLE_FILTER
# Line 198  namespace LinuxSampler { namespace gig { Line 204  namespace LinuxSampler { namespace gig {
204    
205                  this->Pos += pitch;                  this->Pos += pitch;
206              }              }
207              inline void InterpolateOneStep_Mono(sample_t* pSrc, int& i, float& effective_volume, float& pitch, float& cutoff, float& resonance) {              inline void InterpolateOneStep_Mono(sample_t* pSrc, int& i, float& effective_volume, float& pitch,  biquad_param_t& bq_base, biquad_param_t& bq_main) {
208                  int   pos_int   = RTMath::DoubleToInt(this->Pos);  // integer position                  int   pos_int   = RTMath::DoubleToInt(this->Pos);  // integer position
209                  float pos_fract = this->Pos - pos_int;             // fractional part of position                  float pos_fract = this->Pos - pos_int;             // fractional part of position
210    
211                  #if ENABLE_FILTER                  #if 0 //ENABLE_FILTER
212                      UpdateFilter_Mono(cutoff + FILTER_CUTOFF_MIN, resonance);                      UpdateFilter_Mono(cutoff + FILTER_CUTOFF_MIN, resonance);
213                  #endif // ENABLE_FILTER                  #endif // ENABLE_FILTER
214    
# Line 220  namespace LinuxSampler { namespace gig { Line 226  namespace LinuxSampler { namespace gig {
226                  #endif // USE_LINEAR_INTERPOLATION                  #endif // USE_LINEAR_INTERPOLATION
227    
228                  #if ENABLE_FILTER                  #if ENABLE_FILTER
229                      sample_point = this->FilterLeft.Apply(sample_point);                      sample_point = this->FilterLeft.Apply(&bq_base, &bq_main, sample_point);
230                  #endif // ENABLE_FILTER                  #endif // ENABLE_FILTER
231    
232                  pOutputLeft[i]    += sample_point;                  pOutputLeft[i]    += sample_point;
# Line 228  namespace LinuxSampler { namespace gig { Line 234  namespace LinuxSampler { namespace gig {
234    
235                  this->Pos += pitch;                  this->Pos += pitch;
236              }              }
237    #if 0
238              inline void UpdateFilter_Stereo(float cutoff, float& resonance) {              inline void UpdateFilter_Stereo(float cutoff, float& resonance) {
239                  if (!(++FilterUpdateCounter % FILTER_UPDATE_PERIOD) && (cutoff != FilterLeft.Cutoff() || resonance != FilterLeft.Resonance())) {                  if (!(++FilterUpdateCounter % FILTER_UPDATE_PERIOD) && (cutoff != FilterLeft.Cutoff() || resonance != FilterLeft.Resonance())) {
240                      FilterLeft.SetParameters(cutoff, resonance, SampleRate);                      FilterLeft.SetParameters(cutoff, resonance, SampleRate);
# Line 239  namespace LinuxSampler { namespace gig { Line 246  namespace LinuxSampler { namespace gig {
246                      FilterLeft.SetParameters(cutoff, resonance, SampleRate);                      FilterLeft.SetParameters(cutoff, resonance, SampleRate);
247                  }                  }
248              }              }
249    #endif
250              inline float Constrain(float ValueToCheck, float Min, float Max) {              inline float Constrain(float ValueToCheck, float Min, float Max) {
251                  if      (ValueToCheck > Max) ValueToCheck = Max;                  if      (ValueToCheck > Max) ValueToCheck = Max;
252                  else if (ValueToCheck < Min) ValueToCheck = Min;                  else if (ValueToCheck < Min) ValueToCheck = Min;

Legend:
Removed from v.56  
changed lines
  Added in v.80

  ViewVC Help
Powered by ViewVC