[continue autosave] Learn Sporth
log in learn new browse

P Registers

P-registers were an early way to share information without using the stack. It is simply an array accessible to Sporth where values can be easily read/written to. There are 16 p-registers, though this is easy to change in the source.

Here is a simple patch demonstrating this:

 440 0 pset
 0 p 0.3 sine

In the example above, the value of p-register 0 is being set to 440 via pset. In the line below, the value of p-register 0 is being read with p.

P-registers are mostly useful for intergating Sporth with other applications, as they are trivial to read/write from the API. Another useful property of p-registers is that they persist from one sample to the next, so they allow the creation of nested delay lines and filters, or nesting other effects within a delay line, for example:

tick 1 0.3 0 dust +
500 (-200 500 30 randh)+ 0.3 110 pluck
1 p 0 0.2 delay 0.6 *
-1 500 50 pshift
dup dup 1 1 5000 zrev + 2 * +
50 buthp dup rot + 1 pset

A little silly side note on P-registers: the "P" stands for parameter. The term itself is borrowed from Csound, where p-fields, or parameter fields, are optional values read from a Csound score.

Previous: Variables | Back | Next: Prop

Compile & play Stop audio