Пример #1
0
        /// <summary>
        /// Audio EQ Cookbook に依った Bi-Quad フィルタ
        /// </summary>
        /// <param name="input"></param>
        /// <param name="b0"></param>
        /// <param name="b1"></param>
        /// <param name="b2"></param>
        /// <param name="a0"></param>
        /// <param name="a1"></param>
        /// <param name="a2"></param>
        /// <returns></returns>
        public static Node <float> BiQuadFilter(Node <float> input,
                                                Node <float> b0, Node <float> b1, Node <float> b2,
                                                Node <float> a0, Node <float> a1, Node <float> a2)
        {
            IEnumerable <float> signal()
            {
                var inDelay  = new DelayBuffer <float>(2);
                var outDelay = new DelayBuffer <float>(2);

                foreach (var values in input.UseAsStream().Zip(
                             b0.UseAsStream(),
                             b1.UseAsStream(),
                             b2.UseAsStream(),
                             a0.UseAsStream(),
                             a1.UseAsStream(),
                             a2.UseAsStream(),
                             Tuple.Create))
                {
                    var inValue  = values.Item1;
                    var b0_      = values.Item2;
                    var b1_      = values.Item3;
                    var b2_      = values.Item4;
                    var a0_      = values.Item5;
                    var a1_      = values.Item6;
                    var a2_      = values.Item7;
                    var outValue = (b0_ * inValue + b1_ * inDelay[0] + b2_ * inDelay[-1] - a1_ * outDelay[0] - a2_ * outDelay[-1]) / a0_;
                    inDelay.Push(inValue);
                    outDelay.Push(outValue);

                    yield return(outValue);
                }
            }

            return(Node.Create(signal(), true, input, b0, b1, b2, a0, a1, a2));
        }
Пример #2
0
        public static Node <float> Delay(this Node src, Node time_smp, Node feedbackLevel, Node wetLevel, int maxTime_smp)
        {
            var buffer = new DelayBuffer <float>(maxTime_smp);

            IEnumerable <float> signal()
            {
                foreach (var stfw in src.AsFloat().UseAsStream().Zip(
                             time_smp.AsInt().UseAsStream(),
                             feedbackLevel.AsFloat().UseAsStream(),
                             wetLevel.AsFloat().UseAsStream(),
                             Tuple.Create))
                {
                    // TODO 添字が誤っていないかチェック
                    yield return(stfw.Item1 + buffer[-(stfw.Item2 - 1)] * stfw.Item4);

                    buffer.Push(stfw.Item1 + stfw.Item3 * buffer[-(stfw.Item2 - 1)]);
                }
            }

            return(Node.Create(signal(), true, src, time_smp, feedbackLevel, wetLevel));
        }