From 8001d09b576820595806ac4576eab4c3d6c5e0a1 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Fri, 7 Feb 2020 10:30:50 +0100 Subject: [PATCH] Record pitch, amplitude and duration --- voicegardens/static/voicegardens.js | 34 +++++++++++------------------ 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index 389cdcf..d4c712e 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -50,11 +50,19 @@ var toScreenY = 0; // All shapes generated var shapes = []; +// Sound properties +var amplitude; +var duration; +var fft; +var pitch; + function record() { /** * Start recording a sound. **/ if (microphone.enabled) { + fft = new p5.FFT(); + fft.setInput(recorder); setTimeout(recorder.record(recording), recordingTimeout); } } @@ -68,6 +76,11 @@ function stop() { // signal to the draw loop that we should generate a new shape newSoundJustRecorded = true; + + // store sound properties from recording + pitch = fft.analyze(); + amplitude = recording.getPeaks(); + duration = recording.duration(); } } @@ -131,27 +144,6 @@ function setupRecording() { archiveButton.mousePressed(archive); } -function getSoundInfo() { - /** - * Retrieve sound information like pitch, amplitude, duration, etc. - **/ - amplitude = recording.getPeaks(); - duration = recording.duration(); - - // pitch (frequency?) I think we can use fft.analyze() and then find the - // highest value (0 -> 1024) that has a non-zero value this gives us the - // highest frequency from the recording - // https://p5js.org/reference/#/p5.FFT - // https://p5js.org/reference/#/p5.FFT/analyze - - // nuance? - // "I meant the amount of variation in the voice - i.e is it one single - // monotone note or does it go up and down octaves or start soft and high and - // become deep and guttural etc." - // - // How do to do this? Unsure ... -} - class GeneratedShape { constructor() { /**