my dog learned polymorphism*
The moose likes I/O and Streams and the fly likes How to read headers of a audio file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to read headers of a audio file?" Watch "How to read headers of a audio file?" New topic
Author

How to read headers of a audio file?

Rithya Lath
Greenhorn

Joined: Feb 25, 2013
Posts: 4
Hello everyone, I want to read then write all the headers of a AU audio file to another AU file. I understand different audio formats have different headers. I'm specifically dealing with AU files here. Here is the header data for a AU file, http://docs.python.org/2/library/sunau.html. I can retrieve the magic word field by using FileInputStream. Here is what I have so far.



I know there are libraries that already handle this but I need to do this without those libraries. Help is appreciated!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2405
    
  50
Do you know how the bytes are encoded, ie big endian or little endian, are the bytes signed etc.
Can you show an example of the bytes you need to convert to an int and the actual int value they represent.
Rithya Lath
Greenhorn

Joined: Feb 25, 2013
Posts: 4
They are all 32-bit unsigned integers encoded in big-endian byte order.

Changing the System.out.print to System.out.println in the original code above would print



I'm trying to print


Here is a reference to results i'm trying to print out to the console, http://en.wikipedia.org/wiki/Au_file_format
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2405
    
  50
Sorry but I can't see how you can get those numbers from the bytes shown.
Also you seem to be missing a byte or as you have 4 bytes for the magic word and then 27 bytes which isn't divisible by 4.
Rithya Lath
Greenhorn

Joined: Feb 25, 2013
Posts: 4
I must of made typos. This is what I get.



I did figure to out using this as a reference, http://stackoverflow.com/questions/4492711/java-convert-byte-to-integer

What I did was loop through the byteBuffer array by increments of four then used this in the loop



This prints out



I appreciate your help!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2405
    
  50
Here's some code I knocked up to do the conversion from a byte array and print out the parts:

The output is:
Rithya Lath
Greenhorn

Joined: Feb 25, 2013
Posts: 4
Thanks!!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2405
    
  50
My pleasure
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read headers of a audio file?