My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//ze blinker, seeedstudio carnival 2011 entry (c) by michu / neophob.com
import processing.serial.*;

import com.neophob.lib.rainbowduino.test.*;
import com.neophob.lib.rainbowduino.*;

//blinkenlight processing src: http://code.google.com/p/processing-blinkenlights/
import processing.lib.blinken.jaxb.*;
import processing.lib.blinken.*;

import ddf.minim.AudioInput;
import ddf.minim.Minim;
import ddf.minim.analysis.BeatDetect;

private Minim minim;
private AudioInput in;
private BeatDetect beat;
private BeatListener bl;

private static final int FPS=25;
private static final int SOUND_BUFFER_RESOLUTION = int(1.0f/(float)FPS);
private static int SIZE = 16;
private static final String[] ALL_BML_FILES = {
"torus.bml",
"bnf_auge.bml",
"flatter_flatter.bml",
"cube.bml",
"kreise-versetzt.bml"
};

BlinkenLibrary blink;
Rainbowduino r;
int blmFrames,sndLoop;
String currentFile;
float sndVolumeMax, currentFrame=0.0f;

//-------------------------------------------

void setup() {
loadBlink(ALL_BML_FILES[0]);
frameRate(FPS);
size(SIZE, SIZE);
background(0);

List<Integer> list = new ArrayList<Integer>();
list.add(16);
list.add(17);
list.add(18);
list.add(19);
try {
r = new Rainbowduino(this, list);
}
catch (Exception e) {
println("FAILED to open serial port!!");
e.printStackTrace();
exit();
}

minim = new Minim(this);
in = minim.getLineIn( Minim.STEREO, 512 );
beat = new BeatDetect(in.bufferSize(), in.sampleRate());
beat.setSensitivity(20);
bl = new BeatListener(beat, in);
}

//-------------------------------------------

void draw() {

float volume = getSoundVolume();
float addStep=0.1+volume*1.7f;
if (beat.isKick()) {
addStep=4.5f;
}

currentFrame+=addStep;
blink.jump(int(currentFrame));

if (int(currentFrame)>=blmFrames) {
//load a new .bml file and make sure we pick a new file
String name=currentFile;
while (name.equals(currentFile)) {
name=ALL_BML_FILES[int(random(0, ALL_BML_FILES.length))];
}
loadBlink(name);
}

image(blink, 0, 0, SIZE, SIZE);
//send sketch content to four rainbowduino's
r.sendRgbFrame((byte)16, (byte)18, (byte)19, (byte)17, this);
}


//-------------------------------------------

float getSoundVolume() {
if (sndLoop>SOUND_BUFFER_RESOLUTION) {
sndVolumeMax*=.93f;
}
float f = in.mix.level();
if (f>sndVolumeMax) {
sndVolumeMax=f;
sndLoop=0;
}
sndLoop++;

float norm=(1.0f/sndVolumeMax)*f;

//im a bad coder! limit it!
if (norm>1f) {
norm=1f;
}

//if the sound volume is very low, limit the normalized volume
if (sndVolumeMax<0.004f) {
norm/=2;
}

return norm;
}

//-------------------------------------------

void loadBlink(String name) {
int r=0,g=0,b=0;
while (r+g+b<400) {
r = int(random(255));
g = int(random(255));
b = int(random(255));
}
currentFile=name;
if (blink==null) {
blink = new BlinkenLibrary(this, name, r, g, b);
}
else {
blink.loadFile(name, r, g, b);
}
blmFrames = blink.getNrOfFrames();
//ignore the delay of the movie, use our fps!
blink.setIgnoreFileDelay(true);
currentFrame=0.0f;
blink.jump(int(currentFrame));
}

Change log

r176 by mi...@neophob.com on Jan 3, 2011   Diff
update ze blinker - add audio listener
Go to: 
Project members, sign in to write a code review

Older revisions

r175 by michudroid on Jan 2, 2011   Diff
update example
r173 by mi...@neophob.com on Jan 2, 2011   Diff
add new example
All revisions of this file

File info

Size: 3204 bytes, 144 lines
Powered by Google Project Hosting