public RefreshVisualOutputEventArgs(VisualOutputMode mode, int[] dimensions, float[,,] values, bool changedSinceLastRefresh)
 {
     this.Mode       = mode;
     this.Dimensions = dimensions;
     this.Values     = values;
     this.ChangedSinceLastRefresh = changedSinceLastRefresh;
 }
Example #2
0
        public VisualOutput(MultiChannelInput <IDataChannel> mci, int maxFramesPerSecond, VisualOutputMode mode)
        {
            this.mode = mode;
            if (mode == VisualOutputMode.Matrix)
            {
                channels   = ChannelMapper.Get2DChannelMatrix(mci);
                dimensions = new int[3] {
                    channels.GetLength(0), channels.GetLength(1), 1
                };
                values = new float[channels.GetLength(0), channels.GetLength(1), 1];
            }
            else if (mode == VisualOutputMode.Waveform)
            {
                channels = new IDataChannel[mci.ChannelCount, 1];
                for (int i = 0; i < mci.ChannelCount; i++)
                {
                    channels[i, 0] = mci.GetChannel(i);
                }
                dimensions = new int[3] {
                    mci.ChannelCount, mci.SamplesPerSecond, 1
                };
                values = new float[mci.ChannelCount, mci.SamplesPerSecond, 1];
            }
            else if (mode == VisualOutputMode.Spectrum)
            {
                channels = new IDataChannel[mci.ChannelCount, 1];
                int?blockSize = null;

                for (int i = 0; i < mci.ChannelCount; i++)
                {
                    channels[i, 0] = mci.GetChannel(i);

                    var filter = FilterManager.FindFilter <FFTWFilter>(channels[i, 0]);
                    if (filter == null)
                    {
                        throw new Exception("VisualOutput's Spectrum mode supports FFTWFilter only.");
                    }
                    var filterSettings = filter.GetSettings();
                    if (filterSettings.OutputFormat != FFTOutputFormat.Magnitude)
                    {
                        throw new InvalidDataException($"VisualOutput's Spectrum mode needs and FFT output format of 'Magnitude'. Your FFT filter has '{filterSettings.OutputFormat}'.");
                    }

                    if (!blockSize.HasValue)
                    {
                        blockSize = filter.OutputBlockSize;
                    }
                    if (blockSize != filter.OutputBlockSize)
                    {
                        throw new Exception("All of the OutputBlockSizes of the filters of the multichannel input must be the same.");
                    }
                }

                dimensions = new int[3] {
                    mci.ChannelCount, blockSize.Value, 1
                };
                values = new float[mci.ChannelCount, blockSize.Value, 1];
            }
            else if (mode == VisualOutputMode.DominanceMatrix)
            {
                channels = ChannelMapper.Get2DChannelMatrix(mci);

                var filter = FilterManager.FindFilter <FFTWFilter>(channels[0, 0]);
                if (filter == null)
                {
                    throw new Exception("VisualOutput's DominanceMatrix mode supports FFTWFilter only.");
                }
                var filterSettings = filter.GetSettings();
                if (filterSettings.OutputFormat != FFTOutputFormat.FrequencyMagnitudePair)
                {
                    throw new InvalidDataException($"VisualOutput's DominanceMatrix mode needs and FFT output format of 'FrequencyMagnitudePair'. Your FFT filter has '{filterSettings.OutputFormat}'.");
                }

                dimensions = new int[3] {
                    channels.GetLength(0), channels.GetLength(1), 5 * 2
                };                                                                                  // will containg the top 5 frequencies and their strength
                values = new float[channels.GetLength(0), channels.GetLength(1), 5 * 2];
            }

            mci.DataChanged += DataChanged;

            refreshVisualOutputTimer = new Timer(UpdateVisualOutput, this, 0, 1000 / maxFramesPerSecond);
        }