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 › Troubles data to sound SOLVED
Page Index Toggle Pages: 1
Troubles data to sound SOLVED (Read 2044 times)
Troubles data to sound SOLVED
Jun 8th, 2010, 4:39pm
 
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();
}

Re: Troubles data to sound
Reply #1 - Jun 8th, 2010, 6:28pm
 
sorry, posted the wrong code.
Re: Troubles data to sound
Reply #2 - Jun 10th, 2010, 7:20pm
 
SOLVED!
Code:

import ddf.minim.*;
import ddf.minim.signals.*;
byte[] data;
Minim minim;
AudioOutput out;
SineWave sine;
PImage b;
int imageWidth = 391;
int imageHeight = 480;
int counter = 0;
int posX = 0;
int posY = 0;
int imageWidthMax;

void setup()
{




size(imageWidth, imageHeight);

frameRate(30);
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");

int totalSize = imageWidth * imageHeight;
int ByteSize = data.length;
int posAmount = totalSize/ByteSize;
int imageWidthMax = imageWidth/3;

b = loadImage("foto.jpg");
noStroke();
image(b, 0, 0);
}

void draw()
{


float freq = map(abs(data[frameCount]), 0, 150, 100, 0);
sine.setFreq(freq);
float pan = map(abs(frameCount), 0, 150, -1, 1);
sine.setPan(pan);
fill(#FF0303);
rect(posX, posY, 1, 1);
posX ++;

if (posX == imageWidth){
posY++;
posX = 1;
}
}




void stop()
{
out.close();
minim.stop();

super.stop();
}
Page Index Toggle Pages: 1