예제 #1
0
 /* apply filter to a sample value */
 public static float ApplyFirstOrderLowpass(
     FirstOrderLowpassRec Filter,
     float Xin)
 {
     Filter.iir.Y9 = Filter.iir.A * Xin - Filter.iir.B * Filter.iir.Y9;
     return(Filter.iir.Y9);
 }
예제 #2
0
 /* apply filter to an array of values, modifying array */
 public static void ApplyFirstOrderLowpassVectorModify(
     FirstOrderLowpassRec Filter,
     float[] Vector,
     int VectorOffset,
     int VectorLength)
 {
     IIR1AllPole(
         ref Filter.iir,
         Vector,
         VectorOffset,
         Vector,
         VectorOffset,
         VectorLength);
 }
예제 #3
0
            public static void SetFirstOrderLowpassCoefficients(
                FirstOrderLowpassRec Filter,
                double Cutoff,
                double SamplingRate)
            {
                if (Cutoff == Filter.OldCutoff)
                {
                    return;
                }
                Filter.OldCutoff = Cutoff;

                ComputeFirstOrderLowpassCoefficients(
                    ref Filter.iir,
                    Cutoff,
                    SamplingRate);
            }
예제 #4
0
            /* create a new histogram processor */
            public static HistogramRec NewHistogram(
                HistogramSpecRec Template,
                SynthParamRec SynthParams)
            {
                double Cutoff;

                HistogramRec Histogram = new HistogramRec();

                Histogram.HistogramString = GetHistogramSpecLabel(Template);

                Histogram.NumBins  = GetHistogramSpecNumBins(Template);
                Histogram.BinArray = new int[Histogram.NumBins];

                Histogram.LeftLowpass  = new FirstOrderLowpassRec();
                Histogram.RightLowpass = new FirstOrderLowpassRec();

                Cutoff = GetHistogramSpecPowerEstimatorCutoff(Template);
                FirstOrderLowpassRec.SetFirstOrderLowpassCoefficients(
                    Histogram.LeftLowpass,
                    Cutoff,
                    SynthParams.dSamplingRate);
                FirstOrderLowpassRec.SetFirstOrderLowpassCoefficients(
                    Histogram.RightLowpass,
                    Cutoff,
                    SynthParams.dSamplingRate);

                Histogram.Min    = GetHistogramSpecBottom(Template);
                Histogram.Max    = GetHistogramSpecTop(Template);
                Histogram.Unders = 0;
                Histogram.Overs  = 0;

                Histogram.IgnoreUnders  = GetHistogramSpecDiscardUnders(Template);
                Histogram.Logarithmic   = GetHistogramSpecBinDistribution(Template);
                Histogram.ChannelSelect = GetHistogramSpecChannelSelector(Template);
                Histogram.FilterMethod  = GetHistogramSpecPowerEstimatorMethod(Template);
                Histogram.ChartWidth    = GetHistogramSpecBarChartWidth(Template);

                Histogram.IgnoreUnders = Histogram.IgnoreUnders || (Histogram.Min == 0);
                if (Histogram.Logarithmic)
                {
                    Histogram.LnMin = Math.Log(Histogram.Min);
                    Histogram.LnMax = Math.Log(Histogram.Max);
                }

                return(Histogram);
            }
예제 #5
0
            /* create a new analyzer processor */
            public static AnalyzerRec NewAnalyzer(
                AnalyzerSpecRec Template,
                SynthParamRec SynthParams)
            {
                AnalyzerRec Analyzer = new AnalyzerRec();

                Analyzer.AnalyzerString = GetAnalyzerSpecString(Template);

                Analyzer.LeftMinimum       = Int32.MaxValue;
                Analyzer.LeftMaximum       = Int32.MinValue;
                Analyzer.RightMinimum      = Int32.MaxValue;
                Analyzer.RightMaximum      = Int32.MinValue;
                Analyzer.FrameCount        = 0;
                Analyzer.LeftPowerMaximum  = Int32.MinValue;
                Analyzer.RightPowerMaximum = Int32.MinValue;

                Analyzer.PowerEnabled = IsAnalyzerSpecPowerEstimatorEnabled(Template);
                if (Analyzer.PowerEnabled)
                {
                    Analyzer.LeftLowpass = new FirstOrderLowpassRec();
                    FirstOrderLowpassRec.SetFirstOrderLowpassCoefficients(
                        Analyzer.LeftLowpass,
                        GetAnalyzerSpecPowerEstimatorCutoff(Template),
                        SynthParams.dSamplingRate);

                    Analyzer.RightLowpass = new FirstOrderLowpassRec();
                    FirstOrderLowpassRec.SetFirstOrderLowpassCoefficients(
                        Analyzer.RightLowpass,
                        GetAnalyzerSpecPowerEstimatorCutoff(Template),
                        SynthParams.dSamplingRate);

                    Analyzer.PowerMethod = GetAnalyzerSpecPowerEstimatorMethod(Template);
#if DEBUG
                    if ((Analyzer.PowerMethod != AnalyzerPowerEstType.eAnalyzerPowerAbsVal) &&
                        (Analyzer.PowerMethod != AnalyzerPowerEstType.eAnalyzerPowerRMS))
                    {
                        Debug.Assert(false);
                        throw new ArgumentException();
                    }
#endif
                }

                return(Analyzer);
            }
예제 #6
0
            /* apply filter to an array of values, adding result to output array */
            public void Apply(
                float[] XinVector,
                int XinVectorOffset,
                float[] YoutVector,
                int YoutVectorOffset,
                int VectorLength,
                float OutputScaling,
                SynthParamRec SynthParams)
            {
                FirstOrderLowpassRec Filter = this;

                IIR1AllPoleMAcc(
                    ref Filter.iir,
                    XinVector,
                    XinVectorOffset,
                    YoutVector,
                    YoutVectorOffset,
                    VectorLength,
                    OutputScaling);
            }
