Skip to content

Parameter Mapping

Hans Lindetorp edited this page Mar 17, 2024 · 19 revisions

One core feature of WebAudioXML is the syntax for specifying how external variables can be mapped to a specific parameter in WebAudioXML. The feature applies to <var> elements. The mapping can be a very straightforward, linear transformation from an incoming range of the external variable to a target range that suits an audio parameter. This makes it possible to map incoming values between e.g. 0 and 100 to a parameter value between 100 and 1000 (that might be useful for the frequency of a filter or an oscillator).

In many cases, the value needs to be transformed in a more complex way. E.g. the frequency value would benefit from an exponential increase rather than a linear and a MIDI note number (values between 0 and 127) needs to be converted to the frequency domain to make musical sense. On the way, the value might need to be snapped to a value in a list of steps to map interpolated values to an asymmetric pattern of values. All this can be done using the mapin, mapout, curve, steps and convert attributes similar to the example below. Please read more about the different attributes for the <var>-element: var

<!-- The variable "f", stores a transformed value from variable "slider_val". 
The slider is supposed to vary between 0 and 1 which is transformed to a 
frequency value matching a key in C major by first snapping the float value 
to a . -->
<var name="f" default="60" value="$slider_val" mapin="0,1" mapout="60,62,64,65,67,69,71,72" curve="step" convert="MIDI->frequency" />
<OscillatorNode frequency="$f" />