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: reading nth columns
    ... e.g suppose format of my file is something like ... I know of fscanf which can be used like ... succeeded in reading anything. ... into a chararray and using sscanfon the array; ...
    (comp.lang.c)
  • Re: reading nth columns
    ... e.g suppose format of my file is something like ... I know of fscanf which can be used like ... succeeded in reading anything. ... into a chararray and using sscanfon the array; ...
    (comp.lang.c)
  • 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)

Quantcast