예제 #7
0
            /* helper function to generate filter */
            private static void HistogramFilter(
                HistogramRec Histogram,
                float[] Workspace,
                int WorkspaceOffset,
                int Length,
                FirstOrderLowpassRec Lowpass)
            {
                switch (Histogram.FilterMethod)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case HistogramPowerEstType.eHistogramAbsVal:
                case HistogramPowerEstType.eHistogramSmoothedAbsVal:
                    FloatVectorAbsVal(
                        Workspace,
                        WorkspaceOffset,
                        Workspace,
                        WorkspaceOffset,
                        Length);
                    break;

                case HistogramPowerEstType.eHistogramSmoothedRMS:
                    FloatVectorSquare(
                        Workspace,
                        WorkspaceOffset,
                        Workspace,
                        WorkspaceOffset,
                        Length);
                    break;
                }

                switch (Histogram.FilterMethod)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case HistogramPowerEstType.eHistogramAbsVal:
                    break;

                case HistogramPowerEstType.eHistogramSmoothedAbsVal:
                case HistogramPowerEstType.eHistogramSmoothedRMS:
                    FirstOrderLowpassRec.ApplyFirstOrderLowpassVectorModify(
                        Lowpass,
                        Workspace,
                        WorkspaceOffset,
                        Length);
                    break;
                }

                switch (Histogram.FilterMethod)
                {
                default:
                    Debug.Assert(false);
                    throw new ArgumentException();

                case HistogramPowerEstType.eHistogramAbsVal:
                case HistogramPowerEstType.eHistogramSmoothedAbsVal:
                    break;

                case HistogramPowerEstType.eHistogramSmoothedRMS:
                    FloatVectorSquareRoot(
                        Workspace,
                        WorkspaceOffset,
                        Length);
                    break;
                }
            }
예제 #8
0
            /* apply analyzer to some stuff */
            public SynthErrorCodes Apply(
                float[] workspace,
                int lOffset,
                int rOffset,
                int nActualFrames,
                SynthParamRec synthParams)
            {
                this.FrameCount += nActualFrames;

#if DEBUG
                Debug.Assert(!synthParams.ScratchWorkspace1InUse);
                synthParams.ScratchWorkspace1InUse = true;
#endif
                int LeftBufferOffset  = synthParams.ScratchWorkspace1LOffset;
                int RightBufferOffset = synthParams.ScratchWorkspace1ROffset;

                /* build buffers */
                FloatVectorCopy(
                    workspace,
                    lOffset,
                    workspace,
                    LeftBufferOffset,
                    nActualFrames);
                FloatVectorCopy(
                    workspace,
                    rOffset,
                    workspace,
                    RightBufferOffset,
                    nActualFrames);

                FloatVectorReductionMinMax(
                    ref this.LeftMinimum,
                    ref this.LeftMaximum,
                    workspace,
                    LeftBufferOffset,
                    nActualFrames);
                FloatVectorReductionMinMax(
                    ref this.RightMinimum,
                    ref this.RightMaximum,
                    workspace,
                    RightBufferOffset,
                    nActualFrames);

                /* compute power analysis */
                if (this.PowerEnabled)
                {
                    switch (this.PowerMethod)
                    {
                    default:
                        Debug.Assert(false);
                        throw new ArgumentException();

                    case AnalyzerPowerEstType.eAnalyzerPowerAbsVal:
                    {
                        float Min = 0;

                        /* absval the vector */
                        FloatVectorAbsVal(
                            workspace,
                            LeftBufferOffset,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FloatVectorAbsVal(
                            workspace,
                            RightBufferOffset,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);

                        /* apply filter */
                        FirstOrderLowpassRec.ApplyFirstOrderLowpassVectorModify(
                            this.LeftLowpass,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FirstOrderLowpassRec.ApplyFirstOrderLowpassVectorModify(
                            this.RightLowpass,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);

                        /* compute maximum */
                        FloatVectorReductionMinMax(
                            ref Min,
                            ref this.LeftPowerMaximum,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FloatVectorReductionMinMax(
                            ref Min,
                            ref this.RightPowerMaximum,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);
                    }
                    break;

                    case AnalyzerPowerEstType.eAnalyzerPowerRMS:
                    {
                        float Min = 0;

                        /* square the vector */
                        FloatVectorSquare(
                            workspace,
                            LeftBufferOffset,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FloatVectorSquare(
                            workspace,
                            RightBufferOffset,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);

                        /* apply filter */
                        FirstOrderLowpassRec.ApplyFirstOrderLowpassVectorModify(
                            this.LeftLowpass,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FirstOrderLowpassRec.ApplyFirstOrderLowpassVectorModify(
                            this.RightLowpass,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);

                        /* compute square root */
                        FloatVectorSquareRoot(
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FloatVectorSquareRoot(
                            workspace,
                            RightBufferOffset,
                            nActualFrames);

                        /* compute maximum */
                        FloatVectorReductionMinMax(
                            ref Min,
                            ref this.LeftPowerMaximum,
                            workspace,
                            LeftBufferOffset,
                            nActualFrames);
                        FloatVectorReductionMinMax(
                            ref Min,
                            ref this.RightPowerMaximum,
                            workspace,
                            RightBufferOffset,
                            nActualFrames);
                    }
                    break;
                    }
                }

#if DEBUG
                synthParams.ScratchWorkspace1InUse = false;
#endif

                return(SynthErrorCodes.eSynthDone);
            }