Cristina Cochior 4 years ago
parent
commit
ba76310757
  1. 18
      voicegardens/static/voicegardens.js

18
voicegardens/static/voicegardens.js

@ -52,16 +52,12 @@ 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);
}
}
@ -76,9 +72,6 @@ function stop() {
// signal to the draw loop that we should generate a new shape
newSoundJustRecorded = true;
// https://p5js.org/reference/#/p5.FFT/analyze
pitch = getMaxPitch(fft.analyze());
// https://p5js.org/reference/#/p5.SoundFile/getPeaks
amplitude = recording.getPeaks(1)[0] * 100;
@ -419,14 +412,3 @@ function windowResized() {
**/
resizeCanvas(windowWidth, windowHeight);
}
function getMaxPitch(spectrum) {
/**
* Get max pitch.
*/
for (let x = spectrum.length - 1; x > 0; x--) {
if (spectrum[x] != 0) {
return x;
}
}
}

Loading…
Cancel
Save