Archive for the ‘ Programming ’ Category

News – 4/21/2012

Some news:

  • My short paper “DIY Hybrid Analog/Digital Modular Synthesis” – which covers the USB-Octomod, tabulaRasa, and snake.corral –  has been accepted for NIME 2012, and I will present a poster version at the conference. The conference runs from May 21 – 23, in Ann Arbor, MI.
  • I will perform 4/27 at UCSD and 4/28 as part of the California Electronic Music Exchange Concert series.
  • Finally, I’ve started posting some live coding videos:

pucktronix Absolute Pitch Trainer Software

Here’s a link to download a little absolute pitch ear training program I recently completed.

It associates pitch chroma with visual colors, tracks your performance over time, allows you to experiment with different timbres, and allows you to save data in a simple text format for outside processing.

The interface.

.

Preset Management in Pure Data

96 Independent Parameters

I recently spent a few hours putting together a preset manager in Pure Data. The above image shows a set of controls for 8 independent (but identical) signal processing channels. Clearly, 96 parameters is too many to realistically handle in performance, so I needed some way to store and recall settings. As shown in the image, each parameter has a [receive] object which listens for messages of a specific type. Then, a [route] object filters out all messages except those meant for that specific parameter instance.

Here’s the object preset-manager.pd - though it will take a decent amount of modification to get it to work for another patch.

The preset manager interface.

Above is the preset manager interface. A particular slot is accessed via the number box, and that slot can be read or written to with a message box.

Innards of the preset manager object.

Here are the innards of the preset manager object. The block on the right stores presets, and the block on the left recalls them. Presets are stored as raw text files, named with sequential numbers, and are formatted like this:

filter-bypass 1 1 1 1 0 0 0 0;
filter-rate-mod 0.02 0.81 0 50 0 0 0 0;
filter-rate 0.22 0.66 0.95 106 0 0 0 0;
am-bypass 1 1 0 1 0 0 0 0;
am-width 0 0.5 0.52 87 0 0 0 0;
am-rate-mod 16 0.38 0.54 46 0 0 0 0;
am-rate 2.02 1.48 2.54 3.83 0 0 0 0;
fm-bypass 0 0 0 1 0 0 0 0;
fm-rate 173 97 25 1.64 0 0 0 0;
fm-pos/width 55 64 108 96 0 0 0 0;
fm-mode 2 2 2 1 1 0 0 0;
fm-register 1 0 2 2 1 1 1 0;

Each parameter type is followed by eight values – one for each channel. The [textfile] object works really well for reading and writing text files line-by-line.

Code for writing a preset.

Code for reading a preset.

pucktronix.snake.corral python interface

