1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#!/usr/bin/python
import glob
import os.path
import sys
import ao
print('ao:', ao.__file__)
try:
from urllib.request import urlopen
except ImportError:
from urllib import urlopen
print(sys.version_info)
PYTHON_VERSION = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
for p in glob.glob("../build/lib.*-" + PYTHON_VERSION):
print("Inserting build path {}".format(p))
sys.path.insert(0, p)
print('paths: ', sys.path)
import mad
print('mad:', mad.__file__)
def play(u):
print('opening', u)
mf = mad.MadFile(u)
if mf.layer() == mad.LAYER_I:
print("MPEG Layer I")
elif mf.layer() == mad.LAYER_II:
print("MPEG Layer II")
elif mf.layer() == mad.LAYER_III:
print("MPEG Layer III")
else:
print("unexpected layer value")
if mf.mode() == mad.MODE_SINGLE_CHANNEL:
print("single channel")
elif mf.mode() == mad.MODE_DUAL_CHANNEL:
print("dual channel")
elif mf.mode() == mad.MODE_JOINT_STEREO:
print("joint (MS/intensity) stereo")
elif mf.mode() == mad.MODE_STEREO:
print("normal L/R stereo")
else:
print("unexpected mode value")
if mf.emphasis() == mad.EMPHASIS_NONE:
print("no emphasis")
elif mf.emphasis() == mad.EMPHASIS_50_15_US:
print("50/15us emphasis")
elif mf.emphasis() == mad.EMPHASIS_CCITT_J_17:
print("CCITT J.17 emphasis")
else:
print("unexpected emphasis value")
print(("bitrate %lu bps" % mf.bitrate()))
print(("samplerate %d Hz" % mf.samplerate()))
sys.stdout.flush()
millis = mf.total_time()
secs = millis / 1000
print("total time %d ms (%dm%2ds)" % (millis, secs / 60, secs % 60))
dev = ao.AudioDevice(0, rate=mf.samplerate())
while 1:
buffy = mf.read()
if buffy is None:
break
print('buffy:', len(buffy))
dev.play(bytes(buffy))
print("current time: %d ms" % mf.current_time())
if __name__ == "__main__":
print(("pymad version %s" % mad.__version__))
for filename in sys.argv[1:]:
if os.path.exists(filename):
play(filename)
else:
u = urlopen(filename)
if u:
# if os.path.exists(file):
print(("playing %s" % filename))
play(u)
|