Пример #1
0
        /// <summary>
        /// Exports a stream of audio.
        /// </summary>
        /// <param name="source">The source stream of audio.</param>
        /// <param name="name">The name for the source stream.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="streamWritersToClose">The collection of stream writers to be closed.</param>
        internal static void Export(this IProducer <AudioBuffer> source, string name, string outputPath, List <StreamWriter> streamWritersToClose)
        {
            // export to .wav file
            source.PipeTo(
                new WaveFileWriter(
                    source.Out.Pipeline,
                    DataExporter.EnsurePathExists(Path.Combine(outputPath, name, $"{name}.wav"))));

            // export individual raw audio buffers to `Audio000123.bin` files along with timing information
            var buffersPath    = Path.Combine(outputPath, name, "Buffers");
            var timingFilePath = DataExporter.EnsurePathExists(Path.Combine(buffersPath, $"Timing.txt"));
            var timingFile     = File.CreateText(timingFilePath);

            streamWritersToClose.Add(timingFile);
            var bufferCounter = 0;

            source
            .Do(
                (buffer, envelope) =>
            {
                if (buffer.HasValidData)
                {
                    var data = buffer.Data;
                    var file = File.Create(DataExporter.EnsurePathExists(Path.Combine(buffersPath, $"Audio{bufferCounter:000000}.bin")));
                    file.Write(data, 0, data.Length);
                    file.Close();
                    file.Dispose();
                    timingFile.WriteLine($"{bufferCounter++}\t{envelope.OriginatingTime.ToText()}");
                }
            });
        }
Пример #2
0
        /// <summary>
        /// Exports a stream of hand infomation.
        /// </summary>
        /// <param name="source">The source stream of hand information.</param>
        /// <param name="directory">The directory in which to persist.</param>
        /// <param name="name">The name for the source stream.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="streamWritersToClose">The collection of stream writers to be closed.</param>
        internal static void Export(this IProducer <Hand> source, string directory, string name, string outputPath, List <StreamWriter> streamWritersToClose)
        {
            var filePath = DataExporter.EnsurePathExists(Path.Combine(outputPath, directory, $"{name}.txt"));
            var file     = File.CreateText(filePath);

            streamWritersToClose.Add(file);
            source
            .Do(
                (hand, envelope) =>
            {
                var result = new StringBuilder();
                result.Append($"{envelope.OriginatingTime.ToText()}\t");
                result.Append($"{hand.IsGripped.ToText()}\t");
                result.Append($"{hand.IsPinched.ToText()}\t");
                result.Append($"{hand.IsTracked.ToText()}\t");
                if (hand.IsTracked)
                {
                    foreach (var joint in hand.Joints)
                    {
                        result.Append($"{joint.ToText()}\t");
                    }
                }

                file.WriteLine(result.ToString().TrimEnd('\t'));
            });
        }
Пример #3
0
            /// <summary>
            /// Initializes a new instance of the <see cref="StreamObservable{T}"/> class.
            /// </summary>
            /// <param name="stream">The source stream to observe.</param>
            /// <param name="deliveryPolicy">An optional delivery policy.</param>
            public StreamObservable(IProducer <T> stream, DeliveryPolicy deliveryPolicy = null)
            {
                stream.Out.Pipeline.PipelineCompleted += (_, args) =>
                {
                    foreach (var obs in this.observers)
                    {
                        foreach (var err in args.Errors)
                        {
                            obs.Value.OnError(err);
                        }

                        obs.Value.OnCompleted();
                    }
                };

                stream.Do(
                    x =>
                {
                    foreach (var obs in this.observers)
                    {
                        obs.Value.OnNext(x.DeepClone());
                    }
                },
                    deliveryPolicy);
            }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StreamEnumerable{T}"/> class.
 /// </summary>
 /// <param name="stream">Stream to enumerate.</param>
 /// <param name="predicate">Predicate (filter) function.</param>
 public StreamEnumerable(IProducer <T> stream, Func <T, bool> predicate = null)
 {
     this.enumerator = new StreamEnumerator(predicate ?? (_ => true));
     stream.Do(x =>
     {
         this.enumerator.Queue.Enqueue(x);
         this.enumerator.Enqueued.Set();
     });
 }
