Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/test/analyserbpmtest.cpp

Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <QDebug>
00003 #include <QDir>
00004 
00005 #include "trackinfoobject.h"
00006 #include "configobject.h"
00007 #include "analyserbpm.h"
00008 
00009 #define BIGBUF_SIZE (1024 * 1024)  //Megabyte
00010 #define CANARY_SIZE (1024*64) // Make it one block size (32768*2)
00011 #define MAGIC_FLOAT 1234.567890f
00012 #define CANARY_FLOAT 0.0f
00013 
00014 namespace {
00015 
00016 class AnalyserBPMTest: public testing::Test {
00017   protected:
00018     virtual void SetUp() {
00019         qDebug() << "SetUp";
00020         config = new ConfigObject<ConfigValue>(QDir::homePath().append("/").append(SETTINGS_PATH).append(SETTINGS_FILE));
00021         abpm = new AnalyserBPM(config);
00022         tio = TrackPointer(new TrackInfoObject("foo"));
00023         //Subpixels per second, from waveformrenderer.cpp:247
00024         tio->setVisualResampleRate(200);
00025 
00026         bigbuf = new CSAMPLE[BIGBUF_SIZE];
00027         for (int i = 0; i < BIGBUF_SIZE; i++)
00028             bigbuf[i] = MAGIC_FLOAT;
00029 
00030         //Memory layout for canaryBigBuf looks like
00031         //  [ canary | big buf | canary ]
00032         //
00033 
00034         canaryBigBuf = new CSAMPLE[BIGBUF_SIZE + 2*CANARY_SIZE];
00035         for (int i = 0; i < CANARY_SIZE; i++)
00036             canaryBigBuf[i] = CANARY_FLOAT;
00037         for (int i = CANARY_SIZE; i < CANARY_SIZE+BIGBUF_SIZE; i++)
00038             canaryBigBuf[i] = MAGIC_FLOAT;
00039         for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++)
00040             canaryBigBuf[i] = CANARY_FLOAT;
00041     }
00042 
00043     virtual void TearDown() {
00044         qDebug() << "TearDown";
00045         delete abpm;
00046         delete [] bigbuf;
00047         delete [] canaryBigBuf;
00048     }
00049 
00050     AnalyserBPM* abpm;
00051     ConfigObject<ConfigValue>* config;
00052     TrackPointer tio;
00053     CSAMPLE* bigbuf;
00054     CSAMPLE* canaryBigBuf;
00055 };
00056 
00057 //Test to make sure we don't modify the source buffer.
00058 TEST_F(AnalyserBPMTest, simpleAnalyze) {
00059     abpm->initialise(tio, 44100, BIGBUF_SIZE);
00060     abpm->process(bigbuf, BIGBUF_SIZE);
00061     abpm->finalise(tio);
00062     for (int i = 0; i < BIGBUF_SIZE; i++) {
00063         EXPECT_FLOAT_EQ(bigbuf[i], MAGIC_FLOAT);
00064     }
00065 }
00066 
00067 //Basic test to make sure we don't step out of bounds.
00068 TEST_F(AnalyserBPMTest, canary) {
00069     abpm->initialise(tio, 44100, BIGBUF_SIZE);
00070     abpm->process(&canaryBigBuf[CANARY_SIZE], BIGBUF_SIZE);
00071     abpm->finalise(tio);
00072     for (int i = 0; i < CANARY_SIZE; i++) {
00073         EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
00074     }
00075     for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++) {
00076         EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
00077     }
00078 }
00079 
00080 //Test to make sure that if an incorrect totalSamples is passed to
00081 //initialise(..) and process(..) is told to process more samples than that,
00082 //that we don't step out of bounds.
00083 TEST_F(AnalyserBPMTest, wrongTotalSamples) {
00084     abpm->initialise(tio, 44100, BIGBUF_SIZE);
00085     //Process in a loop
00086     int wrongTotalSamples = BIGBUF_SIZE+1; //Too big by 1 sample...
00087     //Note that the correct totalSamples would just be BIGBUF_SIZE. :)
00088     int blockSize = 2*32768;
00089     for (int i = CANARY_SIZE; i < CANARY_SIZE+wrongTotalSamples; i += blockSize) {
00090         abpm->process(&canaryBigBuf[i], blockSize);
00091     }
00092     abpm->finalise(tio);
00093     //Ensure the source buffer is intact
00094     for (int i = CANARY_SIZE; i < BIGBUF_SIZE; i++) {
00095         EXPECT_FLOAT_EQ(canaryBigBuf[i], MAGIC_FLOAT);
00096     }
00097     //Make sure our canaries are still OK
00098     for (int i = 0; i < CANARY_SIZE; i++) {
00099         EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
00100     }
00101     for (int i = CANARY_SIZE+BIGBUF_SIZE; i < 2*CANARY_SIZE+BIGBUF_SIZE; i++) {
00102         EXPECT_FLOAT_EQ(canaryBigBuf[i], CANARY_FLOAT);
00103     }
00104 }
00105 
00106 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines