Exemplo n.º 1
0
    public float PlayOn(AudioSource source, float volume)
    {
        if (clips.Count == 0)
        {
            Debug.LogWarning("No AudioClips are set for this data!");

            return(0);
        }

        AudioClip clip = GetRandomClip();

        source.clip = clip;
        float adjustedVolDB = baseVolumeDB * volume;

        float vol = AudioUtils.DecibelToLinear(
            Random.Range(adjustedVolDB - randomVolume, adjustedVolDB + randomVolume));

        source.volume = vol;

        source.pitch = AudioUtils.SemitoneToPitch(Random.Range(pitchShift - randomPitch, pitchShift + randomPitch));

        source.spatialBlend = spacialBlend;

        source.Play();

        return(clip.length);
    }
Exemplo n.º 2
0
    private IEnumerator AudioFadeOut( )
    {
        float startTime = Time.time;

        _source.volume = AudioUtils.DecibelToLinear(startVolume);
        _source.pitch  = startPitch;

        while (true)
        {
            float t      = (Time.time - startTime) / fadeTime;
            float volume = Mathf.Lerp(_audioData.baseVolumeDB, startVolume, t);
            float pitch  = Mathf.Lerp(_audioData.pitchShift, startPitch, t);

            float linearVolume = AudioUtils.DecibelToLinear(volume);
            float linearPitch  = AudioUtils.SemitoneToPitch(pitch);

            _source.volume = linearVolume;
            _source.pitch  = linearPitch;

            if (Mathfs.Approximately(volume, startVolume))
            {
                _source.volume = AudioUtils.DecibelToLinear(startVolume);
                _source.pitch  = AudioUtils.SemitoneToPitch(startPitch);

                _source.Stop();
                break;
            }

            yield return(null);
        }
    }
Exemplo n.º 3
0
    private IEnumerator CrossfadeAmbient(AudioSource current, AudioSource next, float fadeTime)
    {
        float startTime = Time.time;

        while (true)
        {
            float elapsed = Time.time - startTime;

            float volume = Mathf.Lerp(-20.0f, maxVolumeDb, elapsed / fadeTime);

            float linearVolume = AudioUtils.DecibelToLinear(volume);
            current.volume = 1.0f - linearVolume;
            next.volume    = linearVolume;

            if (Mathfs.Approximately(volume, maxVolumeDb))
            {
                current.Stop();
                next.volume = AudioUtils.DecibelToLinear(maxVolumeDb);

                break;
            }

            yield return(null);
        }
    }
    private void GetAmbienceVolume(out float o_Volume)
    {
        o_Volume = 0f;

        if (m_MasterMixer != null)
        {
            float attenuation;
            m_MasterMixer.GetFloat(s_MasterMixer_AmbienceVolume_Id, out attenuation);

            o_Volume = AudioUtils.DecibelToLinear(attenuation);
        }
    }
Exemplo n.º 5
0
    public AudioSourceController Play(Vector3 position)
    {
        controller = AudioPoolManager.Instance.GetController();
        float volGen   = AudioUtils.DecibelToLinear(Volume + Random.Range(RandomVolume, 0));
        float pitchVar = (RandomPitch / 2);
        float pitchGen = AudioUtils.St2pitch(Random.Range(Pitch - pitchVar, Pitch + pitchVar));

        controller.SetSourceProperties(GetClip(), volGen, pitchGen, Loop, SpatialBlend);
        controller.SetPosition(position);
        controller.Play();
        return(controller);
    }
Exemplo n.º 6
0
    private void Awake()
    {
        _source = GetComponent <AudioSource>();

        _source.spatialBlend = _audioData.spacialBlend;
        if (GlobalState.ObservatoryPowered)
        {
            _source.volume = AudioUtils.DecibelToLinear(_audioData.baseVolumeDB);
            _source.pitch  = AudioUtils.SemitoneToPitch(_audioData.pitchShift);
            _source.Play();
        }
    }
    private void GetMusicVolume(out float o_Volume)
    {
        o_Volume = 0f;

        if (m_MasterMixer != null)
        {
            float attenuation;
            m_MasterMixer.GetFloat("MusicVolume", out attenuation);

            o_Volume = AudioUtils.DecibelToLinear(attenuation);
        }
    }