void Update()
    {
        float LPFA = speed * 1.5f;

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Lowpassfreq, LPFA);

        //Array Sum

        //foreach(float item in freqscale){
        //	ampsum += item;

        //	}



        //transform.localScale = new Vector3 (CoreScaleA * (1+CoreScaleB), CoreScaleA * (1 + CoreScaleB), CoreScaleA * (1 + CoreScaleB));

        speed = PlayerFlight.extspeed;
    }
    // Use this for initialization
    void Start()
    {
        //AudioSource functions

        Core1 = GetComponent(typeof(AudioSource)) as AudioSource;

        Core1.spatialBlend = 1;

        //	freqscale = new float[128];
        //	InvokeRepeating ("getAudio", 0f, audioGetRepeatRate);



        // Heavy Param Control

        Hv_coreofinal_AudioLib CoreA = GetComponent <Hv_coreofinal_AudioLib> ();

        MastVoiceVolA = 0.8f;         //Voice Volume or Amplitude: Controls Amp at the End of the Chain
        OscMidiFreqA  = 1 + Mathf.Round(Random.value * 120f);

        //Clock Loop Length. For a static, all-encompassing loop, remove Random.value * 12000f
        //With this in place, all cores will operate on an independent loop-length, making the piece hardly repetitive.
        MetroA = 4000f + Random.value * 12000f;

        //Attack and Decay Times: If Attack Time is less-than or equal to 150ms, set it to a random value between 1ms and 10ms. etc
        AtktA = Random.Range(1f, 400f);
        if (AtktA <= 150f)
        {
            AtktA = Random.Range(5f, 15f);
        }
        DectA = Random.Range(50f, 2000f);
        if (DectA <= 900f)
        {
            DectA = Random.Range(40f, 100f);
        }

        //Place within loop time
        objVarA = Mathf.Round(Random.value * 16);

        //Upper partial amplitudes? Needs clarification
        HV1A = (Random.value * 10f);
        HV2A = (Random.value * 10f);
        HV3A = (Random.value * 10f);
        HV4A = (Random.value * 10f);
        //Upper partial spectral structure? Needs clarification
        HF1A = Mathf.Sin(Random.Range(10f, 20f) * 10);
        HF2A = Mathf.Sin(Random.Range(10f, 20f) * 10);
        HF3A = Mathf.Sin(Random.Range(10f, 20f) * 10);
        HF4A = Mathf.Sin(Random.Range(10f, 20f) * 10);
        //Distortion Level
        DistA = 0.01f + (Random.value * 2);

        //Delaytimes Left and Right
        delayTimeLeft  = (Random.value * 4000);
        delayTimeRight = (Random.value * 4000);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Masterclock, MetroA);
        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Objvar, objVarA);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Mastervoicevolume, MastVoiceVolA);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Oscfreq, OscMidiFreqA);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Atkt, AtktA);          //Attack Time

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Dect, DectA);          //Decay Time

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv1, HV1A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv2, HV2A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv3, HV3A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv4, HV4A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf1, HF1A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf2, HF2A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf3, HF3A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf4, HF4A);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Distortioncrush, DistA);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Lowpassfreq, LPFA);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeleft, delayTimeLeft);

        CoreA.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeright, delayTimeRight);



        //PD Send Receiver Callback

        CoreA.RegisterSendHook();

        CoreA.FloatReceivedCallback += OnFloatMessage;

        float CoreScaleB = 1f;
    }
    public override void OnInspectorGUI()
    {
        bool isEnabled = _dsp.IsInstantiated();

        if (!isEnabled)
        {
            EditorGUILayout.LabelField("Press Play!", EditorStyles.centeredGreyMiniLabel);
        }
        GUILayout.EndVertical();

        // parameters
        GUI.enabled = true;
        GUILayout.BeginVertical();
        EditorGUILayout.Space();
        EditorGUI.indentLevel++;

        // AtkVol
        GUILayout.BeginHorizontal();
        float AtkVol    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Atkvol);
        float newAtkvol = EditorGUILayout.Slider("AtkVol", AtkVol, 0.0f, 5.0f);

        if (AtkVol != newAtkvol)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Atkvol, newAtkvol);
        }
        GUILayout.EndHorizontal();

        // Atkt
        GUILayout.BeginHorizontal();
        float Atkt    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Atkt);
        float newAtkt = EditorGUILayout.Slider("Atkt", Atkt, 0.0f, 10000.0f);

        if (Atkt != newAtkt)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Atkt, newAtkt);
        }
        GUILayout.EndHorizontal();

        // DecVol
        GUILayout.BeginHorizontal();
        float DecVol    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Decvol);
        float newDecvol = EditorGUILayout.Slider("DecVol", DecVol, 0.0f, 5.0f);

        if (DecVol != newDecvol)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Decvol, newDecvol);
        }
        GUILayout.EndHorizontal();

        // Dect
        GUILayout.BeginHorizontal();
        float Dect    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Dect);
        float newDect = EditorGUILayout.Slider("Dect", Dect, 0.0f, 10000.0f);

        if (Dect != newDect)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Dect, newDect);
        }
        GUILayout.EndHorizontal();

        // HF1
        GUILayout.BeginHorizontal();
        float HF1    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf1);
        float newHf1 = EditorGUILayout.Slider("HF1", HF1, 0.0f, 25.0f);

        if (HF1 != newHf1)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf1, newHf1);
        }
        GUILayout.EndHorizontal();

        // HF2
        GUILayout.BeginHorizontal();
        float HF2    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf2);
        float newHf2 = EditorGUILayout.Slider("HF2", HF2, 0.0f, 25.0f);

        if (HF2 != newHf2)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf2, newHf2);
        }
        GUILayout.EndHorizontal();

        // HF3
        GUILayout.BeginHorizontal();
        float HF3    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf3);
        float newHf3 = EditorGUILayout.Slider("HF3", HF3, 0.0f, 25.0f);

        if (HF3 != newHf3)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf3, newHf3);
        }
        GUILayout.EndHorizontal();

        // HF4
        GUILayout.BeginHorizontal();
        float HF4    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf4);
        float newHf4 = EditorGUILayout.Slider("HF4", HF4, 0.0f, 25.0f);

        if (HF4 != newHf4)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hf4, newHf4);
        }
        GUILayout.EndHorizontal();

        // HV1
        GUILayout.BeginHorizontal();
        float HV1    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv1);
        float newHv1 = EditorGUILayout.Slider("HV1", HV1, 0.0f, 1.0f);

        if (HV1 != newHv1)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv1, newHv1);
        }
        GUILayout.EndHorizontal();

        // HV2
        GUILayout.BeginHorizontal();
        float HV2    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv2);
        float newHv2 = EditorGUILayout.Slider("HV2", HV2, 0.0f, 1.0f);

        if (HV2 != newHv2)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv2, newHv2);
        }
        GUILayout.EndHorizontal();

        // HV3
        GUILayout.BeginHorizontal();
        float HV3    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv3);
        float newHv3 = EditorGUILayout.Slider("HV3", HV3, 0.0f, 1.0f);

        if (HV3 != newHv3)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv3, newHv3);
        }
        GUILayout.EndHorizontal();

        // HV4
        GUILayout.BeginHorizontal();
        float HV4    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv4);
        float newHv4 = EditorGUILayout.Slider("HV4", HV4, 0.0f, 1.0f);

        if (HV4 != newHv4)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Hv4, newHv4);
        }
        GUILayout.EndHorizontal();

        // MasterClock
        GUILayout.BeginHorizontal();
        float MasterClock    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Masterclock);
        float newMasterclock = EditorGUILayout.Slider("MasterClock", MasterClock, 1000.0f, 100000.0f);

        if (MasterClock != newMasterclock)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Masterclock, newMasterclock);
        }
        GUILayout.EndHorizontal();

        // OscFreq
        GUILayout.BeginHorizontal();
        float OscFreq    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Oscfreq);
        float newOscfreq = EditorGUILayout.Slider("OscFreq", OscFreq, 1.0f, 127.0f);

        if (OscFreq != newOscfreq)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Oscfreq, newOscfreq);
        }
        GUILayout.EndHorizontal();

        // delayLevel
        GUILayout.BeginHorizontal();
        float delayLevel    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaylevel);
        float newDelaylevel = EditorGUILayout.Slider("delayLevel", delayLevel, 0.0f, 1.0f);

        if (delayLevel != newDelaylevel)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaylevel, newDelaylevel);
        }
        GUILayout.EndHorizontal();

        // delayTimeLeft
        GUILayout.BeginHorizontal();
        float delayTimeLeft    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeleft);
        float newDelaytimeleft = EditorGUILayout.Slider("delayTimeLeft", delayTimeLeft, 1.0f, 4000.0f);

        if (delayTimeLeft != newDelaytimeleft)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeleft, newDelaytimeleft);
        }
        GUILayout.EndHorizontal();

        // delayTimeRight
        GUILayout.BeginHorizontal();
        float delayTimeRight    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeright);
        float newDelaytimeright = EditorGUILayout.Slider("delayTimeRight", delayTimeRight, 1.0f, 4000.0f);

        if (delayTimeRight != newDelaytimeright)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Delaytimeright, newDelaytimeright);
        }
        GUILayout.EndHorizontal();

        // distortionCrush
        GUILayout.BeginHorizontal();
        float distortionCrush    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Distortioncrush);
        float newDistortioncrush = EditorGUILayout.Slider("distortionCrush", distortionCrush, 0.0f, 1.0f);

        if (distortionCrush != newDistortioncrush)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Distortioncrush, newDistortioncrush);
        }
        GUILayout.EndHorizontal();

        // lowpassFreq
        GUILayout.BeginHorizontal();
        float lowpassFreq    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Lowpassfreq);
        float newLowpassfreq = EditorGUILayout.Slider("lowpassFreq", lowpassFreq, 30.0f, 18000.0f);

        if (lowpassFreq != newLowpassfreq)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Lowpassfreq, newLowpassfreq);
        }
        GUILayout.EndHorizontal();

        // masterVoiceOnOff
        GUILayout.BeginHorizontal();
        float masterVoiceOnOff    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Mastervoiceonoff);
        float newMastervoiceonoff = EditorGUILayout.Slider("masterVoiceOnOff", masterVoiceOnOff, 0.0f, 1.0f);

        if (masterVoiceOnOff != newMastervoiceonoff)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Mastervoiceonoff, newMastervoiceonoff);
        }
        GUILayout.EndHorizontal();

        // masterVoiceVolume
        GUILayout.BeginHorizontal();
        float masterVoiceVolume    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Mastervoicevolume);
        float newMastervoicevolume = EditorGUILayout.Slider("masterVoiceVolume", masterVoiceVolume, 0.0f, 1.0f);

        if (masterVoiceVolume != newMastervoicevolume)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Mastervoicevolume, newMastervoicevolume);
        }
        GUILayout.EndHorizontal();

        // objVar
        GUILayout.BeginHorizontal();
        float objVar    = _dsp.GetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Objvar);
        float newObjvar = EditorGUILayout.Slider("objVar", objVar, 1.0f, 16.0f);

        if (objVar != newObjvar)
        {
            _dsp.SetFloatParameter(Hv_coreofinal_AudioLib.Parameter.Objvar, newObjvar);
        }
        GUILayout.EndHorizontal();
        EditorGUI.indentLevel--;
    }