[PD] pyext~
patrick
patrick at 11h11.com
Fri Oct 12 19:11:09 CEST 2007
hi all, thomas,
is it possible to use pyext~ this way:
try:
import pyext
except:
print "ERROR: This script must be loaded by the PD/Max py/pyext
external"
try:
import psyco
psyco.full()
print "Using JIT compilation"
except:
# don't care
pass
import sys, math, mad, socket, urlparse, os.path
from optparse import OptionParser
try:
import numarray
except:
print "Failed importing numarray module:",sys.exc_value
class play(pyext._class):
"""MP3 Player"""
def __init__(self,*args):
scheme, netloc, path, params, query, fragment =
urlparse.urlparse('http://freesound.iua.upf.edu/data/19/previews/19560__11h11__itmightbeempty_preview.mp3')
try:
host, port = netloc.split(':')
except ValueError:
host, port = netloc, 80
if not path:
path = '/'
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, int(port)))
sock.send('GET %s HTTP/1.0\r\n\r\n' % path)
reply = sock.recv(1500)
file = sock.makefile()
mf = mad.MadFile(file)
print "bitrate %lu bps & samplerate %d Hz - ready" %
(mf.bitrate(), mf.samplerate())
def _dsp(self):
if not self._arraysupport():
print "No DSP support"
return False
def _signal(self):
self._outvec(0)[:] = self.mf.read()
#self._outvec(0)[:] = self._invec(0)
mad is for playing mp3 file. i know it's hopeless to just try to pass the
buffer to _signal... but i am wonderign if it's possible:
self._outvec(0)[:] = self.mf.read() maybe combined with a while.
if not, then there's only readanysf~ for playing distant mp3 file, but it's
not working for me with a long url
('http://freesound.iua.upf.edu/data/19/previews/19560__11h11__itmightbeempty_preview.mp3')
don't know why...
or maybe there's another solution?
pat
More information about the Pd-list
mailing list