Clip.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Clip.h
  3. Copyright 2004-5 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. oversampled hard ('diode', 'transistor', sometimes 'op-amp') clipper.
  6. */
  7. /*
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. 02111-1307, USA or point your web browser to http://www.gnu.org.
  20. */
  21. #ifndef _CLIP_H_
  22. #define _CLIP_H_
  23. #include "dsp/util.h"
  24. #include "dsp/FIR.h"
  25. #include "dsp/sinc.h"
  26. #include "dsp/windows.h"
  27. class Clip
  28. : public Plugin
  29. {
  30. public:
  31. sample_t gain, gain_db;
  32. sample_t threshold[2];
  33. enum {
  34. OVERSAMPLE = 8,
  35. FIR_SIZE = 64,
  36. };
  37. /* antialias filters */
  38. DSP::FIRUpsampler up;
  39. DSP::FIR down;
  40. template <sample_func_t F>
  41. void one_cycle (int frames);
  42. inline sample_t clip (sample_t x);
  43. public:
  44. static PortInfo port_info[];
  45. Clip()
  46. : up (FIR_SIZE, OVERSAMPLE),
  47. down (FIR_SIZE)
  48. { }
  49. void init();
  50. void activate()
  51. {
  52. up.reset();
  53. down.reset();
  54. gain_db = *ports[1];
  55. gain = DSP::db2lin (gain_db);
  56. }
  57. void run (int n)
  58. {
  59. one_cycle<store_func> (n);
  60. }
  61. void run_adding (int n)
  62. {
  63. one_cycle<adding_func> (n);
  64. }
  65. };
  66. #endif /* _CLIP_H_ */