numm.one-bit-instrument(7)

numm.one-bit-instrument7

How to make a gnarly synth with numm-run

Usage

numm-run FILE

Overview

In this tutorial we will learn how to live-code a one-bit synthesizer controlled by mouse position. It is intended as a gentle introduction to development with numm-run.

To get started, create a text file with the following method stubs:

def audio_out(a):
    pass
def video_out(a):
    pass

Save the file as onebit.py, and then launch it with numm-run:

numm-run onebit.py

You should see a blank window appear. We will now make some sound and light by changing the value of a in the audio_out and video_out functions:

def audio_out(a):
    a[::100] = 2**15
def video_out(a):
    a.flat[::100] = 255

Save the file, and you should see and hear the sketch update. This is using numpy's array-indexing to turn every hundredth audio sample and pixel-color on. The audio sample rate is by default 44100Hz, so it produces a series of clicks that will be perceived as a 441Hz tone. We can turn this into an instrument by connecting mouse motion to frequency:

period = 100
def audio_out(a):
    a[::period] = 2**15
def video_out(a):
    a.flat[::period] = 255
def mouse_in(type,px,py,button):
    global period
    period = px*1000

Finally, let's use the keyboard to record and jump to notes. The first time you press a key, it records the period, and subsequant depressions play the saved period:

period = 100
record = {}
def audio_out(a):
    a[::period] = 2**15
def video_out(a):
    a.flat[::period] = 255
def mouse_in(type,px,py,button):
    global period
    period = px*1000
def keyboard_in(type,key):
    global period
    if record.has_key(key):
        period = record[key]
    elif record.has_key(key):
        record[] = period

Releases

Unchanged in 2 releases since Debian 7 (Wheezy).

  1. 7–8

From python-numm 0.5-1 in Debian 8 (Jessie). Parsed by carta from the page's man source.