예제 #1
0
        public TimeWarpStream(IAudioStream sourceStream)
            : base(sourceStream)
        {
            byteMappings = new ByteTimeWarpCollection(0);
            Mappings     = new TimeWarpCollection();
            length       = sourceStream.Length;
            position     = sourceStream.Position;

            ResetStream();
        }
예제 #2
0
        private void mappings_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            var alpha = new ByteTimeWarp {
                From = 0, To = 0
            };
            var omega = new ByteTimeWarp {
                From = sourceStream.Length, To = sourceStream.Length
            };

            if (mappings.Count > 0)
            {
                // Convert time mappings to byte mappings
                // This is the place where the TimeWarps and ByteTimeWarps are kept in sync!!
                byteMappings = new ByteTimeWarpCollection(mappings.Count);
                foreach (TimeWarp mapping in mappings)
                {
                    byteMappings.Add(ByteTimeWarp.Convert(mapping, Properties));
                }

                var first = byteMappings.Alpha;
                if (first.From > alpha.From)
                {
                    // The first mapping is not at the start of the stream, insert start of stream alpha
                    byteMappings.Insert(0, alpha);
                }

                var last = byteMappings.Omega;
                if (last.From < omega.From)
                {
                    // The last mapping is not at the end of the stream, insert EOS omega
                    omega.To += last.Offset;
                    byteMappings.Insert(byteMappings.Count, omega);
                }
            }
            else
            {
                byteMappings.Add(alpha);
                byteMappings.Add(omega);
            }

            if (position > byteMappings.Omega.To)
            {
                Position = byteMappings.Omega.To;
            }

            ResetStream();
        }