File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 2
2
// We need p5.AudioIn (mic / sound source), p5.SoundRecorder
3
3
// (records the sound), and a p5.SoundFile (play back).
4
4
5
- var mic , recorder , soundFile ;
5
+ let mic , recorder , soundFile ;
6
+
7
+ let state = 0 ; // mousePress will increment from state = 0 (Record), to 1(Stop), to 2(Play)
6
8
7
- var state = 0 ; // mousePress will increment from Record, to Stop, to Play
8
9
9
10
function setup ( ) {
10
11
createCanvas ( 400 , 400 ) ;
@@ -26,10 +27,11 @@ function setup() {
26
27
}
27
28
28
29
function mousePressed ( ) {
30
+ userStartAudio ( ) ;
29
31
// use the '.enabled' boolean to make sure user enabled the mic (otherwise we'd record silence)
30
32
if ( state === 0 ) {
31
33
// users must manually enable their browser microphone for recording to work properly!
32
- mic . start ( function ( ) {
34
+ mic . start ( function ( ) {
33
35
// Tell recorder to record to a p5.SoundFile which we will use for playback
34
36
recorder . record ( soundFile ) ;
35
37
@@ -46,4 +48,4 @@ function mousePressed() {
46
48
} else if ( state === 2 ) {
47
49
soundFile . play ( ) ; // play the result!
48
50
}
49
- }
51
+ }
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const ac = p5sound.audiocontext;
20
20
* @example
21
21
* <div><code>
22
22
* let mic, recorder, soundFile;
23
+ * // mousePress will increment from state = 0 (Record), to 1(Stop), to 2(Play)
23
24
* let state = 0;
24
25
*
25
26
* function setup() {
@@ -76,7 +77,6 @@ const ac = p5sound.audiocontext;
76
77
* else if (state === 2) {
77
78
* soundFile.play(); // play the result!
78
79
* save(soundFile, 'mySound.wav');
79
- * state++;
80
80
* }
81
81
* }
82
82
* </div></code>
You can’t perform that action at this time.
0 commit comments