/// <inheritdoc />
        protected override void DoCancel()
        {
            if (hapticRoutine == null)
            {
                return;
            }

            StopCoroutine(hapticRoutine);
            hapticRoutine = null;
            HapticPulser.Cancel();
            ResetIntensity();
        }
        /// <summary>
        /// Enumerates through <see cref="AudioSource"/> and pulses for each amplitude of the wave.
        /// </summary>
        /// <returns>An Enumerator to manage the running of the Coroutine.</returns>
        protected override IEnumerator HapticProcessRoutine()
        {
            int outputSampleRate = AudioSettings.outputSampleRate;

            while (AudioSource.isPlaying)
            {
                int   sampleIndex   = (int)((AudioSettings.dspTime - filterReadDspTime) * outputSampleRate);
                float currentSample = 0;
                if (filterReadData != null && sampleIndex * filterReadChannels < filterReadData.Length)
                {
                    for (int i = 0; i < filterReadChannels; ++i)
                    {
                        currentSample += filterReadData[sampleIndex + i];
                    }
                    currentSample /= filterReadChannels;
                }
                HapticPulser.Intensity = currentSample * IntensityMultiplier;
                HapticPulser.Begin();
                yield return(null);
            }
            ResetIntensity();
        }
        /// <summary>
        /// Enumerates through <see cref="AudioClip"/> and pulses for each amplitude of the wave.
        /// </summary>
        /// <returns>An Enumerator to manage the running of the Coroutine.</returns>
        protected override IEnumerator HapticProcessRoutine()
        {
            int   sampleOffset = -BufferSize;
            float startTime    = Time.time;
            float length       = AudioClip.length;
            float endTime      = startTime + length;
            float sampleRate   = AudioClip.samples;

            while (Time.time <= endTime)
            {
                float lerpVal     = (Time.time - startTime) / length;
                int   sampleIndex = (int)(sampleRate * lerpVal);
                if (sampleIndex >= sampleOffset + BufferSize)
                {
                    AudioClip.GetData(audioData, sampleIndex);
                    sampleOffset = sampleIndex;
                }
                float currentSample = Mathf.Abs(audioData[sampleIndex - sampleOffset]);
                HapticPulser.Intensity = currentSample * IntensityMultiplier;
                HapticPulser.Begin();
                yield return(null);
            }
            ResetIntensity();
        }
 /// <inheritdoc />
 public override bool IsActive()
 {
     return(base.IsActive() && HapticPulser != null && AudioClip != null && HapticPulser.IsActive());
 }