test_rapidPiPo.cpp 3.98 KB
Newer Older
Michael Zbyszyński's avatar
Michael Zbyszyński committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//
//  test_rapidPiPoTools.cpp
//  Unit tests for rapidPiPoTools
//

#ifndef CATCH_CONFIG_MAIN
#define CATCH_CONFIG_MAIN
#endif

#ifdef RTA_USE_VECLIB
#undef RTA_USE_VECLIB
#endif

#include <unistd.h>
#include "catch.hpp"
#include "signalProcessing.h"

18
//#define MAX_PATH_SIZE 256
Michael Zbyszyński's avatar
Michael Zbyszyński committed
19

20
//=============================== ONSEG TEST =================================//
Michael Zbyszyński's avatar
Michael Zbyszyński committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

SCENARIO("Test rapidPiPoHost", "[signalProcessing]")
{
    GIVEN("A rapidPiPoHost class with a rapidPiPo chain and an audio file")
    {
        maxiSample buffer;

        // in XCode this gives the path to DerivedData folder
        // char pathStrBuf[MAX_PATH_SIZE];
        // char *cwd = getcwd(pathStrBuf, sizeof(pathStrBuf));
        // std::cout << std::string(cwd) << std::endl;
        
        // but here we just add the file to the Copy File(s) Build Phase
        buffer.load("./DnB-loop-175BPM.wav", 0);
        // ( source : http://freesound.org/people/yewbic/sounds/40107/ )

        buffer.reset(); // (no real need to do this here)
        
        //====================================================================//

        // instantiate PiPo related classes here :
42
        rapidmix::pipoHost host; // -> this class is located in rapidPiPoTools
Michael Zbyszyński's avatar
Michael Zbyszyński committed
43
44
45
46
47
48
49
        
        // if we want to add some custom PiPos to our collection :
        // #include "myCustomPiPo.h"
        // PiPoCollection::addToCollection("myCustomPiPo", new PiPoCreator<myCustomPiPo>);
        // now we can write :
        // pipoHost.setChain("myCustomPiPo");

50
// #include "PiPoMaximChroma.h"
Michael Zbyszyński's avatar
Michael Zbyszyński committed
51
        // this one is not part of the default collection :
52
        // PiPoCollection::addToCollection("chroma", new PiPoCreator<PiPoMaximChroma>);
Michael Zbyszyński's avatar
Michael Zbyszyński committed
53
        
54
        host.setGraph("slice:fft:sum:scale:onseg");
Michael Zbyszyński's avatar
Michael Zbyszyński committed
55
        
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
        host.setAttr("slice.size", 1024);
        host.setAttr("slice.hop", 256);
        host.setAttr("slice.norm", "power");
        host.setAttr("fft.mode", "power");
        host.setAttr("fft.weighting", "itur468");
        host.setAttr("scale.inmin", 1.);
        host.setAttr("scale.inmax", 10.);
        host.setAttr("scale.outmin", 0.);
        host.setAttr("scale.outmax", 10.);
        host.setAttr("scale.func", "log");
        host.setAttr("scale.base", 10.);
        host.setAttr("onseg.duration", 1.);
        host.setAttr("onseg.min", 0.);
        host.setAttr("onseg.max", 1.);
        host.setAttr("onseg.mean", 0.);
        host.setAttr("onseg.stddev", 0.);
        host.setAttr("onseg.startisonset", 1.);
        host.setAttr("onseg.threshold", 9.);
        host.setAttr("onseg.offthresh", -120.);
Michael Zbyszyński's avatar
Michael Zbyszyński committed
75
        
76
77
78
79
80
81
82
83
84
85
86
87
88
89
        std::cout << "onseg threshold : ";
        std::cout << host.getDoubleAttr("onseg.threshold") << std::endl;
        std::cout << "fft mode : ";
        std::cout << host.getEnumAttr("fft.mode") << std::endl;
        std::cout << "param names : " << std::endl;

        std::vector<std::string> attrs = host.getAttrNames();
        
        for (int i = 0; i < attrs.size(); ++i)
        {
            std::cout << "- " << attrs[i] << std::endl;
        }

        std::cout << host.getJSON() << std::endl;
Michael Zbyszyński's avatar
Michael Zbyszyński committed
90
91
92
93
94
        // set another chain :
        // pipoHost.setChain("chroma");
        
        WHEN("file is processed")
        {
95
            rapidmix::pipoStreamAttributes sa;
96
97
98
            sa.hasTimeTags = true;
            sa.rate = 44100;
            sa.offset = 0;
99
100
            sa.width = 1;
            sa.height = 1;
101
102
103
104
105
106
            sa.labels = std::vector<std::string>();
            sa.hasVarSize = false;
            sa.domain = 0;
            sa.maxFrames = 1;
            
            host.setInputStreamAttributes(sa);
Michael Zbyszyński's avatar
Michael Zbyszyński committed
107
108
109
110
            
            float value;
            for (unsigned int i = 0; i < buffer.length; ++i) {
                value = buffer.play();
111
                host.frames((double)i, 0.0, &value, 1, 1);
Michael Zbyszyński's avatar
Michael Zbyszyński committed
112
113
114
115
116
117
118
119
120
121
122
            }

            THEN("compare results of actual processing and same file processed in another envrironment")
            {
                // compare the results of the processing

                REQUIRE(true);
            }
        }
    }
}