Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/analyserrg.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include <QtDebug>
00004 #include <time.h>
00005 #include <math.h>
00006 
00007 #include "trackinfoobject.h"
00008 #include "analyserrg.h"
00009 #include "../lib/replaygain/replaygain_analysis.h"
00010 
00011 AnalyserGain::AnalyserGain(ConfigObject<ConfigValue> *_config) {
00012     m_pConfigReplayGain = _config;
00013     m_iStepControl = 0;
00014     m_pLeftTempBuffer = NULL;
00015     m_pRightTempBuffer = NULL;
00016     m_iBufferSize = 0;
00017 }
00018 
00019 AnalyserGain::~AnalyserGain() {
00020     delete [] m_pLeftTempBuffer;
00021     delete [] m_pRightTempBuffer;
00022 }
00023 
00024 //TODO: On may think on rewriting replaygain/replagain_analys.* to improve performances. Anyway those willing to do should be sure of
00025 //              the resulting values to exactly coincide with "classical" replaygain_analysis.* ones.
00026 //              On the other hand, every other ReplayGain tagger uses exactly these methods so that we do not have problems about
00027 //              values to coincide.
00028 
00029 void AnalyserGain::initialise(TrackPointer tio, int sampleRate, int totalSamples) {
00030 
00031     bool bAnalyserEnabled = (bool)m_pConfigReplayGain->getValueString(ConfigKey("[ReplayGain]","ReplayGainAnalyserEnabled")).toInt();
00032     float fReplayGain = tio->getReplayGain();
00033     if(totalSamples == 0 || fReplayGain != 0 || !bAnalyserEnabled) {
00034         //qDebug() << "Replaygain Analyser will not start.";
00035         //if (fReplayGain != 0 ) qDebug() << "Found a ReplayGain value of " << 20*log10(fReplayGain) << "dB for track :" <<(tio->getFilename());
00036         return;
00037     }
00038     m_iStepControl = InitGainAnalysis( (long)sampleRate );
00039 }
00040 
00041 
00042 
00043 
00044 void AnalyserGain::process(const CSAMPLE *pIn, const int iLen) {
00045     if(m_iStepControl != 1)
00046         return;
00047 
00048     int halfLength = static_cast<int>(iLen / 2);
00049     if (halfLength > m_iBufferSize) {
00050         delete [] m_pLeftTempBuffer;
00051         delete [] m_pRightTempBuffer;
00052         m_pLeftTempBuffer = new CSAMPLE[halfLength];
00053         m_pRightTempBuffer = new CSAMPLE[halfLength];
00054     }
00055 
00056     for (int i = 0; i < halfLength; ++i) {
00057         m_pLeftTempBuffer[i] = pIn[i*2] * 32767;
00058         m_pRightTempBuffer[i] = pIn[i*2+1] * 32767;
00059     }
00060     m_iStepControl = AnalyzeSamples(m_pLeftTempBuffer, m_pRightTempBuffer,
00061                                     halfLength, 2);
00062 }
00063 
00064 
00065 
00066 
00067 void AnalyserGain::finalise(TrackPointer tio) {
00068 
00069     if(m_iStepControl!=1) return;
00070 
00071     //TODO: We are going to store values as relative peaks so that "0" means that no replaygain has been evaluated.
00072     // This means that we are going to transform from dB to peaks and viceversa.
00073     // One may think to digg into replay_gain code and modify it so that
00074     // it directly sends results as relative peaks.
00075     // In that way there is no need to spend resources in calculating log10 or pow.
00076 
00077     float fReplayGain_Result = pow(10,GetTitleGain()/20);
00078     tio->setReplayGain(fReplayGain_Result);
00079     //if(fReplayGain_Result) qDebug() << "ReplayGain Analyser found a ReplayGain value of "<< 20*log10(fReplayGain_Result) << "dB for track " << (tio->getFilename());
00080     m_iStepControl=0;
00081     fReplayGain_Result=0;
00082     //m_iStartTime = clock() - m_iStartTime;
00083     //qDebug() << "AnalyserGain :: Generation took " << double(m_iStartTime) / CLOCKS_PER_SEC << " seconds";
00084 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines