示例#1
0
文件: MidiVoice.cs 项目: DotLab/Midif
        public override void Process(float[] buffer)
        {
            var temp = BufferControl.RequestBuffer();

            Component.Process(temp);

            if (IsStereo)
            {
                var tempRight = BufferControl.RequestBuffer();
                RightComponent.Process(tempRight);

                for (int i = 0; i < buffer.Length; i += 2)
                {
                    buffer[i]     += temp[i >> 1] * (float)LeftGain;
                    buffer[i + 1] += tempRight[i >> 1] * (float)RightGain;
                }

                BufferControl.FreeBuffer(tempRight);
            }
            else
            {
                for (int i = 0; i < buffer.Length; i += 2)
                {
                    buffer[i]     += temp[i >> 1] * (float)LeftGain;
                    buffer[i + 1] += temp[i >> 1] * (float)RightGain;
                }
            }

            BufferControl.FreeBuffer(temp);
        }
示例#2
0
    void CreateHeepDevice()
    {
        List <byte> ID = new List <byte>();

        for (byte i = 0; i < 4; i++)
        {
            ID.Add(i);
        }

        DeviceID myID = new DeviceID(ID);

        myDevice = new HeepDevice(myID);

        myDevice.LoadDeviceMemoryFromFile();

        Control theControl = Control.CreateControl(Control.CtrlInputOutput.input, Control.CtrlType.OnOff, "First", sendAnalytics);

        myDevice.AddControl(theControl);
        Control newControl = Control.CreateControl(Control.CtrlInputOutput.output, Control.CtrlType.OnOff, "Second", sendAnalytics);

        myDevice.AddControl(newControl);
        Control bufferControl = new BufferControl(0, Control.CtrlInputOutput.output, Control.CtrlType.buffer, 10, 0, 0, "Buffer", true);

        myDevice.AddControl(bufferControl);
        myDevice.SetDeviceNameStartup("Unity");
        myDevice.StartListening();
    }
示例#3
0
        public Client(IPEndPoint remoteEndPoint, BaseProtocol handler)
        {
            _remoteEndPoint = remoteEndPoint;
            _socket         = new Socket(remoteEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            _bufferControl = new BufferControl(BufferSize, BufferSize);
            _bufferControl.Init();

            _protocol = handler;
        }
示例#4
0
        public Server(EndPoint localEndPoint, int numConnections, BaseProtocol handler)
        {
            _listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            _listenSocket.Bind(localEndPoint);
            _listenSocket.Listen(100);

            _bufferControl            = new BufferControl(ReceiveBufferSize * numConnections, ReceiveBufferSize);
            _maxNumberAcceptedClients = new Semaphore(numConnections, numConnections);
            _sessions = new ConcurrentDictionary <uint, Session>();
            _bufferControl.Init();

            _protocol = handler;
        }
示例#5
0
        public override void Process(float[] buffer)
        {
            var lfoTemp = BufferControl.RequestBuffer();

            Lfo.Process(lfoTemp);
            Envelope.Process(buffer);

            if (ModBuffer != null)
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] *= (float)(Math.Sin(phase + feedback + ModBuffer[i]) * (1 - (lfoTemp[i] + 1) * lfoAmpGain * 0.5));
                    feedback   = buffer[i] * FeedbackRatio;

                    phase += phaseStep * Math.Pow(lfoPitchGain, lfoTemp[i]);
                    if (phase >= Pi2)
                    {
                        phase -= Pi2;
                    }

                    buffer[i] *= (float)outputGain;
                }
            }
            else
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] *= (float)(Math.Sin(phase + feedback) * (1 - (lfoTemp[i] + 1) * lfoAmpGain * 0.5));
                    feedback   = buffer[i] * FeedbackRatio;

                    phase += phaseStep * Math.Pow(lfoPitchGain, lfoTemp[i]);
                    if (phase >= Pi2)
                    {
                        phase -= Pi2;
                    }

                    buffer[i] *= (float)outputGain;
                }
            }

            BufferControl.FreeBuffer(lfoTemp);
        }
示例#6
0
文件: Dx7Voice.cs 项目: DotLab/Midif
        // Additive buffer!
        public override void Process(float[] buffer)
        {
            var temp = new float[6][];

            for (int opi = 5; opi >= 0; --opi)
            {
                var op = Operators[opi];
                if (!op.Enabled)
                {
                    continue;
                }

                if (temp[opi] != null)
                {
                    continue;
                }
                temp[opi] = BufferControl.RequestBuffer();

                if (Algorithm.ModulationMatrix[opi].Length > 0)                   // Has dependency
                {
                    var modTemp = BufferControl.RequestBuffer();
                    modTemp[0] = float.MaxValue;
                    foreach (var modi in Algorithm.ModulationMatrix[opi])
                    {
                        var mod = Operators[modi];
                        if (op == mod || !mod.Enabled)
                        {
                            continue;
                        }

                        if (temp[modi] == null)                           // Modulator not yet rendered
                        {
                            temp[modi] = BufferControl.RequestBuffer();
                            mod.Process(temp[modi]);
                        }

                        if (modTemp[0] == float.MaxValue)
                        {
                            for (int k = 0; k < modTemp.Length; k++)                             // Add to modTemp
                            {
                                modTemp[k] = temp[modi][k];
                            }
                        }
                        else
                        {
                            for (int k = 0; k < modTemp.Length; k++)                             // Add to modTemp
                            {
                                modTemp[k] += temp[modi][k];
                            }
                        }
                    }
                    op.ModBuffer = modTemp;
                    op.Process(temp[opi]);
                    op.ModBuffer = null;
                    BufferControl.FreeBuffer(modTemp);
                }
                else
                {
                    op.ModBuffer = null;
                    op.Process(temp[opi]);
                }
            }

            foreach (var opi in Algorithm.OutputMix)
            {
                var op = Operators[opi];
                if (!op.Enabled)
                {
                    continue;
                }

                for (int j = 0; j < buffer.Length; j += 2)
                {
                    buffer[j]     += (float)(temp[opi][j >> 1] * op.AmplitudeLeft * PER_VOICE_LEVEL / Algorithm.OutputMix.Length * LeftGain);
                    buffer[j + 1] += (float)(temp[opi][j >> 1] * op.AmplitudeRight * PER_VOICE_LEVEL / Algorithm.OutputMix.Length * RightGain);
                }
            }

            for (int i = 0; i < 6; i++)
            {
                if (temp[i] != null)
                {
                    BufferControl.FreeBuffer(temp[i]);
                }
            }
        }