FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
webaudio/src/cpp/audio-node.cpp at master · node-3d/webaudio · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
node-3d
/
webaudio
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
20
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
webaudio
/
src
/
cpp
/
audio-node.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
278 lines (210 loc) · 6.49 KB
Breadcrumbs
webaudio
/
src
/
cpp
/
audio-node.cpp
Copy path
File metadata and controls
278 lines (210 loc) · 6.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#
include
"
audio-node.hpp
"
#
include
"
audio-context.hpp
"
#
include
"
audio-param.hpp
"
IMPLEMENT_ES5_CLASS
(AudioNode);
void
AudioNode::init
(Napi::Env env, Napi::Object exports) {
Napi::Function ctor =
wrap
(env);
JS_ASSIGN_SETTER
(channelInterpretation);
JS_ASSIGN_SETTER
(channelCountMode);
JS_ASSIGN_SETTER
(channelCount);
JS_ASSIGN_METHOD
(disconnect);
JS_ASSIGN_METHOD
(connect);
JS_ASSIGN_GETTER
(numberOfOutputs);
JS_ASSIGN_GETTER
(numberOfInputs);
JS_ASSIGN_GETTER
(context);
JS_ASSIGN_METHOD
(destroy);
JS_ASSIGN_METHOD
(diagnose);
exports.
Set
(
"
AudioNode
"
, ctor);
}
bool
AudioNode::isAudioNode
(Napi::Object obj) {
return
obj.
InstanceOf
(_ctorEs5.
Value
());
}
inline
std::string
fromChannelCountMode
(lab::ChannelCountMode mode) {
if
(mode == lab::ChannelCountMode::ClampedMax) {
return
"
clamped-max
"
;
}
else
if
(mode == lab::ChannelCountMode::Explicit) {
return
"
explicit
"
;
}
else
{
return
"
max
"
;
}
}
inline
lab::ChannelCountMode
toChannelCountMode
(
const
std::string &mode) {
if
(mode ==
"
clamped-max
"
) {
return
lab::ChannelCountMode::ClampedMax;
}
else
if
(mode ==
"
explicit
"
) {
return
lab::ChannelCountMode::Explicit;
}
else
{
return
lab::ChannelCountMode::Max;
}
}
inline
std::string
fromChannelInterpretation
(lab::ChannelInterpretation io) {
if
(io == lab::ChannelInterpretation::Discrete) {
return
"
discrete
"
;
}
else
{
return
"
speakers
"
;
}
}
inline
lab::ChannelInterpretation
toChannelInterpretation
(
const
std::string &io) {
if
(io ==
"
discrete
"
) {
return
lab::ChannelInterpretation::Discrete;
}
else
{
return
lab::ChannelInterpretation::Speakers;
}
}
AudioNode::AudioNode
(
const
Napi::CallbackInfo &info) : CommonNode(info.This(), "AudioNode") {
NAPI_ENV
;
super
(info);
Napi::Object context = info[
0
].
As
<Napi::Object>();
Napi::External<
void
> extNode = info[
1
].
As
<Napi::External<
void
>>();
NodePtr *ext =
reinterpret_cast
<NodePtr *>(extNode.
Data
());
reset
(context, *ext);
_channelCountMode =
fromChannelCountMode
(_impl->
channelCountMode
());
_channelInterpretation =
fromChannelInterpretation
(_impl->
channelInterpretation
());
}
AudioNode::~AudioNode
() {
_destroy
();
}
void
AudioNode::_destroy
() {
DES_CHECK
;
CommonNode::_destroy
();
}
//
node2 node1.connect(node2);
//
node2 node1.connect(node2, output);
//
node2 node1.connect(node2, output, input);
//
undefined node1.connect(param);
//
undefined node1.connect(param, output);
JS_IMPLEMENT_METHOD
(AudioNode, connect) {
THIS_CHECK
;
REQ_OBJ_ARG
(
0
, destination);
Napi::Object context = _context.
Value
();
AudioContext *audioContext =
AudioContext::unwrap
(context);
lab::AudioContext *ctx = audioContext->
getCtx
().
get
();
if
(
isAudioNode
(destination)) {
LET_INT32_ARG
(
1
, output);
LET_INT32_ARG
(
2
, input);
AudioNode *destNode =
AudioNode::unwrap
(destination);
ctx->
connect
(destNode->
_impl
, _impl, input, output);
if
(destNode->
_impl
.
get
() ==
static_cast
<lab::AudioNode *>(ctx->
destinationNode
().
get
())) {
ctx->
synchronizeConnections
();
}
}
else
if
(
AudioParam::isAudioParam
(destination)) {
LET_INT32_ARG
(
1
, output);
AudioParam *destParam =
AudioParam::unwrap
(destination);
ctx->
connectParam
(destParam->
getParam
(), _impl, output);
}
RET_UNDEFINED
;
}
//
undefined node1.disconnect();
//
undefined node1.disconnect(dest);
//
undefined node1.disconnect(dest, output);
//
undefined node1.disconnect(dest, output, input);
//
MAP TO --->
//
ctx->disconnect(NodePtr destination, NodePtr source, int input, int output)
//
ctx->disconnect(NodePtr source, int output)
JS_IMPLEMENT_METHOD
(AudioNode, disconnect) {
THIS_CHECK
;
int
output =
0
;
int
input =
0
;
Napi::Object destination;
Napi::Object context = _context.
Value
();
AudioContext *audioContext =
AudioContext::unwrap
(context);
lab::AudioContext *ctx = audioContext->
getCtx
().
get
();
if
(info.
Length
() ==
1
) {
if
(info[
0
].
IsObject
()) {
REQ_OBJ_ARG
(
0
, destArg);
destination = destArg;
}
else
if
(info[
0
].
IsNumber
()) {
REQ_INT_ARG
(
0
, outputArg);
output = outputArg;
}
}
else
if
(info.
Length
() ==
2
) {
REQ_OBJ_ARG
(
0
, destArg);
REQ_INT_ARG
(
1
, outputArg);
destination = destArg;
output = outputArg;
}
else
if
(info.
Length
() ==
3
) {
REQ_OBJ_ARG
(
0
, destArg);
REQ_INT_ARG
(
1
, outputArg);
REQ_INT_ARG
(
2
, inputArg);
destination = destArg;
output = outputArg;
input = inputArg;
}
else
{
//
Disconnect self
ctx->
disconnect
(_impl, output);
RET_UNDEFINED
;
}
if
(
AudioNode::isAudioNode
(destination)) {
AudioNode *destNode =
AudioNode::unwrap
(destination);
ctx->
disconnect
(destNode->
_impl
, _impl, input, output);
}
else
if
(
AudioParam::isAudioParam
(destination)) {
AudioParam *destParam =
AudioParam::unwrap
(destination);
ParamPtr param = destParam->
getParam
();
ctx->
disconnectParam
(param, _impl, output);
}
RET_UNDEFINED
;
}
JS_IMPLEMENT_GETTER
(AudioNode, context) {
THIS_CHECK
;
RET_VALUE
(_context.
Value
());
}
JS_IMPLEMENT_GETTER
(AudioNode, numberOfInputs) {
THIS_CHECK
;
RET_NUM
(
static_cast
<
uint32_t
>(_impl->
numberOfInputs
()));
}
JS_IMPLEMENT_GETTER
(AudioNode, numberOfOutputs) {
THIS_CHECK
;
RET_NUM
(
static_cast
<
uint32_t
>(_impl->
numberOfOutputs
()));
}
JS_IMPLEMENT_GETTER
(AudioNode, channelCount) {
THIS_CHECK
;
RET_NUM
(
static_cast
<
uint32_t
>(_impl->
channelCount
()));
}
JS_IMPLEMENT_SETTER
(AudioNode, channelCount) {
THIS_CHECK
;
SETTER_UINT32_ARG
;
Napi::Object context = _context.
Value
();
AudioContext *audioContext =
AudioContext::unwrap
(context);
lab::ContextGraphLock
graphLock
(audioContext->
getCtx
().
get
(),
"
AudioNode::channelCountSetter
"
);
_impl->
setChannelCount
(graphLock, v);
emit
(
"
channelCount
"
,
1
, &value);
RET_UNDEFINED
;
}
JS_IMPLEMENT_GETTER
(AudioNode, channelCountMode) {
THIS_CHECK
;
RET_STR
(_channelCountMode);
}
JS_IMPLEMENT_SETTER
(AudioNode, channelCountMode) {
THIS_CHECK
;
SETTER_STR_ARG
;
CACHE_CAS
(_channelCountMode, v);
//
TODO: may be additional actions on change?
emit
(
"
channelCountMode
"
,
1
, &value);
RET_UNDEFINED
;
}
JS_IMPLEMENT_GETTER
(AudioNode, channelInterpretation) {
THIS_CHECK
;
RET_STR
(_channelInterpretation);
}
JS_IMPLEMENT_SETTER
(AudioNode, channelInterpretation) {
THIS_CHECK
;
SETTER_STR_ARG
;
CACHE_CAS
(_channelInterpretation, v);
//
TODO: may be additional actions on change?
emit
(
"
channelInterpretation
"
,
1
, &value);
RET_UNDEFINED
;
}
JS_IMPLEMENT_METHOD
(AudioNode, destroy) {
THIS_CHECK
;
emit
(
"
destroy
"
);
_destroy
();
RET_UNDEFINED
;
}
JS_IMPLEMENT_METHOD
(AudioNode, diagnose) {
THIS_CHECK
;
Napi::Object context = _context.
Value
();
AudioContext *audioContext =
AudioContext::unwrap
(context);
lab::AudioContext *ctx = audioContext->
getCtx
().
get
();
ctx->
diagnose
(_impl);
RET_UNDEFINED
;
}
Back
|
FazBrowse Home
|
New Git URL