memory address problem

Hi,
I am working on this project.
I am trying to take a .wav file and read the data (headers, chuncks, samples and addresses of the samples, ETC...).
I have this code:


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
import java.lang.Exception;


public class Project_Ala

{
    public static void main(String[] args) throws java.lang.IllegalArgumentException,
                        java.io.IOException,
                        java.lang.Exception
    {      
        FileReader fr = null;
        FileWriter fw = null;
       
        try
        {
              File      sourceFile = new File("C:/Documents and Settings/s118608/Desktop/School/CIS416_PROGRAMMING/Project/dsclip.wav");      
              
              AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(sourceFile);                                                            
                  AudioFileFormat.Type targetFileType = fileFormat.getType();                                                                                    
                  AudioFormat audioFormat = fileFormat.getFormat();                                                                                                
                  System.out.println("fileFormat "+fileFormat);
                                                                                                                  System.out.println();                                                                                                                                          
                                    
            fr = new FileReader("C:/Documents and Settings/s118608/Desktop/School/CIS416_PROGRAMMING/Project/dsclip.wav");
                   
            fw = new FileWriter("C:/Documents and Settings/s118608/Desktop/School/CIS416_PROGRAMMING/Project/dsclip.txt");
           
                  int ch = 0, i = 0;
         
       while((ch = fr.read()) != -1)
                  {
                  //System.out.print(ch);                                                
                  fw.write(ch);                                                                  
                System.out.print(Integer.toHexString(ch));
                System.out.print(" ");
                //fw.write(Integer.toHexString(ch));
                fw.write(" ");
                     i++;                                                                               
                      if (i%4==0)
                           {                                                                              
                           System.out.print("   ");                                                                        
                        }                    
                     if (i == 24)                                                                  
                           {                                                                              
                           System.out.println();                                                
                           i=0;                                                                        
                        }
                  }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }  
        finally
        {
            try
            {
                fr.close();
                fw.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }            
        }    
    }
}


Here is a sample output:

--------------------Configuration: <Default>--------------------
fileFormat WAVE (.wav) file, byte length: 10051, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 10005

52 49 46 46    3b 27 0 0    57 41 56 45    66 6d 74 20    12 0 0 0    7 0 1 0    
40 1f 0 0    40 1f 0 0    1 0 8 0    0 0 64 61    74 61 15 27    0 0 ef e9    
ff 72 fe ea    eb f5 f6 7b    f6 7a 68 7d    70 7e 71 72    fe fe f1 f2    7e 6a fe fe    
73 fd fd fd    fe fe fe f1    ff ff ff 72    fe fe fe ea    71 6a fd fd    fd fe fe fe    
73 74 e9 f1    ff f2 f3 70    71 72 73 f0    e3 eb f6 6e    6f 7d 7d f4    7c 6f 71 6a  

What I need is to get the output to look like this:

--------------------Configuration: <Default>--------------------
fileFormat WAVE (.wav) file, byte length: 10051, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 10005

52 49 46 46    3b 27 0 0    57 41 56 45    66 6d 74 20    12 0 0 0    7 0 1 0    
40 1f 0 0    40 1f 0 0    1 0 8 0    0 0 64 61    74 61 15 27    0 0 ef e9    

value 7F hex is located at address 1E7A hex
or
7F @1E7A

I can get the hex value out but not the hex address of that value.
How do I get the address out?
Thanks
Al


lacroix_alAsked:
Who is Participating?
 
CEHJCommented:
You're already tracking the offset:

>>i++;

so you just need to keep a track of/print the offset-value from whatever data section you need.              

http://www.cs.caltech.edu/~fowlkes/writeup/source/WAVReader.java
0
 
CEHJCommented:
Surely all you need to do is to map the value to the offset?
0
 
lacroix_alAuthor Commented:
ok
So how do I go about doing that?
Al
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
lacroix_alAuthor Commented:
Cehj,
Ok so in this program arg[0] = the input file.
What does arg[1] =?
Al
0
 
objectsCommented:
args[1] is ther number of amplitudes to output.
0
 
lacroix_alAuthor Commented:
Thank you
Al
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.