By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

16 bit wav file reading

P: n/a
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);
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.