CPBeatShader

org.cosplay.prefabs.shaders.CPBeatShader
class CPBeatShader(snd: Option[CPSound], smoothing: CPBeatShaderSmoothing, thresholdGain: Float, thresholdTailMs: Int) extends CPShader

A shader that changes brightness of its object based on the perceived beat of the given sound. This shader uses a simple beat-detection algorithm based on calculating root mean square (RMS) of amplitudes across all channels. RMS is constantly recalculated over a sliding window of the past few seconds. If the current amplitude value is above the RMS the beat is detected.

It is important to note that this shader does not work by default for all types of sounds. For each particular sound profile you may need to "play" with smoothing and threshold gain to achieve the best visual effect.

Note that by default this shader is inactive and user must call start method to start this shader.

Value parameters

smoothing

Smoothing mode. Default value is SMOOTH_UP.

snd

Sound asset to analyze for the beat detection. Note that the start of playing this sound should generally be synchronized in time with calling start method on this shader. If not provided - ensure that method setSound is called before this shader is started.

thresholdGain

A constant that can be used to fine tune the calculated RMS-based threshold. Once threshold is calculated it will be multiplied by this constant. Default value is 1.0f. Typical fine tuning values are between 0.5f and 0.9f.

thresholdTailMs

Duration of the sliding window in milliseconds that is used for calculating RMS-based threshold.

Attributes

Source
CPBeatShader.scala
Graph
Supertypes
trait CPShader
trait CPAsset
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def isActive: Boolean

Tests whether this shader is in progress or not.

Tests whether this shader is in progress or not.

Attributes

Source
CPBeatShader.scala
override def render(ctx: CPSceneObjectContext, objRect: CPRect, inCamera: Boolean): Unit

Called on each frame pass on scene object that has this shaders attached to it. This callback is called regardless of whether or not the scene object is visible or in camera frame.

Called on each frame pass on scene object that has this shaders attached to it. This callback is called regardless of whether or not the scene object is visible or in camera frame.

Attributes

Definition Classes
Source
CPBeatShader.scala
def setSound(snd: CPSound): Unit

Sets given sound asset for this shader. Note that if this shader is currently active it will be stopped by calling method stop first. After the sound is set you need to call method start to active this shader. Note that the start of playing this sound should generally be synchronized in time with calling start method on this shader.

Sets given sound asset for this shader. Note that if this shader is currently active it will be stopped by calling method stop first. After the sound is set you need to call method start to active this shader. Note that the start of playing this sound should generally be synchronized in time with calling start method on this shader.

Attributes

Source
CPBeatShader.scala
def start(): Unit

Starts the shader effect. Note that the start of playing the sound this shader is configured with must be generally synchronized in time with calling this method.

Starts the shader effect. Note that the start of playing the sound this shader is configured with must be generally synchronized in time with calling this method.

Attributes

See also
Source
CPBeatShader.scala
def stop(): Unit

Stops the shader effect.

Stops the shader effect.

Attributes

See also
Source
CPBeatShader.scala
def toggle(): Unit

Toggles this shader effect on and off by calling either start or stop methods.

Toggles this shader effect on and off by calling either start or stop methods.

Attributes

See also
Source
CPBeatShader.scala

Inherited fields

override val getOrigin: String

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Attributes

Inherited from:
CPShader
Source
CPShader.scala