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.

66 lines
2.2KB

  1. #!/usr/bin/python2.5
  2. #
  3. # Copyright 2012 Olivier Gillet.
  4. #
  5. # Author: Olivier Gillet (ol.gillet@gmail.com)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. # -----------------------------------------------------------------------------
  19. #
  20. # Waveshaper lookup tables.
  21. import numpy
  22. waveshapers = []
  23. def scale(x, min=-32766, max=32766, center=True):
  24. if center:
  25. x -= x.mean()
  26. mx = numpy.abs(x).max()
  27. x = (x + mx) / (2 * mx)
  28. x = x * (max - min) + min
  29. x = numpy.round(x)
  30. return x.astype(int)
  31. x = ((numpy.arange(0, 257) / 128.0 - 1.0))
  32. x[-1] = x[-2]
  33. violent_overdrive = numpy.tanh(8.0 * x)
  34. overdrive = numpy.tanh(5.0 * x)
  35. moderate_overdrive = numpy.tanh(2.0 * x)
  36. # Wavefolder curves from the first version
  37. # tri_fold = numpy.abs(4.0 * x - numpy.round(4.0 * x)) * numpy.sign(x)
  38. # sine_fold = numpy.sin(5 * numpy.pi * x)
  39. tri_fold = numpy.sin(numpy.pi * (3 * x + (2 * x) ** 3))
  40. # In v1.4 RC
  41. window = numpy.exp(-x * x * 4) ** 1.5
  42. sine = numpy.sin(8 * numpy.pi * x)
  43. sine_fold = sine * window + numpy.arctan(3 * x) * (1 - window)
  44. sine_fold /= numpy.abs(sine_fold).max()
  45. # Another curve for the sine wavefolder inspired by the uFold response
  46. # frequency = 4 / (1 + (1.5 * x) ** 2) ** 2
  47. # window = numpy.exp(-24 * numpy.maximum(numpy.abs(x) - 0.25, 0) ** 2)
  48. # sine = numpy.sin(2 * numpy.pi * frequency * x) * window
  49. # cubic = (x ** 3 + 0.5 * x ** 2 + 0.5 * x) / 3
  50. # knee = numpy.minimum(x + 0.7, 0.0)
  51. # sine_fold = sine + cubic + knee
  52. waveshapers.append(('moderate_overdrive', scale(moderate_overdrive)))
  53. waveshapers.append(('violent_overdrive', scale(violent_overdrive)))
  54. waveshapers.append(('sine_fold', scale(sine_fold, center=False)))
  55. waveshapers.append(('tri_fold', scale(tri_fold)))