<commit_before>import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;

public class WaveFile {

	public static void main(String[] args) throws IOException {
		WaveFile waveFile = new WaveFile(new File("test.wav"));
		System.out.println(waveFile.getSampleRate());
		System.out.println(waveFile.getBitsPerSample());
		System.out.println(waveFile.getDuration());
	}

	public WaveFile(File file) throws IOException {
		setFile(file);
		readBytes();
		readSampleRate();
		readBitsPerSample();
	}

	/**
	 * Gets the sample rate in kHz.
	 *
	 * @return	the sample rate in kHz.
	 */
	public int getSampleRate() {
		return mSampleRate;
	}

	public short getBitsPerSample() {
		return mBitsPerSample;
	}


	/**
	 * Gets the duration of the WAVE file in seconds.
	 *
	 * @return	The duration of the WAVE file in seconds.
	 */
	public double getDuration() {
		// Data length is the total number of bytes minus the header.
		long dataLength = mFile.length() - 44;
		// Here we assume that bits per sample will always be a multiple of 8.
		long numSamples = dataLength / (getBitsPerSample() / 8);
		return (double) numSamples / mSampleRate;
	}

	private void setFile(File file) {
		mFile = file;
	}

	private void readBytes() throws IOException {
		mBytes = FileUtils.readFileToByteArray(mFile);
	}

	private void readSampleRate() {
		byte[] sampleRateBytes = Arrays.copyOfRange(mBytes, 24, 28);
		for (byte b : sampleRateBytes) {
			System.out.println(b);
		}
		ByteBuffer bb = ByteBuffer.wrap(sampleRateBytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		mSampleRate = bb.getInt();
	}

	/**
	 * Gets the number of bits per sample.
	 *
	 * @return	The number of bits per sample.
	 */
	private void readBitsPerSample() {
		byte[] bpsBytes = Arrays.copyOfRange(mBytes, 34, 36);
		ByteBuffer bb = ByteBuffer.wrap(bpsBytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		mBitsPerSample = bb.getShort();
	}

	private File mFile;
	private byte[] mBytes;
	private int mSampleRate;
	private short mBitsPerSample;
}<commit_msg>factored in the number of channels to the duration calculation<commit_after>import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;

public class WaveFile {

	public static void main(String[] args) throws IOException {
		WaveFile waveFile = new WaveFile(new File("ok.wav"));
		System.out.println(waveFile.getSampleRate());
		System.out.println(waveFile.getBitsPerSample());
		System.out.println(waveFile.getDuration());
		System.out.println(waveFile.getNumChannels());
	}

	public WaveFile(File file) throws IOException {
		setFile(file);
		readBytes();
		readNumChannels();
		readSampleRate();
		readBitsPerSample();
	}

	/**
	 * Gets the sample rate in kHz.
	 *
	 * @return	the sample rate in kHz.
	 */
	public int getSampleRate() {
		return mSampleRate;
	}

	/**
	 * Gets the number of bits per sample.
	 *
	 * @return	The number of bits per sample.
	 */
	public short getBitsPerSample() {
		return mBitsPerSample;
	}

	/**
	 * Gets the number of channels (Mono = 1, Stereo = 2).
	 *
	 * @return	The number of channels.
	 */
	public short getNumChannels() {
		return mNumChannels;
	}


	/**
	 * Gets the duration of the WAVE file in seconds.
	 *
	 * @return	The duration of the WAVE file in seconds.
	 */
	public double getDuration() {
		// Data length is the total number of bytes minus the header.
		long dataLength = mFile.length() - 44;
		// Here we assume that bits per sample will always be a multiple of 8.
		long numSamples = dataLength / ((getBitsPerSample() / 8) * mNumChannels);
		return (double) numSamples / mSampleRate;
	}

	///////////////////////////////////////////////////////////////////////////

	private void setFile(File file) {
		mFile = file;
	}

	private void readBytes() throws IOException {
		mBytes = FileUtils.readFileToByteArray(mFile);
	}

	private void readSampleRate() {
		byte[] sampleRateBytes = Arrays.copyOfRange(mBytes, 24, 28);
		ByteBuffer bb = ByteBuffer.wrap(sampleRateBytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		mSampleRate = bb.getInt();
	}

	private void readBitsPerSample() {
		byte[] bpsBytes = Arrays.copyOfRange(mBytes, 34, 36);
		ByteBuffer bb = ByteBuffer.wrap(bpsBytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		mBitsPerSample = bb.getShort();
	}

	private void readNumChannels() {
		byte[] ncBytes = Arrays.copyOfRange(mBytes, 22, 24);
		ByteBuffer bb = ByteBuffer.wrap(ncBytes);
		bb.order(ByteOrder.LITTLE_ENDIAN);
		mNumChannels = bb.getShort();
	}

	private File mFile;
	private byte[] mBytes;
	private int mSampleRate;
	private short mBitsPerSample;
	private short mNumChannels;
}
{'fraction_non_alphanumeric': 0.127047459050819, 'fraction_numerical': 0.00629987400251995, 'mean_word_length': 3.6926108374384237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550111', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1506, 'n_words': 427}