JDK-4312196 : Java Sound Demo: error in CapturePlayback.java
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic,linux
  • CPU: generic,x86
  • Submitted: 2000-02-12
  • Updated: 2006-05-31
  • Resolved: 2006-05-31
Related Reports
Duplicate :  
Description
Name: rlT66838			Date: 02/11/2000


java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, symcjit)

I believe that I found a bug in your CapturePlayback.java program.

(I am working with the version found in the demo/sound/src directory of jdk 1.3
release candidate 1; the source file says that this version is 1.11 

The bug is in the run  method, and the offending code block is

	int numBytesRemaining = numBytesRead;
	while (numBytesRemaining > 0) {
		numBytesRemaining -= sourceDataLine.write(data, 0,
numBytesRemaining);
	}

The bug is that the offset -- which you keep at a fixed value of 0 -- will
actually be changing should you have to execute the while loop more than once.
(The reason why you probably did not catch this bug is because the while loop
almost always needs to execute only once.)

Here is a code block which I believe will correct the problem:

	int offset = 0;
	int numBytesRemaining = numBytesRead;
	while (numBytesRemaining > 0) {
		int numBytesWrote = line.write(data, offset, numBytesRemaining);
		numBytesRemaining -= numBytesWrote;
		offset += numBytesWrote;
	}


(Review ID: 101143) 
======================================================================

Name: yyT116575			Date: 11/06/2000


[root@wlglap projects]# java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)



run CapturePlayback and press the Record button.

The problem lies in the fact that getLine has a Line.Info argument;
Consequently, it cannot know if it needs a Source- or TargetDataLine.
It always returns the Source one first, so one cannot record.

This is also true for Mixer.getLine() .

It really needs a way to differentiate between Source and Target formats.
(Review ID: 111847)
======================================================================

Comments
EVALUATION sharon.huang@eng 2000-09-27 This is a java sound bug. Checked that this bug is still in solaris jdk1.3 FCS ###@###.### 2002-03-12 Fixed in private workspace. Will be published on Java Sound Homepage along with other fixes in the Demo ( http://java.sun.com/products/java-media/sound/ )
12-03-2002