protected override void ApplyValue(float value)
 {
     if (sound != null)
     {
         if (showDebug)
         {
             Debug.Log(base.name + " Sound Lerp ");
         }
         float num = Mathf.Lerp(AudioUtils.DBToValue(from), AudioUtils.DBToValue(to), value);
         sound.SetVolume(num);
         if (showDebug)
         {
             Debug.Log(base.name + " Current Volume = " + num);
         }
     }
     else if (unitySound != null)
     {
         if (showDebug)
         {
             Debug.Log(base.name + " Audio Source Lerp ");
         }
         float num2 = Mathf.Lerp(AudioUtils.DBToValue(from), AudioUtils.DBToValue(to), value);
         unitySound.volume = num2;
         if (showDebug)
         {
             Debug.Log(base.name + " Current Volume = " + num2);
         }
     }
 }
Beispiel #2
0
        private void OnImpact(NetStream stream)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Impact ");
            }
            float impact = AudioUtils.DBToValue(NetFloat.Dequantize(stream.ReadInt32(6), 64f, 6) - 32f);

            PlayImpact(impact);
        }
Beispiel #3
0
 private void OnEnable()
 {
     if (clipsRms.Length == 0)
     {
         volumeAdjust = 0f;
     }
     else
     {
         volumeAdjust = AudioUtils.DBToValue(levelDB) / clipsRms[0];
     }
     compressorTreshold = AudioUtils.DBToValue(compressorTresholdDB);
 }
Beispiel #4
0
    public IEnumerator Play(string resource, bool duckDrones)
    {
        currentSong = resource;
        float vol = 1f;

        for (int i = 0; i < songList.Length; i++)
        {
            if (songList[i].Equals(resource))
            {
                vol = levels[i];
            }
        }
        SoundLibrary.SerializedSample soundSample = new SoundLibrary.SerializedSample
        {
            builtIn  = true,
            category = "Music",
            name     = resource,
            loaded   = true,
            vB       = AudioUtils.DBToValue(vol)
        };
        AudioClip audioClip = HFFResources.instance.GetMusicTrack(resource);

        yield return(null);

        SoundLibrary.SerializedClip clip = soundSample.AddClip(resource, resource, null, audioClip);
        lastSample       = soundSample;
        base.soundSample = soundSample;
        if (base.isPlaying)
        {
            CrossfadeSound(clip, loop: false, 0f, crossfadeDuration, fadeoutDuration, fadeinDuration);
        }
        else
        {
            PlaySound(clip, loop: false);
        }
        if (duckDrones)
        {
            menuDrones.Duck(this);
        }
        loadCoroutine = null;
    }
        public void OnReceiveCollisionAudio(NetStream stream)
        {
            if (showDebug)
            {
                Debug.Log(base.name + " Recieve Collision Audio ");
            }
            ushort                  libId   = (ushort)stream.ReadUInt32(8);
            AudioChannel            channel = (!stream.ReadBool()) ? (stream.ReadBool() ? AudioChannel.Body : AudioChannel.Physics) : AudioChannel.Footsteps;
            Vector3                 b       = NetVector3.Read(stream, 3, 10).Dequantize(100f);
            Vector3                 pos     = base.transform.position + b;
            float                   emit    = AudioUtils.DBToValue(NetFloat.Dequantize(stream.ReadInt32(6), 64f, 6) - 32f);
            float                   num     = AudioUtils.CentsToRatio(NetFloat.Dequantize(stream.ReadInt32(3, 8), 4800f, 8));
            CollisionAudioHitConfig config  = CollisionAudioEngine.instance.GetConfig(libId);

            if (config != null)
            {
                if (showDebug)
                {
                    Debug.Log(base.name + " There is no audio engine ");
                }
                config.PlayWithKnownEmit(channel, null, pos, emit, num);
            }
        }
    public bool PlayWithKnownEmit(AudioChannel channel, CollisionAudioHitMonitor monitor, Vector3 pos, float emit, float pitch)
    {
        if (Listener.instance == null)
        {
            return(false);
        }
        float magnitude = (pos - Listener.instance.transform.position).magnitude;
        float num       = (!(magnitude < 2f)) ? (2f / magnitude) : 1f;
        float num2      = AudioUtils.DBToValue(compTresholdDB) / num;
        float num3      = 1f;

        if (emit > num2)
        {
            float num4    = AudioUtils.ValueToDB(emit);
            float num5    = AudioUtils.ValueToDB(num2);
            float decibel = (num5 - num4) * (1f - 1f / compRatio);
            num3 = AudioUtils.DBToValue(decibel);
        }
        float num6 = emit * num3;
        float rms  = num6 * AudioUtils.DBToValue(levelDB);

        return(sampleLib.PlayRMS(channel, pos, rms, pitch));
    }
Beispiel #7
0
    public static float DrawHorizontalSlider(Rect rect, float from, float to, float def, float value, AudioSliderType type)
    {
        EnsureStyle();
        GUI.color = new Color(0f, 0f, 0f, 0f);
        bool flag = Event.current.button == 1 && rect.Contains(Event.current.mousePosition);

        if (flag)
        {
            value = def;
        }
        float num;

        switch (type)
        {
        case AudioSliderType.Level:
            num = value;
            break;

        case AudioSliderType.Volume:
            num = DBtoFader(AudioUtils.ValueToDB(value));
            break;

        case AudioSliderType.Pitch:
            num = AudioUtils.RatioToCents(value);
            break;

        case AudioSliderType.Linear:
            num = value;
            break;

        case AudioSliderType.Log2:
            num  = Mathf.Log(value, 2f);
            from = Mathf.Log(from, 2f);
            to   = Mathf.Log(to, 2f);
            break;

        case AudioSliderType.Log10:
            num  = Mathf.Log(value, 10f);
            from = Mathf.Log(from, 10f);
            to   = Mathf.Log(to, 10f);
            break;

        default:
            throw new InvalidOperationException();
        }
        float num2 = (!flag) ? GUI.HorizontalSlider(rect, num, from, to) : num;

        GUI.color = Color.white;
        DrawRect(new Rect(rect.x + 4f, rect.y + 4f, rect.width - 6f, rect.height - 8f), new Color(0.1f, 0.1f, 0.1f, 1f));
        DrawRect(new Rect(rect.x + 5f, rect.y + 5f, (rect.width - 8f) * Mathf.InverseLerp(from, to, num2), rect.height - 10f), new Color(0.25f, 0.5f, 0.25f, 1f));
        float num3;

        switch (type)
        {
        case AudioSliderType.Level:
            num3 = num2;
            break;

        case AudioSliderType.Volume:
            num3 = FaderToDB(num2);
            num2 = ((num2 != num) ? AudioUtils.DBToValue(FaderToDB(num2)) : value);
            break;

        case AudioSliderType.Pitch:
            num3 = num2;
            num2 = ((num2 != num) ? AudioUtils.CentsToRatio(num2) : value);
            break;

        case AudioSliderType.Linear:
            num3 = num2;
            break;

        case AudioSliderType.Log2:
            num2 = ((num2 != num) ? Mathf.Pow(2f, num2) : value);
            num3 = num2;
            break;

        case AudioSliderType.Log10:
            num2 = ((num2 != num) ? Mathf.Pow(10f, num2) : value);
            num3 = num2;
            break;

        default:
            throw new InvalidOperationException();
        }
        GUI.Label(new Rect(rect.x, rect.y, rect.width, rect.height), FormatNumber(num3), style);
        return(num2);
    }