Simple as Possible

Now that the Slipmat dev code is up at github, I can write smaller examples rather than cram everything into one large script. The example test_tone.py is written specifically to demonstrate the simplest possible script that generates audio. Here’s the code:

import slipmat

s = slipmat.ScoreEvents()
s.event(0, 4, slipmat.Sine())
slipmat.ScoreEventsToWave(s, "./test_tone.wav")

This produces a 4-second 440Hz sine tone, and writes it to a wave file.

Here’s the line-by-line run down. First, the slipmat module is imported, essentially turning Python into a synthesizer. Then a score object is created from class slipmat.ScoreEvents(); this is akin to a Csound score file, as it is responsible for scheduling events for unit generators and instruments. A slipmat.Sine() object is instantiated then scheduled to play for 4-seconds using the default frequency of 440Hz. Then slipmat.ScoreEventsToWave() parses the score and renders the audio, writing the results to the file “./test_tone.wav”.

This is how it looks today. As Slipmat changes and evolves, so will this example.

Comments are closed.