-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple_main.cpp
80 lines (71 loc) · 2.15 KB
/
simple_main.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
#include "component.h"
#include "componentmanager.h"
#include "eq.h"
#include "ffmpeg.h"
#include "metadata.h"
#include "notifier_impl.h"
#include "player.h"
#include "pulse.h"
#include "resampler.h"
#include "threadpool.h"
#include <cassert>
using namespace vrok;
float BandValues[] = {5.0, 4.0, 3.0, 0.0, -0.2, -0.3, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0, 0.0, 1.0, 2.0, 3.0, 3.0 };
Player player;
Resampler resampler;
EffectSSEQ eq;
DriverPulse out;
ThreadPool pool(2);
std::string filename;
void Play(const std::string &filename);
class PlayerEv : public Player::Events {
public:
void QueueNext() { Play(filename); }
void OnMetadataUpdate(Metadata *metadata) {
for (auto m : *metadata) {
std::cout << m.first << ":" << m.second << std::endl;
}
Metadata::Destory(metadata);
}
};
PlayerEv playerEv;
void Setup() {
Notify::GetInstance()->SetNotifier(new CNotifier);
player.SetEvents(&playerEv);
player.SetQueueNext(true);
player.RegisterSink(&eq);
eq.RegisterSource(&player);
eq.RegisterSink(&resampler);
resampler.RegisterSink(&out);
resampler.RegisterSource(&eq);
out.RegisterSource(&resampler);
player.Preallocate();
eq.Preallocate();
resampler.Preallocate();
out.Preallocate();
Component* comp = ComponentManager::GetSingleton()->GetComponent("ShibatchSuperEQ:0");
for (int i=0;i<sizeof(BandValues)/sizeof(float);i++) {
char bandNameBuf[16];
snprintf(bandNameBuf, 16, "Band%02d", i);
PropertyBase* prop = ComponentManager::GetSingleton()->GetProperty(comp, bandNameBuf);
ComponentManager::GetSingleton()->SetProperty(comp, prop, std::to_string(BandValues[i]));
}
pool.RegisterWork(0, &player);
pool.RegisterWork(1, &eq);
pool.RegisterWork(0, &resampler);
pool.RegisterWork(1, &out);
pool.CreateThreads();
}
void Play(const std::string &filename) {
DecoderFFMPEG *dec = new DecoderFFMPEG();
Resource res;
res._filename = filename;
if (dec->Open(&res))
player.SubmitForPlayback(dec);
}
int main(int argc, char **argv) {
Setup();
filename = argv[1];
Play(filename);
pool.JoinThreads();
}