The AMR storage format is set out in
RFC 4867, section 5. A file is a magic
number, an optional channel description, and then frames with nothing between them. The
narrowband codec (AMR, 8 kHz, .amr) and the wideband codec (AMR-WB, 16 kHz,
.awb) share this layout.
Magic numbers
The magic includes the final line feed, which is what tells the single-channel and multi-channel forms apart.
| Form | ASCII | Hex | Size |
|---|---|---|---|
| AMR, single channel | #!AMR\n | 23 21 41 4D 52 0A | 6 |
| AMR-WB, single channel | #!AMR-WB\n | 23 21 41 4D 52 2D 57 42 0A | 9 |
| AMR, multi-channel | #!AMR_MC1.0\n | 23 21 41 4D 52 5F 4D 43 31 2E 30 0A | 12 |
| AMR-WB, multi-channel | #!AMR-WB_MC1.0\n | 23 21 41 4D 52 2D 57 42 5F 4D 43 31 2E 30 0A | 15 |
Multi-channel header
A multi-channel magic is followed by a 32-bit field:
| Bits | Name | Meaning |
|---|---|---|
| 31–4 | reserved | 0 on writing; ignored on reading |
| 3–0 | CHAN | the number of channels |
Channels follow the order in RFC 3551, section 4.1:
| Channels | Order |
|---|---|
| 1 | mono |
| 2 | left, right |
| 3 | left, right, centre |
| 4 | left, centre, right, surround |
| 5 | front left, front right, front centre, surround left, surround right |
| 6 | left, left centre, centre, right, right centre, surround |
Speech frames
Frames are in time order, and each is 20 ms, 160 samples of narrowband or 320 of wideband. Each frame is a single header byte, then the speech bits, padded with zeroes to a whole byte.
| Bits | Name | Meaning |
|---|---|---|
| 7 | P | padding; 0 on writing, ignored on reading |
| 6–3 | FT | the frame type, which gives the mode and the length |
| 2 | Q | frame quality: 0 means the frame is damaged or bad |
| 1–0 | P | padding; 0 on writing, ignored on reading |
In a multi-channel file, frames are grouped into frame blocks: one frame per channel, starting at channel 1.
Missing and silent frames
A file keeps its timing by storing a frame for every 20 ms slot:
- During silence, the codec sends a SID frame (FT 8 for AMR, FT 9 for AMR-WB) only now and then, and the frames in between are stored as
NO_DATA(FT 15). - A frame that was lost in transmission is stored as
NO_DATA, or for AMR-WB asSPEECH_LOST(FT 14). In a multi-channel file a complete frame block is written. - Comfort-noise frames of other systems (FT 9, 10 and 11 of AMR) must not appear in the file format.
An example
An AMR file at 12.2 kbit/s:
23 21 41 4D 52 0A #!AMR and a line feed
3C frame header: FT 7 (12.2 kbit/s), Q 1
.. 31 bytes .. 244 speech bits, padded to 31 bytes
3C frame header of the next frame
…
3C is 0011 1100: P 0, FT 0111 (7), Q 1, then two
padding bits.
AMR in 3GP files
Phones often store AMR in a 3GP file instead, an
MPEG-4 file with an audio sample entry of type samr (narrowband) or
sawb (wideband). The entry holds the usual fields, then a
damr box:
| Size | Field | Meaning |
|---|---|---|
| 4 | vendor | a four-character vendor code |
| 1 | decoder_version | version of the decoder |
| 2 | mode_set | a bit mask of the modes in use; 0 means all |
| 1 | mode_change_period | how often the mode may change, in frames; 0 for any time |
| 1 | frames_per_sample | frames stored per media sample |
The frames inside keep the same one-byte headers as above. The structure is defined in 3GPP TS 26.244, which could not be read; the fields are as common tools write them.