Studio hhjjj workshop

Participation

위키 공동 편집을 원하시는 분은 다음 이메일로 자기소개를 부탁드립니다.
Send me an email to participate in workshop wiki.

songhojun@gmail.com

SensorComm Board

최근 사이트 활동

라이선스 안내

Creative Commons License
본 사이트의 모든 저작물크리에이티브 커먼즈 저작자표시-동일조건변경허락 2.0 대한민국 라이선스에 따라 이용할 수 있습니다.

audio sensor processing code

import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;


import processing.serial.*;






Serial myPort; // Create object from Serial class
String myString = null;
int adc;
char play_flag = 0;
char stop_flag = 0;
Minim minim;
AudioPlayer in;








void setup()
{


size(512, 200);
//Start Sonia
minim = new Minim(this);
// load a file, default sample buffer size is 1024
in = minim.loadFile("dirty.wav");
// play the file



// List all the available serial ports
println(Serial.list());
String portName = Serial.list()[1];
myPort = new Serial(this, portName, 9600);
}




void draw()
{
myPort.write('a');
while (myPort.available() > 0)
{
char inByte = myPort.readChar();
adc = int(inByte);
println(adc);
}
// if adc > 125 and play_flag = 0, play the music
if (adc > 125 && play_flag == 0)
{
in.play();
play_flag =1;
}


// if adc < 80 and stop_flag = 0, stop the music
if (adc < 80 && stop_flag == 0)
{
//in.close();
minim.stop();
stop_flag = 1;
}


// if 80 < adc < 125, reset the flags
if (adc > 80 && adc < 125)
{
play_flag = 0;
stop_flag = 0;
}


}




// Safely close the sound engine upon Browser shutdown.
public void stop(){
minim.stop();
super.stop();
}