Skip to content

Channel

Tempestissiman edited this page Jul 26, 2022 · 3 revisions

Descriptions

Allow for creation of value channels

Remarks

This class is only for channel and creation, and is NOT actually a channel.

Methods


named(name)

Descriptions

Change the name of channels created with this object.

Parameters

Name Type Description
name string The name of the channel(s)

Return types

Channel

Remarks

This is almost always used in a chain to create named channel.

Example

local channel = Channel.named("something").keyframe()

keyframe()

Descriptions

Create a key channel.

Return types

KeyChannel

Remarks

This is almost always used in a chain to create named channel.

Example

local channel = Channel.keyframe()
local namedChannel = Channel.named("keyframeChannel").keyframe()

fft(freqBandMin, freqBandMax, min, max, smoothness = 0.1, scalar = 1)

Descriptions

Create a FFT (Fast Fourier Transform) channel, that calculates the loudness of currently playing audio within the frequency band.

Parameters

Name Type Description
freqBandMin number The mininum frequency band to sample
freqBandMax number The maxinum frequency band to sample
min number Minimum value output
max number Maxinum value output
smoothness number Smoothness of return value over time (0-1)
scalar number Value output multiplier

Return types

ValueChannel

Remarks

freqBandMin and freqBandMax are in the unit of frequency bands, not hertz. By default the audio is sampled in 256 frequency bands. You can change this number with Channel.setGlobalFFTResolution()

Internally the channel tries it best to make sure output stays consistent with different FFT resolution. However the output value range can still be quite unpredictable, therefore the min and max parameters are not guaranteed to be accurate. Please use scalar to manually tune the channel if you run into trouble with this.

Example

local channel = Channel.fft(0, 30, 0, 1, 0.5)

setGlobalFFTResolution(resolution, windowDetail = 1)

Descriptions

Configures all subsequently created fft channels' frequency resolution.

Parameters

Name Type Description
resolution number The number of frequency bands to sample in
windowDetail number The window detail. Higher is more accurate but more expensive to calculate

Return types

nil

Remarks

resolution must be a square integer that's no smaller than 64 and no larger than 8192. E.g: 64, 128, 256, 512,...

windowDetail should be an integer number from 0 to 5.

Example

Channel.setGlobalFFTResolution(512)
local channel = Channel.fft(300, 512, 0, 1, 0.5)

constant(value)

Descriptions

Creates a constant value channel.

Parameters

Name Type Description
value number The constant value

Return types

ValueChannel

Remarks

_

Example

Scene.track.colorA = Channel.constant(127)

random(min, max, seed = 0)

Descriptions

Creates a channel that returns random value everytime.

Parameters

Name Type Description
min number Minimum value output
max number Maximum value output
seed number The randomizer's seed

Return types

ValueChannel

Remarks

Although you can set the randomizer's seed, the behaviour is still unpredictable because it's unclear how much time the randomizer has generated values at any point in time.

This channel also returns different values at the same timing point.

Example

sprite.colorR = Channel.random(200, 255)

noise(frequency, min, max, offset = 0, octave = 1)

Descriptions

Creates a perlin noise channel.

Parameters

Name Type Description
frequency number The perlin noise's frequency
min number Mininum value output
max number Maximum value output
offset number How much to offset the noise by
octave number The perlin noise's octave value

Return types

ValueChannel

Remarks

This channel is not actually random, although it may appear so. Two different perlin noise channels will return the same value, which may not be what you're trying to do. Use the offset parameter to mitigate this.

Multiple octave perlin noise essentially behaves like multiple perlin noises added on top of each other. The output value range is not well defined in this case, so min and max may not be accurate for octaves higher than 1.

Example

track.translationX = Channel.noise(10, -1, 1)
track.translationY = Channel.noise(10, -1, 1, 30)

sine(period, min, max, offset)

Descriptions

Creates a sine wave channel.

Parameters

Name Type Description
period number Looping duration
min number Mininum value output
max number Maximum value output
offset number How much to offset the wave by

Return types

ValueChannel

Remarks

The formula used to calculate this is min + (max-min) * sin(2*pi*(timing+offset)/period)

Example

sprite.colorA = Channel.sine(2000, 180, 255)

saw(easing, period, min, max, offset)

Descriptions

Creates a saw wave channel with easing method used at each interval.

Parameters

Name Type Description
easing string The easing to use
period number Looping duration
min number Mininum value output
max number Maximum value output
offset number How much to offset the wave by

Return types

ValueChannel

Remarks

For each duration, the value starts at max, then transition to min according to the provided easing.

Example

sprite.colorA = Channel.saw(2000, 255, 0)

min(channelA, channelB)

Descriptions

Creates a channel that take the minimum of two other channels.

Parameters

Name Type Description
channelA ValueChannel The first channel
channelB ValueChannel The second channel

Return types

ValueChannel

Remarks

_

Example

local keyChannel = Channel.keyframe()
sprite.colorA = Channel.minimum(Channel.constant(255), keyChannel)

max(channelA, channelB)

Descriptions

Creates a channel that take the maximum of two other channels.

Parameters

Name Type Description
channelA ValueChannel The first channel
channelB ValueChannel The second channel

Return types

ValueChannel

Remarks

_

Example

local keyChannel = Channel.keyframe()
sprite.translationZ = Channel.maximum(Channel.constant(0), keyChannel)

clamp(channelValue, channelMin, channelMax)

Descriptions

Creates a channel that limits the value of a channel between two other.

Parameters

Name Type Description
channelValue ValueChannel The lower bound channel
channelMin ValueChannel The lower bound channel
channelMax ValueChannel The upper bound channel

Return types

ValueChannel

Remarks

_

Example

local keyChannel = Channel.keyframe()
sprite.colorA = Channel.clamp(keyChannel, Channel.constant(50), Channel.constant(200))

Clone this wiki locally