-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamer.cpp
More file actions
92 lines (75 loc) · 1.66 KB
/
Copy pathstreamer.cpp
File metadata and controls
92 lines (75 loc) · 1.66 KB
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
#include "streamer.h"
#include "op.h"
#include <map>
#include <set>
#include <functional>
#include <string>
#include <math.h>
#define SAMPLE_RATE 44100
#define PI 3.1415926535
void Streamer::stream (float *buffer, int samples)
{
for (Op *op : Ops)
op->generate (samples);
ConstStream output = Out->getStream ();
for (int i = 0; i < samples; ++i, ++output)
{
buffer[2*i+0] = (float)output;
buffer[2*i+1] = (float)output;
}
}
void Streamer::ln (Op &op, const char *name)
{
std::set<Op*> visited;
std::function<void(Op*)> visit = [&] (Op *o)
{
if (visited.find (o) != visited.end ())
return;
visited.insert (o);
for (Op::In &input : o->inputs ())
if (input.CnOp != NULL)
visit (input.CnOp);
for (Op::Out &output : o->outputs ())
output.Buffer.resize (65536);
Ops.push_back (o);
};
Ops.clear ();
visit (&op);
Out = &op.output (name);
}
typedef std::map<std::string, Streamer*> StreamerMap;
static StreamerMap *Streamers = NULL;
Streamer::Register::Register (const char *name, Streamer *streamer)
{
if (Streamers == NULL)
Streamers = new StreamerMap ();
(*Streamers)[name] = streamer;
}
static Streamer* Current = NULL;
Streamer *Streamer::initStreamer (const char *name)
{
if (Current)
Current->release ();
if (name != NULL)
{
StreamerMap::iterator it = Streamers->find (name);
if (it != Streamers->end ())
{
Current = it->second;
if (Current->init ())
return Current;
}
}
for (StreamerMap::iterator it = Streamers->begin (); it != Streamers->end (); ++it)
{
Current = it->second;
if (Current->init ())
return Current;
}
Current = NULL;
return NULL;
}
Streamer *Streamer::getStreamer ()
{
return Current;
}