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.

76 lines
2.4KB

  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. # Lookup table definitions.
  30. import numpy
  31. import pylab
  32. def scale(x):
  33. xc = x - x.mean()
  34. abs_max = numpy.abs(xc).max()
  35. xc /= abs_max
  36. return xc
  37. def fshift(x, shift):
  38. s = x[:-1] + 0
  39. s = numpy.fft.rfft(s)
  40. s[1:] *= shift
  41. xh = numpy.fft.irfft(s)
  42. xh -= xh.mean()
  43. return numpy.array(list(xh) + [xh[0]])
  44. def make_quadrature(name, x, angle_1=0, angle_2=0.5):
  45. xc = fshift(x, numpy.exp(1j * angle_1 * numpy.pi))
  46. xh = fshift(x, numpy.exp(1j * angle_2 * numpy.pi))
  47. scale = max(numpy.abs(xc).max(), numpy.abs(xh).max())
  48. return [(name + '_i', xc / scale), (name + '_q', xh / scale)]
  49. SAMPLE_RATE = 96000
  50. WAVETABLE_SIZE = 1024
  51. t = numpy.arange(WAVETABLE_SIZE + 1) / float(WAVETABLE_SIZE) * 2 * numpy.pi
  52. sine = -numpy.sin(t)
  53. harmonics = -numpy.sin(t) - 0.5 * numpy.sin(2 * t) + 0.5 * numpy.sin(5 * t)
  54. buzzy = 0
  55. for i in xrange(7):
  56. buzzy += numpy.sin((1 + i) * t + 1.012 * i) * numpy.sin(1.123 * i)
  57. iq_waveforms = []
  58. iq_waveforms += make_quadrature('sine', sine)
  59. iq_waveforms += make_quadrature('harmonics', harmonics)
  60. iq_waveforms += make_quadrature('buzzy', buzzy)