Guest User

Untitled

a guest
Apr 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. --- a/src/DSP/SVFilter.cpp
  2. +++ b/src/DSP/SVFilter.cpp
  3. @@ -102,6 +102,7 @@ SVFilter::response SVFilter::computeResponse(int type,
  4.  
  5. void SVFilter::computefiltercoefs(void)
  6. {
  7. + //printf("compute coeff (%f, %f, %d)\n", freq, q, stages);
  8. par.f = freq / samplerate_f * 4.0f;
  9. if(par.f > 0.99999f)
  10. par.f = 0.99999f;
  11. @@ -125,7 +126,7 @@ void SVFilter::setfreq(float frequency)
  12. bool nyquistthresh = (abovenq ^ oldabovenq);
  13.  
  14. //if the frequency is changed fast, it needs interpolation
  15. - if((rap > 3.0f) || nyquistthresh) { //(now, filter and coefficients backup)
  16. + if(true || (rap > 3.0f) || nyquistthresh) { //(now, filter and coefficients backup)
  17. if(!firsttime)
  18. needsinterpolation = true;
  19. ipar = par;
  20. @@ -168,7 +169,7 @@ void SVFilter::setstages(int stages_)
  21. computefiltercoefs();
  22. }
  23.  
  24. -void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
  25. +void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par, parameters &par2)
  26. {
  27. float *out = NULL;
  28. switch(type) {
  29. @@ -189,10 +190,16 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
  30. warnx("Impossible SVFilter type encountered [%d]", type);
  31. }
  32.  
  33. + //printf("delta q = %f\n", (par.q-par2.q)/buffersize_f);
  34. + //printf("delta f = %f\n", (par.f-par2.f)/buffersize_f);
  35. for(int i = 0; i < buffersize; ++i) {
  36. - x.low = x.low + par.f * x.band;
  37. - x.high = par.q_sqrt * smp[i] - x.low - par.q * x.band;
  38. - x.band = par.f * x.high + x.band;
  39. + const float t = i/buffersize_f;
  40. + const float par_f = (1-t)*par.f + t*par2.f;
  41. + const float par_q = (1-t)*par.q + t*par2.q;
  42. + const float par_q_sqrt = sqrtf(par_q);
  43. + x.low = x.low + par_f * x.band;
  44. + x.high = par_q_sqrt * smp[i] - x.low - par_q * x.band;
  45. + x.band = par_f * x.high + x.band;
  46. x.notch = x.high + x.low;
  47. smp[i] = *out;
  48. }
  49. @@ -211,6 +218,8 @@ void SVFilter::singlefilterout(float *smp, fstage &x, parameters &par)
  50.  
  51. void SVFilter::filterout(float *smp)
  52. {
  53. + //printf("SVFilter::filterout\n");
  54. +#if 0
  55. for(int i = 0; i < stages + 1; ++i)
  56. singlefilterout(smp, st[i], par);
  57.  
  58. @@ -227,6 +236,15 @@ void SVFilter::filterout(float *smp)
  59. }
  60. needsinterpolation = false;
  61. }
  62. +#endif
  63. + if(needsinterpolation) {
  64. + //printf("interpolating...\n");
  65. + for(int i = 0; i < stages + 1; ++i)
  66. + singlefilterout(smp, st[i], ipar, par);
  67. + needsinterpolation = false;
  68. + } else
  69. + for(int i = 0; i < stages + 1; ++i)
  70. + singlefilterout(smp, st[i], par, par);
  71.  
  72. for(int i = 0; i < buffersize; ++i)
  73. smp[i] *= outgain;
  74. diff --git a/src/DSP/SVFilter.h b/src/DSP/SVFilter.h
  75. index 7cb7e989..57e82494 100644
  76. --- a/src/DSP/SVFilter.h
  77. +++ b/src/DSP/SVFilter.h
  78. @@ -56,7 +56,7 @@ class SVFilter:public Filter
  79. float f, q, q_sqrt;
  80. } par, ipar;
  81.  
  82. - void singlefilterout(float *smp, fstage &x, parameters &par);
  83. + void singlefilterout(float *smp, fstage &x, parameters &par, parameters &);
  84. void computefiltercoefs(void);
  85. int type; // The type of the filter (LPF1,HPF1,LPF2,HPF2...)
  86. int stages; // how many times the filter is applied (0->1,1->2,etc.)
Add Comment
Please, Sign In to add comment