Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ScriptProcessorNode in p5.SoundRecorder with AudioWorkletNode #369

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["preval"]
}
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eol-last": ["error", "always"],
"guard-for-in": 2,
"indent": ["error", 2, { "SwitchCase": 1 }],
"max-len": [1, 120, 2, {ignoreComments: true}],
"max-len": [1, 120, 2, { "ignoreComments": true }],
"new-cap": 2,
"no-caller": 2,
"no-cond-assign": [
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
examples/__test
p5soundnotes
*.DS_Store
.vscode
306 changes: 157 additions & 149 deletions lib/p5.sound.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/p5.sound.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/p5.sound.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/p5.sound.min.js.map

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,21 @@
"almond": "~0.2.7",
"amdclean": "~2.0",
"babel-loader": "^8.0.6",
"babel-plugin-preval": "^3.0.1",
"grunt": "~0.4.5",
"grunt-cli": "^0.1.13",
"grunt-contrib-connect": "^1.0.2",
"grunt-eslint": "^20.0.0",
"grunt-mocha": "^1.0.4",
"grunt-open": "^0.2.3",
"grunt-webpack": "^3.1.3",
"raw-loader": "^3.0.0",
"uglify-loader": "^3.0.0",
"uglifyjs-webpack-plugin": "^2.1.3",
"webpack": "^4.33.0"
},
"dependencies": {
"audioworklet-polyfill": "^1.1.2",
"startaudiocontext": "^1.2.1",
"tone": "0.10.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

define(function (require) {

require('audioworklet-polyfill');
require('shims');
require('audiocontext');
var p5SOUND = require('master');
require('helpers');
require('errorHandler');
require('audioWorklet');
require('panner');
require('soundfile');
require('amplitude');
Expand Down
11 changes: 11 additions & 0 deletions src/audioWorklet/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"globals": {
"currentFrame": true,
"currentTime": true,
"sampleRate": true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so this is global to the AudioWorklet global scope? Maybe worth adding the other attributes listed here?
https://www.w3.org/TR/webaudio/#AudioWorkletGlobalScope-attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that's a good suggestion, I'll go ahead and add the other two global variables listed there

"preval": true
},
"parserOptions": {
"sourceType": "module"
}
}
26 changes: 26 additions & 0 deletions src/audioWorklet/index.js
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);
});
3 changes: 3 additions & 0 deletions src/audioWorklet/processorNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
recorderProcessor: 'recorder-processor'
};
Loading