Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="BpmDetect&lt;TSampleType, TLongSampleType&gt;"/> class.
        /// </summary>
        /// <param name="numChannels">Number of channels in sample data.</param>
        /// <param name="sampleRate">Sample rate in Hz.</param>
        protected BpmDetect(int numChannels, int sampleRate)
        {
            _sampleRate = sampleRate;
            Channels    = numChannels;

            DecimateSum   = default(TLongSampleType);
            DecimateCount = 0;

            _envelopeAccu = 0;

            // choose decimation factor so that result is approx. 1000 Hz
            DecimateBy = sampleRate / 1000;
            Debug.Assert(DecimateBy > 0);
            Debug.Assert(INPUT_BLOCK_SAMPLES < DecimateBy * DECIMATED_BLOCK_SAMPLES);

            // Calculate window length & starting item according to desired min & max bpms
            WindowLen   = (60 * sampleRate) / (DecimateBy * MIN_BPM);
            WindowStart = (60 * sampleRate) / (DecimateBy * MAX_BPM);

            Debug.Assert(WindowLen > WindowStart);

            // allocate new working objects
            Xcorr = new float[WindowLen];

            // allocate processing buffer
            Buffer = new FifoSampleBuffer <TSampleType>();
            // we do processing in mono mode
            Buffer.SetChannels(1);
            Buffer.Clear();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clears all the samples in the object.
        /// </summary>
        public override void Clear()
        {
            _outputBuffer.Clear();
            _midBuffer.Clear();
            _inputBuffer.Clear();

            // prefill buffer to avoid losing first samples at beginning of stream
            int prefil = Latency;

            _inputBuffer.AddSilent(prefil);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BpmDetect"/> class.
        /// </summary>
        /// <param name="numChannels">Number of channels in sample data.</param>
        /// <param name="sampleRate">Sample rate in Hz.</param>
        public BpmDetect(int numChannels, int sampleRate)
        {
            _beat_lpf = new IIR2Filter(_LPF_coeffs);

            _beats = new List <Beat>(250);

            _sampleRate = sampleRate;
            _channels   = numChannels;

            _decimateSum   = 0;
            _decimateCount = 0;

            // choose decimation factor so that result is approx. 1000 Hz
            _decimateBy = sampleRate / TARGET_SRATE;
            if ((_decimateBy <= 0) || (_decimateBy * DECIMATED_BLOCK_SIZE < INPUT_BLOCK_SIZE))
            {
                throw new ArgumentOutOfRangeException(nameof(sampleRate), Strings.Argument_SampleRateTooSmall);
            }

            // Calculate window length & starting item according to desired min & max bpms
            _windowLen   = (60 * sampleRate) / (_decimateBy * MIN_BPM);
            _windowStart = (60 * sampleRate) / (_decimateBy * MAX_BPM_RANGE);

            Debug.Assert(_windowLen > _windowStart, "Window length exceeds window start");

            // allocate new working objects
            _xcorr = new float[_windowLen];

            _pos                  = 0;
            _peakPos              = 0;
            _peakVal              = 0;
            _init_scaler          = 1;
            _beatcorr_ringbuffpos = 0;
            _beatcorr_ringbuff    = new float[_windowLen];

            // allocate processing buffer
            _buffer = new FifoSampleBuffer
            {
                // we do processing in mono mode
                Channels = 1
            };

            _buffer.Clear();

            // calculate hamming windows
            _hamw = new float[XCORR_UPDATE_SEQUENCE];
            Hamming(_hamw);
            _hamw2 = new float[XCORR_UPDATE_SEQUENCE / 2];
            Hamming(_hamw2);
        }
 /// <summary>
 /// Clears all the samples in the object.
 /// </summary>
 public override void Clear()
 {
     _outputBuffer.Clear();
     _storeBuffer.Clear();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Clears all the samples in the object.
 /// </summary>
 public override void Clear()
 {
     _outputBuffer.Clear();
     _midBuffer.Clear();
     _inputBuffer.Clear();
 }
Ejemplo n.º 6
0
 /// <summary>Clears the sample buffers</summary>
 public override void Clear()
 {
     _outputBuffer.Clear();
     ClearInput();
 }
Ejemplo n.º 7
0
 /// <summary>Clears the input buffer</summary>
 public void ClearInput()
 {
     _inputBuffer.Clear();
     ClearMidBuffer();
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Clears the input buffer.
 /// </summary>
 public void ClearInput()
 {
     _inputBuffer.Clear();
     ClearMidBuffer();
     _isBeginning = true;
 }