|
-
- import pymod
- import sys
- import numpy as np
-
- mp3 = pymod._ysynth_mp3_open(sys.argv[1])
- samplerate, channels = pymod._ysynth_mp3_get_format(mp3)
- print "Samplerate:", samplerate, "Channels:", channels
-
- x = pymod._ysynth_init(samplerate, channels)
- first_time = True
-
- def play_mp3(channels):
- """
- Play contents of MP3 file.
- """
-
- global first_time
-
- if first_time:
- print "First time callback occurred"
- print "Array shape is: %s" % str(channels.shape)
- first_time = False
-
- next_chunk = pymod._ysynth_mp3_read(mp3, channels.shape[0])
- next_chunk = np.minimum(np.maximum(next_chunk, -1.0), 1.0)
- # Using 32767.5 as a factor causes overflow, we need to fix this
- # in the most uniformly distributed way possible
- np.round(next_chunk * 32767, 0, out=channels)
-
- return
-
- pymod._ysynth_set_callback(x, play_mp3)
|