Exemple #1
0
        public IAsyncAction CloseAsync()
        {
            return(Task.Run(async() =>
            {
                await BodyIndexReader?.CloseAsync();
                BodyIndexReader?.Dispose();
                BodyIndexReader = null;

                await BodyReader?.CloseAsync();
                BodyReader?.Dispose();
                BodyReader = null;

                await ColorReader?.CloseAsync();
                ColorReader?.Dispose();
                ColorReader = null;

                await DepthReader?.CloseAsync();
                DepthReader?.Dispose();
                DepthReader = null;

                AudioReader?.Close();
                AudioReader?.Dispose();
                AudioReader = null;

                _mediaCapture?.Dispose();
                _mediaCapture = null;

                _networkClient?.CloseConnection();
                _networkClient = null;

                _networkServer?.CloseConnection();
                _networkServer = null;
            }).AsAsyncAction());
        }
        /*
         * Yet im not able to calculate FFT with non power of 2 fftsize. !!! check it out? !!! it is important? !!!
         * -------> WIP <---------------
         * public ShortTimeFourierTransform(string filePath, double frequencyGap, double timeResolution = 0.010)
         * {
         *  FilePath = filePath;
         *  TimeResolution = timeResolution;
         *  Reset();
         *  FFTLength = (int)(AudioReader.WaveFormat.SampleRate / frequencyGap);
         *  m = (int)Math.Log(FFTLength, 2.0);
         * } */
        public void Start()
        {
            Reset();
            float[]   samples   = new float[SampleCount];
            Stopwatch stopwatch = Stopwatch.StartNew();

            SampleProvider.Read(new float[SampleCount], 0, SampleCount);
            SampleProvider.Sample -= OnSample;
            stopwatch.Stop();
            AudioReader.Dispose();
            Ended?.Invoke(stopwatch.Elapsed.TotalSeconds);
        }
        public async Task FFmpegWrapperProgressTest()
        {
            var path  = Res.GetPath(Res.Audio_Ogg);
            var opath = "out-test.mp3";

            double lastval = -1;

            try
            {
                var audio = new AudioReader(path);

                await audio.LoadMetadataAsync();

                var dur = audio.Metadata.Duration;
                audio.Dispose();

                Assert.True(Math.Abs(dur - 1.515102) < 0.01);

                var p        = FFmpegWrapper.ExecuteCommand("ffmpeg", $"-i \"{path}\" \"{opath}\"");
                var progress = FFmpegWrapper.RegisterProgressTracker(p, dur);
                progress.ProgressChanged += (s, prg) => lastval = prg;
                p.WaitForExit();

                await Task.Delay(300);

                Assert.True(lastval > 50 && lastval <= 100);

                audio = new AudioReader(opath);

                await audio.LoadMetadataAsync();

                Assert.True(audio.Metadata.Channels == 2);
                Assert.True(audio.Metadata.Streams.Length == 1);
                Assert.True(Math.Abs(audio.Metadata.Duration - 1.515102) < 0.2);

                audio.Dispose();
            }
            finally
            {
                if (File.Exists(opath))
                {
                    File.Delete(opath);
                }
            }
        }