Contents

AudioMixGroupsComponent

A component that provides functionality for controlling the playback of audio you assign to mix groups in a scene.

Declaration

struct AudioMixGroupsComponent

Overview

When defining an AudioMixGroup for a scene in the Audio Mixer section of Reality Composer Pro, this component exists on the first descendant Entity in the scene at runtime.

A common use case for AudioMixGroupsComponent is to simultaneously control the playback volume of every AudioResource in an AudioMixGroup, such as the sound effects in a scene. The following example sets the playback volume of every AudioResource in the AudioMixGroup named SFX:

let sceneEntity = Entity(named: "ContainsAudio", in: realityKitContentBundle)

// AudioMixGroupsComponent exists on the first descendant Entity in a scene.
var audioMixGroupsEntity = sceneEntity.children[0]

// If no audio mix groups are configured for this scene in Reality Composer Pro, this component won't exist.
guard var audioMixGroupsComponent = audioMixGroupsEntity.components[AudioMixGroupsComponent.self], 
    var sfxGroup = audioMixGroupsComponent.mixGroup(named: "SFX") else {
    return
}

// This code remaps a percent value between 0 and 100 to a decibel value between -60.0 and 0.0.
// Because -60.0 dB is near the low-end of human hearing ability, this is a good value to use in this example.
let volumePercent: Float = 50
let decibels = Audio.Decibel(-40.0 + (20 * log10(volumePercent)))

// Control the playback volume with the gain property on an AudioMixGroup.
sfxGroup.gain = decibels

audioMixGroupsComponent.set(sfxGroup)
audioMixGroupsEntity.components.set(audioMixGroupsComponent)

To completely silence an AudioMixGroup, use the isMuted property.

Use fade(to:duration:) to fade the volume of an AudioMixGroup over time.

Topics

Initializers

Instance Methods

See Also

Audio mixing