From d49d94895ebd06204eeb11880466c0b91a6b2672 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sat, 15 Feb 2020 15:31:35 +0100 Subject: [PATCH] Tuck this sound related stuff into the success cb --- voicegardens/static/voicegardens.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index f939c1d..88a3c66 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -68,17 +68,6 @@ function stop() { **/ if (recorder.recording) { recorder.stop(); - - // https://p5js.org/reference/#/p5.SoundFile/getPeaks - amplitude = recording.getPeaks(1)[0] * 100; - - // https://p5js.org/reference/#/p5.SoundFile/duration - duration = recording.duration(); - - // automatically archive this sound to the back-end - sendToArchive(); - - // signal to the draw loop that we should generate a new shape newSoundJustRecorded = true; } } @@ -556,9 +545,12 @@ function draw() { let soundBlob = recording.getBlob(); let data = new p5.File(soundBlob); let recordedSound = new p5.SoundFile(data, function() { + amplitude = recording.getPeaks(1)[0] * 100; + duration = recording.duration(); let newShape = new GeneratedShape(recordedSound, amplitude, duration); shapes.push(newShape); newSoundJustRecorded = false; + sendToArchive(); }); }