16 bit wav file reading
From: Cormac O'Donnell (cormacodonnell_at_hotmail.com)
Date: 02/26/04
- Next message: NotAsDumbAsILook: "Re: Passing objects (not stones)"
- Previous message: kaiwing18_at_hotmail.com: "JAVA ResultSet Problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Feb 2004 08:20:26 -0800
I am implementing an fft algorithm in java and would like to clear
this point up. I am reading a 16 bit wav file with format :
float sampleRate = 16000; //8000,11025,16000,22050,44100
int sampleSizeInBits = 16; //8,16
int channels = 1; //1,2
boolean signed = true; //true,false
boolean bigEndian = false
i am looking to read the file into an array to manipulate it. Each
sample is 16 bit represented by two 8 bit bytes. . if i use the code
below am i reading the file accurately, i want to end up with an array
of integers in the range + or - 16000.:
File fileIn = new File(name);
try {
AudioInputStream audioInputStream =
AudioSystem.getAudioInputStream(fileIn);
byte[] Sample1= null;
// lines.removeAllElements(); // clear the old
vector
AudioFormat format = audioInputStream.getFormat();
if (Sample == null) {
try {
Sample1 = new byte[
(int) (audioInputStream.getFrameLength()
* format.getFrameSize())];
audioInputStream.readSamples(Sample1);
} catch (Exception ex) {
// reportStatus(ex.toString());
return;
}
}
Sample = new double[Sample1.length];
for(int jl=0;jl<Sample1.length;jl++){
Sample[jl] =Sample1[jl];
}
nSamples = Sample1.length;
} catch (Exception e) {
System.out.println(e);
- Next message: NotAsDumbAsILook: "Re: Passing objects (not stones)"
- Previous message: kaiwing18_at_hotmail.com: "JAVA ResultSet Problem?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|