1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include "../src/core/sampleChannel.h"
#include "../src/core/wave.h"
#include "../src/core/waveManager.h"
#include <catch.hpp>
using namespace giada;
using namespace giada::m;
TEST_CASE("sampleChannel")
{
const int BUFFER_SIZE = 1024;
std::vector<ChannelMode> modes = { ChannelMode::LOOP_BASIC,
ChannelMode::LOOP_ONCE, ChannelMode::LOOP_REPEAT,
ChannelMode::LOOP_ONCE_BAR, ChannelMode::SINGLE_BASIC,
ChannelMode::SINGLE_PRESS, ChannelMode::SINGLE_RETRIG,
ChannelMode::SINGLE_ENDLESS };
SampleChannel ch(false, BUFFER_SIZE);
Wave* w;
waveManager::create("tests/resources/test.wav", &w);
ch.pushWave(w);
SECTION("push wave")
{
REQUIRE(ch.status == ChannelStatus::OFF);
REQUIRE(ch.wave == w);
REQUIRE(ch.begin == 0);
REQUIRE(ch.end == w->getSize() - 1);
REQUIRE(ch.name == w->getBasename());
}
SECTION("begin/end")
{
ch.setBegin(-100);
REQUIRE(ch.getBegin() == 0);
REQUIRE(ch.tracker == 0);
REQUIRE(ch.trackerPreview == 0);
ch.setBegin(100000);
REQUIRE(ch.getBegin() == w->getSize());
REQUIRE(ch.tracker == w->getSize());
REQUIRE(ch.trackerPreview == w->getSize());
ch.setBegin(16);
REQUIRE(ch.getBegin() == 16);
REQUIRE(ch.tracker == 16);
REQUIRE(ch.trackerPreview == 16);
ch.setEnd(0);
REQUIRE(ch.getEnd() == 17);
ch.setEnd(100000);
REQUIRE(ch.getEnd() == w->getSize() - 1);
ch.setEnd(32);
REQUIRE(ch.getEnd() == 32);
ch.setBegin(64);
REQUIRE(ch.getBegin() == 31);
}
SECTION("pitch")
{
ch.setPitch(40.0f);
REQUIRE(ch.getPitch() == G_MAX_PITCH);
ch.setPitch(-2.0f);
REQUIRE(ch.getPitch() == G_MIN_PITCH);
ch.setPitch(0.8f);
REQUIRE(ch.getPitch() == 0.8f);
}
SECTION("position")
{
REQUIRE(ch.getPosition() == -1); // Initially OFF
ch.status = ChannelStatus::PLAY;
ch.tracker = 1000;
REQUIRE(ch.getPosition() == 1000);
ch.begin = 700;
REQUIRE(ch.getPosition() == 300);
}
SECTION("empty")
{
ch.empty();
REQUIRE(ch.status == ChannelStatus::EMPTY);
REQUIRE(ch.begin == 0);
REQUIRE(ch.end == 0);
REQUIRE(ch.tracker == 0);
REQUIRE(ch.volume == G_DEFAULT_VOL);
REQUIRE(ch.boost == G_DEFAULT_BOOST);
REQUIRE(ch.hasActions == false);
REQUIRE(ch.wave == nullptr);
}
SECTION("can record audio")
{
REQUIRE(ch.canInputRec() == false); // Can't record if not armed
ch.armed = true;
REQUIRE(ch.canInputRec() == false); // Can't record with Wave in it
ch.empty();
REQUIRE(ch.canInputRec() == true);
}
/* TODO - fillBuffer, isAnyLoopMode, isAnySingleMode, isOnLastFrame */
}
|