We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Help with Microphone plz
Page Index Toggle Pages: 1
Help with Microphone plz (Read 2130 times)
Help with Microphone plz
Feb 16th, 2010, 7:37am
 
Hi!
I´m a processing newbie. I want to make a file where a picture changes colors depending on the sound i make by myself (whistle for example). But I have no idea where to start... So please help me.
Thanks
Re: Help with Microphone plz
Reply #1 - Feb 16th, 2010, 8:53am
 
seems that hcue had a simiar idea:

http://processing.org/discourse/yabb2/num_1264634410.html

may be you could join forces.
Re: Help with Microphone plz
Reply #2 - Feb 16th, 2010, 9:40am
 
Also, to get realtime audio, aside from adjusting your system audio preferences (recording levels especially!), you want a "line in" reading.

See in the examples that come with Processing:
File (menu) > Examples > Libraries > Minim (Sound) > GetLineIn

Also look at the docs for Minim, especially AudioInput

Quote:
An AudioInput is a connection to the current record source of the computer. How the record source for a computer is set will depend on the soundcard and OS, but typically a user can open a control panel and set the source from there. Unfortunately, there is no way to set the record source from Java. This is particularly problematic on the Mac because the input will always wind up being connected to the Mic-In, even if the user has set the input differently using their audio control panel. You can obtain an AudioInput from Minim by using one of the getLineIn methods


-spxl
Re: Help with Microphone plz
Reply #3 - Feb 17th, 2010, 12:10am
 
Thank u very much, it will help a lot  Smiley
Re: Help with Microphone plz
Reply #4 - Feb 18th, 2010, 12:24am
 
One more question, sry Smiley

I have a programm where a line rotates round the courser. Additionally I have selfmade shapes wich i can activate by pushing a key but they don´t work.Their names are "02.svg"-"06.svg"(illustrator)
And the line is sensible preferring to the sound. A loud noise will make the line kick out. But additionally i want to make a random color for every loud noise like clap e.g. Can someone help me and take a look at my code?
Would help me a lot.
Thx=)

import processing.pdf.*;
boolean recordPDF = false;


float lineModuleSize = 0;
float angle = 0;
float angleSpeed = 0.2;
PShape lineModule = null;


int clickPosX = 0;
int clickPosY = 0;
import ddf.minim.*;
color col = color(0,0,0,25);

Minim minim;
AudioInput in;


void setup()
{
size(screen.width, screen.height );
background(255);
cursor(CROSS);
smooth();
minim = new Minim(this);
minim.debugOn();
 
// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO,800);
}

void draw()
{
 
if (mousePressed) {
  int x = mouseX;
  int y = mouseY;
   
 
  strokeWeight(1.0);
  stroke(col);
  pushMatrix();
  translate(x, y);
  rotate(radians(angle));
  if (lineModule != null) {
    shape(lineModule, 0, 0, lineModuleSize, lineModuleSize);
   }
  else {
    line(0, 0, lineModuleSize, lineModuleSize);
    angle = angle + angleSpeed;
    for(int i = 0; i < in.bufferSize() - 1; i++)
    line(i, 150 + in.right.get(i)*50000, i+1, 150 + in.right.get(i+1)*50);

     }
   
   

  popMatrix();

   
   
 }
}

void keyReleased() {
if (key == DELETE || key == BACKSPACE) background(255);
if (key == 's' || key == 'S') saveFrame(timestamp()+"_##.png");

// reverse direction and mirrow angle
if (key=='d' || key=='D') {
  angle = angle + 180;
  angleSpeed = angleSpeed * -1;
}

// r g b alpha
if (key == ' ') col = color(random(255),random(255),random(255),random(80,150));

//default colors from 1 to 4
if (key == '1') col = color(0,0,0,100);
if (key == '2') col = color(0,255,0,100);
if (key == '3') col = color(0,0,255,100);
if (key == '4') col = color(255,255,255,100);
if (key == 'q') col = color(154,111,76,100);
if (key == 'w') col = color(255,0,0,100);
 
if (key == 'f') {
  col = color(0,0,0,100);
  lineModuleSize += 100;
}
 
  if (key == 'g') {
  col = color(154,111,76,100);
  lineModuleSize += 100;
}
      if (key == 'c') {
  col = color(0,0,0,100);
  lineModuleSize -= 100;
}
    if (key == 'v') {
  col = color(154,111,76,100);
  lineModuleSize -= 100;
}

// load svg for line module
if (key=='5') lineModule = null;
if (key=='6') lineModule = loadShape("02.svg");
if (key=='7') lineModule = loadShape("03.svg");
if (key=='8') lineModule = loadShape("04.svg");
if (key=='9') lineModule = loadShape("05.svg");
if (lineModule != null) {
  lineModule.disableStyle();
   
   
}
if (key =='r' || key =='R') {
  if (recordPDF == false) {
    beginRecord(PDF, timestamp()+".pdf");
    println("recording started");
    recordPDF = true;
  }
}
else if (key == 'e' || key =='E') {
  if (recordPDF) {
    println("recording stopped");
    endRecord();
    recordPDF = false;
    background(255);
  }
}
}

void keyPressed() {
if (keyCode == UP) lineModuleSize += 100;
if (keyCode == DOWN) lineModuleSize -= 100;
if (keyCode == LEFT) angleSpeed -= 0.2;
if (keyCode == RIGHT) angleSpeed += 0.2;
}
void stop()
{  
in.close();
minim.stop();
 
super.stop();
}
String timestamp() {
Calendar now = Calendar.getInstance();
return String.format("%1$ty%1$tm%1$td_%1$tH%1$tM%1$tS", now);
}
Re: Help with Microphone plz
Reply #5 - Feb 18th, 2010, 2:37am
 
Did you look at / try the in.mix.level() method?

If so, you should have mentioned it here. If not, you should go do that and come back with what you came up with.

-spxl
Re: Help with Microphone plz
Reply #6 - Feb 18th, 2010, 8:54am
 
tried it but it doesn´t work.... there is no difference.... Sad
Re: Help with Microphone plz
Reply #7 - Feb 18th, 2010, 9:50am
 
what operating system are you using? i seem to recall a problem with macs.

code works fine here. i get a waveform at least. but i need to press the mouse before i see anything and the screen fills up pretty quickly (i added a background(255) at start of draw so i could see)

check your recording controls. mine has 'Stereo Mix' selected as an input and the waveform corresponds to what i am hearing from winamp.

(newer soundcards and operating systems hide or disable this option lest people use it for recording streams)

(this is WinXP 2002 btw)
Re: Help with Microphone plz
Reply #8 - Feb 19th, 2010, 12:44am
 
At my Mac it works fine too. And it was my intention that the screen fills up after i pushed the mouse button. It doesn´t matter how long it needs to fill up the screen because this is a intendet setting.... if i set one number a little bit smaller, the screen needs longer to fill up....

My Problem is that i don´t know how to make the color of the line changing randomly after a noise like clap e. g..... I tried it with:

while, with the in.mix.level() etc. but i don´t know how to make this.....
Page Index Toggle Pages: 1