OSC and Networking

Boot the server to get going.

Peeling Back the Abstraction

In SuperCollider, UGens and Synths are simply client-side abstractions for OSC messages that get sent to the server where the audio is actually produced. The information for SynthDefs, Synths, and other audio producing classes are translated to OSC messages and sent using the method .sendMsg.

A Synth in SuperCollider is simply a convenience class for sending an OSC message to the server to produce a particular instrument created through a SynthDef.

Below we can set up execute the equivalent of x = Synth(\sine) by sending an OSC message below. The address /s_new specifies a function on the serve that will process the message. In this case, the function is responsible for creating a new instance of a SynthDef.

This is also true when we want to create synths with specific arguments.

Your Turn

Create two sine nodes in octaves of a frequency of your choosing. Make the amplitude of each sine wave 0.2.

Free both of those nodes.

Simple Loopback

Below we will write some code to interact with SuperCollider and your localhost network on your computer.

Note that sclang generally listens on port 57120 but if that port is alreeady taken by your system then another port may be used. Furthermore, these are UDP ports, not TCP.

Let's create a function to listen for incoming osc messages with a specific address. This can be done using the class OSCdef.

Now we can see that we have one matching function called \msg that is listening for OSC messages with the address /msg. Note the differences between the two slashes.

To send a message to sclang from sclang, we first need to know the address and port number where sclang is listening.

Exercise: Using OSC Messages to Play Sounds

Below is a SynthDef for playing a sine wave with an envelope and a function called ~printUgenMsg that nicely formats an OSC message for posting. Below write an OSC definition called \sine that will receive OSC messages at address "/sounds/sine". If a message is received it should play the sine wave by creating a Synth and post to the window that the message was received using the ~printUgenMsg. You can assume each OSC message has five arguments in this order: frequency, phase, amplitude, duration, and pan position.

The End!