Ejemplo n.º 1
0
        public static bool OpenSource(SpectrumVideoFileConfig cfg, out SpectrumVideoSource source)
        {
            //Set default
            source = null;

            //Make sure file exists
            if (!File.Exists(cfg.pathname))
            {
                return(false);
            }

            //Open stream
            FileStream fs = new FileStream(cfg.pathname, FileMode.Open, FileAccess.Read);

            //Attempt to load as a WAV file
            ISampleReader reader;

            try
            {
                reader = new WavFileReader(fs);
            } catch
            {
                //Fall back to loading RAW files
                fs.Position = 0;
                if (cfg.raw_rate == 0)
                {
                    return(false);
                }
                reader = new StreamSampleReader(fs, cfg.raw_format, cfg.raw_rate, 0, 2, 32768);
            }

            //Get source
            source = new SpectrumVideoSource(fs, reader);
            return(true);
        }
 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);
 }
        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]);
            }
        }