16 bit wav file reading

From: Cormac O'Donnell (cormacodonnell_at_hotmail.com)
Date: 02/26/04


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);



Relevant Pages

  • Re: opening multiple files in fortran
    ... last format: r_hifreq10000.out ... array, outnu. ... - so each of my 10,000 output files would have 14,391 entries apiece). ... you are truly reading a large number of files, ...
    (comp.lang.fortran)
  • Re: unbuffered file IO?
    ... and where im reading contents into the array ... since the array is a longand therefore strings can't be placed in it ... looking at files which have the special sort of format you're ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Really Stuck, Please Help
    ... I am not sure how to construct an array. ... Reading Master Log", of the "Copreco Master Log" workbook. ... Dim sourceBook As String ...
    (microsoft.public.excel.programming)
  • Re: Problem with a script
    ... a loop there becomes impractical. ... You still have them as uniquely named array indexes... ... writing the code twice will only ... reading your entire code and parsing it in their head, ...
    (comp.lang.php)
  • Re: Problem with a script
    ... Okay, so variables have unique labels, that doesn't mean they still couldn't be handled in a loop. ... You still have them as uniquely named array indexes... ... I believe that for the new guy this code would be readable, and identifying problems should really not be any more difficult with this, plus I think that it actually might save some time to write the actual code from the beginnig, even though it's not at it's final stage, instead of first writing everything spread out, and then rewriting the same code again cleaned. ... If you expect a person to spend an hour reading your entire code and parsing it in their head, you wont get any help and have to solve the problem by yourself. ...
    (comp.lang.php)