Example #1
0
        private float[] GenerateFilterCoeff(double fc, double q)
        {
            fc = SynthHelper.ClampD(fc, SynthConstants.DenormLimit, .49);
            float[] coeff = new float[4];
            switch (FilterMethod)
            {
            case FilterType.BiquadLowpass:
            {
                double w0    = SynthConstants.TwoPi * fc;
                double cosw0 = Math.Cos(w0);
                double alpha = Math.Sin(w0) / (2.0 * q);
                double a0inv = 1.0 / (1.0 + alpha);
                coeff[0] = (float)(-2.0 * cosw0 * a0inv);
                coeff[1] = (float)((1.0 - alpha) * a0inv);
                coeff[2] = (float)((1.0 - cosw0) * a0inv * (1.0 / Math.Sqrt(q)));
                coeff[3] = _b1 * 0.5f;
            }
            break;

            case FilterType.BiquadHighpass:
            {
                double w0    = SynthConstants.TwoPi * fc;
                double cosw0 = Math.Cos(w0);
                double alpha = Math.Sin(w0) / (2.0 * q);
                double a0inv = 1.0 / (1.0 + alpha);
                double qinv  = 1.0 / Math.Sqrt(q);
                coeff[0] = (float)(-2.0 * cosw0 * a0inv);
                coeff[1] = (float)((1.0 - alpha) * a0inv);
                coeff[2] = (float)((-1.0 - cosw0) * a0inv * qinv);
                coeff[3] = (float)((1.0 + cosw0) * a0inv * qinv * 0.5);
            }
            break;

            case FilterType.OnePoleLowpass:
                coeff[0] = 1.0f - (float)Math.Exp(-2.0 * Math.PI * fc);
                break;
            }
            return(coeff);
        }
Example #2
0
 /// <inheritdoc />
 public void SetChannelVolume(int channel, double volume)
 {
     volume = SynthHelper.ClampD(volume, SynthConstants.MinVolume, SynthConstants.MaxVolume);
     _synth.PostMessage(new { cmd = AlphaSynthWebWorker.CmdSetChannelVolume, channel = channel, volume = volume });
 }
Example #3
0
 /// <inheritdoc />
 public void SetChannelVolume(int channel, double volume)
 {
     volume = SynthHelper.ClampD(volume, SynthConstants.MinVolume, SynthConstants.MaxVolume);
     _synthesizer.SetChannelVolume(channel, volume);
 }