Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/tonal/tonalanalyser.cpp

Go to the documentation of this file.
00001 #include "tonalanalyser.h"
00002 #include "DiscontinuousSegmentation.hxx"
00003 #include "../segmentation.h"
00004 #include "../trackinfoobject.h"
00005 
00006 #include <QDebug>
00007 #include <QString>
00008 
00009 TonalAnalyser::TonalAnalyser() :
00010                 m_ce() {
00011 
00012     m_bCanRun = true;
00013         m_ce.filterInertia( 0.7 );
00014         m_ce.enableTunning( true );
00015         m_ce.enablePeakWindowing( true );
00016         m_ce.hopRatio( 8.0 );
00017         m_ce.segmentationMethod( 1 );
00018 }
00019 
00020 void TonalAnalyser::finalise(TrackInfoObject* tio) {
00021     if(!m_bCanRun)
00022         return;
00023 
00024         CLAM::DiscontinuousSegmentation segmentation = m_ce.segmentation();
00025 
00026         Segmentation<QString> segs;
00027 
00028         for (unsigned i=0; i<segmentation.onsets().size(); i++)
00029         {
00030                 unsigned chordIndex = m_ce.chordIndexes()[i];
00031                 std::string chordName = m_ce.root(chordIndex) + " " + m_ce.mode(chordIndex);
00032                 //segmentation.setLabel(i,chordName);
00033                 segs.addSeg(segmentation.onsets()[i], segmentation.offsets()[i], chordName.c_str());
00034                 //qDebug() << "Got chord " << chordName.c_str() << " at " << segmentation.onsets()[i] << " until " << segmentation.offsets()[i];
00035         }
00036 
00037         m_ce.clear();
00038 
00039         tio->setChordData(segs);
00040 
00041 }
00042 
00043 void TonalAnalyser::initialise(TrackInfoObject* tio, int sampleRate, int totalSamples) {
00044         m_time = 0;
00045     if(tio->getChannels() == 1) {
00046         m_bCanRun = false;
00047     } else
00048         m_bCanRun = true;
00049 }
00050 
00051 void TonalAnalyser::process(const CSAMPLE *pIn, const int iLen) {
00052 
00053     if(!m_bCanRun)
00054         return;
00055     
00056         m_time += (iLen/2)/44100.0f;
00057 
00058         CSAMPLE* mono = new CSAMPLE[32768];
00059 
00060         for (int i = 0; i < iLen/2; i++) {
00061                 mono[i] = 0.5f*(pIn[i*2] + pIn[i*2+1]);
00062         }
00063 
00064         m_ce.doIt(mono, m_time);
00065 
00066         CLAM::DiscontinuousSegmentation segmentation = m_ce.segmentation();     
00067         segmentation.dragOffset(segmentation.onsets().size()-1, m_time);
00068 
00069         // ??
00070         //_currentTime += _implementation->hop()/44100.0;
00071 
00072 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines