Post by microfarad on Feb 6, 2011 8:57:35 GMT
Well... Out of the blue, MF spends an entire day on a project nobody even knew about. And he turns out a product!
This is my MicroPy_Music module, and a quick little program to test it with. It's basically a bunch of convenience functions for writing sound files. Soon I'll be doing some more complicated stuff. But I've already gotten it to play Twinkle Twinkle Little Star!
Having made it, it seems simple to use for me. But it will probably be super complicated for anyone else.
The Snippet class provides an easy way to store tracks of sound information. The Snippet comes with a convenient Cycle function, which can only be used if you don't have any super complicated stuff in mind. It writes a single cycle of a wave to the snippet. Just pass it a PWWave class, a frequency (in hz), a wave offset (keep this unfinished feature 0), a volume (0-1), and the framerate MicroPy_Music.samplerate
The PWWave class (Piecewise wave) lets you define a wave from a piecewise function, or use one of the presets, which are in the PWWaves dictionary. Here's a simple example function...
[['0<=x<.5','1'],['.5<=x<1','-1']]
if x is greater than or equal to 0 and less than half of a cycle, return 1
if x is greater than or equal to half a cycle and less than a full cycle, return 0
It's a square wave!
Save is used to write snippet data to a file. Just call the Format() function on a snippet, and pass that to the signal parameter, stick in the framerate, and give it a string representing a location on your computer to save it at (extension should be .wav).
Note() is a handy feature. It takes a note, written with a somewhat non-standard notation which I preffer, and turns it into a frequency.
C#4, for example, is a C sharp. 4 represents the octave.
440 Hz is represented by A4
If you have any questions, ask!
This is my MicroPy_Music module, and a quick little program to test it with. It's basically a bunch of convenience functions for writing sound files. Soon I'll be doing some more complicated stuff. But I've already gotten it to play Twinkle Twinkle Little Star!
Having made it, it seems simple to use for me. But it will probably be super complicated for anyone else.
The Snippet class provides an easy way to store tracks of sound information. The Snippet comes with a convenient Cycle function, which can only be used if you don't have any super complicated stuff in mind. It writes a single cycle of a wave to the snippet. Just pass it a PWWave class, a frequency (in hz), a wave offset (keep this unfinished feature 0), a volume (0-1), and the framerate MicroPy_Music.samplerate
The PWWave class (Piecewise wave) lets you define a wave from a piecewise function, or use one of the presets, which are in the PWWaves dictionary. Here's a simple example function...
[['0<=x<.5','1'],['.5<=x<1','-1']]
if x is greater than or equal to 0 and less than half of a cycle, return 1
if x is greater than or equal to half a cycle and less than a full cycle, return 0
It's a square wave!
Save is used to write snippet data to a file. Just call the Format() function on a snippet, and pass that to the signal parameter, stick in the framerate, and give it a string representing a location on your computer to save it at (extension should be .wav).
Note() is a handy feature. It takes a note, written with a somewhat non-standard notation which I preffer, and turns it into a frequency.
C#4, for example, is a C sharp. 4 represents the octave.
440 Hz is represented by A4
If you have any questions, ask!