Homework assignment #6

Abstraction, and real-time signal tracking in Pd

Your Pd patch for hw4 probably got a bit cluttered by spaghetti in the end. If you haven't yet learned the trick for encapsulating patches in Pd, please see /usr/lib/pd/doc/2.control.examples/12.PART2.subpatch.pd

and practice making a subpatch abstraction. This will make your programming cleaner, less prone to bugs, and ultimately much easier to understand when you go back to it. Please use subpatches when you architect this assignment.

(We already have seen the concept of abstractions in Scheme, for example, coding the dynamical system expression into a procedure called tick in hw4, or the midi file track reader into a procedure called get-track-data in hw5.)

Choose either a composition sketch or a music programming demo.

Composition Sketch

HW#6 Use your mic and Pd to track a soloist in real time, using the system to create a second voice as an accompaniment with one of the Stk instruments and (optionally) processing their sound. Explore the fullest range of possible relationships given your chosen acoustical / electronic combination. In other words, probe a wide variety of relationships and then use them in a way that shows these off as contrasts. The sketch should be scored in some graphical way that helps you organize the timeline of musical changes and to direct a Pd assistant (who might be needed to perform this). Contrasting sections should be marked in the score. Post the .wav file as usual and make is a long or short as you want.

Music Programming Demo

HW#6 Create a new Pd patch for tracking playing on any instrument via your mic (even a sawed-off piece of PVC pipe will do or something from the blue bin in my office). Use pitch and amplitude detectors to control Stk instrument synthesis in real-time. The relationship can be one-to-one or one-to-many, where the latter means that you would be triggering an algorithm which produces the notes on the synth. There should be at least two modes in your completed work that cause the synthesis to behave differently. Add mode change functionality to switch between the modes by detecting a difference in your playing. Switching will happen when you for example, hit a low note, or you pause for over 3 secs (i.e., from the signal, not from computer keyboard or mouse). Post a sound file which is sufficient to demonstrate your machine without explanation.

Quick Start:

Fiddle~ A Pd pitch and amplitude tracker

Pd tracking uses the fiddle~ pitch and amplitude detector object and the lbyl object for filtering its mistakes

fiddle~ is an object in Pd's standard library, try it out first with these steps:

Start qjackctl, start Pd, open a new document, put new instances of the adc~ and dac~ objects (by typing their names into new objects) wire them together and start computing audio. You should hear your mic coming through the loudspeakers or headphones. Add a fiddle~ object and print the pitches it detects to the terminal:


Right-click fiddle~ invoking it's help window to see what else it can output. You'll notice pitches being printed in greater number than the notes that you are playing into the mic. Some of these are probably mistakes...


LBYL a filter for fiddle's mistakes

The lbyl object can make it a bit more reliable by filtering out false pitch detections. Matt Wright contributed a fiddle improver called Look Before You Leap (lbyl) which is not a part of the standard Pd library.

Install it in your own directory and then tell Pd where to find it. This is a rehearsal on how to customize Pd.

From a terminal in the directory you want it to live in, type

cp -r ~cc/220a/pd/lbyl .

which will copy over a directory containing the custom object and it's help patch.


Now tell Pd about the path to this directory by adding it to a Pd preferences file. If you don't have one already, create and edit a file called .pdrc in your home directory (note the `dot' in the file name). Add to it the line

-path /user/<your-initial>/<your-login>/<wherever>/lbyl

so that Pd will always reference this new object when it wakes up. In mine, I also added

-jack

to this file so that jack will be the default audio subsystem for Pd


Restart Pd and make a patch like this:



Explore different tolerance and quota values as you play into the system.

Stk synthesis in Pd

Next, add the Stk synth instruments to Pd. These are also custom externals for Pd and so far only exist in 220a. You add them by copying these files into the directory you want them to live in, type

cp -r ~cc/220a/pd/stk .

This directory should now also be added as a path in your .pdrc file, and after you restart Pd you can create objects for:

Clarinet BlowHole Saxofony Flute Brass BlowBotl

Bowed Plucked StifKarp Sitar Mandolin Mesh2D

Moog Simple Drummer Shakers

ModalBar BandedWG Resonate VoicForm Whistle


Preview these outside of Pd first, using the Stk demo. To run that, first, start Jack, then

go to the demo directory

cd ~cc/220a/system/stk-4.2.1/projects/demo/

and execute the demo

./StkDemo &

In the new Pd objects, none of have a help patch yet, so this is the documentation!

All these Stk instrument objects have 4 inlets and 1 outlet:

inlet 1 (leftmost) -- signal -- for now, just a passthrough that mixes its input into the output (basically useless and you should ignore)

inlet 2 -- float number (0-127) -- a new number appearing here will cause a new noteOn with the number as amplitude in the range 0-127

inlet 3 -- float number (0-big) -- a new number here will set frequency in Hertz, but for some unpitched instruments it will instead select a different instrument subtype, e.g., see the Stk documentation for the Shakers instrument

inlet 4 (rightmost) -- list `stkCtrl' integer number (0-127), integer number (0-127) -- controller number, controller value

outlet 1 -- signal -- instrument output (mixed with inlet 1)

Test patch example which runs the ModalBar object (compare to the ModalBar in Stk's documentation, and StkDemo)

You can copy this from ~cc/220a/pd/ModalBar~.pd





(warning: keep dogs and children away from loudspeakers! this is very fresh, untested code, let me know of bugs -- and there are at least some, including Stk documentation)


So, back to the assignment. What you should do is 1) build up a subpatch for how you want the instrument to behave, testing with sliders. Use the Stk documentation and StkDemo to understand the patch. 2) build a subpatch with fiddle~ and lbyl that displays triggers and relevant numbers to confirm your tracking mechanism works with your instrument 3) tie these together 4) add extra functionality depending on the type of project 5) record takes live to Audacity 6) post resulting file

Fiddle~ and lbyl are using midi keynums, so you need to convert to freq as shown in my file ~cc/220a/pd/test-track.pd

7) celebrate having finished all the homeworks for this quarter!