would it be feasable to write python DJing software

Tom Anderson twic at urchin.earth.li
Fri Feb 3 11:37:57 EST 2006


On Fri, 3 Feb 2006, Ivan Voras wrote:

> Levi Campbell wrote:
>
>> Hi, I'm thinking about writing a system for DJing in python, but I'm 
>> not sure if Python is fast enough to handle the realtime audio needed 
>> for DJing, could a guru shed some light on this subject and tell me if 
>> this is doable or if I'm out of my fscking mind?

Perhaps surprisingly, it is:

http://www.python.org/pycon/dc2004/papers/6/

At least, you can certainly mix in realtime in pure python, and can 
probably manage some level of effects processing. I'd be skeptical about 
decoding MP3 in realtime, but then you don't want to write your own MP3 
decoder anyway, and the existing ones you might reuse are all native code.

> Any and all mixing would probably happen in some sort of multimedia 
> library written in C (it would be both clumsy to program and slow to 
> execute if the calculations of raw samples/bytes were done in python)

Clumsy? Clumsier than C? No, python isn't as good with binary data as it 
is with text or objects, but on the whole program scale, it's still miles 
ahead of C.

My advice would be to tackle the task in the same way you'd tackle any 
other: write it in pure python, then fall back to native code where it's 
unavoidable. When i say 'pure python', i don't mean 'not using any native 
modules at all', obviously - if someone's written an MP3 decoder, don't 
eschew it because it happens to be in C. Also, bear in mind that resorting 
to native code doesn't automatically mean writing in C - you can start 
doing stuff like moving from representing buffers as lists of ints to 
using NumPy arrays, using the functions in the standard audioop module, 
whatever; if that's not fast enough, rewrite chunks of the code in pyrex 
(a derivative of python that can be compiled to native code, via 
translation to C); if it's still not fast enough, go to C.

Oh, and before you start going native, try running your program under 
psyco.

tom

-- 
Throw bricks at lawyers if you can!



More information about the Python-list mailing list