Friday, August 31, 2007

Music Control Tools: Python-Based

In the previous part of this series of articles I looked at dedicated programming languages for music creation. But why invent a new language for this one special domain? Surely it makes more sense to use one of the many existing languages, provide libraries for required protocols and interface with the correct hardware?

Well, that is not necessarily true. As we saw in our short look at ChucK, new paradigms of coding ("strictly-timed") may enhance development in a specific domain.

However, the advantages of adopting an existing language are obvious. The developer need not work out their own grammar, syntax and tools, but can rather concentrate on the actual audio part of the problem.

In this article I will look at audio development tools based in my language of choice, Python. These will all have the advantages of that language: clear syntax, pragmatic mix of functional, object-oriented and imperative models, strong OOP implementation, etc.

PyGame, based on the Simple DirectMedia Layer (SDL), has lots of graphics functionality, but also plays back MPG files and accesses devices like CD-ROM drives and joysticks. It can queue and play music streams, and contains sound sample manipulation, but is not robust enough in this regard for our purposes. For instance, it can handle only one audio stream at a time and has no DSP functionality.

pySonic is a wrapper for the FMOD library and provides sound file playback and recording, MIDI, 3D sound and support for many formats (wav, aiff, mp3, ogg, mod, etc.). FMOD is not free or open source, so one would have to abide by their license restrictions.

PyPortMidi provides MIDI I/O, although the latest binary is for only Python 2.4. Likewise here's a module for OpenSoundControl (OSC) client functionality.

PySndObj is a wrapper for the SndObj Sound Object Library which provides realtime audio IO and MIDI input (though not on all platforms). Currently this is too immature to recommend for the task at hand.

PyMedia is a library for sound file playback and recording which supports wav, mp3, ogg, avi, divx, dvd, cdda etc. It also has some DSP functionality, namely resampling and frequency analysis.

athenaCL is an interactive command line program specifically designed for algorithmic composition and pitch models studies. It has a host of tools in this regard, outputting results to Csound, MIDI, audio file, XML and text formats. While not requiring Csound, it is tightly integrated with that programme, containing Csound format instrument. (Without it, results can nonetheless be rendered to MIDI files.) This programme looks excellent within the domain it is targeting.

Finally, MusicKit includes serial and MIDI I/O, scheduling and synchronization, real-time (or non-realtime) synthesis (FM, wavetable, physical modeling etc.) and DSP. It supports quadraphonic sound, MP3 and Ogg/Vorbis plus multiple inputs and outputs. Furthermore, the package comes with high-end tools including a sampler, sequencer and score player.

Of all the packages here, it potentially provides the most robust toolkit for sound creation and manipulation. Unfortunately, not only is the GUI on Windows incomplete, but so is MIDI support and the DSP functions. Critically, MIDI and DSP are also missing from the LINUX version. (MusicKit had its genesis on the NeXT and so works just fine in OpenStep... in case that helps you.) There has been no version since May 2005, so it is fair to say this tool is ripe for salvage.

The conclusion of this article must therefore be that there is no Python-based system that meets our needs at present. And while it would be possible to scrape one together from bits and pieces of the packages listed here, that would be far more work than could be justified.

Reference: The wiki entry PythonInMusic contains tools I have not covered here, such as those for media playback and cataloging.

I thank the Arts Council for their support in this research.



robin said...

Illume: I do hope that PyGame or another of these solutions evolves into a more robust audio tool. It always seems to be about the "next release"!

Piede Rosso said...

PySndObj is not at all immature; it
provides great support for lots of
different signal processing tasks,
time and frequency-domain. It is
based on the SndObj library, which
has over 100 classes, so it's
pretty complete.
Furthermore, with just a little
bit of C++, new classes can be
added to it.

q845712 said...

thx for this post - i'm trying to decide between exactly these libraries. do you think much has changed in the past couple years?

robin said...

I have not worked with these lately. Perhaps someone else has more recent information?

Anonymous said...

Maybe have a look at pyglet ( It is similar to PyGame, but does not have external dependencies on SDL.

Post a Comment