PHASEBlendNodeDefinition
A node that smoothly fades between the audio of its child nodes.
Declaration
class PHASEBlendNodeDefinitionOverview
This class defines a threshold and a numeric parameter the app increases and decreases to fade between child nodes. Each child node defines a range within the threshold in which the child node plays audio. As the app moves the blend parameter value between 0 and the threshold, the blend node plays the audio of its child nodes whose range and fade curve overlap at the current value.
[Image]
Play a Blend of Simultaneous Audio Data
To gradually change the audio that a sound event plays, define blend thresholds and a number metaparameter that incrementally increases or decreases between the thresholds. For example, the following code sets up a sound event hierarchy containing two sampler nodes that play audio, with each one modeling a different terrain. The app sets the metaparameter value based on the value of the terrain the player stands on. When the app starts a sound event from this hierarchy, PHASE plays:
A grass footstep for terrain values between
0and0.33A cobblestone footstep for terrain values between
0.67and1.0A blend of both footstep sounds for values between
0.33and0.67
// Create a meta parameter definition that chooses among different terrains.
let terrainBlendParameter = PHASENumberMetaParameterDefinition(
value: 0.5,
minimum: 0.0,
maximum: 1.0,
identifier: "terrain")
// Create a blend node and pass in the meta parameter.
let terrainBlendNode = PHASEBlendNodeDefinition(blendMetaParameterDefinition: terrainBlendParameter)
// Add two samples nodes to blend between.
terrainBlendNode.addRangeForInputValuesAbove(
value: 0.33,
fullGainAtValue: 1.0,
fadeCurveType: .linear,
subtree:cobblestoneSamplerNode)
terrainBlendNode.addRangeForInputValuesBelow(
value: 0.67,
fullGainAtValue: 0.0,
fadeCurveType: .linear,
subtree:grassSamplerNode)
// Create a sound event.
var footstepEvent: PHASESoundEvent?
do { footstepEvent = try PHASESoundEvent(engine: myEngine, assetIdentifier: "terrain") }
catch { fatalError("Failed to create the sound event due to: \(error)") }
// Set the "terrain" metaparameter value to a midpoint that
// plays audio from both subtrees at an equal volume.
guard let terrainParameter = footstepEvent?.metaParameters["terrain"] else { fatalError() }
terrainParameter.value = 0.5
// Play the sound and hear a mix of both terrains.
footstepEvent?.start() { reason in
/* Perform completion tasks. */ }Topics
Creating a Blend Node
init(blendMetaParameterDefinition:)init(blendMetaParameterDefinition:identifier:)init(spatialMixerDefinition:)init(spatialMixerDefinition:identifier:)
Accessing Blend Properties
Adding Child Nodes
addRange(envelope:subtree:)addRangeForInputValuesAbove(value:fullGainAtValue:fadeCurveType:subtree:)addRangeForInputValuesBelow(value:fullGainAtValue:fadeCurveType:subtree:)addRangeForInputValuesBetween(lowValue:highValue:fullGainAtLowValue:fullGainAtHighValue:lowFadeCurveType:highFadeCurveType:subtree:)