Пример #1
0
        /// <summary>
        /// Merge close Time lines if volume the same
        /// </summary>
        private void MergeTimeLines()
        {
            // save all indexes to delete and then delete those indexes

            TimeLineVolume PreviousTimeLine = DetectedTime[0];

            for (int i = 1; i < DetectedTime.Count; i++)
            {
                if (PreviousTimeLine.Volume == DetectedTime[i].Volume)
                {
                    // set Previous timeLine.end next timeLine.end
                    PreviousTimeLine.End = DetectedTime[i].End;

                    // then delete because we merged this time lines
                    DetectedTime.RemoveAt(i);

                    // we have deleted time line we need to decrease i value
                    i--;

                    // and we set value to item with longer duration
                    DetectedTime[i] = PreviousTimeLine;
                }
                else
                {
                    DetectedTime[i - 1] = PreviousTimeLine;
                    PreviousTimeLine    = DetectedTime[i];
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Reformating DetectedTime into start-end TimeSpan list
        /// </summary>
        /// <param name="DetectedTime">result of DetectVolumeLevel()</param>
        /// <returns> squeezed list </returns>
        private void FormatDetectedTimeSpans(List <TimeSpanVolume> DetectedTime)
        {
            if (DetectedTime.Count < 1)
            {
                throw new ArgumentException($"Size of list DetectedTime ({DetectedTime.Count}) less than 1");
            }

            List <TimeLineVolume> formatedList = new List <TimeLineVolume>();

            // first elem case
            TimeLineVolume tmp = new TimeLineVolume(DetectedTime[0].Volume, new TimeSpan(), new TimeSpan());

            foreach (var span in DetectedTime)
            {
                if (tmp.Volume != span.Volume)
                {
                    if (tmp.Duration > TimeSpan.FromMilliseconds(0))
                    {
                        formatedList.Add(tmp);
                    }

                    // clear tmp and set span

                    tmp        = new TimeLineVolume(span.Volume, tmp.End, tmp.End);
                    tmp.Volume = span.Volume;
                    tmp.End   += span.TimeSpan;
                }
                else
                {
                    tmp.End += span.TimeSpan;
                }
            }
            if (tmp.Duration > TimeSpan.FromMilliseconds(0))
            {
                tmp.End = AudioReader.TotalTime; // set to the end because sometimes it Round millisec so we got less time
                formatedList.Add(tmp);
            }
            formatedList.TrimExcess();
            this.DetectedTime = formatedList;
        }