示例#1
0
        public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
        {
            layerModel.ApplyProperties(true);
            var newProperties = (AudioPropertiesModel)layerModel.Properties;

            if (_properties == null)
            {
                _properties = newProperties;
            }

            SubscribeToAudioChange();

            if (_audioCapture == null || newProperties.Device != _properties.Device || newProperties.DeviceType != _properties.DeviceType)
            {
                var device = GetMmDevice();
                if (device != null)
                {
                    _audioCapture = _audioCaptureManager.GetAudioCapture(device, newProperties.DeviceType);
                }
            }

            _properties = newProperties;

            if (_audioCapture == null)
            {
                return;
            }

            _audioCapture.Pulse();

            var direction = ((AudioPropertiesModel)layerModel.Properties).Direction;

            int    currentLines;
            double currentHeight;

            if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
            {
                currentLines  = (int)layerModel.Width;
                currentHeight = layerModel.Height;
            }
            else
            {
                currentLines  = (int)layerModel.Height;
                currentHeight = layerModel.Width;
            }

            // Get a new line spectrum if the lines changed, it is null or the layer hasn't rendered for a few frames
            if (_lines != currentLines || _lineSpectrum == null || DateTime.Now - _lastRender > TimeSpan.FromMilliseconds(100))
            {
                _lines        = currentLines;
                _lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
            }

            var newLineValues = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel)?.GetLineValues(currentHeight);

            if (newLineValues != null)
            {
                _lineValues = newLineValues;
                _lastRender = DateTime.Now;
            }
        }
示例#2
0
        public void Update(LayerModel layerModel, ModuleDataModel dataModel, bool isPreview = false)
        {
            layerModel.ApplyProperties(true);
            var newProperties = (AudioPropertiesModel)layerModel.Properties;

            if (_properties == null)
            {
                _properties = newProperties;
            }

            SubscribeToAudioChange();

            if (_audioCapture == null || newProperties.Device != _properties.Device ||
                newProperties.DeviceType != _properties.DeviceType)
            {
                var device = GetMmDevice();
                if (device != null)
                {
                    _audioCapture = _audioCaptureManager.GetAudioCapture(device, newProperties.DeviceType);
                }
            }

            _properties = newProperties;

            if (_audioCapture == null)
            {
                return;
            }

            _audioCapture.Pulse();

            var direction = ((AudioPropertiesModel)layerModel.Properties).Direction;

            int    currentLines;
            double currentHeight;

            if (direction == Direction.BottomToTop || direction == Direction.TopToBottom)
            {
                currentLines  = (int)layerModel.Width;
                currentHeight = layerModel.Height;
            }
            else
            {
                currentLines  = (int)layerModel.Height;
                currentHeight = layerModel.Width;
            }

            if (_lines != currentLines || _lineSpectrum == null)
            {
                _lines        = currentLines;
                _lineSpectrum = _audioCapture.GetLineSpectrum(_lines, ScalingStrategy.Decibel);
                if (_lineSpectrum == null)
                {
                    return;
                }
            }

            var newLineValues = _lineSpectrum?.GetLineValues(currentHeight);

            if (newLineValues != null)
            {
                _lineValues = newLineValues;
            }
        }