File tree Expand file tree Collapse file tree 2 files changed +10
-17
lines changed Expand file tree Collapse file tree 2 files changed +10
-17
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,10 @@ define(function (require) {
53
53
this . audiocontext = p5sound . audiocontext ;
54
54
this . _workletNode = new AudioWorkletNode ( this . audiocontext , processorNames . amplitudeProcessor , {
55
55
outputChannelCount : [ 1 ] ,
56
- parameterData : { smoothing : smoothing || 0 } ,
57
- processorOptions : { normalize : false }
56
+ processorOptions : {
57
+ normalize : false ,
58
+ smoothing : smoothing || 0
59
+ }
58
60
} ) ;
59
61
60
62
this . _workletNode . port . onmessage = function ( event ) {
@@ -256,7 +258,7 @@ define(function (require) {
256
258
*/
257
259
p5 . Amplitude . prototype . smooth = function ( s ) {
258
260
if ( s >= 0 && s < 1 ) {
259
- this . _workletNode . parameters . get ( 'smoothing' ) . value = s ;
261
+ this . _workletNode . port . postMessage ( { name : 'smoothing' , smoothing : s } ) ;
260
262
} else {
261
263
console . log ( 'Error: smoothing must be between 0 and 1' ) ;
262
264
}
Original file line number Diff line number Diff line change 2
2
const processorNames = preval . require ( './processorNames' ) ;
3
3
4
4
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
-
17
5
constructor ( options ) {
18
6
super ( ) ;
19
7
20
8
const processorOptions = options . processorOptions || { } ;
9
+ this . smoothing = processorOptions . smoothing || 0 ;
21
10
this . normalize = processorOptions . normalize || false ;
22
11
23
12
this . stereoVol = [ 0 , 0 ] ;
@@ -29,15 +18,17 @@ class AmplitudeProcessor extends AudioWorkletProcessor {
29
18
const data = event . data ;
30
19
if ( data . name === 'toggleNormalize' ) {
31
20
this . normalize = data . normalize ;
21
+ } else if ( data . name === 'smoothing' ) {
22
+ this . smoothing = Math . max ( 0 , Math . min ( 1 , data . smoothing ) ) ;
32
23
}
33
24
} ;
34
25
}
35
26
36
27
// TO DO make this stereo / dependent on # of audio channels
37
- process ( inputs , outputs , parameters ) {
28
+ process ( inputs , outputs ) {
38
29
const input = inputs [ 0 ] ;
39
30
const output = outputs [ 0 ] ;
40
- const smoothing = parameters . smoothing ;
31
+ const smoothing = this . smoothing ;
41
32
42
33
for ( let channel = 0 ; channel < input . length ; ++ channel ) {
43
34
const inputBuffer = input [ channel ] ;
You can’t perform that action at this time.
0 commit comments