示例#1
0
    void Awake()
    {
        sal = Listener.GetComponent <SpatialAudioListener> ();

        phaseLeftAngle  = 90 + (sal.phaseWidth / 2);
        phaseRightAngle = 90 - (sal.phaseWidth / 2);
        listener        = GameObject.FindObjectOfType <AudioListener> ().transform;
        sampleRate      = AudioSettings.outputSampleRate;
        var samplesPerMillisecond = 88;

        if (sampleRate != 44100)
        {
            var scaler = sampleRate / 44100.0f;
            samplesPerMillisecond = Mathf.FloorToInt(scaler * samplesPerMillisecond);
            for (var i = 0; i < reverbDelay.Length; i++)
            {
                var delay = Mathf.FloorToInt(scaler * reverbDelay [i]);
                if ((delay & 1) == 0)
                {
                    delay++;
                }
                while (!IsPrime(delay))
                {
                    delay += 2;
                }
                reverbDelay [i] = delay;
            }
        }
        allpass1 = new DelayLine(reverbDelay [0]);
        allpass2 = new DelayLine(reverbDelay [1]);
        comb1    = new DelayLine(reverbDelay [2]);
        comb2    = new DelayLine(reverbDelay [3]);
        var combScale = -3.0f / (sal.decayTime * sampleRate);

        comb1Coeff = Mathf.Pow(10.0f, combScale * comb1.Length);
        comb2Coeff = Mathf.Pow(10.0f, combScale * comb2.Length);
        left       = new VariableDelayLine(samplesPerMillisecond * sal.interauralDelay);
        right      = new VariableDelayLine(samplesPerMillisecond * sal.interauralDelay);
        eL         = Equalizer.Default();
        eR         = Equalizer.Default();
    }