Name: rmT116609 Date: 02/19/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]
EXTRA RELEVANT SYSTEM CONFIGURATION :
Analog Devices SoundMAX (smwdm.sys 5.12.0001.3045)
A DESCRIPTION OF THE PROBLEM :
When playing back an audio stream using the javax.sound.sampled SourceDataLine API, sound does not stop when the end of data has been reached. Instead, the audio loops infinitely.
For example, if you write 5000 samples of a sine wave tone to a SourceDataLine at 44100 Hz, then do not play any more, you would expect to hear a ~0.1 second tone followed by silence. In fact, you hear the 0.1 second tone, then a pause, then the same tone, and so on.
This loop continues indefinitely unless you manually stop the line, close the buffer, etc. The specification does not require you to stop the buffer. You should not need to keep track of precise timing for when the buffer is likely to need stopping.
(This is likely the result of the DirectX buffer not being stopped.)
It is easiest to detect this problem with a short sound, but the same problem applies even if you write a large quantity of audio data. If you change the LOOPS constant in the attached sample code, for example to 1000 (which should last approximately 2 seconds) the sinewave will now become a continuous, infinite tone lasting until the program exits.
This precise problem does not occur in 1.4.2_03. The test case works correctly in 1.4.2_03 (a bit of a miracle in itself since JavaSound streaming is still seriously broken there, but hey).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Write a small quantity of sound data to a SourceDataLine
2. Do not call stop() on the line.
3. Sleep for a bit
EXPECTED VERSUS ACTUAL BEHAVIOR :
A short sound should be heard, once.
The short sound was repeated at approximately 1 second intervals.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No errors appear.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class JavaSound
public static void main(String args) throws Exception
short asSineWave=new short;
asSineWave[i]=(short)(32767.0*Math.sin(2.0 * Math.PI * (double)i / 100.0));
ByteArrayOutputStream baosConversionBuffer=new ByteArrayOutputStream();
AudioFormat af=new AudioFormat(44100f,16,1,true,bBigEndian);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You could write a buffer's worth of extra blank data at the end of the audio (so that the looping part is blank and therefore inaudible).... while this would be a possible solution for the test case it would be somewhat difficult in real use, particularly in Internet streaming applications which need graceful handling for the case when audio data does not arrive on time.
(Incident Review ID: 239500)