public PcmFormat(PcmFormat rhs)
 {
     NumChannels = rhs.NumChannels;
     ChannelId   = rhs.ChannelId;
     SampleRate  = rhs.SampleRate;
     NumSamples  = rhs.NumSamples;
 }
Beispiel #2
0
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            var r = new PcmFormat(inputFormat);

            r.SampleRate *= Factor;
            r.NumSamples *= Factor;
            return(r);
        }
Beispiel #3
0
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            SampleRate     = inputFormat.SampleRate;
            mFilterFreq    = ButterworthFilter.Design(SampleRate, CutoffFrequency, FFT_LEN, FilterSlopeDbOct);
            mIfftAddBuffer = null;
            mFirstFilterDo = true;

            return(new PcmFormat(inputFormat));
        }
Beispiel #4
0
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            mNumSamples = inputFormat.NumSamples;

            mPcmAllChannels = new WWUtil.LargeArray <double> [inputFormat.NumChannels];
            mChannelId      = inputFormat.ChannelId;

            return(new PcmFormat(inputFormat));
        }
Beispiel #5
0
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            var r = new PcmFormat(inputFormat);

            r.SampleRate /= Factor;
            r.NumSamples /= Factor;

            // mFFT.SetNumOutSamples(r.NumSamples);
            return(r);
        }
Beispiel #6
0
        public override PcmFormat Setup(PcmFormat inputFormat) {
            mInputPcmFormat = inputFormat;

            var r = new PcmFormat(inputFormat);
            r.SampleRate *= Factor;
            r.NumSamples *= Factor;

            mOutputPcmFormat = r;

            SetupCoeffs();
            return r;
        }
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            if (Int32.MaxValue <= inputFormat.NumSamples)
            {
                MessageBox.Show("Input PCM data is too long");
                return(null);
            }

            /*
             *  ジッター発生の原理
             *  ①ジッターによって揺さぶられたクロックで時を刻む。
             *  ②①の各時刻について、音声信号の波高値をSincリサンプラーにより算出する。
             *
             *  sampleRate        == 96000 Hz
             *  jitterFrequency   == 50 Hz
             *  jitterPicoseconds == 1 ps の場合
             *
             *  サンプル位置posのθ= 2 * PI * pos * 50 / 96000 (ラジアン)
             *
             *  サンプル間隔= 1/96000秒 = 10.4 μs
             *
             *  1ms = 10^-3秒
             *  1μs= 10^-6秒
             *  1ns = 10^-9秒
             *  1ps = 10^-12秒
             *
             *  1psのずれ                     A サンプルのずれ
             *  ───────────── = ─────────
             *  10.4 μs(1/96000)sのずれ      1 サンプルのずれ
             *
             *  1psのサンプルずれA = 10^-12 ÷ (1/96000) = 10^-12 * 96000 (サンプルのずれ)
             *
             *  サンプルを採取する位置= pos + Asin(θ)
             */

            mTotalSamples = inputFormat.NumSamples;
            mSampleRate   = inputFormat.SampleRate;

            // SineJitterNanosecはRMS値で与えられる。振幅は√2倍。
            mSineJitterAmp = 1.0e-9 * SineJitterNanosec * inputFormat.SampleRate * Math.Sqrt(2);
            mTpdfJitterAmp = 1.0e-9 * TpdfJitterNanosec * inputFormat.SampleRate * 2;
            mRpdfJitterAmp = 1.0e-9 * RpdfJitterNanosec * inputFormat.SampleRate;

            if (!SetupTimingErrorFile())
            {
                //MessageBox.Show("Error: JitterAddFilter::Setup() failed!");
                return(null);
            }

            PrepareResamplePosArray(inputFormat.SampleRate, (int)inputFormat.NumSamples);
            return(new PcmFormat(inputFormat));
        }
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            mSampleRate   = inputFormat.SampleRate;
            mDelaySamples = (int)(mSampleRate / CutoffFreq / 2 / 1.2);

            mMovingAveragerList = new List <MovingAverager>();
            for (int i = 0; i < MOVING_AVERAGER_NUM; ++i)
            {
                mMovingAveragerList.Add(new MovingAverager(mDelaySamples));
            }
            mDelayX         = new Delay(mDelaySamples * 2 - 2);
            mDiscardSamples = mDelaySamples * 2 - 2;
            return(inputFormat);
        }
        private static PcmFormat FilterSetup(AudioData from, int ch, List <FilterBase> filters)
        {
            var fmt = new PcmFormat(from.meta.channels, ch, from.meta.sampleRate, from.meta.totalSamples);

            foreach (var f in filters)
            {
                fmt = f.Setup(fmt);
                if (null == fmt)
                {
                    return(null);
                }
            }
            return(fmt);
        }
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            mPcmFormat = new PcmFormat(inputFormat);

            /* 周波数の精度 = メインローブの幅/2
             * Bartlett窓やHann窓のとき 4π/M ラジアン、M == FFTsize
             * 人間の耳は、超低音域の音程は長3音(=1.26倍)ずれていても気にならないという。
             */
            mFftLength = Functions.NextPowerOf2(mPcmFormat.SampleRate);
            mFFTfwd    = new WWTimeDependentForwardFourierTransform(mFftLength,
                                                                    WWTimeDependentForwardFourierTransform.WindowType.Hann);
            mFFTinv = new WWTimeDependentInverseFourierTransform(mFftLength);

            mTotalSamples     = inputFormat.NumSamples;
            mProcessedSamples = 0;

            return(inputFormat);
        }
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            if (inputFormat.NumChannels != mCoeffNumChannels)
            {
                MessageBox.Show("Crossfeed NumChannels Mismatch!");
                return(null);
            }
            if (inputFormat.SampleRate != mCoeffSampleRate)
            {
                MessageBox.Show("Crossfeed SampleRate Mismatch! (among crossfeed coefficient file and input pcm file)");
                return(null);
            }
            mNumSamples  = inputFormat.NumSamples;
            mNumChannels = inputFormat.NumChannels;
            mChannelId   = inputFormat.ChannelId;

            mPcmAllChannels = new WWUtil.LargeArray <double> [mNumChannels];
            return(inputFormat);
        }
