2012-07-11 2 views
1

작은 덩어리로 만들고 싶은 큰 wav 파일이 있습니다. 작은 덩어리가 있어야하는 프레임 속도 길이가있는 .cue 파일도 있습니다. 나는 wav를 분할하는 방법을 알아 냈지만, 만들어지는 모든 wav 파일은 같은 소리이다. 새 wav를 만들 때마다 큰 wav 파일이 처음부터 시작되어 새 파도를 올바른 길이로 만들지 만 동일한 소리로 만드는 것 같습니다.큰 Wav 파일을 Java의 작은 덩어리로 추출

은 내가

내가 시간이에서 봤는데, 다음 ... 등, 독서를 계속 다른 파일에 기록 후, 파일에 쓰기 특정 프레임에 WAV를 읽을 수있는 방법을 필요가 있다고 생각 그것을 알아낼 수없는 것 같습니다. 어떤 도움이라도 대단히 감사하겠습니다. 다음은 내 코드입니다. 주석 처리 된 모든 내용은 내가 시도한 잘못된 코드입니다. 이 모든 사이클을 재현되지 않도록

AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1)); 

가져가하고 while 루프의 외부에 넣어 :

int count2 = 0; 
    int totalFramesRead = 0; 
     //cap contains the how many wav's are to be made 
     //counter contains the vector position. 
     String wavFile1 = "C:\\Users\\DC3\\Desktop\\wav&text\\testwav.wav"; 
      //String wavFile2 = "C:\\Users\\DC3\\Desktop\\waver\\Battlefield.wav"; 
      while(count2 != counter){ 
      try { 
        AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1)); 
        int bytesPerFrame = clip1.getFormat().getFrameSize(); 
        //System.out.println(bytesPerFrame); 
//      int numBytes = safeLongToInt(clip1.getFrameLength()) * bytesPerFrame; 
//      byte[] audioBytes = new byte[numBytes]; 
//      int numBytesRead = 0; 
//      int numFramesRead = 0; 
//      // Try to read numBytes bytes from the file. 
//      while ((numBytesRead = 
//      clip1.read(audioBytes)) != -1) { 
//      // Calculate the number of frames actually read. 
//      clip1.read(audioBytes) 
//      numFramesRead = numBytesRead/bytesPerFrame; 
//      totalFramesRead += numFramesRead; 
//      System.out.println(totalFramesRead); 
//      } 

        long lengthofclip = Integer.parseInt(time.get(count2))- silence; 

        globallength = clip1.getFrameLength(); 
        AudioInputStream appendedFiles = new AudioInputStream(clip1, clip1.getFormat(), lengthofclip); 
        //long test = (appendedFiles.getFrameLength() *24 *2)/8; 
        //int aaaaa = safeLongToInt(test); 
        //appendedFiles.mark(aaaaa); 
        AudioSystem.write(appendedFiles, 
          AudioFileFormat.Type.WAVE, 
          new File("C:\\Users\\DC3\\Desktop\\wav&text\\" + name.get(count2))); 
          count2++; 
      } catch (Exception e) { 
        e.printStackTrace(); 
      } 
     } 
    } 
    public static int safeLongToInt(long l) { 
    if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { 
     throw new IllegalArgumentException 
      (l + " cannot be cast to int without changing its value."); 
    } 
    return (int) l; 
} 

답변

2

첫눈에 그냥 생각하지만 난이 줄 문제를주고 있으리라 믿고있어 . 그래서 같이 :

//... 
    String wavFile1 = "C:\\Users\\DC3\\Desktop\\wav&text\\testwav.wav"; 
    AudioInputStream clip1 = AudioSystem.getAudioInputStream(new File(wavFile1)); 
    int bytesPerFrame = clip1.getFormat().getFrameSize(); 

     while(count2 != counter){ 
     try { 
//... 

이 또한 내가 시간을 당신이 그 질문 - D

을 요구하지 않았기 때문에 생각을 낭비하지 않을거야하는 알고리즘이 올바른지 가정
관련 문제