Skip to content

Commit 1cdf255

Browse files
(Gsoc'21)💚 minor improvements in soundRecorder example
1 parent a4affd2 commit 1cdf255

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

examples/record/sketch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
// We need p5.AudioIn (mic / sound source), p5.SoundRecorder
33
// (records the sound), and a p5.SoundFile (play back).
44

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)
68

7-
var state = 0; // mousePress will increment from Record, to Stop, to Play
89

910
function setup() {
1011
createCanvas(400, 400);
@@ -26,10 +27,11 @@ function setup() {
2627
}
2728

2829
function mousePressed() {
30+
userStartAudio();
2931
// use the '.enabled' boolean to make sure user enabled the mic (otherwise we'd record silence)
3032
if (state === 0) {
3133
// users must manually enable their browser microphone for recording to work properly!
32-
mic.start(function() {
34+
mic.start(function () {
3335
// Tell recorder to record to a p5.SoundFile which we will use for playback
3436
recorder.record(soundFile);
3537

@@ -46,4 +48,4 @@ function mousePressed() {
4648
} else if (state === 2) {
4749
soundFile.play(); // play the result!
4850
}
49-
}
51+
}

src/soundRecorder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const ac = p5sound.audiocontext;
2020
* @example
2121
* <div><code>
2222
* let mic, recorder, soundFile;
23+
* // mousePress will increment from state = 0 (Record), to 1(Stop), to 2(Play)
2324
* let state = 0;
2425
*
2526
* function setup() {
@@ -76,7 +77,6 @@ const ac = p5sound.audiocontext;
7677
* else if (state === 2) {
7778
* soundFile.play(); // play the result!
7879
* save(soundFile, 'mySound.wav');
79-
* state++;
8080
* }
8181
* }
8282
* </div></code>

0 commit comments

Comments
 (0)