예제 #1
0
        private void ProcessAudio(float[][] inputs, float[][] outputs)
        {
            ReadMemoryMap();

            if (impulseResponse == null)
            {
                return;
            }

            var irLeft  = impulseResponse[0];
            var irRight = impulseResponse[1];

            if (irLeft == null || irRight == null || irLeft.Length != irRight.Length)
            {
                return;
            }

            var  selInL  = selectedInputL;
            var  selInR  = selectedInputR;
            var  selOutL = selectedOutputL;
            var  selOutR = selectedOutputR;
            bool clipAny = false;

            if (selInL >= 0 && selInL < inputs.Length)
            {
                if (selOutL >= 0 && selOutL < outputs.Length)
                {
                    bool clipped = false;
                    ProcessConv.Process(inputs[selInL], outputs[selOutL], gain, ref bufferIndexL, irLeft, bufferL, ref clipped);
                    clipAny = clipped;

                    if (clipped)
                    {
                        clipTimeLeft = DateTime.UtcNow;
                    }
                }
            }

            if (selInR >= 0 && selInR < inputs.Length)
            {
                if (selOutR >= 0 && selOutR < outputs.Length)
                {
                    bool clipped = false;
                    ProcessConv.Process(inputs[selInR], outputs[selOutR], gain, ref bufferIndexR, irRight, bufferR, ref clipped);
                    clipAny = clipAny | clipped;

                    if (clipped)
                    {
                        clipTimeRight = DateTime.UtcNow;
                    }
                }
            }

            if (clipAny)
            {
                SharedMemoryState.WriteClipIndicators(mmAccessor, clipTimeLeft, clipTimeRight);
            }
        }
예제 #2
0
        private void ReadMemoryMap()
        {
            var state = SharedMemoryState.Read(mmAccessor, stateIndex);

            if (state != null)
            {
                Console.WriteLine("Status update, StateId: {0}, Left IR Length: {1} Right IR Length: {2}", state.Id, state.IrLeft.Length, state.IrRight.Length);
                stateIndex      = state.Id;
                impulseResponse = new[] { state.IrLeft, state.IrRight };
                selectedInputL  = state.SelectedInputLeft;
                selectedInputR  = state.SelectedInputRight;
                selectedOutputL = state.SelectedOutputLeft;
                selectedOutputR = state.SelectedOutputRight;
                gain            = state.Gain;
            }
        }
예제 #3
0
        private void UpdateMemoryMap()
        {
            var state = new SharedMemoryState
            {
                Gain                = (float)Utils.DB2gain(VolumeDb),
                Id                  = ++stateIndex,
                IrLeft              = outputIr[0],
                IrRight             = outputIr[1],
                IrLength            = outputIr[0].Length,
                SelectedInputLeft   = SelectedInputL,
                SelectedInputRight  = selectedInputR,
                SelectedOutputLeft  = SelectedOutputL,
                SelectedOutputRight = SelectedOutputR
            };

            state.Write(mmAccessor);
        }
예제 #4
0
        private void UpdateClipIndicators()
        {
            while (true)
            {
                try
                {
                    var clipTimes = SharedMemoryState.ReadClipIndicators(mmAccessor);

                    if ((DateTime.UtcNow - clipTimes[0]).TotalMilliseconds < 500)
                    {
                        if (ClipLBrush.Equals(Brushes.Transparent))
                        {
                            ClipLBrush = Brushes.Red;
                        }
                    }
                    else
                    {
                        ClipLBrush = Brushes.Transparent;
                    }

                    if ((DateTime.UtcNow - clipTimes[1]).TotalMilliseconds < 500)
                    {
                        if (ClipRBrush.Equals(Brushes.Transparent))
                        {
                            ClipRBrush = Brushes.Red;
                        }
                    }
                    else
                    {
                        ClipRBrush = Brushes.Transparent;
                    }
                }
                catch (Exception)
                {
                    Thread.Sleep(500);
                    // swallow
                }

                Thread.Sleep(20);
            }
            // ReSharper disable once FunctionNeverReturns
        }