MD Package Technical & APi Documentation
MDM_SoundReact
Namespace: MDPackage.Modifiers
Simple sound reaction modifier - add another modifier to sync with the audio data.
Read more here (Online documentation slide)
Properties
// Output audio data of the currently running sound react modifier
public float OutputData { get; }
public bool IsProcessing { get; }

// Target audio source that will be used for sound reaction analysis
public AudioSource TargetAudioSrc { get; set; }
// Sample length of x128, x256, x512, x1024, x2048, x4096
public SampleDataLength CurrentSampleDataLength { get; set; }
public float TransitionSmoothness { get; set; }
public float Multiplication { get; set; }
public float MinimumOutputValue { get; set; }
public float MaximumOutputValue { get; set; }
public float UpdateInterval { get; set; }
Public Methods
// Start analysing audio - start receiving audio data from the target audio source
public void SoundReact_Start()
// Start analysing audio with a custom clip. The audio source must be assigned
public void SoundReact_StartWithClip(AudioClip newClip)
// Stop analysing audio - stop receiving audio data from the target audio source
public void SoundReact_Stop()
Examples
The following paragraphs contain Sound React modifier used in a practical example - make the target gameObject's scale change according to the output audio data.
using UnityEngine;
using MDPackage.Modifiers;

public class SampleScript : MonoBehaviour
{
// Assign an audio clip that will push its audio data to the Sound react modifier
 [SerializeField] private AudioClip clip;
// Assign a target gameObject that will change according to the Audio output
 [SerializeField] private GameObject targetObject;

private MDM_SoundReact sound;

// Create a Sound React modifier, apply audio clip, start and subscribe to an event
private void Start()
 {
  sound = gameObject.AddComponent<MDM_SoundReact>();
  sound.TargetAudioSrc = gameObject.AddComponent<AudioSource>();
  sound.OnAudioOutputListener += RefreshData;
  sound.SoundReact_StartWithClip(clip);
  // Or you can just use OutputData in your custom Update method...
  // targetObject.transform.localScale = Vector3.one * sound.OutputData;
 }

// Unsubscribe from event
private void OnDestroy()
 {
  sound.OnAudioOutputListener -= RefreshData;
 }

// Refresh the current audio data event
private void RefreshData(float outputData)
 {
  targetObject.transform.localScale = Vector3.one * outputData;
 }
}