package Sounde; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.TargetDataLine; import javax.sound.sampled.UnsupportedAudioFileException; public class example { private static AudioFileFormat.Type fileType = AudioFileFormat.Type.WAVE; private static AudioInputStream audioInputStream; private static AudioFormat format; final static int W = 1024; private static int BITS_IN_BYTE = 8; public static void main(String[] args) { String PatnToFile = "C:\\test\\mix20" + "." + fileType; File AudioFile = new File(PatnToFile); ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedInputStream in; try { audioInputStream = AudioSystem.getAudioInputStream(AudioFile); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } format = audioInputStream.getFormat(); DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); if (!AudioSystem.isLineSupported(info)) { System.out.println("Error"); } TargetDataLine line = null; try { line = (TargetDataLine) AudioSystem.getLine(info); line.open(format); } catch (LineUnavailableException ex) { System.out.println("Error"); } line.start(); byte[] data = new byte[W * format.getSampleSizeInBits() / BITS_IN_BYTE * 2]; try { in = new BufferedInputStream(new FileInputStream(AudioFile)); int read; while ((read = in.read(data)) > 0) { out.write(data, 0, read); } out.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } data = out.toByteArray(); int sampleSize = format.getSampleSizeInBits() / 8; long framesCount = data.length / (sampleSize * format.getChannels()); float sec = framesCount / format.getFrameRate(); // Продолжительность // файла! в секундах int len = (int) ((0.25 * format.getFrameRate()) * sampleSize); // System.out.println("Секунд: " + sec); // System.out.println(len); /* * byte[] mas1 = new byte[len]; System.arraycopy(data, 0, mas1, 0, len); * int mas2[] = new int[len]; System.arraycopy(data, len, mas2, 0, len); * int mas3[] = new int[len]; System.arraycopy(data, len * 2, mas3, 0, * len); int mas4[] = new int[len]; System.arraycopy(data, len * 3, * mas4, 0, len); int mas5[] = new int[len]; System.arraycopy(data, len * * 4, mas5, 0, len); int mas6[] = new int[len]; System.arraycopy(data, * len * 5, mas6, 0, len); int mas7[] = new int[len]; * System.arraycopy(data, len * 6, mas7, 0, len); int mas8[] = new * int[len]; System.arraycopy(data, len * 7, mas8, 0, len); int mas9[] = * new int[len]; System.arraycopy(data, len * 8, mas9, 0, len); int * mas10[] = new int[len]; System.arraycopy(data, len * 9, mas10, 0, * len); */ byte[] ms1 = new byte[len]; ms1 = Arrays.copyOfRange(data, 0, len); byte[] ms2 = new byte[len]; masCopy(ms2,data,2); byte[] ms3 = new byte[len]; masCopy(ms3,data,3); byte[] ms4 = new byte[len]; masCopy(ms4,data,4); byte[] ms5 = new byte[len]; masCopy(ms5,data,5); byte[] ms6 = new byte[len]; masCopy(ms6,data,6); byte[] ms7 = new byte[len]; masCopy(ms7,data,7); byte[] ms8 = new byte[len]; masCopy(ms8,data,8); byte[] ms9 = new byte[len]; masCopy(ms9,data,9); } private static void masCopy(byte[] mas,byte[] data, int c){ int leengt = 8000; mas = Arrays.copyOfRange(data, leengt*c-1, leengt*c); } }