mortserg
Ex Member
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(); }