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)
Public Methods
// Start sound reaction - start receiving audio data from the target audio source
public void SoundReact_Start()
// Stop sound reaction - stop receiving audio data from the target audio source
public void SoundReact_Stop()
// Returns a processed audio OutputData property
public float SoundReact_GetAudioOutpudData()
Public Fields and Properties
public AudioSource targetAudioSrc;
public SampleDataLength sampleDataLength = SampleDataLength.x1024;

public float transitionSmoothness = 128.0f;
public float multiplication = 2.0f;
public float minimumOutputValue = 0.0f;
public float maximumOutputValue = 10.0f;

public float updateInterval = 0.01f;

// Main output data
public float OutputData { get; }
public UnityEvent outputEvent;
// Subscribe to this event to receive a current audio output data
public event Action<float> outputActionEvent;
Examples
The following paragraphs contain Sound React modifier used in a practical example - make the target gameObject's scale change according to the sound react output 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
public AudioClip clip;
// Assign a target gameObject that will change according to the Audio output
public 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.targetAudioSrc.clip = clip;
  sound.targetAudioSrc.Play();
  sound.outputActionEvent += RefreshData;
  sound.SoundReact_Start();
  // Or you can just use OutputData in your custom Update method...
  // targetObject.transform.localScale = Vector3.one * sound.SoundReact_GetAudioOutpudData();
 }

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

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