-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ScriptProcessorNode in p5.SoundRecorder with AudioWorkletNode (…
…#369) Replace scriptProcessorNode in p5.SoundRecorder with transpiled AudioWorkletNode; polyfill AudioWorklet
- Loading branch information
Showing
17 changed files
with
520 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": ["preval"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules | |
examples/__test | ||
p5soundnotes | ||
*.DS_Store | ||
.vscode |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"globals": { | ||
"currentFrame": true, | ||
"currentTime": true, | ||
"sampleRate": true, | ||
"preval": true | ||
}, | ||
"parserOptions": { | ||
"sourceType": "module" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const p5sound = require('master'); | ||
const moduleSources = [ | ||
require('raw-loader!./recorderProcessor').default | ||
]; | ||
const ac = p5sound.audiocontext; | ||
|
||
function loadAudioWorkletModules() { | ||
return Promise.all(moduleSources.map(function(moduleSrc) { | ||
const blob = new Blob([moduleSrc], { type: 'application/javascript' }); | ||
const objectURL = URL.createObjectURL(blob); | ||
return ac.audioWorklet.addModule(objectURL); | ||
})); | ||
} | ||
|
||
p5.prototype.registerMethod('init', function() { | ||
// ensure that a preload function exists so that p5 will wait for preloads to finish | ||
if (!this.preload && !window.preload) { | ||
this.preload = function() {}; | ||
} | ||
// use p5's preload system to load necessary AudioWorklet modules before setup() | ||
this._preloadCount++; | ||
const onWorkletModulesLoad = function() { | ||
this._decrementPreload(); | ||
}.bind(this); | ||
loadAudioWorkletModules().then(onWorkletModulesLoad); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
recorderProcessor: 'recorder-processor' | ||
}; |
Oops, something went wrong.