Python synthesizer stuff
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.

35 lines
865B

  1. import pymod
  2. import sys
  3. import numpy as np
  4. mp3 = pymod._ysynth_mp3_open(sys.argv[1])
  5. samplerate, channels = pymod._ysynth_mp3_get_format(mp3)
  6. print "Samplerate:", samplerate, "Channels:", channels
  7. x = pymod._ysynth_init(samplerate, channels)
  8. first_time = True
  9. def play_mp3(channels):
  10. """
  11. Play contents of MP3 file.
  12. """
  13. global first_time
  14. if first_time:
  15. print "First time callback occurred"
  16. print "Array shape is: %s" % str(channels.shape)
  17. first_time = False
  18. next_chunk = pymod._ysynth_mp3_read(mp3, channels.shape[0])
  19. next_chunk = np.minimum(np.maximum(next_chunk, -1.0), 1.0)
  20. # Using 32767.5 as a factor causes overflow, we need to fix this
  21. # in the most uniformly distributed way possible
  22. np.round(next_chunk * 32767, 0, out=channels)
  23. return
  24. pymod._ysynth_set_callback(x, play_mp3)