Beispiel #1
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);
        }
        public WavetableCalculator(IWaveformCalculator calculator)
        {
            int wavetableSize = 1024;

            List<float> wavetableSamples = new List<float>();

            for (int position = 0; position < wavetableSize; position++)
            {
                float sample = calculator.CalculateForSample(position, wavetableSize, wavetableSize*wavetableSize);
                wavetableSamples.Add(sample);
            }

            wavetable = new Wavetable(wavetableSamples);
        }
        public WavetableCalculator(IWaveformCalculator calculator)
        {
            int wavetableSize = 1024;

            List <float> wavetableSamples = new List <float>();

            for (int position = 0; position < wavetableSize; position++)
            {
                float sample = calculator.CalculateForSample(position, wavetableSize, wavetableSize * wavetableSize);
                wavetableSamples.Add(sample);
            }

            wavetable = new Wavetable(wavetableSamples);
        }