-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_audio_AudioTrack.js.html
More file actions
444 lines (343 loc) · 47.3 KB
/
Copy pathexport_audio_AudioTrack.js.html
File metadata and controls
444 lines (343 loc) · 47.3 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>export/audio/AudioTrack.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BuiltinAssets.html">BuiltinAssets</a></li><li><a href="GlobalAPI.html">GlobalAPI</a><ul class='methods'><li data-type='method'><a href="GlobalAPI.html#gotoAndPlay">gotoAndPlay</a></li><li data-type='method'><a href="GlobalAPI.html#gotoAndStop">gotoAndStop</a></li><li data-type='method'><a href="GlobalAPI.html#gotoNextFrame">gotoNextFrame</a></li><li data-type='method'><a href="GlobalAPI.html#gotoPrevFrame">gotoPrevFrame</a></li><li data-type='method'><a href="GlobalAPI.html#hideCursor">hideCursor</a></li><li data-type='method'><a href="GlobalAPI.html#isKeyDown">isKeyDown</a></li><li data-type='method'><a href="GlobalAPI.html#isKeyJustPressed">isKeyJustPressed</a></li><li data-type='method'><a href="GlobalAPI.html#isMouseDown">isMouseDown</a></li><li data-type='method'><a href="GlobalAPI.html#keyIsDown">keyIsDown</a></li><li data-type='method'><a href="GlobalAPI.html#keyIsJustPressed">keyIsJustPressed</a></li><li data-type='method'><a href="GlobalAPI.html#onEvent">onEvent</a></li><li data-type='method'><a href="GlobalAPI.html#play">play</a></li><li data-type='method'><a href="GlobalAPI.html#playSound">playSound</a></li><li data-type='method'><a href="GlobalAPI.html#showCursor">showCursor</a></li><li data-type='method'><a href="GlobalAPI.html#stop">stop</a></li><li data-type='method'><a href="GlobalAPI.html#stopAllSounds">stopAllSounds</a></li><li data-type='method'><a href="GlobalAPI.html#stopSound">stopSound</a></li></ul></li><li><a href="paper.SelectionGUI.html">SelectionGUI</a><ul class='methods'><li data-type='method'><a href="paper.SelectionGUI.html#destroy">destroy</a></li><li data-type='method'><a href="paper.SelectionGUI.html#moveHandleAndRotate">moveHandleAndRotate</a></li><li data-type='method'><a href="paper.SelectionGUI.html#moveHandleAndScale">moveHandleAndScale</a></li></ul></li><li><a href="paper-paper.Selection.html">Selection</a></li><li><a href="SelectionWidget.html">SelectionWidget</a><ul class='methods'><li data-type='method'><a href="SelectionWidget.html#build">build</a></li><li data-type='method'><a href="SelectionWidget.html#finishTransformation">finishTransformation</a></li><li data-type='method'><a href="SelectionWidget.html#flipHorizontally">flipHorizontally</a></li><li data-type='method'><a href="SelectionWidget.html#flipVertically">flipVertically</a></li><li data-type='method'><a href="SelectionWidget.html#rotateSelection">rotateSelection</a></li><li data-type='method'><a href="SelectionWidget.html#scaleSelection">scaleSelection</a></li><li data-type='method'><a href="SelectionWidget.html#startTransformation">startTransformation</a></li><li data-type='method'><a href="SelectionWidget.html#transformSelection">transformSelection</a></li><li data-type='method'><a href="SelectionWidget.html#translateSelection">translateSelection</a></li><li data-type='method'><a href="SelectionWidget.html#updateTransformation">updateTransformation</a></li></ul></li><li><a href="Wick.AutoSave.html">AutoSave</a><ul class='methods'><li data-type='method'><a href="Wick.AutoSave.html#.addAutosaveToList">addAutosaveToList</a></li><li data-type='method'><a href="Wick.AutoSave.html#.delete">delete</a></li><li data-type='method'><a href="Wick.AutoSave.html#.deleteAutosaveData">deleteAutosaveData</a></li><li data-type='method'><a href="Wick.AutoSave.html#.generateAutosaveData">generateAutosaveData</a></li><li data-type='method'><a href="Wick.AutoSave.html#.generateProjectFromAutosaveData">generateProjectFromAutosaveData</a></li><li data-type='method'><a href="Wick.AutoSave.html#.getAutosavesList">getAutosavesList</a></li><li data-type='method'><a href="Wick.AutoSave.html#.load">load</a></li><li data-type='method'><a href="Wick.AutoSave.html#.readAutosaveData">readAutosaveData</a></li><li data-type='method'><a href="Wick.AutoSave.html#.removeAutosaveFromList">removeAutosaveFromList</a></li><li data-type='method'><a href="Wick.AutoSave.html#.save">save</a></li><li data-type='method'><a href="Wick.AutoSave.html#.updateAutosavesList">updateAutosavesList</a></li><li data-type='method'><a href="Wick.AutoSave.html#.writeAutosaveData">writeAutosaveData</a></li></ul></li><li><a href="Wick.Base.html">Base</a><ul class='methods'><li data-type='method'><a href="Wick.Base.html#.fromData">fromData</a></li><li data-type='method'><a href="Wick.Base.html#.import">import</a></li><li data-type='method'><a href="Wick.Base.html#addChild">addChild</a></li><li data-type='method'><a href="Wick.Base.html#copy">copy</a></li><li data-type='method'><a href="Wick.Base.html#deserialize">deserialize</a></li><li data-type='method'><a href="Wick.Base.html#export">export</a></li><li data-type='method'><a href="Wick.Base.html#getChild">getChild</a></li><li data-type='method'><a href="Wick.Base.html#getChildren">getChildren</a></li><li data-type='method'><a href="Wick.Base.html#getChildrenRecursive">getChildrenRecursive</a></li><li data-type='method'><a href="Wick.Base.html#getLinkedAssets">getLinkedAssets</a></li><li data-type='method'><a href="Wick.Base.html#insertChild">insertChild</a></li><li data-type='method'><a href="Wick.Base.html#removeChild">removeChild</a></li><li data-type='method'><a href="Wick.Base.html#serialize">serialize</a></li></ul></li><li><a href="Wick.Button.html">Button</a></li><li><a href="Wick.Clip.html">Clip</a><ul class='methods'><li data-type='method'><a href="Wick.Clip.html#addObjects">addObjects</a></li><li data-type='method'><a href="Wick.Clip.html#applySingleFramePosition">applySingleFramePosition</a></li><li data-type='method'><a href="Wick.Clip.html#applySyncPosition">applySyncPosition</a></li><li data-type='method'><a href="Wick.Clip.html#breakApart">breakApart</a></li><li data-type='method'><a href="Wick.Clip.html#circleHits">circleHits</a></li><li data-type='method'><a href="Wick.Clip.html#clone">clone</a></li><li data-type='method'><a href="Wick.Clip.html#convexHits">convexHits</a></li><li data-type='method'><a href="Wick.Clip.html#ensureActiveFrameIsContentful">ensureActiveFrameIsContentful</a></li><li data-type='method'><a href="Wick.Clip.html#gotoAndPlay">gotoAndPlay</a></li><li data-type='method'><a href="Wick.Clip.html#gotoAndStop">gotoAndStop</a></li><li data-type='method'><a href="Wick.Clip.html#gotoNextFrame">gotoNextFrame</a></li><li data-type='method'><a href="Wick.Clip.html#gotoPrevFrame">gotoPrevFrame</a></li><li data-type='method'><a href="Wick.Clip.html#hits">hits</a></li><li data-type='method'><a href="Wick.Clip.html#hitTest">hitTest</a></li><li data-type='method'><a href="Wick.Clip.html#play">play</a></li><li data-type='method'><a href="Wick.Clip.html#radiusAtPointInDirection">radiusAtPointInDirection</a></li><li data-type='method'><a href="Wick.Clip.html#rectangleHits">rectangleHits</a></li><li data-type='method'><a href="Wick.Clip.html#remove">remove</a></li><li data-type='method'><a href="Wick.Clip.html#removeClone">removeClone</a></li><li data-type='method'><a href="Wick.Clip.html#resetTimelinePosition">resetTimelinePosition</a></li><li data-type='method'><a href="Wick.Clip.html#setText">setText</a></li><li data-type='method'><a href="Wick.Clip.html#stop">stop</a></li><li data-type='method'><a href="Wick.Clip.html#updateTimelineForAnimationType">updateTimelineForAnimationType</a></li></ul></li><li><a href="Wick.Clipboard.html">Clipboard</a><ul class='methods'><li data-type='method'><a href="Wick.Clipboard.html#copyObjectsToClipboard">copyObjectsToClipboard</a></li><li data-type='method'><a href="Wick.Clipboard.html#pasteObjectsFromClipboard">pasteObjectsFromClipboard</a></li></ul></li><li><a href="Wick.FileCache.html">FileCache</a><ul class='methods'><li data-type='method'><a href="Wick.FileCache.html#.addFile">addFile</a></li><li data-type='method'><a href="Wick.FileCache.html#.clear">clear</a></li><li data-type='method'><a href="Wick.FileCache.html#.getAllFiles">getAllFiles</a></li><li data-type='method'><a href="Wick.FileCache.html#.getFile">getFile</a></li><li data-type='method'><a href="Wick.FileCache.html#.loadFilesFromLocalforage">loadFilesFromLocalforage</a></li><li data-type='method'><a href="Wick.FileCache.html#.removeFile">removeFile</a></li></ul></li><li><a href="Wick.Frame.html">Frame</a><ul class='methods'><li data-type='method'><a href="Wick.Frame.html#addClip">addClip</a></li><li data-type='method'><a href="Wick.Frame.html#addPath">addPath</a></li><li data-type='method'><a href="Wick.Frame.html#addTween">addTween</a></li><li data-type='method'><a href="Wick.Frame.html#applyClipSingleFramePositions">applyClipSingleFramePositions</a></li><li data-type='method'><a href="Wick.Frame.html#applyTweenTransforms">applyTweenTransforms</a></li><li data-type='method'><a href="Wick.Frame.html#containedWithin">containedWithin</a></li><li data-type='method'><a href="Wick.Frame.html#createTween">createTween</a></li><li data-type='method'><a href="Wick.Frame.html#cut">cut</a></li><li data-type='method'><a href="Wick.Frame.html#distanceFrom">distanceFrom</a></li><li data-type='method'><a href="Wick.Frame.html#extendAndPushOtherFrames">extendAndPushOtherFrames</a></li><li data-type='method'><a href="Wick.Frame.html#getActiveTween">getActiveTween</a></li><li data-type='method'><a href="Wick.Frame.html#getLinkedAssets">getLinkedAssets</a></li><li data-type='method'><a href="Wick.Frame.html#getRelativePlayheadPosition">getRelativePlayheadPosition</a></li><li data-type='method'><a href="Wick.Frame.html#getTweenAtCurrentPlayheadPosition">getTweenAtCurrentPlayheadPosition</a></li><li data-type='method'><a href="Wick.Frame.html#getTweenAtPosition">getTweenAtPosition</a></li><li data-type='method'><a href="Wick.Frame.html#inPosition">inPosition</a></li><li data-type='method'><a href="Wick.Frame.html#inRange">inRange</a></li><li data-type='method'><a href="Wick.Frame.html#isSoundPlaying">isSoundPlaying</a></li><li data-type='method'><a href="Wick.Frame.html#playSound">playSound</a></li><li data-type='method'><a href="Wick.Frame.html#remove">remove</a></li><li data-type='method'><a href="Wick.Frame.html#removeAllTweens">removeAllTweens</a></li><li data-type='method'><a href="Wick.Frame.html#removeClip">removeClip</a></li><li data-type='method'><a href="Wick.Frame.html#removePath">removePath</a></li><li data-type='method'><a href="Wick.Frame.html#removeSound">removeSound</a></li><li data-type='method'><a href="Wick.Frame.html#removeTween">removeTween</a></li><li data-type='method'><a href="Wick.Frame.html#seekTweenBehind">seekTweenBehind</a></li><li data-type='method'><a href="Wick.Frame.html#seekTweenInFront">seekTweenInFront</a></li><li data-type='method'><a href="Wick.Frame.html#shrinkAndPullOtherFrames">shrinkAndPullOtherFrames</a></li><li data-type='method'><a href="Wick.Frame.html#stopSound">stopSound</a></li><li data-type='method'><a href="Wick.Frame.html#updateClipTimelinesForAnimationType">updateClipTimelinesForAnimationType</a></li></ul></li><li><a href="Wick.GUIElement.Project.html">Project</a><ul class='methods'><li data-type='method'><a href="Wick.GUIElement.Project.html#_onMouseWheel">_onMouseWheel</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#checkForPlayheadAutoscroll">checkForPlayheadAutoscroll</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#closePopupMenu">closePopupMenu</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#createCanvasEvent">createCanvasEvent</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#createDocumentEvent">createDocumentEvent</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#dragAssetAtPosition">dragAssetAtPosition</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#draw">draw</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#markElementAsDrawn">markElementAsDrawn</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#onProjectModified">onProjectModified</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#onProjectSoftModified">onProjectSoftModified</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#openPopupMenu">openPopupMenu</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#removeAllEventListeners">removeAllEventListeners</a></li><li data-type='method'><a href="Wick.GUIElement.Project.html#resize">resize</a></li></ul></li><li><a href="Wick.GUIElement.Timeline.html">Timeline</a><ul class='methods'><li data-type='method'><a href="Wick.GUIElement.Timeline.html#draw">draw</a></li></ul></li><li><a href="Wick.GUIElement-Wick.GUIElement.Breadcrumbs.html">Breadcrumbs</a></li><li><a href="Wick.GUIElement-Wick.GUIElement.Button.html">Button</a></li><li><a href="Wick.History.html">History</a><ul class='methods'><li data-type='method'><a href="Wick.History.html#getObjectUUIDs">getObjectUUIDs</a></li><li data-type='method'><a href="Wick.History.html#loadSnapshot">loadSnapshot</a></li><li data-type='method'><a href="Wick.History.html#popState">popState</a></li><li data-type='method'><a href="Wick.History.html#pushState">pushState</a></li><li data-type='method'><a href="Wick.History.html#recoverState">recoverState</a></li><li data-type='method'><a href="Wick.History.html#reset">reset</a></li><li data-type='method'><a href="Wick.History.html#saveSnapshot">saveSnapshot</a></li></ul></li><li><a href="Wick.HTMLExport.html">HTMLExport</a><ul class='methods'><li data-type='method'><a href="Wick.HTMLExport.html#.bundleProject">bundleProject</a></li></ul></li><li><a href="Wick.HTMLPreview.html">HTMLPreview</a><ul class='methods'><li data-type='method'><a href="Wick.HTMLPreview.html#.previewProject">previewProject</a></li></ul></li><li><a href="Wick.ImageSequence.html">ImageSequence</a><ul class='methods'><li data-type='method'><a href="Wick.ImageSequence.html#.toPNGSequence">toPNGSequence</a></li></ul></li><li><a href="Wick.Layer.html">Layer</a><ul class='methods'><li data-type='method'><a href="Wick.Layer.html#activate">activate</a></li><li data-type='method'><a href="Wick.Layer.html#addFrame">addFrame</a></li><li data-type='method'><a href="Wick.Layer.html#addTween">addTween</a></li><li data-type='method'><a href="Wick.Layer.html#findGaps">findGaps</a></li><li data-type='method'><a href="Wick.Layer.html#getFrameAtPlayheadPosition">getFrameAtPlayheadPosition</a></li><li data-type='method'><a href="Wick.Layer.html#getFramesContainedWithin">getFramesContainedWithin</a></li><li data-type='method'><a href="Wick.Layer.html#getFramesInRange">getFramesInRange</a></li><li data-type='method'><a href="Wick.Layer.html#insertBlankFrame">insertBlankFrame</a></li><li data-type='method'><a href="Wick.Layer.html#move">move</a></li><li data-type='method'><a href="Wick.Layer.html#remove">remove</a></li><li data-type='method'><a href="Wick.Layer.html#removeFrame">removeFrame</a></li><li data-type='method'><a href="Wick.Layer.html#resolveGaps">resolveGaps</a></li><li data-type='method'><a href="Wick.Layer.html#resolveOverlap">resolveOverlap</a></li></ul></li><li><a href="Wick.Path.html">Path</a><ul class='methods'><li data-type='method'><a href="Wick.Path.html#.booleanOp">booleanOp</a></li><li data-type='method'><a href="Wick.Path.html#.createImagePath">createImagePath</a></li><li data-type='method'><a href="Wick.Path.html#.createImagePathSync">createImagePathSync</a></li><li data-type='method'><a href="Wick.Path.html#.intersect">intersect</a></li><li data-type='method'><a href="Wick.Path.html#.subtract">subtract</a></li><li data-type='method'><a href="Wick.Path.html#.unite">unite</a></li><li data-type='method'><a href="Wick.Path.html#flatten">flatten</a></li><li data-type='method'><a href="Wick.Path.html#getLinkedAssets">getLinkedAssets</a></li><li data-type='method'><a href="Wick.Path.html#remove">remove</a></li><li data-type='method'><a href="Wick.Path.html#setText">setText</a></li><li data-type='method'><a href="Wick.Path.html#updateJSON">updateJSON</a></li></ul></li><li><a href="Wick.Project.html">Project</a><ul class='methods'><li data-type='method'><a href="Wick.Project.html#addAsset">addAsset</a></li><li data-type='method'><a href="Wick.Project.html#addObject">addObject</a></li><li data-type='method'><a href="Wick.Project.html#breakApartSelection">breakApartSelection</a></li><li data-type='method'><a href="Wick.Project.html#cleanupUnusedAssets">cleanupUnusedAssets</a></li><li data-type='method'><a href="Wick.Project.html#copySelectionToClipboard">copySelectionToClipboard</a></li><li data-type='method'><a href="Wick.Project.html#createClipFromLayers">createClipFromLayers</a></li><li data-type='method'><a href="Wick.Project.html#createClipFromSelection">createClipFromSelection</a></li><li data-type='method'><a href="Wick.Project.html#createClipInstanceFromAsset">createClipInstanceFromAsset</a></li><li data-type='method'><a href="Wick.Project.html#createImagePathFromAsset">createImagePathFromAsset</a></li><li data-type='method'><a href="Wick.Project.html#createSVGInstanceFromAsset">createSVGInstanceFromAsset</a></li><li data-type='method'><a href="Wick.Project.html#createTween">createTween</a></li><li data-type='method'><a href="Wick.Project.html#cutSelectedFrames">cutSelectedFrames</a></li><li data-type='method'><a href="Wick.Project.html#cutSelectionToClipboard">cutSelectionToClipboard</a></li><li data-type='method'><a href="Wick.Project.html#deleteSelectedObjects">deleteSelectedObjects</a></li><li data-type='method'><a href="Wick.Project.html#destroy">destroy</a></li><li data-type='method'><a href="Wick.Project.html#distributeSelectionToLayers">distributeSelectionToLayers</a></li><li data-type='method'><a href="Wick.Project.html#doBooleanOperationOnSelection">doBooleanOperationOnSelection</a></li><li data-type='method'><a href="Wick.Project.html#duplicateSelection">duplicateSelection</a></li><li data-type='method'><a href="Wick.Project.html#errorOccured">errorOccured</a></li><li data-type='method'><a href="Wick.Project.html#extendFrames">extendFrames</a></li><li data-type='method'><a href="Wick.Project.html#extendFramesAndPushOtherFrames">extendFramesAndPushOtherFrames</a></li><li data-type='method'><a href="Wick.Project.html#focusTimelineOfParentClip">focusTimelineOfParentClip</a></li><li data-type='method'><a href="Wick.Project.html#focusTimelineOfSelectedClip">focusTimelineOfSelectedClip</a></li><li data-type='method'><a href="Wick.Project.html#generateAudioSequence">generateAudioSequence</a></li><li data-type='method'><a href="Wick.Project.html#generateAudioTrack">generateAudioTrack</a></li><li data-type='method'><a href="Wick.Project.html#generateImageSequence">generateImageSequence</a></li><li data-type='method'><a href="Wick.Project.html#generateSoundInfo">generateSoundInfo</a></li><li data-type='method'><a href="Wick.Project.html#getAllFrames">getAllFrames</a></li><li data-type='method'><a href="Wick.Project.html#getAllOnionSkinnedFrames">getAllOnionSkinnedFrames</a></li><li data-type='method'><a href="Wick.Project.html#getAssetByName">getAssetByName</a></li><li data-type='method'><a href="Wick.Project.html#getAssetByUUID">getAssetByUUID</a></li><li data-type='method'><a href="Wick.Project.html#getAssets">getAssets</a></li><li data-type='method'><a href="Wick.Project.html#getAudioInfo">getAudioInfo</a></li><li data-type='method'><a href="Wick.Project.html#getFonts">getFonts</a></li><li data-type='method'><a href="Wick.Project.html#getObjectByUUID">getObjectByUUID</a></li><li data-type='method'><a href="Wick.Project.html#hasFont">hasFont</a></li><li data-type='method'><a href="Wick.Project.html#importFile">importFile</a></li><li data-type='method'><a href="Wick.Project.html#initialize">initialize</a></li><li data-type='method'><a href="Wick.Project.html#inject">inject</a></li><li data-type='method'><a href="Wick.Project.html#insertBlankFrame">insertBlankFrame</a></li><li data-type='method'><a href="Wick.Project.html#isKeyDown">isKeyDown</a></li><li data-type='method'><a href="Wick.Project.html#isKeyJustPressed">isKeyJustPressed</a></li><li data-type='method'><a href="Wick.Project.html#loadAssets">loadAssets</a></li><li data-type='method'><a href="Wick.Project.html#moveSelectedFramesLeft">moveSelectedFramesLeft</a></li><li data-type='method'><a href="Wick.Project.html#moveSelectedFramesRight">moveSelectedFramesRight</a></li><li data-type='method'><a href="Wick.Project.html#moveSelection">moveSelection</a></li><li data-type='method'><a href="Wick.Project.html#mute">mute</a></li><li data-type='method'><a href="Wick.Project.html#objectIsMouseTarget">objectIsMouseTarget</a></li><li data-type='method'><a href="Wick.Project.html#onError">onError</a></li><li data-type='method'><a href="Wick.Project.html#pasteClipboardContents">pasteClipboardContents</a></li><li data-type='method'><a href="Wick.Project.html#play">play</a></li><li data-type='method'><a href="Wick.Project.html#playSound">playSound</a></li><li data-type='method'><a href="Wick.Project.html#playSoundFromAsset">playSoundFromAsset</a></li><li data-type='method'><a href="Wick.Project.html#prepareProjectForEditor">prepareProjectForEditor</a></li><li data-type='method'><a href="Wick.Project.html#recenter">recenter</a></li><li data-type='method'><a href="Wick.Project.html#redo">redo</a></li><li data-type='method'><a href="Wick.Project.html#removeAsset">removeAsset</a></li><li data-type='method'><a href="Wick.Project.html#resetCache">resetCache</a></li><li data-type='method'><a href="Wick.Project.html#resetTools">resetTools</a></li><li data-type='method'><a href="Wick.Project.html#resetZoomAndPan">resetZoomAndPan</a></li><li data-type='method'><a href="Wick.Project.html#runScheduledScripts">runScheduledScripts</a></li><li data-type='method'><a href="Wick.Project.html#scheduleScript">scheduleScript</a></li><li data-type='method'><a href="Wick.Project.html#selectAll">selectAll</a></li><li data-type='method'><a href="Wick.Project.html#shrinkFrames">shrinkFrames</a></li><li data-type='method'><a href="Wick.Project.html#shrinkFramesAndPullOtherFrames">shrinkFramesAndPullOtherFrames</a></li><li data-type='method'><a href="Wick.Project.html#stop">stop</a></li><li data-type='method'><a href="Wick.Project.html#stopAllSounds">stopAllSounds</a></li><li data-type='method'><a href="Wick.Project.html#stopSound">stopSound</a></li><li data-type='method'><a href="Wick.Project.html#tick">tick</a></li><li data-type='method'><a href="Wick.Project.html#tryToAutoCreateTween">tryToAutoCreateTween</a></li><li data-type='method'><a href="Wick.Project.html#undo">undo</a></li><li data-type='method'><a href="Wick.Project.html#unmute">unmute</a></li><li data-type='method'><a href="Wick.Project.html#zoomIn">zoomIn</a></li><li data-type='method'><a href="Wick.Project.html#zoomOut">zoomOut</a></li></ul></li><li><a href="Wick.Selection.html">Selection</a><ul class='methods'><li data-type='method'><a href="Wick.Selection.html#bringToFront">bringToFront</a></li><li data-type='method'><a href="Wick.Selection.html#clear">clear</a></li><li data-type='method'><a href="Wick.Selection.html#deselect">deselect</a></li><li data-type='method'><a href="Wick.Selection.html#deselectMultipleObjects">deselectMultipleObjects</a></li><li data-type='method'><a href="Wick.Selection.html#flipHorizontally">flipHorizontally</a></li><li data-type='method'><a href="Wick.Selection.html#flipVertically">flipVertically</a></li><li data-type='method'><a href="Wick.Selection.html#getLeftmostFrames">getLeftmostFrames</a></li><li data-type='method'><a href="Wick.Selection.html#getRightmostFrames">getRightmostFrames</a></li><li data-type='method'><a href="Wick.Selection.html#getSelectedObject">getSelectedObject</a></li><li data-type='method'><a href="Wick.Selection.html#getSelectedObjects">getSelectedObjects</a></li><li data-type='method'><a href="Wick.Selection.html#getSelectedObjectUUIDs">getSelectedObjectUUIDs</a></li><li data-type='method'><a href="Wick.Selection.html#isObjectSelected">isObjectSelected</a></li><li data-type='method'><a href="Wick.Selection.html#isSelectable">isSelectable</a></li><li data-type='method'><a href="Wick.Selection.html#moveBackwards">moveBackwards</a></li><li data-type='method'><a href="Wick.Selection.html#moveForwards">moveForwards</a></li><li data-type='method'><a href="Wick.Selection.html#select">select</a></li><li data-type='method'><a href="Wick.Selection.html#selectMultipleObjects">selectMultipleObjects</a></li><li data-type='method'><a href="Wick.Selection.html#sendToBack">sendToBack</a></li></ul></li><li><a href="Wick.SVGFile.html">SVGFile</a><ul class='methods'><li data-type='method'><a href="Wick.SVGFile.html#.fromSVGFile">fromSVGFile</a></li><li data-type='method'><a href="Wick.SVGFile.html#.toSVGFile">toSVGFile</a></li></ul></li><li><a href="Wick.Tickable.html">Tickable</a><ul class='methods'><li data-type='method'><a href="Wick.Tickable.html#_runFunction">_runFunction</a></li><li data-type='method'><a href="Wick.Tickable.html#addEventFn">addEventFn</a></li><li data-type='method'><a href="Wick.Tickable.html#addScript">addScript</a></li><li data-type='method'><a href="Wick.Tickable.html#getAvailableScripts">getAvailableScripts</a></li><li data-type='method'><a href="Wick.Tickable.html#getEventFns">getEventFns</a></li><li data-type='method'><a href="Wick.Tickable.html#getScript">getScript</a></li><li data-type='method'><a href="Wick.Tickable.html#hasScript">hasScript</a></li><li data-type='method'><a href="Wick.Tickable.html#onEvent">onEvent</a></li><li data-type='method'><a href="Wick.Tickable.html#removeScript">removeScript</a></li><li data-type='method'><a href="Wick.Tickable.html#runScript">runScript</a></li><li data-type='method'><a href="Wick.Tickable.html#scheduleScript">scheduleScript</a></li><li data-type='method'><a href="Wick.Tickable.html#scriptIsContentful">scriptIsContentful</a></li><li data-type='method'><a href="Wick.Tickable.html#tick">tick</a></li><li data-type='method'><a href="Wick.Tickable.html#updateScript">updateScript</a></li></ul></li><li><a href="Wick.Timeline.html">Timeline</a><ul class='methods'><li data-type='method'><a href="Wick.Timeline.html#addFrame">addFrame</a></li><li data-type='method'><a href="Wick.Timeline.html#addLayer">addLayer</a></li><li data-type='method'><a href="Wick.Timeline.html#addTween">addTween</a></li><li data-type='method'><a href="Wick.Timeline.html#advance">advance</a></li><li data-type='method'><a href="Wick.Timeline.html#deferFrameGapResolve">deferFrameGapResolve</a></li><li data-type='method'><a href="Wick.Timeline.html#forceFrame">forceFrame</a></li><li data-type='method'><a href="Wick.Timeline.html#getAllFrames">getAllFrames</a></li><li data-type='method'><a href="Wick.Timeline.html#getFrameByName">getFrameByName</a></li><li data-type='method'><a href="Wick.Timeline.html#getFramesAtPlayheadPosition">getFramesAtPlayheadPosition</a></li><li data-type='method'><a href="Wick.Timeline.html#getFramesInRange">getFramesInRange</a></li><li data-type='method'><a href="Wick.Timeline.html#gotoAndPlay">gotoAndPlay</a></li><li data-type='method'><a href="Wick.Timeline.html#gotoAndStop">gotoAndStop</a></li><li data-type='method'><a href="Wick.Timeline.html#gotoFrame">gotoFrame</a></li><li data-type='method'><a href="Wick.Timeline.html#gotoNextFrame">gotoNextFrame</a></li><li data-type='method'><a href="Wick.Timeline.html#gotoPrevFrame">gotoPrevFrame</a></li><li data-type='method'><a href="Wick.Timeline.html#makeTimelineInBounds">makeTimelineInBounds</a></li><li data-type='method'><a href="Wick.Timeline.html#moveLayer">moveLayer</a></li><li data-type='method'><a href="Wick.Timeline.html#play">play</a></li><li data-type='method'><a href="Wick.Timeline.html#removeLayer">removeLayer</a></li><li data-type='method'><a href="Wick.Timeline.html#resolveFrameGaps">resolveFrameGaps</a></li><li data-type='method'><a href="Wick.Timeline.html#resolveFrameOverlap">resolveFrameOverlap</a></li><li data-type='method'><a href="Wick.Timeline.html#stop">stop</a></li></ul></li><li><a href="Wick.Tools-Wick.Tools.Brush.html">Brush</a></li><li><a href="Wick.Tools-Wick.Tools.Cursor.html">Cursor</a></li><li><a href="Wick.Tools-Wick.Tools.Ellipse.html">Ellipse</a></li><li><a href="Wick.Tools-Wick.Tools.Eraser.html">Eraser</a></li><li><a href="Wick.Tools-Wick.Tools.Eyedropper.html">Eyedropper</a></li><li><a href="Wick.Tools-Wick.Tools.FillBucket.html">FillBucket</a></li><li><a href="Wick.Tools-Wick.Tools.Interact.html">Interact</a></li><li><a href="Wick.Tools-Wick.Tools.Line.html">Line</a></li><li><a href="Wick.Tools-Wick.Tools.None.html">None</a></li><li><a href="Wick.Tools-Wick.Tools.Pan.html">Pan</a></li><li><a href="Wick.Tools-Wick.Tools.Pencil.html">Pencil</a></li><li><a href="Wick.Tools-Wick.Tools.Rectangle.html">Rectangle</a></li><li><a href="Wick.Tools-Wick.Tools.Text.html">Text</a></li><li><a href="Wick.Tools-Wick.Tools.Zoom.html">Zoom</a></li><li><a href="Wick.Transformation.html">Transformation</a><ul class='methods'><li data-type='method'><a href="Wick.Transformation.html#copy">copy</a></li></ul></li><li><a href="Wick.Tween.html">Tween</a><ul class='methods'><li data-type='method'><a href="Wick.Tween.html#.interpolate">interpolate</a></li><li data-type='method'><a href="Wick.Tween.html#applyTransformsToClip">applyTransformsToClip</a></li><li data-type='method'><a href="Wick.Tween.html#getNextTween">getNextTween</a></li><li data-type='method'><a href="Wick.Tween.html#remove">remove</a></li><li data-type='method'><a href="Wick.Tween.html#restrictToFrameSize">restrictToFrameSize</a></li></ul></li><li><a href="Wick.View-Wick.View.Clip.html">Clip</a></li><li><a href="Wick.View-Wick.View.Frame.html">Frame</a></li><li><a href="Wick.View-Wick.View.Path.html">Path</a></li><li><a href="Wick.View-Wick.View.Selection.html">Selection</a></li><li><a href="Wick.WickFile.html">WickFile</a><ul class='methods'><li data-type='method'><a href="Wick.WickFile.html#.fromWickFile">fromWickFile</a></li><li data-type='method'><a href="Wick.WickFile.html#.generateMetaData">generateMetaData</a></li><li data-type='method'><a href="Wick.WickFile.html#.toWickFile">toWickFile</a></li></ul></li><li><a href="Wick.WickObjectFile.html">WickObjectFile</a><ul class='methods'><li data-type='method'><a href="Wick.WickObjectFile.html#.fromWickObjectFile">fromWickObjectFile</a></li><li data-type='method'><a href="Wick.WickObjectFile.html#.toWickObjectFile">toWickObjectFile</a></li></ul></li><li><a href="Wick.ZIPExport.html">ZIPExport</a></li><li><a href="WickObjectCache.html">WickObjectCache</a><ul class='methods'><li data-type='method'><a href="WickObjectCache.html#addObject">addObject</a></li><li data-type='method'><a href="WickObjectCache.html#clear">clear</a></li><li data-type='method'><a href="WickObjectCache.html#clearObjectToBeAutosaved">clearObjectToBeAutosaved</a></li><li data-type='method'><a href="WickObjectCache.html#getActiveObjects">getActiveObjects</a></li><li data-type='method'><a href="WickObjectCache.html#getAllObjects">getAllObjects</a></li><li data-type='method'><a href="WickObjectCache.html#getObjectByUUID">getObjectByUUID</a></li><li data-type='method'><a href="WickObjectCache.html#getObjectsNeedAutosaved">getObjectsNeedAutosaved</a></li><li data-type='method'><a href="WickObjectCache.html#markObjectToBeAutosaved">markObjectToBeAutosaved</a></li><li data-type='method'><a href="WickObjectCache.html#objectNeedsAutosave">objectNeedsAutosave</a></li><li data-type='method'><a href="WickObjectCache.html#removeObject">removeObject</a></li><li data-type='method'><a href="WickObjectCache.html#removeObjectByUUID">removeObjectByUUID</a></li><li data-type='method'><a href="WickObjectCache.html#removeTemporaryObjects">removeTemporaryObjects</a></li><li data-type='method'><a href="WickObjectCache.html#removeUnusedObjects">removeUnusedObjects</a></li></ul></li><li><a href="Wick-Wick.Asset.html">Asset</a></li><li><a href="Wick-Wick.AudioTrack.html">AudioTrack</a></li><li><a href="Wick-Wick.ClipAsset.html">ClipAsset</a></li><li><a href="Wick-Wick.Color.html">Color</a></li><li><a href="Wick-Wick.FileAsset.html">FileAsset</a></li><li><a href="Wick-Wick.FontAsset.html">FontAsset</a></li><li><a href="Wick-Wick.GIFAsset.html">GIFAsset</a></li><li><a href="Wick-Wick.GUIElement.html">GUIElement</a></li><li><a href="Wick-Wick.ImageAsset.html">ImageAsset</a></li><li><a href="Wick-Wick.SoundAsset.html">SoundAsset</a></li><li><a href="Wick-Wick.SVGAsset.html">SVGAsset</a></li><li><a href="Wick-Wick.Tool.html">Tool</a></li><li><a href="Wick-Wick.ToolSettings.html">ToolSettings</a></li><li><a href="Wick-Wick.View.html">View</a></li></ul><h3>Global</h3><ul><li><a href="global.html#type">type</a></li><li><a href="global.html#Wick">Wick</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">export/audio/AudioTrack.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Copyright 2020 WICKLETS LLC
*
* This file is part of Wick Engine.
*
* Wick Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wick Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wick Engine. If not, see <https://www.gnu.org/licenses/>.
*/
Wick.AudioTrack = class {
/**
* @type {Wick.Project}
*/
get project () {
return this._project;
}
set project (project) {
this._project = project;
}
/**
* Create a new AudioTrack
* @param {Wick.Project} project - the project to use audio from
*/
constructor (project) {
this._project = project;
}
/**
* Generate an AudioBuffer of all the project's sounds as one audio track.
* Can take sound information from a generated sequence.
* @param {Object} args - callback, onProgress, soundInfo
*/
toAudioBuffer (args) {
if (!args) args = {};
if (!args.callback) args.callback = () => {}
if (!args.onProgress) args.onProgress = (frame, maxFrames) => {}
let genBuffer = (audioInfo) => {
if (!audioInfo) args.callback(null);
if(audioInfo.length === 0) {
// No audio in the project, no AudioBuffer to create
args.callback(null);
return;
}
Wick.AudioTrack.generateProjectAudioBuffer(audioInfo, audioArraybuffer => {
args.callback(audioArraybuffer);
},
args.onProgress);
}
// If audio information is passed in from a previous render, use that. Otherwise, render it again.
if (args.soundInfo) {
genBuffer(args.soundInfo);
} else {
this.project.generateAudioSequence({
onFinish: genBuffer,
onProgress: args.onProgress,
});
}
}
/**
* Create an AudioBuffer from given sounds.
* @param {object[]} projectAudioInfo - infor generated on sounds played in the project.
* @param {Function} callback - callback to recieve the generated AudioBuffer
* @param {Function} onProgress(message, progress) - A function which receive a message.
*/
static generateProjectAudioBuffer (projectAudioInfo, callback, onProgress) {
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var ctx = new AudioContext();
let audiobuffers = [];
let mergeAudio = () => {
onProgress && onProgress("Merging Audio");
audiobuffers.sort((a,b) => {return(a.duration - b.duration)})
let i=0;
let mergedAudioBuffer = audiobuffers.reduce((buffer1, buffer2) => {
let buf = this.mergeBuffers([buffer1, buffer2], ctx, onProgress);
i += 1;
return buf;
});
callback(mergedAudioBuffer);
}
for (let i=0; i<projectAudioInfo.length; i++) {
let audioInfo = projectAudioInfo[i];
this.base64ToAudioBuffer(audioInfo.src, ctx, audiobuffer => {
let offset = audioInfo.offset || 0; // Milliseconds to offset.
let offsetSeconds = offset / 1000; // Adjust to seconds.
let startSeconds = audioInfo.start / 1000;
let endSeconds = audioInfo.end / 1000;
let lengthSeconds = endSeconds - startSeconds;
let volume = audioInfo.volume || 1;
let shiftedAudioBuffer = this.offsetAudioBuffer(audiobuffer, offsetSeconds, ctx);
let croppedAudioBuffer = this.cropAudioBuffer(shiftedAudioBuffer, lengthSeconds, ctx);
let volumeAdjustedAudioBuffer = this.adjustBufferVolume(croppedAudioBuffer, volume, ctx);
let delayedAudiobuffer = this.addStartDelayToAudioBuffer(volumeAdjustedAudioBuffer, startSeconds, ctx);
onProgress && onProgress("Creating Audio " + (i+1) + "/" + projectAudioInfo.length, (i+1)/projectAudioInfo.length);
audiobuffers.push(delayedAudiobuffer);
if (audiobuffers.length >= projectAudioInfo.length) {
mergeAudio();
}
});
}
}
/*
* Merges multiple audiobuffers into a single audiobuffer.
* @param {AudioBuffer[]} buffers - the AudioBuffers to merge together
* @param {AudioContext} ac - An AudioContext instance
*/
static mergeBuffers(buffers, ac, onProgress) {
// original function from:
// https://github.com/meandavejustice/merge-audio-buffers/blob/master/index.js
var maxChannels = 0;
var maxDuration = 0;
// Send back an empty buffer if no information was sent in.
if (!buffers || (buffers && buffers.length === 0)) {
return ac.createBuffer(
2,
1000,
48000,
)
}
// Review the incoming audio to determine output buffer size.
for (let i = 0; i < buffers.length; i++) {
onProgress("Reviewing Audio " + (i+1) + "/" + buffers.length, (i+1) + "/" + buffers.length)
if (buffers[i].numberOfChannels > maxChannels) {
maxChannels = buffers[i].numberOfChannels;
}
if (buffers[i].duration > maxDuration) {
maxDuration = buffers[i].duration;
}
}
// Create new output buffer.
var out = ac.createBuffer(
maxChannels,
ac.sampleRate * maxDuration,
ac.sampleRate
);
for (var i = 0; i < buffers.length; i++) {
onProgress("Merging Audio " + (i+1) + "/" + buffers.length, (i+1) + "/" + buffers.length);
// Go through each channel of the new audio source and copy that data into the output buffer.
for (var srcChannel = 0; srcChannel < buffers[i].numberOfChannels; srcChannel++) {
var outt = out.getChannelData(srcChannel);
var inn = buffers[i].getChannelData(srcChannel);
for (let j = 0; j < inn.length; j++) {
let val = inn[j];
// Some sounds may have corrupted data... don't copy that over.
if (val) {
outt[j] += val;
}
}
out.getChannelData(srcChannel).set(outt, 0);
}
}
return out;
}
/**
* Offsets an audio buffer by a number of seconds.
* @param {audioBuffer} originalBuffer - Buffer to offset.
* @param {Number} offsetSeconds - Number of seconds to offset. Can be negative.
* @param {AudioContext} ctx - Context to use.
* @returns {audioBuffer} - A copy of the audio buffer, offset by the provided number of seconds.
*/
static offsetAudioBuffer(originalBuffer, offsetSeconds, ctx) {
// Create a blank buffer with the length of the original buffer.
var offsetBuffer = ctx.createBuffer(
originalBuffer.numberOfChannels,
originalBuffer.length,
ctx.sampleRate,
);
let copyto = 0;
let copyfrom = 0;
if (offsetSeconds < 0) {
copyto = (-1 * offsetSeconds) * ctx.sampleRate;
} else {
copyfrom = offsetSeconds * ctx.sampleRate;
}
// Copy buffer information.
for (var srcChannel = 0; srcChannel < offsetBuffer.numberOfChannels; srcChannel++) {
// Retrieve sample data...
var offsetBufferChannelData = offsetBuffer.getChannelData(srcChannel);
var originalBufferChannelData = originalBuffer.getChannelData(srcChannel);
// Copy samples from the original buffer to the adjusted buffer, adjusting for the number of seconds to offset.
for (var i=0; i < offsetBufferChannelData.length; i++) {
if ((i + copyfrom) > originalBufferChannelData.length) {
break;
} else if ((i + copyto) > offsetBufferChannelData.length) {
break;
}
offsetBufferChannelData[i + copyto] = originalBufferChannelData[i + copyfrom];
}
offsetBuffer.getChannelData(srcChannel).set(offsetBufferChannelData, 0);
}
return offsetBuffer;
}
/**
* Crops an AudioBuffer to a given length.
* @param {AudioBuffer} originalBuffer - the buffer to crop
* @param {number} delaySeconds - the time, in seconds, to crop the sound at
* @param {AudioContext} ctx - An AudioContext instance
* @returns {AudioBuffer} - The a copy of the buffer, cropped to the specified length.
*/
static cropAudioBuffer (originalBuffer, lengthSeconds, ctx) {
// Create a blank buffer with a length of the crop amount
var croppedBuffer = ctx.createBuffer(
originalBuffer.numberOfChannels,
ctx.sampleRate * lengthSeconds,
ctx.sampleRate,
);
// Copy data from the original buffer into the cropped buffer
for (var srcChannel = 0; srcChannel < croppedBuffer.numberOfChannels; srcChannel++) {
// Retrieve sample data...
var croppedBufferChannelData = croppedBuffer.getChannelData(srcChannel);
var originalBufferChannelData = originalBuffer.getChannelData(srcChannel);
// Copy samples from the original buffer to the cropped buffer
for (var i = 0; i < croppedBufferChannelData.length; i++) {
croppedBufferChannelData[i] = originalBufferChannelData[i];
}
croppedBuffer.getChannelData(srcChannel).set(croppedBufferChannelData, 0);
}
return croppedBuffer;
}
/**
* Adjusts the volume of an audio buffer.
* @param {*} originalBuffer - The original buffer to adjust.
* @param {*} volume - A value between 0 and +Infinity. Values above 1 may cause clipping.
* @param {*} ctx - The audio context to use for buffer generation.
* @returns {AudioBuffer} - Adjusted audio buffer with new volume.
*/
static adjustBufferVolume (originalBuffer, volume, ctx) {
// Create a blank buffer with the length of the original buffer.
var adjustedBuffer = ctx.createBuffer(
originalBuffer.numberOfChannels,
originalBuffer.length,
ctx.sampleRate,
);
// Volume should be at least 0.
volume = Math.max(volume, 0);
for (var srcChannel = 0; srcChannel < adjustedBuffer.numberOfChannels; srcChannel++) {
// Retrieve sample data...
var adjustedBufferChannelData = adjustedBuffer.getChannelData(srcChannel);
var originalBufferChannelData = originalBuffer.getChannelData(srcChannel);
// Copy samples from the original buffer to the adjusted buffer, adjusting for volume.
for (var i = 0; i < adjustedBufferChannelData.length; i++) {
adjustedBufferChannelData[i] = originalBufferChannelData[i] * volume;
}
adjustedBuffer.getChannelData(srcChannel).set(adjustedBufferChannelData, 0);
}
return adjustedBuffer;
}
/**
* Adds silence to the beginning of an AudioBuffer with a given length.
* @param {AudioBuffer} originalBuffer - the buffer to pad with silence
* @param {number} delaySeconds - the amount of time, in seconds, to delay the sound
* @param {AudioContext} ctx - An AudioContext instance
*/
static addStartDelayToAudioBuffer (originalBuffer, delaySeconds, ctx) {
// Create buffer with a length equal to the original buffer's length plus the requested delay
let lengthOfDelay = ctx.sampleRate * delaySeconds;
let lengthOfOriginalSound = ctx.sampleRate * originalBuffer.duration;
var delayedBuffer = ctx.createBuffer(
originalBuffer.numberOfChannels,
lengthOfDelay + lengthOfOriginalSound,
ctx.sampleRate,
);
// For each channel in the audiobuffer...
for (var srcChannel = 0; srcChannel < originalBuffer.numberOfChannels; srcChannel++) {
// Retrieve sample data...
var originalBufferChannelData = originalBuffer.getChannelData(srcChannel);
// Copy samples from the original buffer to the delayed buffer with an offset equal to the delay
var delayOffset = ctx.sampleRate * delaySeconds;
try {
// Copy in the data from the original buffer into the delayed buffer, starting at the delayed position.
delayedBuffer.getChannelData(srcChannel).set(originalBufferChannelData, delayOffset);
} catch (e) {
console.error(e);
console.error("A sound was not added to the project.")
}
}
return delayedBuffer;
}
/**
* Convert a base64 string of an audio file into an AudioBuffer.
* @param {string} base64 - a base64 dataURI of an audio file.
* @param {AudioContext} ctx - an AudioContext instance.
* @param {Function} callback - callback to recieve the generated AudioBuffer
*/
static base64ToAudioBuffer (base64, ctx, callback) {
let base64DataOnly = base64.split(',')[1];
let arraybuffer = Base64ArrayBuffer.decode(base64DataOnly);
ctx.decodeAudioData(arraybuffer, function(audioBuffer) {
callback(audioBuffer);
}, (e) => {
console.log('onError');
console.log(e);
});
}
}
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.11</a> on Sat Mar 01 2025 20:10:08 GMT-0300 (Brasilia Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>