We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to do a project which is about when saying something through microphone, and then can draw something (on Processing).
l watch Daniel Shiffman's video "17.9: Sound Visualization: Graphing Amplitude - p5.js", https://youtube.com/watch?v=jEwAMgcCgOA&t=370s, but what I use is processing and pure data, I have a question about how to put those microphone value into an array in Processing, like the tutorial in the video, (the way of receive sound from microphone I use is Pure data, and I'm successfully connect pd and Processing), but I just don't know how to put those value into an array in processing, and I guess the value also need to greater than a certain value because microphone will also receive value when is not saying.Thank you for your help!
My Pure data and Processing sketch is here https://github.com/nancyjou/Sound-Visualization
and here is only my Processing sketch.
float global1;
float global2;
float adc;
float fiddle;
float colorY;
float alphaX;
import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(800, 800);
background(255);
frameRate(25);
colorMode(HSB, 360, 100, 100);
noStroke();
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this, 12001);
myRemoteLocation = new NetAddress("127.0.0.1", 12000);
}
void draw() {
fiddle = global2;
colorY= map(global2, 25, 150, 0, 360);
alphaX= map(global1, 40, 250, 20, 255);
fill(colorY, 100, 100);
fill(colorY, 100, fiddle+50, alphaX);
for (int y=200; y<(height/4)+1; y+=10) {
ellipse(width/2, random(0, 400), global1, global1);
println(y);
}
adc = global1 + 10;
}
void mousePressed() {
OscMessage myMessage = new OscMessage("/first");
myMessage.add(123);
myMessage.add(12.34);
myMessage.add("some text");
oscP5.send(myMessage, myRemoteLocation);
}
void oscEvent(OscMessage theOscMessage) {
if (theOscMessage.checkAddrPattern("/first")==true) {
float firstValue = theOscMessage.get(0).floatValue();
global1 = firstValue;
}
if (theOscMessage.checkAddrPattern("/second")==true) {
float secondValue = theOscMessage.get(0).floatValue();
global2 = secondValue;
}
println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
}
Answers
Are you familiar with the minim library? You can install it using the library manager i the Processing IDE. After you install the library, you can check the examples as it shows some filtering techniques. This next post should get you started with minim. Notice you can access the mic directly from there.
https://forum.processing.org/one/topic/how-can-i-detect-sound-with-my-mic-in-my-computer.html
You can check the documentation here: http://code.compartmental.net/minim/audioinput_class_audioinput.html
Kf
@kfrajer
I try the minim library, and it works, but I want it is draw only when I saying something through microphone, now it receive all the values, so even if I did't talk, it will also draw. So I think I need to filter the value, when the value is greater than a certain value, it can draw only when talking. How can I do that or is there any other ways to deal with that? Thanks!!
@nancyjou -- Do you want to check
.getVolume()
on anAudioInput
before deciding whether to draw or not?Edit: looks like using
.getVolume()
is wrong -- instead, loop over each bin in the buffer and check if it is greater than a threshhold value, e.g. usingAudioInput.left.get(i)
-- see @kfrajer answer below@jeremydouglass
sorry I have no idea how to use .getVolume() :-S :-S it say:
=== Minim Error === === Volume is not supported.
Consider this example.
Kf
@kfrajer
Thanks a lot!! This example is really good, it works!! but when l set the canvas longer, I found another problem that the line can't draw continuously to the right, it stop drawing to the right at some point on the canvas, I want it can keep drawing to the right like the Daniel Shiffman's video do, and I check my code, I cant't find the problem. #-o
And there is another small question, when I use this minim library to receive mic value, when I press RUN button, it need to wait about a minute before the window will jump out, is that normal? or just my computer's problem?
Taking a minute to start? That is odd. I suggest removing the return statement in line 34. Do you observe the same problem? What operating system btw?
I can't see the video right now. Not sure what you mean with keep drawing to the line (I will need to see the video). You mean the data slides to the left? Or do you mean that after running the code for certain time, the program stops refreshing?
Kf
@kfrajer
Actually, the first time I run the code in the link you give me will need to taking a minute to start(https://forum.processing.org/one/topic/how-can-i-detect-sound-with-my-mic-in-my-computer.html), so if remove the return statement can't solve, I think it is either the minim library's problem, or is my computer's problem... I use PC and processing3.3.6 ( is that the operating system you mean?)
And about keep drawing line problem, sorry just temporarily ignore me, I will try it again later, maybe I can deal with it. Thanks!
Are you a mac or Windows user? Very odd about the delay... So I understand it is only the first time? It is not that bad then, I would say.
Kf
@kfrajer
I am a Windows user, not only the first time, every time I want to check the code how it looks like, I need to wait for a minute ha ha, but it does not matte, the program can work just fine, thanks for your help, the example really help me!!