Code example for SourceDataLine

Methods: getBufferSizegetFormat

0
		return audioData;
	} 
 
	/** Converts a frame count to a duration in milliseconds. */ 
	private long convertFramesToMilliseconds(int frames) {
		return (frames / (long) dataLine.getFormat().getSampleRate()) * 1000;
	} 
 
	/** Converts a duration in milliseconds to a frame count. */ 
	private int convertMillisecondsToFrames(long milliseconds) {
		return (int) (milliseconds / dataLine.getFormat().getSampleRate());
	} 
 
	@Override 
	public void update(LineEvent le) {
		// PlayN.log().debug("update: " + le); 
	} 
 
	@Override 
	public void loop(int count) {
		// PlayN.log().debug("loop(" + count + ") - framePosition: " + 
		// framePosition); 
		loopCount = count;
		countDown = count;
		active = true;
		inputStream.reset();
 
		start(); 
	} 
 
	@Override 
	public void setLoopPoints(int start, int end) {
		if (start < 0 || start > audioData.length - 1 || end < 0
				|| end > audioData.length) {
			throw new IllegalArgumentException("Loop points '" + start
					+ "' and '" + end + "' cannot be set for buffer of size "
					+ audioData.length);
		} 
		if (start > end) {
			throw new IllegalArgumentException("End position " + end
					+ " preceeds start position " + start);
		} 
 
		loopPointStart = start;
		framePosition = loopPointStart;
		loopPointEnd = end;
	} 
 
	@Override 
	public void setMicrosecondPosition(long milliseconds) {
		framePosition = convertMillisecondsToFrames(milliseconds);
	} 
 
	@Override 
	public long getMicrosecondPosition() { 
		return convertFramesToMilliseconds(getFramePosition()); 
	} 
 
	@Override 
	public long getMicrosecondLength() { 
		return convertFramesToMilliseconds(getFrameLength()); 
	} 
 
	@Override 
	public void setFramePosition(int frames) {
		framePosition = frames;
		int offset = framePosition * format.getFrameSize();
		try { 
			inputStream.reset();
			inputStream.read(new byte[offset]);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	} 
 
	@Override 
	public int getFramePosition() { 
		long timeSinceLastPositionSet = System.currentTimeMillis()
				- timelastPositionSet;
		int size = dataLine.getBufferSize() * (format.getChannels() / 2)
				/ bufferUpdateFactor;
 
		// Step down to the next whole frame. 
		size /= dataLine.getFormat().getFrameSize();
		size *= dataLine.getFormat().getFrameSize();
 
		int framesSinceLast = (int) ((timeSinceLastPositionSet / 1000f) * dataLine
				.getFormat().getFrameRate());
		int framesRemainingTillTime = size - framesSinceLast;
		return framePosition - framesRemainingTillTime;
	} 
 
	@Override