// === METHODS === // Use this for initialization void Start() { renderSettings = FindObjectOfType <ISMRenderSettings>(); // Plug the associated audio source to the given mixer group source = GetComponent <AudioSource>(); AudioMixerGroup mixerGroup = renderSettings.mixer.FindMatchingGroups(mixerGroupName)[0]; source.outputAudioMixerGroup = mixerGroup; // initialize impulse responses var irNumSamples = Mathf.CeilToInt( renderSettings.IRLength * AudioSettings.outputSampleRate); ir = new float[irNumSamples]; ir[0] = 1.0f; // Set up Convolution Reverb float fParamIdx; renderSettings.mixer.GetFloat(mixerGroupName, out fParamIdx); paramIdx = (int)fParamIdx; ConvolutionReverbInput.UploadSample(ir, paramIdx, name); nextSync = AudioSettings.dspTime; // Select random vectors as placeholders for the old positions oldSourcePosition = Random.insideUnitSphere * 1e3f; }
// Update is called once per frame void Update() { // Check if either the source or the listener has moved or the // simulation parameters have changed if (LocationsHaveChanged() || renderSettings.IRUpdateRequested) { // Calculate ISM impulse response ISMUpdate(); } // Check if it is time to update the impulse response if (AudioSettings.dspTime > nextSync) { // Upload the final impulse response ConvolutionReverbInput.UploadSample(ir, paramIdx, name); nextSync = nextSync + updateInterval; } // Update old source position oldSourcePosition = SourcePosition; }