Ejemplo n.º 1
0
        private TimeStretch(FifoSampleBuffer <TSampleType> outputBuffer)  : base(outputBuffer)
        {
            _inputBuffer  = new FifoSampleBuffer <TSampleType>();
            _outputBuffer = outputBuffer;

            _quickSeek = false;
            _channels  = 2;

            _midBuffer     = null;
            _overlapLength = 0;

            _autoSeqSetting  = true;
            _autoSeekSetting = true;

            _maxNorm      = 0;
            _maxNormFloat = 1e8f;

            _skipFract = 0;

            _tempo = 1.0f;
            SetParameters(44100, Defaults.SEQUENCE_MS, Defaults.SEEKWINDOW_MS, Defaults.OVERLAP_MS);
            SetTempo(1.0f);

            Clear();
        }
Ejemplo n.º 2
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.º 3
0
        private TimeStretch(FifoSampleBuffer outputBuffer)
            : base(outputBuffer)
        {
            _outputBuffer = outputBuffer;
            _inputBuffer  = new FifoSampleBuffer();

            _bQuickSeek = false;
            _channels   = 2;

#if NET45 || NETSTANDARD1_1
            _pMidBuffer = new float[0];
#else
            _pMidBuffer = Array.Empty <float>();
#endif
            _overlapLength = 0;

            _bAutoSeqSetting  = true;
            _bAutoSeekSetting = true;

            _maxnorm  = 0;
            _maxnormf = 1e8f;

            _skipFract = 0;

            _tempo = 1.0f;
            SetParameters(44100, Defaults.SEQUENCE_MS, Defaults.SEEKWINDOW_MS, Defaults.OVERLAP_MS);
            SetTempo(1.0f);

            Clear();
        }
Ejemplo n.º 4
0
        public virtual int Transpose(FifoSampleBuffer <TSampleType> dest, FifoSampleBuffer <TSampleType> src)
        {
            int numSrcSamples = src.AvailableSamples;
            int sizeDemand    = (int)(numSrcSamples / rate) + 8;
            int numOutput;

            ArrayPtr <TSampleType> psrc  = src.PtrBegin();
            ArrayPtr <TSampleType> pdest = dest.PtrEnd(sizeDemand);

#if !USE_MULTICH_ALWAYS
            if (channels == 1)
            {
                numOutput = TransposeMono(pdest, psrc, ref numSrcSamples);
            }
            else if (channels == 2)
            {
                numOutput = TransposeStereo(pdest, psrc, ref numSrcSamples);
            }
            else
#endif
            {
                Debug.Assert(channels > 0);
                numOutput = TransposeMulti(pdest, psrc, ref numSrcSamples);
            }
            dest.PutSamples(numOutput);
            src.ReceiveSamples(numSrcSamples);
            return(numOutput);
        }
Ejemplo n.º 5
0
        private RateTransposer(FifoSampleBuffer <TSampleType> outputBuffer)
            : base(outputBuffer)
        {
            _useAliasFilter = true;

            _inputBuffer  = new FifoSampleBuffer <TSampleType>();
            _midBuffer    = new FifoSampleBuffer <TSampleType>();
            _outputBuffer = outputBuffer;

            _antiAliasFilter = new AntiAliasFilter <TSampleType>(64);
            _transposer      = NewInstance();
        }
        private RateTransposer(FifoSampleBuffer <TSampleType> outputBuffer)
            : base(outputBuffer)
        {
            _channels       = 2;
            _useAliasFilter = true;
            Rate            = 0f;

            _storeBuffer  = new FifoSampleBuffer <TSampleType>(2);
            _tempBuffer   = new FifoSampleBuffer <TSampleType>(2);
            _outputBuffer = outputBuffer;

            _antiAliasFilter = new AntiAliasFilter <TSampleType>(32);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public int Evaluate(FifoSampleBuffer <TSampleType> dest, FifoSampleBuffer <TSampleType> src)
        {
            ArrayPtr <TSampleType> pdest;
            ArrayPtr <TSampleType> psrc;
            int numSrcSamples;
            int result;
            int numChannels = src.GetChannels();

            Debug.Assert(numChannels == dest.GetChannels());

            numSrcSamples = src.AvailableSamples;
            psrc          = src.PtrBegin();
            pdest         = dest.PtrEnd(numSrcSamples);
            result        = _firFilter.Evaluate(pdest, psrc, numSrcSamples, numChannels);
            src.ReceiveSamples(result);
            dest.PutSamples(result);

            return(result);
        }
Ejemplo n.º 9
0
        private RateTransposer(FifoSampleBuffer outputBuffer)
            : base(outputBuffer)
        {
            _useAAFilter =
#if !SOUNDTOUCH_PREVENT_CLICK_AT_RATE_CROSSOVER
                true;
#else
                // Disable Anti-alias filter if desirable to avoid click at rate change zero value crossover
                false;
#endif

            _inputBuffer  = new FifoSampleBuffer();
            _midBuffer    = new FifoSampleBuffer();
            _outputBuffer = outputBuffer;

            // Instantiates the anti-alias filter
            _pAAFilter  = new AntiAliasFilter(64);
            _transposer = TransposerBase.CreateInstance();
        }