public static IAnalyticStream Window( this IAnalyticStream stream, Windowing.Function function = Windowing.Function.Hamming, int smoothingSamples = 1000) { return(new AnalyticStreamWindower(stream, function, smoothingSamples: smoothingSamples)); }
public static IBGCStream Window( this IBGCStream stream, double totalDuration, Windowing.Function function = Windowing.Function.Hamming, int smoothingSamples = 1000) { return(new StreamWindower(stream, function, totalDuration: totalDuration, smoothingSamples: smoothingSamples)); }
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(); }
public static IBGCStream Window( this IBGCStream stream, Windowing.Function openingFunction, Windowing.Function closingFunction, int openingSmoothingSamples = 1000, int closingSmoothingSamples = 1000, int sampleShift = 0, int totalChannelSamples = -1) { return(new StreamWindower( stream: stream, openingFunction: openingFunction, closingFunction: closingFunction, openingSmoothingSamples: openingSmoothingSamples, closingSmoothingSamples: closingSmoothingSamples, sampleShift: sampleShift, totalChannelSamples: totalChannelSamples)); }
public AnalyticStreamWindower( IAnalyticStream stream, Windowing.Function function, double totalDuration = double.NaN, int smoothingSamples = 1000, int sampleOffset = 0, TransformRMSBehavior rmsBehavior = TransformRMSBehavior.Passthrough) : base(stream) { if (sampleOffset > stream.Samples) { Debug.LogError("Requested a sampleOffset larger than clip length"); sampleOffset = 0; } this.sampleOffset = sampleOffset; if (!double.IsNaN(totalDuration)) { Samples = Math.Min( (int)(totalDuration * SamplingRate), stream.Samples - sampleOffset); } else { Samples = stream.Samples - sampleOffset; } this.rmsBehavior = rmsBehavior; smoothingSamples = Math.Min(smoothingSamples, Samples / 2); window = Windowing.GetHalfWindow64(function, smoothingSamples); endOpeningWindow = smoothingSamples; startClosingWindow = Samples - smoothingSamples; Reset(); }
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(); }
public static string ToDisplayName(this Windowing.Function function) { switch (function) { case Windowing.Function.Hamming: return("Hamming"); case Windowing.Function.Hann: return("Hann"); case Windowing.Function.BlackmanHarris: return("Blackman-Harris"); case Windowing.Function.Sine: return("Sine"); case Windowing.Function.Linear: return("Triangular"); case Windowing.Function.Square: return("Square"); case Windowing.Function.Silence: return("Silence"); default: UnityEngine.Debug.LogError($"Unexpected Windowing.Function: {function}"); return(""); } }
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(); }