コード例 #1
0
    public FMVoice(string name, FMSynthesizer parent)
    {
        Name = name;
        p    = parent.UI;

        eg         = new EnvelopeGenerator(name);
        eg.Attack  = p.Attack1;
        eg.Decay   = p.Decay1;
        eg.Sustain = p.Sustain1;
        eg.Release = p.Release1;

        eg2         = new EnvelopeGenerator(name);
        eg2.Attack  = p.Attack2;
        eg2.Decay   = p.Decay2;
        eg2.Sustain = p.Sustain2;
        eg2.Release = p.Release2;


        table = new float[Settings.SampleRate / 220];

        for (int i = 0; i < table.Length; i++)
        {
            table[i] = Mathf.Sin(TWO_PI * ((float)i / (float)(table.Length - 1))) * .8f;// + (Mathf.Pow( UnityEngine.Random.Range(0,1), 5 )*2-1);
            //Debug.Log(table[i]);
        }
        index = 0;
    }
コード例 #2
0
        public Oscillator(int sampleRate, int channels) : base(sampleRate, channels)
        {
            _amplitudeEnvelope = new EnvelopeGenerator();
            _lfo       = new LFO();
            _isPlaying = false;

            Attack  = .001f;
            Decay   = 0;
            Sustain = 1;
            Release = .001f;

            Amplitude = 1;

            _tuning   = 440;
            _note     = 49;
            Frequency = 440;

            LFOAmplitude = 0;
            LFOFrequency = 1;

            Function    = x => (float)Math.Sin(2 * Math.PI * x);
            LFOFunction = x => (float)Math.Sin(2 * Math.PI * x);

            _phase    = 0;
            _lfoPhase = 0;
        }
コード例 #3
0
 public Voice()
 {
     wave_zero = 0x380;
     voice_DC  = 0x800 * 0xff;
     Envelope  = new EnvelopeGenerator();
     Wave      = new WaveformGenerator();
 }
コード例 #4
0
ファイル: Voice.cs プロジェクト: scemino/nscumm
 public Voice()
 {
     wave_zero = 0x380;
     voice_DC = 0x800 * 0xff;
     Envelope = new EnvelopeGenerator();
     Wave = new WaveformGenerator();
 }
コード例 #5
0
 public AdsrSampleProvider(ISampleProvider source, float Attack, float Decay, float Sustain, float Release)
 {
     this.source       = source;
     adsr              = new EnvelopeGenerator();
     adsr.AttackRate   = Attack * WaveFormat.SampleRate;
     adsr.SustainLevel = Sustain;
     adsr.DecayRate    = Decay * WaveFormat.SampleRate;
     adsr.ReleaseRate  = Release * WaveFormat.SampleRate;
     adsr.Gate(true);
 }
コード例 #6
0
 public AdsrSampleProvider(ISampleProvider source)
 {
     this.source       = source;
     adsr              = new EnvelopeGenerator();
     adsr.AttackRate   = attack * WaveFormat.SampleRate;
     adsr.SustainLevel = sustain;
     adsr.DecayRate    = decay * WaveFormat.SampleRate;
     adsr.ReleaseRate  = release * WaveFormat.SampleRate;
     adsr.Gate(true);
 }
コード例 #7
0
ファイル: AdsrSampleProvider.cs プロジェクト: zhangx3000/GFF
 public AdsrSampleProvider(ISampleProvider source)
 {
     if (source.WaveFormat.Channels > 1)
     {
         throw new ArgumentException("Currently only supports mono inputs");
     }
     this.source            = source;
     this.adsr              = new EnvelopeGenerator();
     this.AttackSeconds     = 0.01f;
     this.adsr.SustainLevel = 1f;
     this.adsr.DecayRate    = 0f * (float)this.WaveFormat.SampleRate;
     this.ReleaseSeconds    = 0.3f;
     this.adsr.Gate(true);
 }
コード例 #8
0
        public FilteredOscillator(int sampleRate) : base(sampleRate, 2)
        {
            _filter = new BiQuadFilter(sampleRate);

            FilterCutoff          = 1000;
            FilterEnvelopeOctaves = 0;

            _filterEnvelope = new EnvelopeGenerator();

            FilterAttack  = .001f;
            FilterDecay   = 2;
            FilterSustain = 0;
            FilterRelease = .001f;

            FilterLevel = 0;
        }
