1
- import "./Superpowered.js" ;
1
+ import "./assets/ Superpowered.js" ;
2
2
3
3
var webaudioManager = null ; // The SuperpoweredWebAudio helper class managing Web Audio for us.
4
4
var Superpowered = null ; // A Superpowered instance.
@@ -10,11 +10,14 @@ var pbPerc = null;
10
10
11
11
function changePitchShift ( e ) {
12
12
// limiting the new pitch shift value
13
- let value = parseInt ( e . target . value ) ;
14
- pitchShift += value ;
15
- if ( pitchShift < - 12 ) pitchShift = - 12 ; else if ( pitchShift > 12 ) pitchShift = 12 ;
13
+ // let value = parseInt(e.target.value);
14
+ // pitchShift += value;
15
+
16
+ pitchShift = Math . min ( 12 , Math . max ( - 12 , pitchShift + parseInt ( e . target . value ) ) ) ;
17
+
18
+ // if (pitchShift < -12) pitchShift = -12; else if (pitchShift > 12) pitchShift = 12;
16
19
// displaying the value
17
- document . getElementById ( 'pitch-shift-display' ) . innerText = ' pitch shift: ' + ( ( pitchShift < 1 ) ? pitchShift : '+' + pitchShift ) + ' ' ;
20
+ document . getElementById ( 'pitch-shift-display' ) . textContent = ' pitch shift: ' + ( ( pitchShift < 1 ) ? pitchShift : '+' + pitchShift ) + ' ' ;
18
21
// sending the new value to the audio node
19
22
audioNode . sendMessageToAudioScope ( { 'pitchShift' : pitchShift } ) ;
20
23
}
@@ -26,23 +29,20 @@ function changeRate() {
26
29
if ( value == 10000 ) text = 'original tempo' ;
27
30
else if ( value < 10000 ) text = '-' + ( 100 - value / 100 ) . toPrecision ( 2 ) + '%' ;
28
31
else text = '+' + ( value / 100 - 100 ) . toPrecision ( 2 ) + '%' ;
29
- document . getElementById ( 'rateDisplay' ) . innerText = text ;
32
+ document . getElementById ( 'rateDisplay' ) . textContent = text ;
30
33
// sending the new rate to the audio node
31
34
audioNode . sendMessageToAudioScope ( { rate : value } ) ;
32
35
}
33
36
34
37
function changePitchBend ( e ) {
35
- let faster = 1 ;
38
+ console . log ( Number ( document . getElementById ( 'holdMsSelect' ) . value ) ) ;
36
39
const value = e . target . value ;
37
- if ( value < 0 ) {
38
- faster = 0 ;
39
- }
40
40
audioNode . sendMessageToAudioScope ( {
41
41
'pitchBend' : true ,
42
42
maxPercent : Math . abs ( value / 100 ) ,
43
43
bendStretch : 0 ,
44
- faster,
45
- holdMs : 100
44
+ faster : value < 0 ? 0 : 1 ,
45
+ holdMs : Number ( document . getElementById ( 'holdMsSelect' ) . value )
46
46
} ) ;
47
47
}
48
48
@@ -60,7 +60,7 @@ function changeBendDbl() {
60
60
maxPercent : 0 ,
61
61
bendStretch : 0 ,
62
62
faster : 0 ,
63
- holdMs : 100
63
+ holdMs : Number ( document . getElementById ( 'holdMsSelect' ) . value )
64
64
} ) ;
65
65
}
66
66
@@ -69,11 +69,11 @@ function togglePlayback(e) {
69
69
let button = document . getElementById ( 'playPause' ) ;
70
70
if ( button . value == 1 ) {
71
71
button . value = 0 ;
72
- button . innerText = 'Play audio' ;
72
+ button . textContent = 'Play audio' ;
73
73
webaudioManager . audioContext . suspend ( ) ;
74
74
} else {
75
75
button . value = 1 ;
76
- button . innerText = 'Pause audio' ;
76
+ button . textContent = 'Pause audio' ;
77
77
webaudioManager . audioContext . resume ( ) ;
78
78
}
79
79
}
@@ -82,22 +82,25 @@ function onMessageFromAudioScope(message) {
82
82
if ( message . loaded ) {
83
83
// UI: innerHTML may be ugly but keeps this example small
84
84
content . innerHTML = '\
85
- <h1>Superpowered AAP pitch bending</h1>\
86
85
<button id="playPause" value="0">Play audio</button>\
87
- <h2>Pitch bend percentage</h2>\
88
- <div style="display: flex; justify-content: space-between;"><span>-30%</span><span>0%</span><span>+30%</span></div>\
86
+ <h3>Pitch bend holdMs</h3>\
87
+ <select id="holdMsSelect"><option>40</option><option>200</option><option>300</option><option>600</option><option>1000</option></select><span>ms</span>\
88
+ <h3>Pitch bend percentage</h3>\
89
+ <div style="width: 100%; display: flex; justify-content: space-between;"><span>-30%</span><span>0%</span><span>+30%</span></div>\
89
90
<input id="pitchBend" type="range" min="-30" max="30" value="0" style="width: 100%">\
90
- <div style="background: #909090; width: 100%; postion: relative;" id="bend-container"><div style="width: 50%; height: 10px; background: black;" id="bend-value"></div></div>\
91
- <div style="text-align: center;"><span>Current pitch bend percentage <span id="pitch-bend-percentage">100</span>%</span></div><br />\
91
+ <div style="overflow: hidden; border-radius: 5px; background: #909090; width: 100%; postion: relative;" id="bend-container"><div style="width: 50%; height: 10px; background: black;" id="bend-value"></div></div>\
92
+ <div style="text-align: center;"><span><span id="pitch-bend-percentage">100</span>%</span></div><br />\
92
93
<button id="reset-bend">Reset pitch bend</button>\
93
- <h2 >Playback Rate:</h2 >\
94
- <p id="rateDisplay">original tempo</p >\
95
- <div style="display: flex; justify-content: space-between;"><span>-50%</span><span>+100%</span></div>\
94
+ <h3 >Playback rate</h3 >\
95
+ <span id="rateDisplay">original tempo</span >\
96
+ <div style="width: 100%; display: flex; justify-content: space-between;"><span>-50%</span><span>+100%</span></div>\
96
97
<input id="rateSlider" type="range" min="5000" max="20000" value="10000" style="width: 100%">\
97
98
<button id="reset-rate">Reset playback rate</button> <br /><br />\
99
+ <div>\
98
100
<button id="pitchMinus" value="-1">-</button>\
99
101
<span id="pitch-shift-display"> pitch shift: 0 </span>\
100
102
<button id="pitchPlus" value="1">+</button>\
103
+ </div>\
101
104
' ;
102
105
document . getElementById ( 'rateSlider' ) . addEventListener ( 'input' , changeRate ) ;
103
106
document . getElementById ( 'pitchBend' ) . addEventListener ( 'input' , changePitchBend ) ;
@@ -112,7 +115,7 @@ function onMessageFromAudioScope(message) {
112
115
}
113
116
if ( message . pitchBendDetails && document . getElementById ( 'bend-value' ) ) {
114
117
if ( pbPerc && ( typeof message . pitchBendDetails . currentPitchBend !== 'undefined' ) ) {
115
- pbPerc . innerText = message . pitchBendDetails . currentPitchBend * 100 ;
118
+ pbPerc . textContent = message . pitchBendDetails . currentPitchBend * 100 ;
116
119
document . getElementById ( 'bend-value' ) . style . width = convertRange ( message . pitchBendDetails . currentPitchBend * 100 , [ 70 , 130 ] , [ 0 , 100 ] ) + '%' ;
117
120
document . getElementById ( 'bend-value' ) . style . background = message . pitchBendDetails . currentPitchBend === 1 ? 'black' : message . pitchBendDetails . currentPitchBend < 1 ? 'red' : 'green' ;
118
121
}
@@ -130,10 +133,9 @@ function requestPitchBendDetails() {
130
133
131
134
// when the START button is clicked
132
135
async function start ( ) {
133
- // content.innerText = 'Creating the audio context and node...';
134
136
webaudioManager = new SuperpoweredWebAudio ( 44100 , Superpowered ) ;
135
137
currentPath = window . location . href . substring ( 0 , window . location . href . lastIndexOf ( '/' ) ) ;
136
- audioNode = await webaudioManager . createAudioNodeAsync ( currentPath + '/processor.js?date=' + Date . now ( ) , 'MyProcessor' , onMessageFromAudioScope ) ;
138
+ audioNode = await webaudioManager . createAudioNodeAsync ( window . location . href + '/assets /processor.js?date=' + Date . now ( ) , 'MyProcessor' , onMessageFromAudioScope ) ;
137
139
// audioNode -> audioContext.destination (audio output)
138
140
webaudioManager . audioContext . suspend ( ) ;
139
141
audioNode . connect ( webaudioManager . audioContext . destination ) ;
@@ -143,18 +145,18 @@ async function start() {
143
145
}
144
146
145
147
async function loadFromMainThread ( ) {
146
- Superpowered . downloadAndDecode ( currentPath + '/track.mp3' , audioNode ) ;
148
+ Superpowered . downloadAndDecode ( window . location . href + '/assets /track.mp3' , audioNode ) ;
147
149
}
148
150
149
151
async function loadJS ( ) {
150
- Superpowered = await SuperpoweredGlue . Instantiate ( 'ExampleLicenseKey-WillExpire-OnNextUpdate' , 'http://localhost:8080/ superpowered-npm.wasm' ) ;
152
+ Superpowered = await SuperpoweredGlue . Instantiate ( 'ExampleLicenseKey-WillExpire-OnNextUpdate' , ` ${ window . location . href } /assets/ superpowered-npm.wasm` ) ;
151
153
152
154
// display the START button
153
155
content = document . getElementById ( 'content' ) ;
154
156
content . innerHTML = `<div>
155
- <button id="loadFromMainThread ">Start</button>
157
+ <button id="startApplication ">Start</button>
156
158
</div>` ;
157
- document . getElementById ( 'loadFromMainThread ' ) . addEventListener ( 'click' , loadFromMainThread ) ;
159
+ document . getElementById ( 'startApplication ' ) . addEventListener ( 'click' , loadFromMainThread ) ;
158
160
start ( ) ;
159
161
}
160
162
0 commit comments