11 July 2010

Python Wave

I'm not expert with audio, both theory and practice, but from time to time, I do simple experiments. Months ago I tried OpenAL, which is pretty cute.
But lately I'm doing also things with Python, and I had some difficulties to make OpenAL running on python (i.e. on Fedora I can't find the package out of the box. Yes, I'm lazy), so I just tried something else.

First choice: SDL Mixer, that is present in pygame. Too bad it hangs when initializing the mixer. So I gave up on that because I didn't have time to check for bugs and so on.
So, alternatives? FMOD? Seems cute, but... I found out another way! It's non-interactive, but still easy to use for my purpose (that is, generating waveforms). I don't mind the realtime, right now...

So, Python Wave library!! Great :D Support for writing and reading wave files. Easy, straightforward, fast to learn.

Well, after few hours (with many distractions...) I made this example.

You know what? It remind me when I used to play with audio on Quick Basic: you gave it a string of notes and some other parameters, and it would sound for you :) How cute.
Feel free to read it, run it, test it (but absolutely you CAN'T modify it or your head will explode) and see how dangerous is for your ears to listen to 8-bit 11kHz sampled sounds... XD

I'm not really interested in improving this ugly code... Not only it's full of magic constants (127, 'b', and so on, which highly depends on the actual configuration), but, I mean, my purpose is not to make computer-generated melodies easily with python just using strings. It's not hard to do that, would require no more than 30 minutes of coding, but I simply don't care (now... Maybe I'll do it as a toy in future :D)

But maybe someone of you can enjoy playing with it, improving, or simply use it as reference when it comes to generate noises using python.

Oh, I didn't care about performances either, clearly. If you do, I suggest to use numpy arrays.

Stay --sync

0 commenti:

Post a Comment