예제 #1
0
        public Oscillator(XmlNode x) : this()
        {
            if (x.Attributes["a"] != null)
            {
                A = float.Parse(x.Attributes["a"].Value, CultureInfo.InvariantCulture);
            }
            if (x.Attributes["d"] != null)
            {
                D = float.Parse(x.Attributes["d"].Value, CultureInfo.InvariantCulture);
            }
            if (x.Attributes["s"] != null)
            {
                S = float.Parse(x.Attributes["s"].Value, CultureInfo.InvariantCulture);
            }
            if (x.Attributes["r"] != null)
            {
                R = float.Parse(x.Attributes["r"].Value, CultureInfo.InvariantCulture);
            }
            if (x.Attributes["randomPhase"] != null)
            {
                randomPhase = bool.Parse(x.Attributes["randomPhase"].Value);
            }
            if (x.Attributes["type"] != null)
            {
                Type = (OscillatorType)Enum.Parse(typeof(OscillatorType), x.Attributes["type"].Value);
            }

            if (x.Attributes["squareRatio"] != null)
            {
                squareRatio = float.Parse(x.Attributes["squareRatio"].Value, CultureInfo.InvariantCulture);
            }
            if (x.Attributes["volume"] != null)
            {
                volume = float.Parse(x.Attributes["volume"].Value, CultureInfo.InvariantCulture);
            }
            Pitchs.Clear();
            foreach (XmlElement pitch in x.ChildNodes)
            {
                Pitchs.Add(float.Parse(pitch.Attributes["value"].Value, CultureInfo.InvariantCulture));
            }
        }
예제 #2
0
        internal float[,] GetSound(float start, float length, Note note)
        {
            long  samples         = (long)Project.current.CountSamples(length);                       //how many samples you need on output
            float samplesTotal    = Project.current.CountSamples(note.Length + R);
            var   phaseTimeWaited = Project.current.CountSamples(randomPhase ? start + 1000 : start); //+1000 to taki trik
            var   realTimeWaited  = Project.current.CountSamples(start);                              //+1000 to taki trik
            var   ret             = new float[2, samples];                                            //sound that will be returned

            foreach (var p in Pitchs.ToArray())
            {
                var waveTime = Project.current.waveTime(note.Pitch + p);
                switch (Type)
                {
                case OscillatorType.sine:
                    createSine(ret, waveTime, phaseTimeWaited);
                    break;

                case OscillatorType.saw:
                    createSaw(ret, waveTime, phaseTimeWaited);
                    break;

                case OscillatorType.square:
                    createSquare(ret, waveTime, phaseTimeWaited);
                    break;

                case OscillatorType.triangle:
                    createTriangle(ret, waveTime, phaseTimeWaited);
                    break;

                case OscillatorType.whiteNoise:
                    createWhite(ret, waveTime, phaseTimeWaited);
                    break;
                }
            }
            var aLen = Project.current.CountSamples(A);
            var dLen = Project.current.CountSamples(D);
            var rLen = Project.current.CountSamples(R);

            for (int i = 0; i < samples; i++)
            {
                float adsrVal;
                var   sumTime = i + realTimeWaited;
                if (sumTime < dLen)
                {
                    adsrVal = S + (1 - S) * (dLen - sumTime) / dLen;
                }
                else
                {
                    adsrVal = S;
                }
                if (sumTime < aLen)
                {
                    adsrVal *= sumTime / aLen;
                }
                var toEnd = samplesTotal - sumTime;
                if (toEnd < rLen)
                {
                    adsrVal *= toEnd / rLen;
                }

                adsrVal   *= volume;
                ret[0, i] *= adsrVal;
                ret[1, i] *= adsrVal;
            }
            return(ret);
        }
    private float midiToScreenCustomY(int midiNote)
    {
        var   mi4   = 50;     //Si Bemol
        float dif   = midiNote - mi4;
        float resto = dif % 12;
        float div   = (int)dif / 12;

        Pitchs foo  = (Pitchs)resto;
        float  newY = 0.0f;

//UnityEngine.Debug.Log ("Midiiiiiii Y Custom: "+ midiNote +foo);
        switch (foo)
        {
        case Pitchs.Mi:
            newY = 0;
            break;

        case Pitchs.Fa:
            newY = this.yDistance;

            break;

        case Pitchs.FaS:
            newY = this.yDistance;
            break;

        case Pitchs.Sol:
            newY = this.yDistance * 2f;

            break;

        case Pitchs.SolS:
            newY = this.yDistance * 2f;
            break;

        case Pitchs.La:
            newY = this.yDistance * 3f;
            break;

        case Pitchs.LaS:
            newY = this.yDistance * 3f;
            break;

        case Pitchs.Si:
            newY = this.yDistance * 4f;
            break;

        case Pitchs.Do:
            newY = this.yDistance * 5f;
            break;

        case Pitchs.DoS:
            newY = this.yDistance * 5f;
            break;

        case Pitchs.Re:
            newY = this.yDistance * 6f;
            break;

        case Pitchs.ReS:
            newY = this.yDistance * 6f;
            break;
        }
        newY = ((y + newY) + (yDistance * (div * 7)));
        UnityEngine.Debug.Log("MidiNote: " + midiNote + " Pitch :" + foo + " " + "New Y:" + newY + " y:" + y + " diff:" + dif + " reso:" + resto + " div" + div);
        return(newY);
    }