Beispiel #12
0
 public override PcmFormat Setup(PcmFormat inputFormat)
 {
     mFormat = inputFormat;
     return(inputFormat);
 }
Beispiel #13
0
 public override PcmFormat Setup(PcmFormat inputFormat)
 {
     DesignFilter();
     return(inputFormat);
 }
        public override PcmFormat Setup(PcmFormat inputFormat)
        {
            double fc         = 20 * 1000;
            double fs         = 150 * 1000;
            int    sampleFreq = 44100 * 64;

            var iir = new WWIIRFilterDesign.IIRFilterDesign();

            if (!iir.Design(fc, fs, sampleFreq, WWIIRFilterDesign.IIRFilterDesign.Method.Bilinear))
            {
                Console.WriteLine("Error: iir.Design failed");
                return(null);
            }

#if false
            // インパルス応答波形を出力。
            {
                var fg = iir.CreateIIRFilterGraph();
                lock (fg) {
                    using (var sw = new System.IO.StreamWriter("C:/audio/impulseResponseBW.csv")) {
                        for (int i = 0; i < 8000; ++i)
                        {
                            double r = fg.Filter(i == 0 ? 1 : 0);
                            sw.WriteLine("{0} {1}", i, r);
                        }
                    }
                }
            }
#endif

            var filterGraph = iir.CreateIIRFilterGraph();
            mOriginalSignal = new Lpf(filterGraph);

            mCandidates = new Lpf[InspectCandidates()];
            for (int i = 0; i < InspectCandidates(); ++i)
            {
                mCandidates[i] = new Lpf(mOriginalSignal);
            }

            // INSPECT_BITSビットのあらゆるビットパターンをそれぞれのフィルターに投入。

            /* INSPECT_BITS == 3のとき 8通り。
             * idx==0 000 : -1, -1, -1
             * idx==1 001 : +1, -1, -1
             * idx==2 010 : -1, +1, -1
             * idx==3 011 : +1, +1, -1
             * idx==4 100 : -1, -1, +1
             * idx==5 101 : +1, -1, +1
             * idx==6 110 : -1, +1, +1
             * idx==7 111 : +1, +1, +1
             */
            Parallel.For(0, InspectCandidates(), idx => {
                var lpf = mCandidates[idx];
                for (int i = 0; i < INSPECT_BITS; ++i)
                {
                    int bit  = 1 & (idx >> i);
                    double v = (bit == 1) ? +1.0 : -1.0;
                    lpf.Filter(v);
                }
            });

            mProcessed = 0;

            return(new PcmFormat(inputFormat));
        }
 public override PcmFormat Setup(PcmFormat inputFormat)
 {
     mMask = 0xffffff00U << (24 - TargetBitsPerSample);
     return(new PcmFormat(inputFormat));
 }
 /// <summary>
 /// perform setup task, set pcm format and returns output format
 /// </summary>
 /// <param name="inputFormat">input pcm format</param>
 /// <returns>output pcm format</returns>
 public virtual PcmFormat Setup(PcmFormat inputFormat)
 {
     return(new PcmFormat(inputFormat));
 }
 public override PcmFormat Setup(PcmFormat inputFormat)
 {
     return(new PcmFormat(inputFormat));
 }