FX INTRODUCTION / 02

Slicer: chop a sustained sound

Slicer creates rhythm by chopping a playing sound into short pieces.

Listen to the performance first, then explore how to use it.

1. Listen to this sound

Press Run. You will hear a finely chopped rhythm while the pitch moves smoothly. Slicer does the chopping; Reverb adds a tail in this example.

Run starts playback and Stop ends it. Stop this performance before trying the next example.

Open this code in a separate Playground tab ↗

To change the chopping, replace choose([0.25, 0.125]) with choose([0.5, 0.25]) and Apply. The chopping interval becomes longer.

Next, use a simple sound to try each Slicer setting separately.

2. Explore settings with a simple sound

The source is the same long sine wave used in the Gain chapter. Instead of retriggering short notes, the FX opens and closes the playing sound.

SettingMeaning
phaseLength of one cycle in beats, not the initial phase
dutyOpen proportion of the cycle; 0.5 means half
floorGain while closed; 0 means silence
mixWet signal proportion; 1 means only processed sound

At BPM 120, one beat lasts 0.5 seconds. phase 0.5 gives a 0.25-second cycle: four openings per second.

In the iframe, use Run to start and Stop to stop. After editing values during playback, use Apply to apply them. Stop the other Playground before comparing; each has an independent audio environment.

After pressing Run, use FX Monitor to select none to see the waveform after the built-in FX.liveFx("none", …) is a pass-through observer. Blue and orange overlap; this is not a before/after comparison of the built-in FX. Edit settings and Apply to see the waveform change.

Open this code in a separate Playground tab ↗

phase 1 chops slowly; 0.25 chops faster. duty 0.2 produces short sound fragments; 0.8 produces short gaps. floor 0.2 avoids complete silence.

3. Think of a cycle as a position from 0 to 1

phase = position / period
level = phase < duty ? 1 : floor
output = input × level

At duty 0.5, the first half is open and the second half is closed. This changes loudness; it does not key the source on/off or restart its envelope.

Cutting sound abruptly introduces waveform discontinuities, clicks, and additional frequency components. At high rates, it may sound like a change in tone rather than rhythm.

4. A Slicer that counts samples

First, separate out conversion from seconds or BPM and specify the period as a sample count.periodSamples: 12000 lasts 0.25 seconds at 48 kHz, or about 0.272 seconds at 44.1 kHz. This example does not automatically follow BPM.

To convert from seconds, use periodSamples = period in seconds × actual output sample rate. To convert from beats, calculate the period in seconds as 60 / BPM × beats. FX Monitor displays the output rate.

Open this code in a separate Playground tab ↗

  1. Press Run and select slicer-lab in FX Monitor. The input continues while some output sections are zero.
  2. Change context.duty to 0.2 or 0.8 and Apply to compare the audible durations.
  3. Set floor to 0.2 and look at the amplitude during closed sections.
  4. Set periodSamples to 1000 to see fine chopping in the waveform. Several cycles fit into the Monitor's 2048-sample window.

With a 12000-sample period, a short window may show only an open or a closed section. Look at changes over time and listen, rather than judging one image alone.

5. Why preserve the position in state?

state.position ??= 0;
// Advance once for each processed sample.
state.position = (state.position + 1) % period;

process is called repeatedly, and i returns to zero each time. Computing the cycle from i alone restarts it every audio block. state.position carries the position into the next block.

Advance the position once after processing both channels so left and right open together. Applying the same name preserves state; Stop discards it.

This rectangular gate is for learning the mechanism, not reproducing every behavior of the built-in effect. As a next experiment, change Gain gradually at boundaries to soften clicks.

← Back to Gain · Next chapter: change waveform shape with Distortion →