<commit_before>package com.shc.silenceengine.audio.formats;

import com.shc.silenceengine.audio.ISoundReader;
import com.shc.silenceengine.core.SilenceException;
import com.shc.silenceengine.utils.*;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

import static org.lwjgl.openal.AL10.*;

/**
 * @author <NAME>
 */
public class WaveReader implements ISoundReader
{
    private ByteBuffer data;

    private int sampleRate;
    private int format;

    public WaveReader(InputStream is)
    {
        // Simply use JavaSound reader here
        try
        {
            AudioInputStream ais = AudioSystem.getAudioInputStream(is);
            AudioFormat fmt = ais.getFormat();

            sampleRate = (int) fmt.getSampleRate();
            format = fmt.getChannels();

            if (format == 1)
            {
                if (fmt.getSampleSizeInBits() == 8)
                    format = AL_FORMAT_MONO8;
                else if (fmt.getSampleSizeInBits() == 16)
                    format = AL_FORMAT_MONO16;
            }
            else if (format == 2)
            {
                if (fmt.getSampleSizeInBits() == 8)
                    format = AL_FORMAT_STEREO8;
                else if (fmt.getSampleSizeInBits() == 16)
                    format = AL_FORMAT_STEREO16;
            }
            else
                throw new SilenceException("Incorrect WAV file format");

            // Length of the WAV file
            int length = ais.available();

            if (length <= 0)
                length = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;

            byte[] samples = new byte[length];<commit_msg>AudioInputStream expects a BufferedInputStream when loading from JAR<commit_after>package com.shc.silenceengine.audio.formats;

import com.shc.silenceengine.audio.ISoundReader;
import com.shc.silenceengine.core.SilenceException;
import com.shc.silenceengine.utils.*;

import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;

import static org.lwjgl.openal.AL10.*;

/**
 * @author <NAME>
 */
public class WaveReader implements ISoundReader
{
    private ByteBuffer data;

    private int sampleRate;
    private int format;

    public WaveReader(InputStream is)
    {
        // Simply use JavaSound reader here
        try
        {
            BufferedInputStream bis = new BufferedInputStream(is);
            AudioInputStream ais = AudioSystem.getAudioInputStream(bis);
            AudioFormat fmt = ais.getFormat();

            sampleRate = (int) fmt.getSampleRate();
            format = fmt.getChannels();

            if (format == 1)
            {
                if (fmt.getSampleSizeInBits() == 8)
                    format = AL_FORMAT_MONO8;
                else if (fmt.getSampleSizeInBits() == 16)
                    format = AL_FORMAT_MONO16;
            }
            else if (format == 2)
            {
                if (fmt.getSampleSizeInBits() == 8)
                    format = AL_FORMAT_STEREO8;
                else if (fmt.getSampleSizeInBits() == 16)
                    format = AL_FORMAT_STEREO16;
            }
            else
                throw new SilenceException("Incorrect WAV file format");

            // Length of the WAV file
            int length = ais.available();

            if (length <= 0)
                length = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;

            byte[] samples = new byte[length];
{'fraction_non_alphanumeric': 0.0968816948345632, 'fraction_numerical': 0.008569388240895025, 'mean_word_length': 2.2199233716475097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4939921', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1157, 'n_words': 264}