1 #include "analyzer/plugins/analyzersoundtouchbeats.h" 2 3 #include <soundtouch/BPMDetect.h> 4 5 #include "analyzer/constants.h" 6 #include "util/sample.h" 7 8 namespace mixxx { 9 AnalyzerSoundTouchBeats()10AnalyzerSoundTouchBeats::AnalyzerSoundTouchBeats() 11 : m_downmixBuffer(kAnalysisFramesPerChunk), // mono, i.e. 1 sample per frame 12 m_fResultBpm(0.0f) { 13 } 14 ~AnalyzerSoundTouchBeats()15AnalyzerSoundTouchBeats::~AnalyzerSoundTouchBeats() { 16 } 17 initialize(int samplerate)18bool AnalyzerSoundTouchBeats::initialize(int samplerate) { 19 m_fResultBpm = 0.0f; 20 m_pSoundTouch = std::make_unique<soundtouch::BPMDetect>(2, samplerate); 21 return true; 22 } 23 processSamples(const CSAMPLE * pIn,const int iLen)24bool AnalyzerSoundTouchBeats::processSamples(const CSAMPLE* pIn, const int iLen) { 25 if (!m_pSoundTouch) { 26 return false; 27 } 28 DEBUG_ASSERT(iLen % kAnalysisChannels == 0); 29 // We analyze a mono mixdown of the signal since we don't think stereo does 30 // us any good. 31 32 CSAMPLE* pDownmix = m_downmixBuffer.data(); 33 for (int i = 0; i < iLen / 2; i += 2) { 34 pDownmix[i] = (pIn[i * 2] + pIn[i * 2 + 1]) * 0.5f; 35 } 36 37 m_pSoundTouch->inputSamples(pIn, iLen / 2); 38 return true; 39 } 40 finalize()41bool AnalyzerSoundTouchBeats::finalize() { 42 if (!m_pSoundTouch) { 43 return false; 44 } 45 m_fResultBpm = m_pSoundTouch->getBpm(); 46 m_pSoundTouch.reset(); 47 return true; 48 } 49 50 } // namespace mixxx 51