-
Bug
-
Resolution: Cannot Reproduce
-
P5
-
None
-
1.3.1
-
x86
-
linux
Name: bsC130419 Date: 07/30/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
Using the following code example (a simple audio player), I hear clicks while
the audio file is playing. I tested it on different machines with sound cards
SB16, SB128 PCI using ALSA or kernel module sound. Other audio applications like
'sox' play the audiofiles well, so I don't think that my audio configuration is
wrong.
Usage of program: java AudioPlayer wav_file
/*
* AudioPlayer.java
*/
/**
* @author Klaus J?nsch
*/
import javax.sound.sampled.*;
import java.io.*;
public class AudioPlayer {
AudioFileFormat affm;
AudioFormat afm;
SourceDataLine sdl;
String filename;
File f;
AudioInputStream s;
byte buf[];
int length;
/** Creates new AudioPlayer */
public AudioPlayer(String filename) {
this.filename = filename;
play(f);
}
public void play(File f) {
try {
f=new File(filename);
affm=AudioSystem.getAudioFileFormat(f);
s=AudioSystem.getAudioInputStream(f);
DataLine.Info info = new DataLine.Info(SourceDataLine.class,
affm.getFormat() );
sdl = (SourceDataLine) AudioSystem.getLine(info);
length=(int)s.getFrameLength()* affm.getFormat().getFrameSize();
buf= new byte[length];
int read;
read=0;
while(read<length) {
read+=s.read(buf,read,length);
}
System.out.println("Read "+read+ " Bytes.");
sdl.open(affm.getFormat());
} catch (Exception e ) {
e.printStackTrace();
System.exit(1);
}
sdl.start();
sdl.write(buf,0,length);
}
public static void main( String args[] ) {
new AudioPlayer(args[0]);
}
}
Thanks.
Klaus J?nsch
(Review ID: 127099)
======================================================================