Exemple #1
0
        public StreamWindower(
            IBGCStream stream,
            Windowing.Function function      = Windowing.Function.Hamming,
            double totalDuration             = double.NaN,
            int smoothingSamples             = 1000,
            int sampleShift                  = 0,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough)
            : base(stream)
        {
            if (sampleShift > stream.ChannelSamples)
            {
                Debug.LogError("Requested a sampleOffset larger than clip length");
                sampleShift = 0;
            }

            this.sampleShift = sampleShift;

            if (!double.IsNaN(totalDuration))
            {
                ChannelSamples = Math.Min(
                    (int)Math.Round(totalDuration * SamplingRate),
                    stream.ChannelSamples - sampleShift);
                TotalSamples = Channels * ChannelSamples;
            }
            else
            {
                if (stream.ChannelSamples == int.MaxValue)
                {
                    ChannelSamples = int.MaxValue;
                    TotalSamples   = int.MaxValue;
                }
                else
                {
                    ChannelSamples = stream.ChannelSamples - sampleShift;
                    TotalSamples   = Channels * ChannelSamples;
                }
            }

            this.rmsBehavior = rmsBehavior;

            smoothingSamples = Math.Min(smoothingSamples, ChannelSamples / 2);

            openingWindow = Windowing.GetHalfWindow(function, smoothingSamples);
            closingWindow = openingWindow;

            endOpeningWindow   = smoothingSamples;
            startClosingWindow = ChannelSamples - smoothingSamples;

            Reset();
        }
Exemple #2
0
        public StreamWindower(
            IBGCStream stream,
            Windowing.Function function = Windowing.Function.Hamming,
            double totalDuration        = double.NaN,
            int smoothingSamples        = 1000,
            int sampleOffset            = 0,
            bool recalculateRMS         = false)
            : base(stream)
        {
            if (sampleOffset > stream.ChannelSamples)
            {
                Debug.LogError("Requested a sampleOffset larger than clip length");
                sampleOffset = 0;
            }

            this.sampleOffset = sampleOffset;

            if (!double.IsNaN(totalDuration))
            {
                ChannelSamples = Math.Min(
                    (int)(totalDuration * SamplingRate),
                    stream.ChannelSamples - sampleOffset);
            }
            else
            {
                ChannelSamples = stream.ChannelSamples - sampleOffset;
            }

            this.recalculateRMS = recalculateRMS;

            smoothingSamples = Math.Min(smoothingSamples, ChannelSamples / 2);

            window = Windowing.GetHalfWindow(function, smoothingSamples);

            endOpeningWindow   = smoothingSamples;
            startClosingWindow = ChannelSamples - smoothingSamples;

            Reset();
        }
Exemple #3
0
        public StreamWindower(
            IBGCStream stream,
            Windowing.Function openingFunction,
            Windowing.Function closingFunction,
            int openingSmoothingSamples      = 1000,
            int closingSmoothingSamples      = 1000,
            int sampleShift                  = 0,
            int totalChannelSamples          = -1,
            TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough)
            : base(stream)
        {
            if (sampleShift > stream.ChannelSamples)
            {
                Debug.LogError("Requested a sampleOffset larger than clip length");
                sampleShift = 0;
            }

            this.sampleShift = sampleShift;
            this.rmsBehavior = rmsBehavior;

            if (totalChannelSamples != -1)
            {
                ChannelSamples = Math.Min(
                    totalChannelSamples,
                    stream.ChannelSamples - sampleShift);
                TotalSamples = Channels * ChannelSamples;
            }
            else
            {
                if (stream.ChannelSamples == int.MaxValue)
                {
                    ChannelSamples = int.MaxValue;
                    TotalSamples   = int.MaxValue;
                }
                else
                {
                    ChannelSamples = stream.ChannelSamples - sampleShift;
                    TotalSamples   = Channels * ChannelSamples;
                }
            }

            if (openingSmoothingSamples + closingSmoothingSamples > ChannelSamples)
            {
                //Requested smoothing samples exceeded remaining stream length
                int totalSmoothingSamples = openingSmoothingSamples + closingSmoothingSamples;
                int excessSamples         = ChannelSamples - totalSmoothingSamples;

                //Allocate reduced smoothing samples based on requested percentage
                openingSmoothingSamples -= (int)Math.Round(
                    excessSamples * (openingSmoothingSamples / (double)totalSmoothingSamples));
                closingSmoothingSamples = ChannelSamples - openingSmoothingSamples;
            }

            openingWindow = Windowing.GetHalfWindow(openingFunction, openingSmoothingSamples);
            closingWindow = Windowing.GetHalfWindow(closingFunction, closingSmoothingSamples);

            endOpeningWindow   = openingSmoothingSamples;
            startClosingWindow = ChannelSamples - closingSmoothingSamples;

            Reset();
        }