Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read and modify amr audio file data?

How can i extract information like sample rate , bit rate etc from an AMR-NB file . Strictly speaking I want the sample rate or any other data that may alter its pitch or tempo.

It was easy for WAV files but here I am constrained with AMR-NB format (J2me Devices)

I have searched a lot on google but can't get anything on it ...

is AMR-NB fixed at 8Khz? or it varies with each sample?

like image 515
user1448559 Avatar asked Nov 03 '22 21:11

user1448559


1 Answers

According to the AMR file format at:http://developer.nokia.com/community/wiki/AMR_format AMR files have a 6 byte header, followed by a set of audio frames, each with a 1 byte header. Each audio frame is 20 ms long and has and the sample rate is given in the header of each frame. so to read the sample rate for the first frame, you need to read the 7th byte in the file. Take the 7th byte and shift it right 3 bits, and mask out the lower 4 bits of the new value. In java this is "((value>>3)& 0x0F)" where value is the 1 byte header for the frame. Then check that number against the table below to determine the bitrate for that frame. then since each frame is 20ms long, you need to multiply the bitrate(they give it as kb/s so multiply that number by 1000 to get the bits per second) by 20 and divide by ((8 bits per byte) * 1000ms per second) = 8000 to get the number of bytes to skip for the next frame header. If you want to modify the contents of the frame simply recopy the frames in sequence to a new file but replace your new frame with an old one. A temp file is good for this.I've copied the bitrate table form the source page below for reference.

0 - AMR 4.75 - Encodes at 4.75kbit/s

1 - AMR 5.15 - Encodes at 5.15kbit/s

2 - AMR 5.9 - Encodes at 5.9kbit/s

3 - AMR 6.7 - Encodes at 6.7kbit/s

4 - AMR 7.4 - Encodes at 7.4kbit/s

5 - AMR 7.95 - Encodes at 7.95kbit/s

6 - AMR 10.2 - Encodes at 10.2kbit/s

7 - AMR 12.2 - Encodes at 12.2kbit/s

like image 165
S E Avatar answered Nov 12 '22 14:11

S E