List of usage examples for javax.sound.sampled AudioInputStream available
@Override public int available() throws IOException
From source file:sec_algo.aud_sec.java
public BufferedWriter getAudioStream() { FileInputStream fin = null;// ww w. j ava 2 s . c om BufferedWriter audstream = null; try { fin = new FileInputStream(this.file); // audstream = new BufferedWriter(new FileWriter(returnFileName()+"_ex."+returnFileExt())); // byte contents[] = new byte[100]; // while(fin.read(contents)!= -1){ // System.out.println("reading & writing from file"); // for(byte b : contents) // for(int x = 0; x < 8; x++) // audstream.write(b>>x & 1); // } // System.out.println("Finished!"); // System.out.println("audstream contents: " + audstream.toString()); byte[] header = new byte[8]; fin.read(header); fin.close(); // System.out.println("header bytes: " + Arrays.toString(header)); ArrayList<String> bitstring = new ArrayList<String>(); for (int i = 0; i < header.length; i++) bitstring.add(String.format("%8s", Integer.toBinaryString(header[i] & 0xFF)).replace(' ', '0')); System.out.print("bit input: [/"); for (int i = 0; i < bitstring.size(); i++) { System.out.print(bitstring.get(i) + " "); } System.out.println("]/"); System.out.println(bitstring.get(0) + " " + bitstring.get(1) + " " + bitstring.get(2)); System.out.println("Bitrate index: " + bitstring.get(2).substring(0, 4)); AudioInputStream in = AudioSystem.getAudioInputStream(this.file); AudioInputStream din = null; AudioFormat baseFormat = in.getFormat(); AudioFormat decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), getBitrate(bitstring.get(2).substring(0, 4)), baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); din = AudioSystem.getAudioInputStream(decodedFormat, in); int size = din.available(); byte[] bytaud = new byte[size]; din.read(bytaud); bitstring = new ArrayList<String>(); for (int i = 0; i < header.length; i++) bitstring.add(String.format("%8s", Integer.toBinaryString(header[i] & 0xFF)).replace(' ', '0')); System.out.print("bit input: [/"); for (int i = 0; i < bitstring.size(); i++) { System.out.print(bitstring.get(i) + " "); } System.out.println("]/"); in.close(); din.close(); } catch (Exception e) { e.printStackTrace(); } return audstream; }