File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,6 @@ let fft;
4
4
let volhistory = [ ] ;
5
5
let w ;
6
6
7
- function toggleSong ( ) {
8
- if ( song . isPlaying ( ) ) {
9
- song . pause ( ) ;
10
- } else {
11
- song . play ( ) ;
12
- }
13
- }
14
7
15
8
function preload ( ) {
16
9
song = loadSound ( "AlesisLive.mp3" ) ;
@@ -19,13 +12,15 @@ function preload() {
19
12
function setup ( ) {
20
13
createCanvas ( windowWidth , windowHeight ) ;
21
14
colorMode ( HSB ) ;
22
- song . play ( ) ;
23
- button = createButton ( "pause" ) ;
24
- button . mousePressed ( toggleSong ) ;
25
15
fft = new p5 . FFT ( 0.9 , 128 ) ;
26
16
w = width / 64
27
17
}
28
18
19
+ function loaded ( ) {
20
+ button = createButton ( 'play' ) ;
21
+ button . mousePressed ( togglePlaying ) ;
22
+ }
23
+
29
24
function draw ( ) {
30
25
background ( 0 ) ;
31
26
let spectrum = fft . analyze ( ) ;
@@ -39,3 +34,14 @@ function draw() {
39
34
console . log ( spectrum ) ;
40
35
41
36
}
37
+
38
+ function togglePlaying ( ) {
39
+ if ( ! song . isPlaying ( ) ) {
40
+ song . play ( ) ;
41
+ song . setVolume ( 0.3 ) ;
42
+ button . html ( 'pause' ) ;
43
+ } else {
44
+ song . stop ( ) ;
45
+ button . html ( 'play' ) ;
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments