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 & HelpIntegration › javax.sound.sampled exporting
Page Index Toggle Pages: 1
javax.sound.sampled exporting (Read 1574 times)
javax.sound.sampled exporting
Jul 27th, 2005, 6:26pm
 
I'm using the java Sound stuff rather than the sound libraries for the ability to access multiple microphones.  I have recently found that while I can do it running processing something changes when I export.

After I export, it can still aquire a line, but when it reads from the line it always gets 0's rather than more useful sound data.  Below is the code I used to read the line... below that is the setup for the line.  Can anyone help?

public  float[] getChannelVals(){
 float[] retVal = {0,0};
 int frameSizeInBytes = format.getFrameSize();
 int bufferLengthInFrames = line.getBufferSize() / 8;
 int bufferLengthInBytes = bufferLengthInFrames*frameSizeInBytes/64;
 byte[] data = new byte[bufferLengthInBytes];
 int numBytesRead;

 if((numBytesRead = line.read(data, 0, bufferLengthInBytes)) == -1) {
   return retVal;
 }

 // changes the byte array into doubles
 double[] dat = changeBytes(data);

 for(int i = 0; i<dat.length/2; i++){
   float tL = (float) (dat[2*i]); // Left Channel
   float tR = (float) (dat[2*i+1]); // Right Channel
   if(tL > retVal[0])
     retVal[0] = tL;
   if(tR > retVal[1])
     retVal[1] = tR;
   }
   retVal[0] = 32000;

   //Proving to myself it was not exiting early
   PFont font = loadFont("A10.vlw");
   textFont(font, 10);
   text(format.toString().substring(0,30),0,20);
   text(format.toString().substring(30,60),0,30);
   text(retVal[0]+" "+retVal[1],0,40);

   return retVal;
 }

/**************************************************/
public void start(){
 audioInputStream = null;
 format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, //encode
                      20000.0f,  // sample rate
                      16,        // sample size (bits)
                      2,         // channels
                      4,         // frame size (bytes per)
                      20000.0f,  // frame rate
                      true);     // big Endian
 DataLine.Info info = null;
 try{
   info = new DataLine.Info(Class.forName("javax.sound.sampled.TargetDataLine") ,(AudioFormat) format);
 }catch(Exception e){ System.out.println("Class not found, biatch");}

 if (!AudioSystem.isLineSupported(info)) {
   System.out.println("Line matching " + info + " not supported.");
   return;
 }
 try {
   line = (TargetDataLine) AudioSystem.getLine(info);
   line.open(format, line.getBufferSize());
 } catch (LineUnavailableException ex){
   System.out.println("Unable to open the line: " + ex);
   return;
 } catch (SecurityException ex) {
   System.out.println(ex.toString());
   return;
 } catch (Exception ex) {
   System.out.println(ex.toString());
   return;
 }
 line.start();
}
Re: javax.sound.sampled exporting
Reply #1 - Jul 28th, 2005, 12:53am
 
most likely you're running into Java security restrictions, that applets aren't allowed to use audio the same way to prevent people from making an applet that, say, just turns on the mic and sends the info back to a server.
Re: javax.sound.sampled exporting
Reply #2 - Jul 28th, 2005, 6:24pm
 
right on... I just ran the exported jar from the command line rather than in a browser and it works just fine.  Thanks.
Page Index Toggle Pages: 1