![]() |
Mixxx
|
00001 #include <QtDebug> 00002 00003 #include "trackinfoobject.h" 00004 #include "analyserwavesummary.h" 00005 00006 // Taken from the old wavesummary.cpp code 00007 #ifndef WAVESUMMARYCONSTANTS 00008 const int kiBlockSize = 2048; 00009 const int kiBeatBlockNo = 1000; 00010 const int kiBeatBins = 100; 00011 const int kiSummaryBufferSize = 2100; 00012 const float kfFeatureStepSize = 0.01f; 00013 #define WAVESUMMARYCONSTANTS 00014 #endif 00015 00016 AnalyserWavesummary::AnalyserWavesummary() { 00017 m_pData = NULL; 00018 } 00019 00020 void AnalyserWavesummary::initialise(TrackPointer tio, int sampleRate, int totalSamples) { 00021 Q_UNUSED(sampleRate); 00022 // Check if the preview has already been generated 00023 const QByteArray* p = tio->getWaveSummary(); 00024 if(p != NULL && p->size() > 0) { 00025 return; 00026 } 00027 00028 // Initialize kiSummaryBufferSize bytes to 0 00029 m_pData = new QByteArray(kiSummaryBufferSize, 0); 00030 00031 // The stride length is the number of samples that correspond 00032 // to one "line" (3 entries) in the data buffer. 00033 m_iStrideLength = (int)ceilf((float)totalSamples/((float)kiSummaryBufferSize/3.)); 00034 if(m_iStrideLength%2 != 0) 00035 m_iStrideLength--; 00036 00037 m_iCurPos = 0; 00038 m_iBufferPos = 0; 00039 m_fMax = -1.0f; 00040 m_fMin = 1.0f; 00041 } 00042 00043 void AnalyserWavesummary::process(const CSAMPLE *pIn, const int iLen) { 00044 // Check if processing is disabled. 00045 if(m_pData == NULL) 00046 return; 00047 00048 //qDebug() << "AnalyserWavesummary::process() processing " << iLen << " samples"; 00049 00050 for(int i=0; i<iLen && m_iCurPos+2 < m_pData->size() ; i++) { 00051 if(m_iBufferPos >= m_iStrideLength) { 00052 (*m_pData)[m_iCurPos] = (char)(m_fMin*127); 00053 (*m_pData)[m_iCurPos+1] = (char)(m_fMax*127); 00054 (*m_pData)[m_iCurPos+2] = 0; 00055 m_iCurPos += 3; 00056 00057 m_iBufferPos = 0; 00058 m_fMax = -1.0f; 00059 m_fMin = 1.0f; 00060 } 00061 00062 if(m_iBufferPos <= kiBlockSize) { 00063 if(pIn[i] > m_fMax) 00064 m_fMax = pIn[i]; 00065 if(pIn[i] < m_fMin) 00066 m_fMin = pIn[i]; 00067 } 00068 m_iBufferPos++; 00069 } 00070 } 00071 00072 void AnalyserWavesummary::finalise(TrackPointer tio) { 00073 if(m_pData == NULL) 00074 return; 00075 tio->setWaveSummary(m_pData, true); 00076 //setWaveSummary copies the waveform from the pointer we pass it, so it's safe 00077 //to delete the pointer. 00078 delete m_pData; 00079 m_pData = NULL; 00080 //qDebug() << "AnalyserWavesummary generation successful for " << tio->getFilename(); 00081 }