Use SoundParameters to control sounds through code
SoundParameters are used to control how SoundEvents are played (e.g. volume, polyphony, fade in length etc).
They can be passed when playing a SoundEvent and set to update either once or continuously.
They have similar functionality as the modifiers, but with scripting capabilities.
Example code:
usingUnityEngine;usingSonity;publicclassExampleSoundParameter:MonoBehaviour{publicSoundEventsoundEvent;SoundParameterVolumeDecibelvolumeParameter=newSoundParameterVolumeDecibel(0f,UpdateMode.Once);voidStart(){ // Sets the volume parameter to a random value between -12 dB and 0 dBvolumeParameter.VolumeDecibel=Random.Range(-12f,0f); // Plays the SoundEvent with the sound parametersoundEvent.Play(transform,volumeParameter);}}
Update Modes
The UpdateMode enum determines if the SoundEvent will take the parameter into consideration only once at start or if it will be updated continuously.
// The SoundParameter will update only onceUpdateMode.Once// The SoundParameter will update continuouslyUpdateMode.Continuous
Parameter Types
The parameter type determines which parameter of the SoundEvent will be controlled.
See modifiers for more detailed info on the individual parameters.
// Volume offset in decibel. Range -Infinity to 0
public class SoundParameterVolumeDecibel(float volumeDecibel = 0f, UpdateMode updateMode = UpdateMode.Once);
// Volume ratio multiplier. Range 0f to 1f
public class SoundParameterVolumeRatio(float volumeRatio = 1f, UpdateMode updateMode = UpdateMode.Once);
// Pitch offset in semitones
public class SoundParameterPitchSemitone(float pitchSemitone = 0f, UpdateMode updateMode = UpdateMode.Once);
// Pitch offset ratio multiplier. Range 0 to Infinity
public class SoundParameterPitchRatio(float pitchRatio = 1f, UpdateMode updateMode = UpdateMode.Once);
// Delay increase. Range 0 to Infinity
public class SoundParameterDelay(float delay = 0f);
// Makes the sound more 2D (less spatialized). Range 0 to 1
public class SoundParameterIncrease2D(float increase2D = 0f, UpdateMode updateMode = UpdateMode.Once);
// Controls the intensity of the SoundContainer
// Go to the SoundContainer to change how intensity will affect the sound
public class SoundParameterIntensity(float intensity = 1f, UpdateMode updateMode = UpdateMode.Once);
// Reverb zone mix offset in decibel. Range -Infinity to 0
public class SoundParameterReverbZoneMixDecibel(float reverbZoneMixDecibel = 0f, UpdateMode updateMode = UpdateMode.Once);
// Reverb zone mix ratio multiplier. Range 0 to 1
public class SoundParameterReverbZoneMixRatio(float reverbZoneMixRatio = 1f, UpdateMode updateMode = UpdateMode.Once);
// Reverb zone mix ratio multiplier. Range 0 to 1
public class SoundParameterReverbZoneMixRatio(float reverbZoneMixRatio = 1f, UpdateMode updateMode = UpdateMode.Once);
// Start position. Range 0 to 1
public class SoundParameterStartPosition(float startPosition = 0f);
// If the sound should be played backwards. If enabled, set the start position to the end.
// Reverse is only supported for AudioClips which are stored in an uncompressed format or will be decompressed at load time.
public class SoundParameterReverse(bool reverse = false);
// The polyphony of the SoundEvent. Range 1 to int.MaxValue
public class SoundParameterPolyphony(int polyphony = 1);
// Distance scale multiplier. Range 0 to Infinity
public class SoundParameterDistanceScale(float distanceScale = 1f);
// Distortion increase. Range 0 to 1
public class SoundParameterDistortionIncrease(float distortionIncrease = 1f, UpdateMode updateMode = UpdateMode.Once);
// Fade in length. Range 0 to Infinity
public class SoundParameterFadeInLength(float fadeInLength = 0f, UpdateMode updateMode = UpdateMode.Once);
// Fade in shape. Range -16 to 16 (negative is exponential, 0 is linear, positive is logarithmic);
public class SoundParameterFadeInShape(float fadeInShape = 2f, UpdateMode updateMode = UpdateMode.Once);
// Fade out length. Range 0 to Infinity
public class SoundParameterFadeOutLength(float fadeOutLength = 0f, UpdateMode updateMode = UpdateMode.Once);
// Fade out shape. Range -16 to 16 (negative is exponential, 0 is linear, positive is logarithmic);
public class SoundParameterFadeOutShape(float fadeOutShape = -2f, UpdateMode updateMode = UpdateMode.Once);
// If the SoundEvent should follow the Transform position
public class SoundParameterFollowPosition(bool followPosition = true, UpdateMode updateMode = UpdateMode.Once);
// If reverb zones should be bypassed
public class SoundParameterBypassReverbZones(bool bypassReverbZones = false, UpdateMode updateMode = UpdateMode.Once);
// If voice effects (distortion/lowpass/highpass) should be bypassed
public class SoundParameterBypassVoiceEffects(bool bypassEffects = false, UpdateMode updateMode = UpdateMode.Once);
// If listener effects should be bypassed
public class SoundParameterBypassListenerEffects(bool bypassListenerEffects = false, UpdateMode updateMode = UpdateMode.Once);