Пример #5
0
        /// <summary>
        /// Exports a stream of 3D rays.
        /// </summary>
        /// <param name="source">The source stream of 3D rays.</param>
        /// <param name="name">The name for the source stream.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="streamWritersToClose">The collection of stream writers to be closed.</param>
        internal static void Export(this IProducer <Ray3D> source, string name, string outputPath, List <StreamWriter> streamWritersToClose)
        {
            var filePath = DataExporter.EnsurePathExists(Path.Combine(outputPath, name, $"{name}.txt"));
            var file     = File.CreateText(filePath);

            streamWritersToClose.Add(file);
            source
            .Do(
                (ray3D, envelope) =>
            {
                file.WriteLine($"{envelope.OriginatingTime.ToText()}\t{ray3D.ToText()}");
            });
        }
Пример #6
0
        /// <summary>
        /// Exports a stream of poses.
        /// </summary>
        /// <param name="source">The source stream of poses.</param>
        /// <param name="name">The name for the source stream.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="streamWritersToClose">The collection of stream writers to be closed.</param>
        internal static void Export(this IProducer <CoordinateSystem> source, string name, string outputPath, List <StreamWriter> streamWritersToClose)
        {
            var filePath = DataExporter.EnsurePathExists(Path.Combine(outputPath, name, $"{name}.txt"));
            var file     = File.CreateText(filePath);

            streamWritersToClose.Add(file);
            source
            .Do(
                (coordinateSystem, envelope) =>
            {
                file.WriteLine($"{envelope.OriginatingTime.ToText()}\t{coordinateSystem.ToText()}");
            },
                DeliveryPolicy.SynchronousOrThrottle);
        }
Пример #7
0
        /// <summary>
        /// Exports a stream of calibration maps.
        /// </summary>
        /// <param name="source">The source stream of calibration maps.</param>
        /// <param name="directory">The directory in which to persist.</param>
        /// <param name="name">The name for the source stream.</param>
        /// <param name="outputPath">The output path.</param>
        /// <param name="streamWritersToClose">The collection of stream writers to be closed.</param>
        internal static void Export(this IProducer <CalibrationPointsMap> source, string directory, string name, string outputPath, List <StreamWriter> streamWritersToClose)
        {
            var filePath = DataExporter.EnsurePathExists(Path.Combine(outputPath, directory, $"{name}.txt"));
            var file     = File.CreateText(filePath);

            streamWritersToClose.Add(file);
            source
            .Do(
                (map, envelope) =>
            {
                var result = new StringBuilder();
                result.Append($"{envelope.OriginatingTime.ToText()}\t");
                result.Append($"{map.Width.ToText()}\t");
                result.Append($"{map.Height.ToText()}\t");
                foreach (var point in map.CameraUnitPlanePoints)
                {
                    result.Append($"{point.ToText()}\t");
                }

                file.WriteLine(result.ToString().TrimEnd('\t'));
            });
        }
Пример #8
0
            /// <summary>
            /// Initializes a new instance of the <see cref="StreamObservable{T}"/> class.
            /// </summary>
            /// <param name="stream">Stream to observe.</param>
            public StreamObservable(IProducer <T> stream)
            {
                stream.Out.Pipeline.PipelineCompletionEvent += (_, args) =>
                {
                    foreach (var obs in this.observers)
                    {
                        foreach (var err in args.Errors)
                        {
                            obs.Value.OnError(err);
                        }

                        obs.Value.OnCompleted();
                    }
                };

                stream.Do(x =>
                {
                    foreach (var obs in this.observers)
                    {
                        obs.Value.OnNext(x.DeepClone());
                    }
                });
            }