.TH one-bit-instrument 7 "February 2012" "numm" "Numm Tutorials" .SH NAME one bit instrument \- how to make a gnarly synth with \fBnumm-run\fR .SH SYNOPSIS numm-run \fIFILE\fR .SH DESCRIPTION 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 \fBnumm-run\fR. .PP To get started, create a text file with the following method stubs: .IP .EX def audio_out(a): pass def video_out(a): pass .EE .PP Save the file as \fIonebit.py\fR, and then launch it with \fBnumm-run\fR: .IP numm-run onebit.py .PP You should see a blank window appear. We will now make some sound and light by changing the value of \fIa\fR in the \fIaudio_out\fR and \fIvideo_out\fI functions: .IP .EX def audio_out(a): a[::100] = 2**15 def video_out(a): a.flat[::100] = 255 .EE .PP 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: .IP .EX 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 .EE .PP 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: .IP .EX 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 .EE .PP .SH SEE ALSO .BR numm-run (1), .BR numm.getting-started (7), .BR numm.spectral-analysis (7)