/** * Export an array of shorts to a wav file. * * @param fileName * The name of the wav file. * @param sampleRate * The sample rate. * @param samples * The array of short samples. * @throws IOException * IOException */ public void export(String fileName, int sampleRate, short[] samples) throws IOException { nBytesPerSample = 2; buf = new byte[samples.length * 2]; // Cast the samples, and byte-swap them in the same loop for (int i = 0; i < samples.length; i++) { buf[2 * i] = (byte) ((samples[i] & 0xff00) >>> 8); buf[2 * i + 1] = (byte) ((samples[i] & 0x00ff)); } // Do the write doWrite(fileName, sampleRate); }
/** * Export an array of shorts to a wav file. * * @param fileName * The name of the wav file. * @param sampleRate * The sample rate. * @param samples * The array of short samples. * @throws IOException * IOException */ public void export(String fileName, int sampleRate, short[] samples) throws IOException { nBytesPerSample = 2; buf = new byte[samples.length * 2]; // Cast the samples, and byte-swap them in the same loop for (int i = 0; i < samples.length; i++) { buf[2 * i] = (byte) ((samples[i] & 0xff00) >>> 8); buf[2 * i + 1] = (byte) ((samples[i] & 0x00ff)); } // Do the write doWrite(fileName, sampleRate); }
/** * Export an array of bytes to a wav file. * * @param fileName * The name of the wav file. * @param sampleRate * The sample rate. * @param samples * The array of short samples, given as a byte array (with low and hi bytes separated). * @throws IOException * IOException */ public void export(String fileName, int sampleRate, byte[] samples) throws IOException { nBytesPerSample = 2; buf = new byte[samples.length]; System.arraycopy(samples, 0, buf, 0, samples.length); // Byte-swap the samples byte b = 0; for (int j = 0; j < buf.length; j += 2) { b = buf[j]; buf[j] = buf[j + 1]; buf[j + 1] = b; } // Do the write doWrite(fileName, sampleRate); }
/** * Export an array of bytes to a wav file. * * @param fileName * The name of the wav file. * @param sampleRate * The sample rate. * @param samples * The array of short samples, given as a byte array (with low and hi bytes separated). * @throws IOException * IOException */ public void export(String fileName, int sampleRate, byte[] samples) throws IOException { nBytesPerSample = 2; buf = new byte[samples.length]; System.arraycopy(samples, 0, buf, 0, samples.length); // Byte-swap the samples byte b = 0; for (int j = 0; j < buf.length; j += 2) { b = buf[j]; buf[j] = buf[j + 1]; buf[j + 1] = b; } // Do the write doWrite(fileName, sampleRate); }