I'm looking at writing a little drum machine in Python for fun. I've googled some and found the python pages on music and basic audio as well as a StackOverflow question on generating audio files, but what I'm looking for is a decent library for music creation. Has anyone on here tried to do something like this before? If so, what was your solution? What, either of the ones I've found, or something I haven't found, would be a decent library for audio manipulation?
Minimally, I'd like to be able to do something similar to Audacity's scope within python, but if anyone knows of a library that can do more... I'm all ears.
Take a close look at cSounds. There are Python bindings allow you to do pretty flexible digital synthesis. There are some pretty complete packages available, too.
See http://www.csounds.com/node/188 for a package.
See http://www.csounds.com/journal/issue6/pythonOpcodes.html for information on Python scripting within cSounds.
I had to do this years ago. I used pymedia. I am not sure if it is still around any way here is some test code I wrote when I was playing with it. It is about 3 years old though.
Edit: The sample code plays an MP3 file
import pymedia
import time
demuxer = pymedia.muxer.Demuxer('mp3') #this thing decodes the multipart file i call it a demucker
f = open(r"path to \song.mp3", 'rb')
spot = f.read()
frames = demuxer.parse(spot)
print 'read it has %i frames' % len(frames)
decoder = pymedia.audio.acodec.Decoder(demuxer.streams[0]) #this thing does the actual decoding
frame = decoder.decode(spot)
print dir(frame)
#sys.exit(1)
sound = pymedia.audio.sound
print frame.bitrate, frame.sample_rate
song = sound.Output( frame.sample_rate, frame.channels, 16 ) #this thing handles playing the song
while len(spot) > 0:
try:
if frame: song.play(frame.data)
spot = f.read(512)
frame = decoder.decode(spot)
except:
pass
while song.isPlaying(): time.sleep(.05)
print 'well done'
There is a variety of Python music software, you can find a catalog here.
If you scroll down the linked page, you find a section on Music Programming in Python describing several music creation packages including MusicKit and PySndObj.
Also check out http://code.google.com/p/pyo/
In addition to what has been mentioned previously, I wrote a simple Python audio editor.
http://code.google.com/p/yaalp/source/browse/#svn/trunk
See main.py.
It also has audio manipulation and some effects.
Code's GPL, so this could be a starting point for you.