An audio tag is a tag of type 8. After the 11-byte
tag header comes the
AudioTagHeader, which describes the sound, then (in an encrypted tag) the
encryption header, then the sound data. A
SoundFormat of 9 is the signal for
Enhanced FLV, in which the other
bits mean something else. Audio tags are like SWF’s DefineSound tag: for the formats
SWF also has, Adobe says the payload is the same in both.
AudioTagHeader
| Field | Type | Meaning |
|---|---|---|
| SoundFormat | UB[4] | Bits 7 to 4: the format of the sound data (below). |
| SoundRate | UB[2] | Bits 3 and 2: the sampling rate. |
| SoundSize | UB[1] | Bit 1: the size of each sample, for uncompressed formats only. Compressed formats always decode to 16 bits. |
| SoundType | UB[1] | Bit 0: mono or stereo. |
| AACPacketType | UI8 | Only when SoundFormat is 10 (AAC): see AAC. |
SoundFormat
| Value | Format | Notes |
|---|---|---|
| 0 | Linear PCM, platform endian | 16-bit samples in the byte order of the machine that made the file; Adobe says it should not be used. |
| 1 | ADPCM | Flash’s own ADPCM, as in SWF files. |
| 2 | MP3 | MPEG-1, 2 or 2.5 audio, Layer III. |
| 3 | Linear PCM, little endian | |
| 4 | Nellymoser 16 kHz mono | SoundRate and SoundType are ignored. |
| 5 | Nellymoser 8 kHz mono | SoundRate and SoundType are ignored. |
| 6 | Nellymoser | At the rate SoundRate gives. |
| 7 | G.711 A-law logarithmic PCM | Reserved for Adobe’s own use. |
| 8 | G.711 mu-law logarithmic PCM | Reserved for Adobe’s own use. |
| 9 | Reserved | Used by Enhanced FLV as ExHeader. |
| 10 | AAC | Flash Player 9.0.115.0 and later. |
| 11 | Speex | Flash Player 10 and later. |
| 12, 13 | Not defined | |
| 14 | MP3 8 kHz | Reserved for Adobe’s own use. |
| 15 | Device-specific sound | Reserved for Adobe’s own use. |
Adobe’s specification names formats 7, 8, 14 and 15 but says they are reserved.
SoundRate, SoundSize and SoundType
| SoundRate | Sample rate |
|---|---|
| 0 | 5.5 kHz |
| 1 | 11 kHz |
| 2 | 22 kHz |
| 3 | 44 kHz |
| SoundSize | Sample size |
|---|---|
| 0 | 8-bit samples |
| 1 | 16-bit samples |
| SoundType | Channels |
|---|---|
| 0 | Mono |
| 1 | Stereo |
Three formats break these rules:
- Nellymoser 8 kHz and 16 kHz have formats of their own because SoundRate cannot say 8 or 16 kHz; Flash Player ignores SoundRate and SoundType for them. Other Nellymoser rates use format 6 with SoundRate and SoundType as usual.
- For AAC, SoundType should be 1 and SoundRate 3, but players ignore both and read the channels and rate from the AAC configuration, so AAC in FLV is not always stereo at 44 kHz.
- Speex in FLV is always mono at 16 kHz: SoundRate shall be 0, SoundSize 1 and SoundType 0.
The rates are nominal: “5.5 kHz” is 5,512.5 Hz (players use 5,512), “11 kHz” 11,025 Hz, “22 kHz” 22,050 Hz and “44 kHz” 44,100 Hz.
AUDIODATA
The sound data is the AudioTagBody, or, in an encrypted tag, the EncryptedBody (the AudioTagBody encrypted; see Encryption). The AudioTagBody is AACAUDIODATA when SoundFormat is 10, and otherwise the format’s own data, described below. An audio tag with no data at all is allowed; Enhanced RTMP uses a zero-length audio message to signal silence.
Linear PCM (formats 0 and 3)
Uncompressed samples. 8-bit samples are unsigned bytes (silence is 128). 16-bit samples are signed: little-endian in format 3, and in format 0 in the byte order of the machine that made the file, which a reader cannot know (in practice little-endian, which is how FFmpeg reads it). Stereo samples alternate left and right.
ADPCM (format 1)
Flash’s ADPCM extends Jack Jansen’s IMA ADPCM to 2-, 3-, 4- and 5-bit codes. A tag’s data is one ADPCMSOUNDDATA record, as in SWF files; its fields are bit fields, packed with no regard to byte boundaries.
| Field | Type | Meaning |
|---|---|---|
| AdpcmCodeSize | UB[2] | The bits in each code, less 2: 0 to 3 for 2 to 5 bits. |
| AdpcmPackets | ADPCMMONOPACKET or ADPCMSTEREOPACKET, one or more | By SoundType. |
| ADPCMMONOPACKET field | Type | Meaning |
|---|---|---|
| InitialSample | SB[16] | The first sample, as in the uncompressed sound. |
| InitialIndex | UB[6] | The starting place in the step size table (0 to 88). |
| AdpcmCodeData | UB[4095 × code size] | 4,095 codes. The last packet may hold fewer. |
| ADPCMSTEREOPACKET field | Type | Meaning |
|---|---|---|
| InitialSampleLeft | SB[16] | The first left sample. |
| InitialIndexLeft | UB[6] | The left channel’s starting step index. |
| InitialSampleRight | SB[16] | The first right sample. |
| InitialIndexRight | UB[6] | The right channel’s starting step index. |
| AdpcmCodeData | UB[8190 × code size] | 4,095 codes a channel, alternating left and right. |
Each code is a sign bit and a magnitude. The step size table and the decoding are IMA ADPCM’s; the step index moves by these tables (the lower half of each, the upper half being the same):
| Code size | Index changes |
|---|---|
| 2 bits | −1, 2 |
| 3 bits | −1, −1, 2, 4 |
| 4 bits | −1, −1, −1, −1, 2, 4, 6, 8 |
| 5 bits | −1, −1, −1, −1, −1, −1, −1, −1, 1, 2, 4, 6, 8, 10, 13, 16 |
MP3 (formats 2 and 14)
MPEG audio Layer III frames, each with its own header; see the MP3 reference. Format 14 is MP3 at 8 kHz (MPEG-2.5), which SoundRate cannot express. Adobe says payloads are the same as in SWF, but files from Adobe’s own tools and from FFmpeg hold the frames alone, without the SeekSamples field that SWF’s MP3SOUNDDATA starts with.
Nellymoser (formats 4, 5 and 6)
Nellymoser Asao, a speech codec from Nellymoser Inc., is mono. Its data is a run of 64-byte blocks, each giving 256 samples: Asao works in the frequency domain, coding which frequency bands are used and their levels. Nellymoser has not published the format; Adobe’s specifications only summarise it. Decoders, FFmpeg’s and this site’s among them, follow a reverse-engineered description: each block holds a 6-bit initial band level and 22 5-bit level changes (23 bands, read from the least significant bit first), then the same coefficients twice, for two halves of 128 samples.
G.711 (formats 7 and 8)
ITU-T G.711 logarithmic PCM: one byte a sample, A-law (7) or mu-law (8). G.711 runs at 8,000 samples a second, a rate SoundRate cannot express; FFmpeg plays both at 8 kHz whatever SoundRate says.
AAC (format 10)
When SoundFormat is 10, the AudioTagHeader has one more byte, AACPacketType, and the body is AACAUDIODATA.
| AACPacketType | AACAUDIODATA |
|---|---|
| 0 | AAC sequence header: the AudioSpecificConfig of ISO/IEC 14496-3 (object type, sampling frequency, channel configuration). Note that this is not the same as the contents of an MP4 file’s esds box. |
| 1 | AAC raw: one raw AAC frame (a raw_data_block), with no ADTS header. |
The sequence header comes before the first raw frame: a decoder needs it to read them.
Speex (format 11)
Speex wideband speech: mono, 16 kHz, decoded to 16-bit samples. Flash Player 10.0.12 has Speex 1.2 beta 3 built in. The data is Speex frames back to back, each 20 ms (320 samples) with its narrowband layer then its high-band layer. There is no Speex header packet, as Ogg files have: the mode is always wideband.
Device-specific sound (format 15)
Reserved, and not described anywhere public: no layout can be given for it.