Esempio n. 1
0
        public static CTCSSDecoder Create(float tone, int sampleRate)
        {
            if (!ValidTones.Contains(tone))
            {
                throw new ArgumentOutOfRangeException(nameof(tone), @"is not a valid CTCSS tone");
            }

            if (sampleRate <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(sampleRate), @"value must be greater than 0");
            }

            float binWidthInHz = CalculateBinWidthForTone(tone);
            float numberOfSamplesForRequiredBinWidth = sampleRate / binWidthInHz;
            float samplesRequiredForOnePEriod        = sampleRate / tone;
            int   frameSize             = (int)Math.Round(numberOfSamplesForRequiredBinWidth + (numberOfSamplesForRequiredBinWidth % samplesRequiredForOnePEriod));
            var   frequenciesOfInterest = new[] { tone - binWidthInHz, tone, tone + binWidthInHz };

            var lowPass = new LowPassFilter(sampleRate, tone + 10);

            var goertzel = Goertzel.Create(frameSize, sampleRate, FFTWindowBuilder.Hann(frameSize), lowPass.Process, frequenciesOfInterest);

            return(new CTCSSDecoder(goertzel, frameSize, binWidthInHz));
        }
Esempio n. 2
0
 private CTCSSDecoder(Goertzel goertzel, int frameSize, float binWidthInHz)
 {
     _binWidthInHz = binWidthInHz;
     _goertzel     = goertzel;
     _frameSize    = frameSize;
 }