-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtest.cpp
188 lines (162 loc) · 5.39 KB
/
test.cpp
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "catch.hpp"
#include "src/MusicDatabase.h"
#include "src/MusicPlayer.h"
#include "src/MusicPlayerList.h"
#include "src/RemoteLoader.h"
#include "src/modutils.h"
#include "src/di.hpp"
namespace di = boost::di;
#include <audioplayer/audioplayer.h>
#include <coreutils/log.h>
#include <musicplayer/chipplugin.h>
#include <musicplayer/plugins/plugins.h>
#include <algorithm>
#include <array>
#include <numeric>
#include <string>
TEST_CASE("modutils", "[machine]")
{
auto x = getTypeAndBase("/blaj/mdat.gurgle%tjosan");
REQUIRE(x == std::make_tuple("mdat", "gurgle%tjosan"));
x = getTypeAndBase("/blaj/skurk.mannen.x.mod");
REQUIRE(x == std::make_tuple("mod", "skurk.mannen.x"));
x = getTypeAndBase("/blaj/mod/mdat/hejsan hoppsan.whatever");
REQUIRE(x == std::make_tuple("whatever", "hejsan hoppsan"));
REQUIRE(getBaseName("/asda/das/test.mod") == "test.mod");
REQUIRE(getTypeFromName("gurgle.format") == "format");
REQUIRE(getTypeFromName("mdat.gurgle") == "mdat");
REQUIRE(getTypeFromName("mdat.gurgle") == "mdat");
REQUIRE(getTypeFromName("ftp%3a%2f%2fftp.modland.com%2fpub%2fmodules%"
"2fSunTronic%2fTSM%2fmsx-intro.sun") == "sun");
REQUIRE(
getTypeFromName("ftp%3a%2f%2fftp.modland.com%2fpub%2fmodules%2fTFMX%"
"2fChris Huelsbeck%2fmdat.apidya (level 3)") == "mdat");
}
TEST_CASE("music database", "[database]")
{
using namespace chipmachine;
const auto injector = di::make_injector(di::bind<utils::path>.to("."));
auto mdb = injector.create<std::unique_ptr<MusicDatabase>>();
REQUIRE(mdb->initFromLua(utils::path(".")) == true);
auto q = mdb->createQuery();
}
struct AudioPlayerNull : public AudioPlayer
{
std::function<void(int16_t*, int)> callback;
virtual void play(std::function<void(int16_t*, int)> cb) override
{
callback = cb;
}
void get(std::vector<int16_t>& target)
{
callback(&target[0], target.size());
}
void seek(int seconds)
{
std::array<int16_t, 44100 * 2> dummy;
while (seconds--) {
callback(dummy.data(), dummy.size());
}
};
};
TEST_CASE("musicplayerlist", "")
{
logging::setLevel(logging::Level::Debug);
AudioPlayerNull ap{};
const auto injector = di::make_injector(di::bind<utils::path>.to("."),
di::bind<AudioPlayer>.to(ap));
musix::ChipPlugin::createPlugins("data");
auto mpl = injector.create<std::unique_ptr<chipmachine::MusicPlayerList>>();
mpl->addSong("music/Amiga/Starbuck - Tennis.mod"s);
mpl->addSong("music/Amiga/Dr.Awesome - Intromusic3.mod"s);
mpl->nextSong();
mpl->wait();
auto state = mpl->getState();
auto info = mpl->getInfo();
LOGI("%s %s %d", info.title, info.path, state);
ap.seek(150);
mpl->wait();
info = mpl->getInfo();
LOGI("%s %s %d", info.title, info.path, state);
}
TEST_CASE("musicplayer", "")
{
AudioPlayerNull ap{};
const auto injector = di::make_injector(di::bind<utils::path>.to("."),
di::bind<AudioPlayer>.to(ap));
musix::ChipPlugin::createPlugins("data");
chipmachine::MusicPlayer mp{ ap };
bool ok = mp.playFile("music/Amiga/Nuke - Loader.mod");
REQUIRE(ok);
mp.update();
std::vector<int16_t> data(8192);
ap.get(data);
auto sum = std::accumulate(data.begin(), data.end(), (int64_t)0);
REQUIRE(sum != 0);
}
template <typename PLUGIN, typename... ARGS>
bool testPlugin(std::string const& dir, std::string const& exclude,
const ARGS&... args)
{
std::array<int16_t, 8192> buffer;
PLUGIN plugin{ args... };
printf("---- %s ----\n", plugin.name().c_str());
logging::setLevel(logging::Level::Warning);
for (auto f : utils::File{ dir }.listFiles()) {
if (exclude != "" && f.getName().find(exclude) != std::string::npos)
continue;
int64_t sum = 0;
printf("Trying %s\n", f.getName().c_str());
auto* player = plugin.fromFile(f.getName());
if (player) {
int count = 15;
while (sum == 0 && count != 0) {
int rc = player->getSamples(&buffer[0], buffer.size());
if (rc > 0) {
sum = std::accumulate(&buffer[0], &buffer[rc], (int64_t)0);
if (sum != 0) {
break;
}
count--;
} else
break;
}
delete player;
}
printf("#### Playing %s : %s\n", f.getName().c_str(),
player ? (sum == 0 ? "NO SOUND" : "OK") : "FAILED");
}
return true;
}
TEST_CASE("gme", "[music]")
{
testPlugin<musix::GMEPlugin>("testmus/gme/working", "");
}
TEST_CASE("adlib", "[music]")
{
testPlugin<musix::AdPlugin>("testmus/adlib", "", "data");
}
TEST_CASE("uade", "[music]")
{
testPlugin<musix::UADEPlugin>("testmus/uade", "smp", "data");
}
TEST_CASE("openmpt", "[music]")
{
testPlugin<musix::OpenMPTPlugin>("testmus/openmpt", "");
}
TEST_CASE("gsf", "[music]")
{
testPlugin<musix::GSFPlugin>("testmus/gsf", "lib");
}
TEST_CASE("nds", "[music]")
{
testPlugin<musix::NDSPlugin>("testmus/nds", "lib");
}
TEST_CASE("psx", "[music]")
{
testPlugin<musix::HEPlugin>("testmus/psx", "lib", "data/hebios.bin");
}
TEST_CASE("zx", "[music]")
{
testPlugin<musix::AyflyPlugin>("testmus/zx", "");
}