Пример #1
0
  public static void main(String[] args) {
    if (args.length < 1) {
      System.err.println("Must supply filename");
      System.exit(1);
    }

    try {
      for (String filename : args) {
        WavFile readWavFile = openWavFile(new File(filename));
        readWavFile.display();

        long numFrames = readWavFile.getNumFrames();
        int numChannels = readWavFile.getNumChannels();
        int validBits = readWavFile.getValidBits();
        long sampleRate = readWavFile.getSampleRate();

        WavFile writeWavFile =
            newWavFile(new File("out.wav"), numChannels, numFrames, validBits, sampleRate);

        final int BUF_SIZE = 5001;

        //				int[] buffer = new int[BUF_SIZE * numChannels];
        //				long[] buffer = new long[BUF_SIZE * numChannels];
        double[] buffer = new double[BUF_SIZE * numChannels];

        int framesRead = 0;
        int framesWritten = 0;

        do {
          framesRead = readWavFile.readFrames(buffer, BUF_SIZE);
          framesWritten = writeWavFile.writeFrames(buffer, BUF_SIZE);
          System.out.printf("%d %d\n", framesRead, framesWritten);
        } while (framesRead != 0);

        readWavFile.close();
        writeWavFile.close();
      }

      WavFile writeWavFile = newWavFile(new File("out2.wav"), 1, 10, 23, 44100);
      double[] buffer = new double[10];
      writeWavFile.writeFrames(buffer, 10);
      writeWavFile.close();
    } catch (Exception e) {
      System.err.println(e);
      e.printStackTrace();
    }
  }
  public boolean processFromFile(String filename) {
    try {

      WavFile wavFile = WavFile.openWavFile(new File(filename));

      int numChannels = wavFile.getNumChannels();
      final int BUFFERSIZE = 1000;
      short buffer[] = new short[BUFFERSIZE * numChannels];
      int numberOfFrames = 0;

      do {

        numberOfFrames = wavFile.readFrames(buffer, 0, BUFFERSIZE);
        if (numberOfFrames == 0) return false;
      } while (!process(buffer, 0, numberOfFrames));

    } catch (Throwable t) {

      t.printStackTrace();
    }
    return true;
  }