public static WaveData create(AudioInputStream ais) {
		//get format of data
		AudioFormat audioformat = ais.getFormat();

		// get channels
		int channels = 0;
		if (audioformat.getChannels() == 1) {
			if (audioformat.getSampleSizeInBits() == 8) {
				channels = AL10.AL_FORMAT_MONO8;
			} else if (audioformat.getSampleSizeInBits() == 16) {
				channels = AL10.AL_FORMAT_MONO16;
			} else {
				throw new RuntimeException("Illegal sample size");
			}
		} else if (audioformat.getChannels() == 2) {
			if (audioformat.getSampleSizeInBits() == 8) {
				channels = AL10.AL_FORMAT_STEREO8;
			} else if (audioformat.getSampleSizeInBits() == 16) {
				channels = AL10.AL_FORMAT_STEREO16;
			} else {
				throw new RuntimeException("Illegal sample size");
			}
		} else {
			throw new RuntimeException("Only mono or stereo is supported");
		}

		//read data into buffer
		byte[] buf =
			new byte[audioformat.getChannels()
				* (int) ais.getFrameLength()
				* audioformat.getSampleSizeInBits()
				/ 8];
		int read = 0, total = 0;
		try {
			while ((read = ais.read(buf, total, buf.length - total)) != -1
				&& total < buf.length) {
				total += read;
			}
		} catch (IOException ioe) {
			return null;
		}

		//insert data into bytebuffer
		ByteBuffer buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16);
/*		ByteBuffer buffer = ByteBuffer.allocateDirect(buf.length);
		buffer.put(buf);
		buffer.rewind();*/

		//create our result
		WaveData wavedata =
			new WaveData(buffer, channels, (int) audioformat.getSampleRate());

		//close stream
		try {
			ais.close();
		} catch (IOException ioe) {
		}

		return wavedata;
	}
public static WaveData create ( AudioInputStream ais ) { AudioFormat audioformat = ais . getFormat ( ) ; int channels = 0 ; if ( audioformat . getChannels ( ) == 1 ) { if ( audioformat . getSampleSizeInBits ( ) == 8 ) { channels = AL10 . AL_FORMAT_MONO8 ; } else if ( audioformat . getSampleSizeInBits ( ) == 16 ) { channels = AL10 . AL_FORMAT_MONO16 ; } else { throw new RuntimeException ( "Illegal sample size" ) ; } } else if ( audioformat . getChannels ( ) == 2 ) { if ( audioformat . getSampleSizeInBits ( ) == 8 ) { channels = AL10 . AL_FORMAT_STEREO8 ; } else if ( audioformat . getSampleSizeInBits ( ) == 16 ) { channels = AL10 . AL_FORMAT_STEREO16 ; } else { throw new RuntimeException ( "Illegal sample size" ) ; } } else { throw new RuntimeException ( "Only mono or stereo is supported" ) ; } byte [ ] buf = new byte [ audioformat . getChannels ( ) * ( int ) ais . getFrameLength ( ) * audioformat . getSampleSizeInBits ( ) / 8 ] ; int read = 0 , total = 0 ; try { while ( ( read = ais . read ( buf , total , buf . length - total ) ) != - 1 && total < buf . length ) { total += read ; } } catch ( IOException ioe ) { return null ; } ByteBuffer buffer = convertAudioBytes ( buf , audioformat . getSampleSizeInBits ( ) == 16 ) ; WaveData wavedata = new WaveData ( buffer , channels , ( int ) audioformat . getSampleRate ( ) ) ; try { ais . close ( ) ; } catch ( IOException ioe ) { } return wavedata ; }
Creates a WaveData container from the specified stream

@param ais AudioInputStream to read from
@return WaveData containing data, or null if a failure occured