In parts 6 and 7, we examined a reactive signal source, audio. There are multiple different reactive sources in Kronos, and this part is about control signals.

Much like audio files, control signals are brought into your program externally, as a cooperation between IO.k and k2cli. At this stage, all control is input via OSC. k2cli listens to an UDP port, configurable via command line switches (please consult –help).

An OSC control signal is produced by the function OSC:In(“address-pattern” initializer). The address-pattern can contain wildcards that comply to the OSC specification. The initializer function, much like in the case of delays, sets the value of this input before receiving any OSC messages. All incoming OSC messages that match the address pattern and the type of the initializer will be sent to this spot.

Testing 1 2 3

Before doing anything serious, let’s verify that we have an OSC connection. To do that, let’s introduce a new reactive sink, ‘–console’. To enter the address pattern, we need a Kronos string directive with double quotes — to sidestep nastiness with command line escaping, let’s just put it in a function in a text file:

    OSC-test = OSC:In("/test" '0)

When you launch ‘k2cli –console “OSC-test()”‘ and send OSC messages consisting of floating point values to the default port (32000), they should appear on screen.

Controlling audio with OSC

To set up a simple, controllable oscillator, we can grab one of our oscillators from part 6 or 7 and use it with some OSC inputs:

    OSC-synth = tri-osc(OSC:In("/freq" '0.5) * 0.25) * OSC:In("/amp" '1)

By sending floating point OSC control data to the addresses ‘/freq’ and ‘/amp’, the oscillator can be remotely controlled.

Reactivity and smoothing

You may notice that changing the pitch and volume introduce some discontinuities in the sound. This is due to control events being relatively abrupt rather than gradual changes. We can fix this by introducing a simple smoothing filter;

smooth-control(sig coef)
    out = z-1('0 out + (Audio:Clock(sig) - out) * coef)
    smooth-control = out

This filter will let its output approach the input by the fraction ‘coef’ for every reactive tick. Reactivity is the key here; consider how we clock the incoming signal to audio by using Audio:Clock, as introduced in part 6. If this part were omitted, the update rate of this filter would be determined by its incoming signals, ‘sig’ and ‘coef’. It is quite likely that ‘sig’ is a control signal and ‘coef’ is a constant. Therefore, the filter would be updated at the rate of control signals. It would only cause a strange control lag, not smooth the signal in any way.

    freq = OSC:In("/freq" '0.5) * 0.25
    amp = OSC:In("/amp" '0.3)
    OSC-synth-smooth = tri-osc(smooth-control(freq 0.002)) * smooth-control(amp 0.002)

Here, the smoothed signal approaches the incomign control signal by 0.2% per sample. This is quite small, and you will hear an audible lag in the sound. Experimentation is always required to find the desired balance between discontinuity and responsiveness.

No Comment.

Add Your Comment

− four = 4