コード例 #9
0
        public ADSRSignalGenerator(int sampleRate, int channel)
        {
            phi        = 0;
            waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, channel);

            // Default
            Type            = SignalGeneratorType.Sin;
            Frequency       = 440.0;
            Gain            = 1;
            PhaseReverse    = new bool[channel];
            SweepLengthSecs = 2;

            env              = new EnvelopeGenerator();
            env.AttackRate   = 0f;
            env.DecayRate    = 0f;
            env.SustainLevel = .8f;
            env.ReleaseRate  = 0f;
        }
コード例 #10
0
        void DrawEnvelope(EnvelopeGenerator env)
        {
            var rect = GUILayoutUtility.GetRect(128, 64);

            // background
            _rectVertices[0] = new Vector3(rect.x, rect.y);
            _rectVertices[1] = new Vector3(rect.xMax, rect.y);
            _rectVertices[2] = new Vector3(rect.xMax, rect.yMax);
            _rectVertices[3] = new Vector3(rect.x, rect.yMax);

            Handles.DrawSolidRectangleWithOutline(
                _rectVertices, Color.white * 0.1f, Color.clear);

            // constants
            const int div = _vertexPerSegment;
            var gated = (env.signalMode == EnvelopeGenerator.InputMode.Gate);

            // segment lengths
            var Ta = env.attackTime;
            var Td = gated ? env.decayTime : 0.0f;
            var Ts = gated ? 0.2f : 0.0f;
            var Tr = env.releaseTime;

            // origin
            var vc = 0;
            _lineVertices[vc++] = PointInRect(rect, 0, 0);

            // attack
            for (var i = 1; i < div; i++)
            {
                var x = Mathf.Min(Ta * i / div, 1.0f);
                var y = env.GetLevelAtTime(x, Ta + Td + Ts);
                _lineVertices[vc++] = PointInRect(rect, x, y);
            }

            // decay
            if (gated)
            {
                for (var i = 0; i < div + 1; i++)
                {
                    var x = Mathf.Min(Ta + Td * i / div, 1.0f);
                    var y = env.GetLevelAtTime(x, Ta + Td + Ts);
                    _lineVertices[vc++] = PointInRect(rect, x, y);
                    if (x == 1.0f) break;
                }
            }

            // release
            if (Ta + Td + Ts <= 1)
            {
                for (var i = 0; i < div + 1; i++)
                {
                    var x = Mathf.Min(Ta + Td + Ts + Tr * i / div, 1.0f);
                    var y = env.GetLevelAtTime(x, Ta + Td + Ts);
                    _lineVertices[vc++] = PointInRect(rect, x, y);
                    if (x == 1.0f) break;
                }

                // zero flat line
                if (Ta + Td + Ts + Tr < 1)
                    _lineVertices[vc++] = PointInRect(rect, 1, 0);
            }
            else if (Ta + Td < 1)
            {
                // sustain level flat line
                var y = env.GetLevelAtTime(1, Ta + Td + Ts);
                _lineVertices[vc++] = PointInRect(rect, 1, y);
            }

            // draw the line
            Handles.DrawAAPolyLine(2.0f, vc, _lineVertices);
        }
コード例 #11
0
 public Func <Time, double> TriggerOff() => Envelope = EnvelopeGenerator.Mute();
コード例 #12
0
 public Func <Time, double> TriggerOn() => Envelope = EnvelopeGenerator.Sustain(SustainLevel());
コード例 #13
0
 /// <summary>
 /// Trigger an automatic ADSR cycle of the envelope modulation.
 /// </summary>
 /// <param name="t0">Start time</param>
 /// <returns></returns>
 public Func <Time, double> TriggerADSR()
 => Envelope = EnvelopeGenerator.TriggerADSR(VoiceOutput.Time, VoiceOutput.Envelope, Attack(), Decay(), SustainLevel(), SustainDuration(), Release());
コード例 #14
0
 /// <summary>
 /// Trigger the release phase of the envelope modulation.
 /// </summary>
 /// <param name="t0">Start time</param>
 /// <returns></returns>
 public Func <Time, double> TriggerRelease()
 => Envelope = EnvelopeGenerator.TriggerRelease(VoiceOutput.Time, VoiceOutput.Envelope, SustainLevel(), Release());
コード例 #15
0
 /// <summary>
 /// Trigger the attack, decay, sustain phases of the envelope modulation.
 /// </summary>
 /// <param name="t0">Start time</param>
 /// <returns></returns>
 public Func <Time, double> TriggerAttack()
 => Envelope = EnvelopeGenerator.TriggerAttack(VoiceOutput.Time, VoiceOutput.Envelope, Attack(), Decay(), SustainLevel());