ToneControls.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. ToneControls.cc
  3. Copyright 2004-7 Tim Goetze <tim@quitte.de>
  4. http://quitte.de/dsp/
  5. 4-way Eq for amplifier emulation plugins
  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. #include "basics.h"
  22. #include <stdio.h>
  23. #include "Amp.h"
  24. PreampBand
  25. ToneControls::bands[] =
  26. {
  27. /* f, Q, g */
  28. { 80, 1.20, 1.61},
  29. { 300, 1.10, 1.10},
  30. {1200, 1.14, 1.07},
  31. {4800, .80, 1.06}
  32. };
  33. void
  34. ToneControls::init (double fs)
  35. {
  36. for (int i = 0; i < 4; ++i)
  37. eq.init_band (i, 2 * bands[i].center * M_PI / fs, bands[i].Q);
  38. }
  39. double
  40. ToneControls::get_band_gain (int i, double g)
  41. {
  42. return bands[i].adjust * DSP::db2lin (g);
  43. }
  44. void
  45. ToneControls::set_band_gain (int i, float g)
  46. {
  47. /* sorry, _ != . but hardly readable -- the difference is between local
  48. * buffered value and actual Eq band gain */
  49. eq_gain[i] = g;
  50. eq.gain[i] = get_band_gain (i, g);
  51. }
  52. void
  53. ToneControls::activate (sample_t ** ports)
  54. {
  55. for (int i = 0; i < 4; ++i)
  56. set_band_gain (i, *ports[i]);
  57. eq.reset();
  58. }