Here’s a Python script which interfaces between OSC and the pucktronix.snake.corral. It’s a work-in-progress, but allows you to toggle individual switches via OSC. You can download the source here: https://bitbucket.org/pucktronix/pucktronix.snake.corral/src/3e9b712971df/control_software/pySnakeCorral.py

 1 __author__ = 'Greg Surges'
 2 
 3 '''
 4     pySnakeCorral.py
 5     interface between OSC messages and pucktronix.snake.corrral hardware
 6     created 08.18.2011
 7     last modified 03.26.2012
 8     greg surges - pucktronix
 9     surgesg@gmail.com
10     http://www.gregsurges.com/
11 '''
12 
13 import OSC
14 import threading
15 import serial
16 from serial.tools.list_ports import comports
17 import time
18 
19 ThreadRun = True
20 
21 address = '127.0.0.1', 9999
22 server = OSC.OSCServer(address)
23 
24 print "Server Initialized..."
25 print "Listening on Port: " + str(address[1])
26 
27 server.addDefaultHandlers()
28 
29 ser = serial.Serial()
30 
31 def init_port():
32         ''' poll serial ports, prompt user for port, open port '''
33         ports = comports()
34         for i, port in enumerate(ports):
35                 print "[" + str(i) + "]" + " " + port[0]
36         port_choice = input("select serial port: ")
37         ser.baudrate = 19200
38         ser.port = ports[port_choice][0]
39         ser.open()
40         if ser.isOpen(): print "opened serial port"
41 
42 def write_bytes(bytes):
43         ''' write bytes to serial port corresponding to a single pin being toggled '''
44         ser.write(bytes)
45 
46 init_port()
47 
48 def print_msg(addr, tags, stuff, source):
49         ''' just print out received data '''
50         print "---"
51         print "received new osc msg from %s" % OSC.getUrlStr(source)
52         print "with addr : %s" % addr
53         print "typetags %s" % tags
54         print "data %s" % stuff
55         print "---"
56 
57 def pin_msg(addr, tags, stuff, source):
58         ''' toggle a single pin on/off '''
59         # osc message should look like "/matrix/one x y state" to match max 
60         if addr == '/matrix/one': chip_byte = 255
61         if addr == '/matrix/two': chip_byte = 254
62         x = stuff[0]
63         y = stuff[1]
64         state = stuff[2]
65         # print chip_byte, x, y, state
66         bytes = ''.join([chr(i) for i in [chip_byte, x, y, state]])
67         write_bytes(bytes)
68 
69 server.addMsgHandler("/print", print_msg) # adding our function
70 server.addMsgHandler("/matrix/one", pin_msg) # add msgs for matrix one 
71 server.addMsgHandler("/matrix/two", pin_msg) # add msgs for matrix two 
72 
73 def osc_process():
74         while ThreadRun:
75                 server.serve_forever
76         print "Stopping OSCServer Thread"
77 
78 
79 print "\nStarting OSCServer. Use ctrl-C to quit."
80 st = threading.Thread( target = osc_process)
81 st.start()
82 
83 try:
84         while 1:
85                 time.sleep(5)
86 except KeyboardInterrupt:
87         ThreadRun = False
88         server.close()


LPC in Matlab

Sitar String Physical Model

As a second challenge in the seminar on how objects vibrate, taught by Miller Puckette at UCSD,
we were asked to simulate the non-linear way a sitar string interacts with the sitar bridge. In a typical
string, like on a guitar, the string maintains a fixed length regardless of whether it is moving upward
or downward. Since a sitar bridge is a wide, flat object, with tapered edges, the string comes into contact with different
amounts of the bridge depending on its direction of travel.

The bridge / string interaction looks something like this:

 When the string travels upward, it comes into contact with the outside edge of the bridge, causing the string to have length N. When the string travels downward, it comes into contact with the inside edge of the bridge, which shortens the length of the string. The string is now something like N – X, where X is the width of the bridge. Part of the characteristic sound of the instrument comes from this alternating shortening and lengthening of the string during the course of a note. My extension to this model, which was proposed to the class, was to imagine the bridge as not simply two termination points, but as a curved surface:

 

Depending on how far “down” the string travels, its length shortens according to the curvature of the bridge. The image below shows the length of the string during one period of vibration. When the string is moving downward, the string length shortens proportionately. When the string is moving upward, the string length is fixed.

Here’s an image of the string simulation patch:

 

I made one final modification to the original idea by adding a set of 13 sympathetically tuned string simulations. Each is a simple Karplus-Strong string model tuned to a specific pitch. This helps to generate the characteristic harmonic activity of the sitar.
Finally, here is a video showing the simulation in action:

absolute pitch trainer

An absolute pitch trainer in development as part of Jerry Balzano's Musical Cognitive Science seminar.

Sampled MFOS State Variable Filter

“Sampling” the transfer function of an analog filter – homemade Music From Outer Space SVF. Here I’m running some sounds through digital models of the hardware at a few different settings. No interpolation (yet) so forgive me the pops and clicks.

 

average / delta performance analysis patch

cross-correlation max/msp javascript

Some recent code – calculates the cross-correlation between two sequences. Download the rest.