예제 #1
0
        public int Read(float[] buffer, int offset, int sampleCount)
        {
            for (int index = 0; index < sampleCount; index++)
            {
                float envelopeAmplitude = envelope.Process();

                buffer[offset + index] = (short)(Amplitude * envelopeAmplitude * Math.Sin(phaseAngle));
                phaseAngle            += 2 * Math.PI * Frequency / WaveFormat.SampleRate;

                if (phaseAngle > 2 * Math.PI)
                {
                    phaseAngle -= 2 * Math.PI;
                }
            }
            return(sampleCount);
        }
예제 #2
0
        public override int Read(float[] buffer, int offset, int sampleCount)
        {
            int sampleRate = WaveFormat.SampleRate;

            for (int n = 0; n < sampleCount; n++)
            {
                float envelopeAmplitude = envelope.Process();

                if (envelopeAmplitude > 0)
                {
                    buffer[n + offset] = Amplitude * envelopeAmplitude * waveformCalculator.CalculateForSample(sample, Frequency, sampleRate);
                }
                else
                {
                    buffer[n + offset] = 0;
                }
                sample++;

                if (sample >= sampleRate)
                {
                    sample = 0;
                }
            }

            return(sampleCount);
        }
예제 #3
0
        /// <summary>
        /// Reads audio from this sample provider
        /// </summary>
        public int Read(float[] buffer, int offset, int count)
        {
            if (adsr.State == EnvelopeGenerator.EnvelopeState.Idle)
            {
                return(0);                                                    // we've finished
            }
            var samples = source.Read(buffer, offset, count);

            for (int n = 0; n < samples; n++)
            {
                buffer[offset++] *= adsr.Process();
            }
            return(samples);
        }
예제 #4
0
        public override int Read(float[] buffer, int offset, int sampleCount)
        {
            for (var index = 0; index < sampleCount; index += WaveFormat.Channels)
            {
                if (_amplitudeEnvelope.State != EnvelopeGenerator.EnvelopeState.Idle)
                {
                    _phase    = _phase + Frequency / WaveFormat.SampleRate;
                    _lfoPhase = _lfoPhase + LFOFrequency / WaveFormat.SampleRate;

                    float lfoCoef = Amplitude - (_lfo.Function((float)_lfoPhase) * _lfo.Amplitude);
                    buffer[offset + index] = lfoCoef * Function((float)_phase) * _amplitudeEnvelope.Process();

                    for (var channel = 1; channel < WaveFormat.Channels; ++channel)
                    {
                        buffer[offset + index + channel] = buffer[offset + index];
                    }
                }
                else
                {
                    if (_isPlaying)
                    {
                        _isPlaying = false;
                        FinishedPlaying?.Invoke(this, new EventArgs());
                        _phase    = 0;
                        _lfoPhase = 0;
                    }

                    for (var channel = 0; channel < WaveFormat.Channels; ++channel)
                    {
                        buffer[index + offset + channel] = 0;
                    }
                }
            }

            return(sampleCount);
        }
예제 #5
0
        public override int Read(float[] buffer, int offset, int sampleCount)
        {
            var samplesRead = base.Read(buffer, offset, sampleCount);

            if (Math.Abs(_filter.Wet) < float.Epsilon)
            {
                return(samplesRead);
            }

            for (var i = 0; i < samplesRead; ++i)
            {
                _filter.Cutoff     = (float)(FilterCutoff * Math.Pow(2, FilterEnvelopeOctaves * _filterEnvelope.Process()));
                buffer[offset + i] = _filter.Apply(buffer[offset + i]) * _filter.Wet + buffer[offset + i] * (1 - _filter.Wet);
            }

            return(samplesRead);
        }