External plugins for Carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.9KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. Filter.cpp - Filters, uses analog,formant,etc. filters
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #include <cmath>
  12. #include <cstdio>
  13. #include <cassert>
  14. #include "Filter.h"
  15. #include "AnalogFilter.h"
  16. #include "FormantFilter.h"
  17. #include "SVFilter.h"
  18. #include "../Params/FilterParams.h"
  19. #include "../Misc/Allocator.h"
  20. namespace zyncarla {
  21. Filter::Filter(unsigned int srate, int bufsize)
  22. : outgain(1.0f),
  23. samplerate(srate),
  24. buffersize(bufsize)
  25. {
  26. alias();
  27. }
  28. Filter *Filter::generate(Allocator &memory, const FilterParams *pars,
  29. unsigned int srate, int bufsize)
  30. {
  31. assert(srate != 0);
  32. assert(bufsize != 0);
  33. unsigned char Ftype = pars->Ptype;
  34. unsigned char Fstages = pars->Pstages;
  35. Filter *filter;
  36. switch(pars->Pcategory) {
  37. case 1:
  38. filter = memory.alloc<FormantFilter>(pars, &memory, srate, bufsize);
  39. break;
  40. case 2:
  41. filter = memory.alloc<SVFilter>(Ftype, 1000.0f, pars->getq(), Fstages, srate, bufsize);
  42. filter->outgain = dB2rap(pars->getgain());
  43. if(filter->outgain > 1.0f)
  44. filter->outgain = sqrt(filter->outgain);
  45. break;
  46. default:
  47. filter = memory.alloc<AnalogFilter>(Ftype, 1000.0f, pars->getq(), Fstages, srate, bufsize);
  48. if((Ftype >= 6) && (Ftype <= 8))
  49. filter->setgain(pars->getgain());
  50. else
  51. filter->outgain = dB2rap(pars->getgain());
  52. break;
  53. }
  54. return filter;
  55. }
  56. float Filter::getrealfreq(float freqpitch)
  57. {
  58. return powf(2.0f, freqpitch + 9.96578428f); //log2(1000)=9.95748f
  59. }
  60. }