forked from LabSound/LabSound
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
71 lines (63 loc) · 3.35 KB
/
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
#include <v8.h>
#include <node.h>
#include <nan.h>
#include <memory>
#include <algorithm>
#include "LabSound/extended/LabSound.h"
#include <Audio.h>
#include <AudioParam.h>
#include <FakeAudioParam.h>
#include <AudioSourceNode.h>
#include <AudioDestinationNode.h>
#include <GainNode.h>
#include <AnalyserNode.h>
#include <PannerNode.h>
#include <StereoPannerNode.h>
#include <OscillatorNode.h>
#include <AudioContext.h>
using namespace std;
using namespace v8;
using namespace node;
namespace webaudio {
unique_ptr<lab::AudioContext> defaultAudioContext;
void Init(Handle<Object> exports) {
Isolate *isolate = Isolate::GetCurrent();
defaultAudioContext = lab::MakeRealtimeAudioContext();
atexit([]() {
defaultAudioContext.reset();
});
exports->Set(JS_STR("Audio"), Audio::Initialize(isolate));
Local<Value> audioParamCons = AudioParam::Initialize(isolate);
exports->Set(JS_STR("AudioParam"), audioParamCons);
Local<Value> fakeAudioParamCons = FakeAudioParam::Initialize(isolate);
exports->Set(JS_STR("FakeAudioParam"), fakeAudioParamCons);
Local<Value> audioListenerCons = AudioListener::Initialize(isolate, fakeAudioParamCons);
exports->Set(JS_STR("AudioListener"), audioListenerCons);
Local<Value> audioSourceNodeCons = AudioSourceNode::Initialize(isolate);
exports->Set(JS_STR("AudioSourceNode"), audioSourceNodeCons);
Local<Value> audioDestinationNodeCons = AudioDestinationNode::Initialize(isolate);
exports->Set(JS_STR("AudioDestinationNode"), audioDestinationNodeCons);
Local<Value> gainNodeCons = GainNode::Initialize(isolate, audioParamCons);
exports->Set(JS_STR("GainNode"), gainNodeCons);
Local<Value> analyserNodeCons = AnalyserNode::Initialize(isolate);
exports->Set(JS_STR("AnalyserNode"), analyserNodeCons);
Local<Value> pannerNodeCons = PannerNode::Initialize(isolate, fakeAudioParamCons);
exports->Set(JS_STR("PannerNode"), pannerNodeCons);
Local<Value> stereoPannerNodeCons = StereoPannerNode::Initialize(isolate, audioParamCons);
exports->Set(JS_STR("StereoPannerNode"), stereoPannerNodeCons);
Local<Value> oscillatorNodeCons = OscillatorNode::Initialize(isolate, audioParamCons);
exports->Set(JS_STR("OscillatorNode"), oscillatorNodeCons);
Local<Value> audioBufferCons = AudioBuffer::Initialize(isolate);
exports->Set(JS_STR("AudioBuffer"), audioBufferCons);
Local<Value> audioBufferSourceNodeCons = AudioBufferSourceNode::Initialize(isolate);
exports->Set(JS_STR("AudioBufferSourceNode"), audioBufferSourceNodeCons);
Local<Value> audioProcessingEventCons = AudioProcessingEvent::Initialize(isolate);
exports->Set(JS_STR("AudioProcessingEvent"), audioProcessingEventCons);
Local<Value> scriptProcessorNodeCons = ScriptProcessorNode::Initialize(isolate, audioBufferCons, audioProcessingEventCons);
exports->Set(JS_STR("ScriptProcessorNode"), scriptProcessorNodeCons);
Local<Value> microphoneMediaStreamCons = MicrophoneMediaStream::Initialize(isolate);
exports->Set(JS_STR("MicrophoneMediaStream"), microphoneMediaStreamCons);
exports->Set(JS_STR("AudioContext"), AudioContext::Initialize(isolate, audioListenerCons, audioSourceNodeCons, audioDestinationNodeCons, gainNodeCons, analyserNodeCons, pannerNodeCons, audioBufferCons, audioBufferSourceNodeCons, audioProcessingEventCons, stereoPannerNodeCons, oscillatorNodeCons, scriptProcessorNodeCons, microphoneMediaStreamCons));
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Init)
}