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
2.5KB

  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 = 256
  32. # Waveforms for the trigger shaper ---------------------------------------------
  33. numpy.random.seed(666)
  34. def scale(x):
  35. if x.min() > 0:
  36. x = (x - x.min()) / (x.max() - x.min()) * 32767.0
  37. else:
  38. abs_max = numpy.abs(x).max()
  39. x = x / abs_max * 32767.0
  40. return numpy.round(x)
  41. t = numpy.arange(0, WAVETABLE_SIZE + 1) / float(WAVETABLE_SIZE)
  42. exponential = numpy.exp(-4.0 * t)
  43. ring = numpy.exp(-3.0 * t) * numpy.cos(8.0 * t * numpy.pi)
  44. steps = numpy.sign(numpy.sin(4.0 * t * numpy.pi)) * (2 ** (-numpy.round(t * 2.0)))
  45. noise = numpy.random.randn(WAVETABLE_SIZE + 1, 1).ravel() * ((1 - t) ** 2)
  46. waveforms = [('exponential', scale(exponential))]
  47. waveforms += [('ring', scale(ring))]
  48. waveforms += [('steps', scale(steps))]
  49. waveforms += [('noise', scale(noise))]
  50. """----------------------------------------------------------------------------
  51. Band-limited waveforms
  52. ----------------------------------------------------------------------------"""
  53. WAVETABLE_SIZE = 1024
  54. # Sine wave.
  55. sine = -numpy.sin(numpy.arange(WAVETABLE_SIZE + 1) / float(WAVETABLE_SIZE) * 2 * numpy.pi) * 32767
  56. waveforms.append(('sine', scale(sine)))