hi,
i've written a simple code to play raw data of a picture and play it as a audio file. The problem is that my code doesn't play constantly After a while it just get stuck. And i want to show where in the picture it is, but the problem with that is that minim wants to show something i think. Here's the code:
Code:
import ddf.minim.*;
import ddf.minim.signals.*;
byte[] data;
Minim minim;
AudioOutput out;
SineWave sine;
PImage b;
int imageWidth = 391;
int imageHeight = 480;
void setup()
{
size(imageWidth, imageHeight);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO);
sine = new SineWave(440, 0.5, out.sampleRate());
sine.portamento(200);
out.addSignal(sine);
data=loadBytes("foto.jpg");
for(int i=0;i<data.length;i++){
String bin = binary(data[i]);
String[] q = splitTokens(bin);
}
}
void draw()
{
b = loadImage("foto2.jpg");
image(b, 0, 0);
int totalSize = imageWidth * imageHeight;
int ByteSize = data.length;
int posAmount = totalSize/ByteSize;
println(posAmount);
int posX = 1;
int posY = 1;
int counter = 0;
for(int i=0;i<data.length;i++){
counter ++;
float freq = map(abs(data[i]), 0, 150, 100, 0);
sine.setFreq(freq);
float pan = map(abs(data[i]), 0, 150, -1, 1);
sine.setPan(pan);
if (counter == 2){
fill(#FF0303);
rect(posX, posY, 1, 1);
posX ++;
}
if (posX == imageWidth){
posY++;
posX = 1;
}
}
stop();
// draw the waveforms
// for(int i = 0; i < out.bufferSize() - 1; i++)
// {
// float x1 = map(i, 0, out.bufferSize(), 0, width);
// float x2 = map(i+1, 0, out.bufferSize(), 0, width);
// line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
// line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
// }
}
void stop()
{
out.close();
minim.stop();
super.stop();
}