示例#1
0
    private float PlayScheduled(InAudioNode startNode, InAudioNode currentNode, InAudioData audioData,
        double playAtDSPTime, float offset, out float nodeVolume)
    {
        float length = 0;
        nodeVolume = 1;
        if (audioData._clip != null)
        {
            var clip = audioData._clip;
            length = clip.ExactLength();

            length -= offset;
            float lengthOffset = offset*clip.frequency;
            var source = Current.AudioSource;


            source.clip = clip;
            nodeVolume = RuntimeHelper.CalcVolume(startNode, currentNode);
            Current.OriginalVolume = nodeVolume;

            SetVolume(Current, audioParameters.Volume);

            source.spatialBlend = RuntimeHelper.CalcBlend(startNode, currentNode);
            source.pitch = RuntimeHelper.CalcPitch(startNode, currentNode) * audioParameters.Pitch;
            source.rolloffMode = RuntimeHelper.CalcAttentutation(startNode, currentNode, source);
            if (audioParameters.SetMixer)
            {
                source.outputAudioMixerGroup = audioParameters.AudioMixer;
            }
            else
            {
                source.outputAudioMixerGroup = currentNode.GetMixerGroup();
            }
            length = RuntimeHelper.LengthFromPitch(length, source.pitch);
            Current.EndTime = playAtDSPTime + length;
            Current.StartTime = playAtDSPTime;
            Current.UsedNode = currentNode;

            source.panStereo += audioParameters.StereoPan;
            source.spread = _spread;
            source.spatialBlend *= audioParameters.SpatialBlend;
            source.timeSamples = (int) (lengthOffset);
            source.PlayScheduled(playAtDSPTime);
        }
        else
        {
            Debug.LogWarning("InAudio: Audio clip missing on audio node \"" + currentNode.Name + "\", id=" + currentNode._ID);
        }
        return length;
    }
示例#2
0
    private void PlayNode(InAudioNode current, DSPTime endTime, float offset, InAudioData audioData)
    {
        float nodeVolume;

        double playTime = endTime.CurrentEndTime;
        double timeLeft = 0;
        if (endTime.Player != null && endTime.Player.clip != null)
        {
            int samples = endTime.Player.timeSamples;
            if (samples > 0 && samples < endTime.Player.clip.samples)
            {
                timeLeft = TimeLeftOfClip(endTime, samples)/endTime.Player.pitch;
                double dspTime = AudioSettings.dspTime;
                playTime = dspTime + timeLeft;
            }
        }

        float length = PlayScheduled(ParentBeforeFolder, current, audioData, playTime,
            offset, out nodeVolume);

        endTime.CurrentEndTime += length;
        endTime.Player = Current.AudioSource;
    }