Skip to content

Commit cc4abf7

Browse files
committed
set amplitude smoothing parameter via message port
1 parent 03d7099 commit cc4abf7

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/amplitude.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ define(function (require) {
5353
this.audiocontext = p5sound.audiocontext;
5454
this._workletNode = new AudioWorkletNode(this.audiocontext, processorNames.amplitudeProcessor, {
5555
outputChannelCount: [1],
56-
parameterData: { smoothing: smoothing || 0 },
57-
processorOptions: { normalize: false }
56+
processorOptions: {
57+
normalize: false,
58+
smoothing: smoothing || 0
59+
}
5860
});
5961

6062
this._workletNode.port.onmessage = function(event) {
@@ -256,7 +258,7 @@ define(function (require) {
256258
*/
257259
p5.Amplitude.prototype.smooth = function(s) {
258260
if (s >= 0 && s < 1) {
259-
this._workletNode.parameters.get('smoothing').value = s;
261+
this._workletNode.port.postMessage({ name: 'smoothing', smoothing: s });
260262
} else {
261263
console.log('Error: smoothing must be between 0 and 1');
262264
}

src/audioWorklet/amplitudeProcessor.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,11 @@
22
const processorNames = preval.require('./processorNames');
33

44
class AmplitudeProcessor extends AudioWorkletProcessor {
5-
static get parameterDescriptors() {
6-
return [
7-
{
8-
name: 'smoothing',
9-
defaultValue: 0,
10-
minValue: 0,
11-
maxValue: 1,
12-
automationRate: 'k-rate'
13-
}
14-
];
15-
}
16-
175
constructor(options) {
186
super();
197

208
const processorOptions = options.processorOptions || {};
9+
this.smoothing = processorOptions.smoothing || 0;
2110
this.normalize = processorOptions.normalize || false;
2211

2312
this.stereoVol = [0, 0];
@@ -29,15 +18,17 @@ class AmplitudeProcessor extends AudioWorkletProcessor {
2918
const data = event.data;
3019
if (data.name === 'toggleNormalize') {
3120
this.normalize = data.normalize;
21+
} else if (data.name === 'smoothing') {
22+
this.smoothing = Math.max(0, Math.min(1, data.smoothing));
3223
}
3324
};
3425
}
3526

3627
// TO DO make this stereo / dependent on # of audio channels
37-
process(inputs, outputs, parameters) {
28+
process(inputs, outputs) {
3829
const input = inputs[0];
3930
const output = outputs[0];
40-
const smoothing = parameters.smoothing;
31+
const smoothing = this.smoothing;
4132

4233
for (let channel = 0; channel < input.length; ++channel) {
4334
const inputBuffer = input[channel];

0 commit comments

Comments
 (0)