linearscale: Create a linear parameter scaling with given minimum and...

linear_scaleR Documentation

Create a linear parameter scaling with given minimum and maximum

Description

linear_scale() linearly transforms its input vector x so that its minimum value is min and its maximum value is max. This is for use as a scaling function in sonscaling. It is unlikely to be directly called by the user.

Usage

  linear_scale(x, limits = NULL, soundlimits, by = NULL)

Arguments

x

A numeric vector or matrix

limits

The limits of the data to train, a numeric vector of length 2. All data values outside these limits are returned as NA. If NULL, the default, the function takes the minimum and maximum of the data

soundlimits

The limits of the sound parameter.

by

The unit to round the sound parameter to. See examples.

Details

This simple function does the important work of actually rescaling the given data of a sonify object into the range of the given sonic parameter, which is why it's included in playitbyr. But it can be used on any vector or matrix.

Value

A numeric vector or matrix of the same type as x, linearly rescaled in the desired way. If x only has one value, linear_scale simply returns the midpoint between min and max.

Note

If by is specified, unexpected results may happen when soundlimits[2] != (soundlimits[1] + n * by) for some n; in these cases the data will be trained to the largest value of (soundlimits[1] + n * by) less than soundlimits[2].

See Also

sonscaling

Examples

x <- 1:10
linear_scale(x, soundlimits = c(-2, -1.5))

## If max<min, it's rescaled in reverse:
linear_scale(x, soundlimits = c(10, 1))

## If 'limits' is specified, these are taken as the maximum and
## minimum of the data to be rescaled to
linear_scale(x, limits = c(-10, 10), soundlimits = c(10, 0))

## any values outside of 'limits' are therefore NA in result
linear_scale(x, limits = c(1, 2), soundlimits = c(1, 10))

## 'by' rounds values appropriately
linear_scale(x, soundlimits = c(1, 2), by = .25)

statisfactions/playitbyr documentation built on Jan. 27, 2024, 1:33 p.m.