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.

74 lines
2.7KB

  1. #!/usr/bin/python2.5
  2. #
  3. # Copyright 2014 Olivier Gillet.
  4. #
  5. # Author: Olivier Gillet (ol.gillet@gmail.com)
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. # See http://creativecommons.org/licenses/MIT/ for more information.
  26. #
  27. # -----------------------------------------------------------------------------
  28. #
  29. # Waveform definitions.
  30. import numpy
  31. WAVETABLE_SIZE = 1024
  32. waveforms = []
  33. """----------------------------------------------------------------------------
  34. Sine wave
  35. ----------------------------------------------------------------------------"""
  36. x = numpy.arange(0, WAVETABLE_SIZE + 1) / float(WAVETABLE_SIZE)
  37. x[-1] = x[0]
  38. sine = numpy.sin(2 * numpy.pi * x)
  39. waveforms.append(('sine', (32767 * sine).astype(int)))
  40. """----------------------------------------------------------------------------
  41. Waveshaper
  42. ----------------------------------------------------------------------------"""
  43. x = numpy.arange(0, WAVETABLE_SIZE + 1) / (WAVETABLE_SIZE / 2.0) - 1.0
  44. x[-1] = x[-2]
  45. window = numpy.exp(-x * x * 4) ** 1.5
  46. sine = numpy.sin(8 * numpy.pi * x)
  47. sine_fold = sine * window + numpy.arctan(3 * x) * (1 - window)
  48. sine_fold /= numpy.abs(sine_fold).max()
  49. power = x ** 7
  50. overdrive = numpy.tanh(5.0 * x)
  51. overdrive /= numpy.abs(overdrive).max()
  52. waveforms.append(('fold_power', numpy.round(32767 * power).astype(int)))
  53. waveforms.append(('fold_sine', numpy.round(32767 * sine_fold).astype(int)))
  54. waveforms.append(('overdrive', numpy.round(32767 * overdrive).astype(int)))
  55. """----------------------------------------------------------------------------
  56. Surprise!
  57. ----------------------------------------------------------------------------"""
  58. digits = file('peaks/data/digits.bin', 'rb').read()
  59. digits = map(ord, digits)
  60. waveforms_8 = [('digits', digits)]