float time = (buf.length) / (rate * vorbisInfo.channels * 2);
float time = (buf.length) / (float)(rate * vorbisInfo.channels * 2);
	private IBuffer loadOGG(URL file) {		int length = 0;		InputStream input = null;		ByteArrayOutputStream baout = new ByteArrayOutputStream();		IBuffer[] tmp = null;		try {			input = file.openStream();			int convsize = 4096 * 2;			byte[] convbuffer = new byte[convsize];			SyncState syncState = new SyncState();			StreamState streamState = new StreamState();			Page page = new Page();			Packet packet = new Packet(); // one raw packet of data for decode			Info vorbisInfo = new Info(); // struct that stores all the static			Comment vorbisComment = new Comment(); // struct that stores all the			DspState dspState = new DspState(); // central working state for the			Block vorbisBlock = new Block(dspState); // local working space for			byte[] buffer;			int bytes = 0;			syncState.init();			while (true) {				int eos = 0;				int index = syncState.buffer(4096);				buffer = syncState.data;				try {					bytes = input.read(buffer, index, 4096);				} catch (Exception e) {					System.err.println(e);					System.exit(-1);				}				syncState.wrote(bytes);				if (syncState.pageout(page) != 1) {					if (bytes < 4096)						break;					LoggingSystem.getLogger().log(Level.SEVERE,							"Input does not appear to be an Ogg bitstream.");					return new Buffer(0);				}				streamState.init(page.serialno());				vorbisInfo.init();				vorbisComment.init();				if (streamState.pagein(page) < 0) {					LoggingSystem.getLogger().log(Level.SEVERE,							"Error reading first page of Ogg bitstream data.");					return new Buffer(0);				}				if (streamState.packetout(packet) != 1) {					LoggingSystem.getLogger().log(Level.SEVERE,							"Error reading initial header packet.");					return new Buffer(0);				}				if (vorbisInfo.synthesis_headerin(vorbisComment, packet) < 0) {					LoggingSystem							.getLogger()							.log(Level.SEVERE,									"This Ogg bitstream does not contain Vorbis audio data.");					return new Buffer(0);				}				int i = 0;				while (i < 2) {					while (i < 2) {						int result = syncState.pageout(page);						if (result == 0)							break; // Need more data						if (result == 1) {							streamState.pagein(page);							while (i < 2) {								result = streamState.packetout(packet);								if (result == 0)									break;								if (result == -1) {									LoggingSystem											.getLogger()											.log(Level.SEVERE,													"Corrupt secondary header.  Exiting.");									return new Buffer(0);								}								vorbisInfo.synthesis_headerin(vorbisComment,										packet);								i++;							}						}					}					index = syncState.buffer(4096);					buffer = syncState.data;					try {						bytes = input.read(buffer, index, 4096);					} catch (Exception e) {						System.err.println(e);						return new Buffer(0);					}					if (bytes == 0 && i < 2) {						LoggingSystem								.getLogger()								.log(Level.SEVERE,										"End of file before finding all Vorbis headers!");						return new Buffer(0);					}					syncState.wrote(bytes);				}				{					byte[][] ptr = vorbisComment.user_comments;					for (int j = 0; j < ptr.length; j++) {						if (ptr[j] == null)							break;						System.err.println(new String(ptr[j], 0,								ptr[j].length - 1));					}					LoggingSystem.getLogger().log(							Level.INFO,							"\nBitstream is " + vorbisInfo.channels									+ " channel, " + vorbisInfo.rate + "Hz");					LoggingSystem.getLogger().log(							Level.INFO,							"Encoded by: "									+ new String(vorbisComment.vendor, 0,											vorbisComment.vendor.length - 1)									+ "\n");				}				convsize = 4096 / vorbisInfo.channels;				dspState.synthesis_init(vorbisInfo);				vorbisBlock.init(dspState);				float[][][] _pcm = new float[1][][];				int[] _index = new int[vorbisInfo.channels];				while (eos == 0) {					while (eos == 0) {						int result = syncState.pageout(page);						if (result == 0)							break;						if (result == -1) {							LoggingSystem									.getLogger()									.log(Level.SEVERE,											"Corrupt or missing data in bitstream; continuing...");						} else {							streamState.pagein(page); // can safely ignore							while (true) {								result = streamState.packetout(packet);								if (result == 0)									break;								if (result == -1) {								} else {									int samples;									if (vorbisBlock.synthesis(packet) == 0) { // test										dspState.synthesis_blockin(vorbisBlock);									}									while ((samples = dspState											.synthesis_pcmout(_pcm, _index)) > 0) {										float[][] pcm = _pcm[0];										int bout = (samples < convsize												? samples												: convsize);										for (i = 0; i < vorbisInfo.channels; i++) {											int ptr = i * 2;											int mono = _index[i];											for (int j = 0; j < bout; j++) {												int val = (int) (pcm[i][mono														+ j] * 32767.);												if (val > 32767) {													val = 32767;												}												if (val < -32768) {													val = -32768;												}												if (val < 0)													val = val | 0x8000;												convbuffer[ptr] = (byte) (val);												convbuffer[ptr + 1] = (byte) (val >>> 8);												ptr += 2 * (vorbisInfo.channels);											}										}										baout.write(convbuffer, 0, 2												* vorbisInfo.channels * bout);										length += 2 * vorbisInfo.channels												* bout;										dspState.synthesis_read(bout);									}								}							}							if (page.eos() != 0)								eos = 1;						}					}					if (eos == 0) {						index = syncState.buffer(4096);						buffer = syncState.data;						try {							bytes = input.read(buffer, index, 4096);						} catch (Exception e) {							System.err.println(e);							return new Buffer(0);						}						syncState.wrote(bytes);						if (bytes == 0)							eos = 1;					}				}				streamState.clear();				vorbisBlock.clear();				dspState.clear();				vorbisInfo.clear();			}			syncState.clear();			byte[] buf = baout.toByteArray();			ByteBuffer data = BufferUtils.createByteBuffer(buf.length);//ByteBuffer.allocateDirect(buf.length);			data.put(buf);			data.rewind();			tmp = generateBuffers(1);			int chans = getChannels(vorbisInfo);			int rate= chans == AL10.AL_FORMAT_MONO16			? vorbisInfo.rate 					: vorbisInfo.rate;			float time = (buf.length) / (rate * vorbisInfo.channels * 2);			tmp[0].configure(data, chans, rate, time);								System.out.println("Sample rate= " + vorbisInfo.rate);			System.out.println("Estimated Play Time " + time);		} catch (IOException ioe) {			ioe.printStackTrace();		}		return tmp[0];	}