“Simple Mic Demo2” by Golan Levin
https://openprocessing.org/sketch/2191104
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will become the forks of "Simple Mic Demo".
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
A fork of Simple Mic Demo by Golan Levin
CC Attribution NonCommercial ShareAlike
Simple Mic Demo2
Levin
xxxxxxxxxx
// Demonstrates contrast between two different lowpass filters.
// Uses https://cdn.jsdelivr.net/npm/p5.sound@0.1.0
let theSlowVolume = 0;
let theFastVolume = 0;
let cx = 300;
let mic, amp;
function setup() {
let cnv = createCanvas(600, 400);
cnv.mousePressed(userStartAudio);
mic = new p5.AudioIn();
mic.start();
amp = new p5.Amplitude();
mic.disconnect();
mic.connect(amp);
}
//----------------------------------------------
function draw() {
background(220);
// Get the overall volume (between 0.0 and 1.0);
// Smooth the volume variable with a running average
let v = amp.getLevel();
let smoothingFast = 0.05; // must be between 0...1
let smoothingSlow = 0.95; // must be between 0...1
theFastVolume = (smoothingFast * theFastVolume) + ((1-smoothingFast) * v);
theSlowVolume = (smoothingSlow * theSlowVolume) + ((1-smoothingSlow) * v);
fill('black');
noStroke();
let diamFast = map(theFastVolume, 0,1, 10,1000);
circle(200, 150, diamFast);
let diamSlow = map(theSlowVolume, 0,1, 10,1000);
circle(400, 150, diamSlow);
textAlign(CENTER);
text(nf(theSlowVolume,1,5), 400,100);
text(nf(theFastVolume,1,5), 200,100);
let restX = 300;
let hideX = 0;
let quietThresh = 0.02;
let loudThresh = 0.10;
if (theSlowVolume < quietThresh){
cx = 0.9*cx + 0.1*restX;
}
if (theFastVolume > loudThresh){
cx = 0.2*cx + 0.8*hideX;
}
text("say Boo!", cx,290);
strokeWeight(12);
stroke(0);
line(cx, 300, cx, 400);
}
See More Shortcuts
Please verify your email to comment
Verify Email