コード例 #1
0
 private static SpectrumVideoSource WrapSource(SpectrumVideoCanvasConfig config)
 {
     if (!SpectrumVideoSource.OpenSource(config.source, out SpectrumVideoSource source))
     {
         throw new Exception("Source file is incorrectly configured for " + config.label);
     }
     return(source);
 }
コード例 #2
0
        public SpectrumVideoCanvas(SpectrumVideoSource source, SpectrumVideoCanvasConfig config, IOutputProvider outputProvider)
        {
            //Set
            width               = config.video_output.width;
            label               = config.label;
            decimation          = config.baseband.decimation;
            frameRate           = config.video_output.frameRate;
            this.outputProvider = outputProvider;
            this.source         = source;

            //Create IQ decimator and oscilator
            oscillator = new Oscillator(SampleRate, config.baseband.freqOffset);
            decimator  = new ComplexDecimator(SampleRate, DecimatedSampleRate, config.baseband.decimation, config.baseband.decimationAttenuation, DecimatedSampleRate * config.baseband.decimationTransitionRatio);

            //Create all audio resources
            foreach (var o in config.audio_outputs)
            {
                AddResource(new AudioResource(o, this));
            }

            //Create all components
            components       = new SpectrumVideoComponent[config.components.Count];
            componentOffsets = new int[config.components.Count];
            for (int i = 0; i < components.Length; i++)
            {
                components[i] = ComponentFactory.MakeComponent(this, config.components[i]);
            }

            //Get the image dimensions by calculating the total height
            height = 0;
            for (int i = 0; i < components.Length; i++)
            {
                componentOffsets[i] = height * ImageWidth;
                height += components[i].Height;
            }

            //Create misc
            videoOutput   = outputProvider.GetVideoOutput(config.video_output.filename, ImageWidth, ImageHeight, config.video_output.frameRate, BufferSize);
            frameBuffer   = UnsafeBuffer.Create(ImageWidth * ImageHeight, out frameBufferPtr);
            buffer        = UnsafeBuffer.Create(BufferSize, out bufferPtr);
            textGenerator = FontStore.CreateRenderer(ImageWidth, ImageHeight);

            //Fill the entire canvas with black
            for (int i = 0; i < ImageWidth * ImageHeight; i++)
            {
                frameBufferPtr[i] = new UnsafeColor(0, 0, 0);
            }

            //Init all components
            for (int i = 0; i < components.Length; i++)
            {
                components[i].Init();
                components[i].InitFrame(frameBufferPtr + componentOffsets[i]);
            }
        }
コード例 #3
0
        public CanvasEditor(SpectrumVideoCanvasConfig config)
        {
            this.config = config;
            InitializeComponent();

            //Bind
            canvasPreview.OnCanvasPreviewSizeChanged += CanvasPreview_OnCanvasPreviewSizeChanged;

            //Link
            ConfigureList(componentList, config.components);
            ConfigureList(demodList, config.audio_outputs);
        }
コード例 #4
0
        private void PreviewWorker()
        {
            SpectrumVideoCanvas canvas = null;
            int       frames           = 0;
            Stopwatch timer            = new Stopwatch();

            while (previewRunning)
            {
                //If the config is not yet set, abort
                if (config == null)
                {
                    Thread.Sleep(100);
                    continue;
                }

                //Process
                try
                {
                    //Update preview if needed
                    if (previewInvalidated)
                    {
                        //Dispose of old bits
                        canvas?.Dispose();

                        //Create new canvas
                        statusString = "Creating...";
                        canvas       = new SpectrumVideoCanvas(source, config, this);

                        //Set flag
                        timer.Restart();
                        frames             = 0;
                        previewInvalidated = false;
                    }

                    //If the canvas has no components, stop
                    if (config.components.Count == 0)
                    {
                        statusString = "No components! Add one in the \"components\" section.";
                        Thread.Sleep(100);
                        continue;
                    }

                    //Tick canvas
                    if (!canvas.TickFrame())
                    {
                        source.PositionSamples = 0; //Reached end. Rewind
                    }
                    frames++;

                    //Create status
                    double timeSinceStart = timer.Elapsed.TotalSeconds;
                    double progress       = (double)frames / canvas.TotalFrames;
                    statusString = $"{imageWidth}x{imageHeight}, {(frames / timeSinceStart).ToString("0.00")} FPS, {((frames / timeSinceStart) / imageFrameRate).ToString("0.00")}x, {SpectrumVideoUtils.FormatTime((long)(timeSinceStart / progress))} estimated time";
                } catch (Exception ex)
                {
                    //Notify of the error
                    MessageBox.Show($"There's a problem with the canvas using the settings you've given: {ex.Message}\n\nThis error was thrown {ex.StackTrace}", "Canvas Problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    statusString = "Error with the canvas settings";

                    //Set flags
                    previewError = true;
                    config       = null;
                }
            }

            //Stop
            canvas?.Dispose();
            Dispose();
        }
コード例 #5
0
 public void InvalidateCanvas(SpectrumVideoCanvasConfig config)
 {
     this.config        = config;
     previewInvalidated = true;
     previewError       = false;
 }
コード例 #6
0
 public SpectrumVideoCanvas(SpectrumVideoCanvasConfig config, IOutputProvider outputProvider) : this(WrapSource(config), config, outputProvider)
 {
 }
 public SpectrumVideoCanvasMultithread(SpectrumVideoCanvasConfig config, IOutputProvider outputProvider) : base(config, outputProvider)
 {
 }