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.

63 lines
2.2KB

  1. #!/usr/bin/python2.5
  2. #
  3. # Copyright 2012 Olivier Gillet.
  4. #
  5. # Author: Olivier Gillet (olivier@mutable-instruments.net)
  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. # Lookup table definitions.
  21. import numpy
  22. lookup_tables = []
  23. lookup_tables_32 = []
  24. """----------------------------------------------------------------------------
  25. Timer oscillator pitch table.
  26. ----------------------------------------------------------------------------"""
  27. notes = numpy.arange(0, 12 * 128 + 16, 16) / 128.0 + 24
  28. frequencies = 2 ** ((notes - 69) / 12) * 440.0
  29. values = 32000000.0 / (2 * 8 * frequencies)
  30. lookup_tables.append(
  31. ('timer_count', numpy.round(values))
  32. )
  33. """----------------------------------------------------------------------------
  34. Digital oscillator pitch table.
  35. ----------------------------------------------------------------------------"""
  36. sample_rate = 32000000 / 666.0
  37. a4_midi = 69
  38. a4_pitch = 440.0
  39. excursion = 65536.0
  40. notes = numpy.arange(116 * 128.0, 128 * 128.0 + 16, 16)
  41. pitches = 2 * a4_pitch * 2 ** ((notes - a4_midi * 128) / (128 * 12))
  42. increments = excursion / sample_rate * pitches
  43. lookup_tables.append(
  44. ('oscillator_increments', increments.astype(int))
  45. )
  46. """----------------------------------------------------------------------------
  47. Bitcrusher pitch table.
  48. ----------------------------------------------------------------------------"""
  49. ratios = [1] * 128
  50. ratios = ratios + list(numpy.linspace(1.0, 64.0, 128))
  51. increments = 65536 / numpy.array(ratios)
  52. lookup_tables.append(
  53. ('bitcrusher_increments', increments.astype(int))
  54. )