On2 Audio for Video Codec: Difference between revisions

From MultimediaWiki
Jump to navigation Jump to search
(→‎Window mode: format as list)
m (Implemented by Kostya)
 
(One intermediate revision by one other user not shown)
Line 87: Line 87:


TODO
TODO
===== Scale differences table =====
Codes (-60..59):
  0x6FFFF, 0xBFFF2, 0xBFFF3, 0xBFFF4, 0xBFFF5, 0xBFFF6,
  0xBFFF7, 0xBFFF8, 0xBFFF9, 0xBFFFA, 0xBFFFB, 0xBFFFC,
  0xBFFFD, 0xBFFFE, 0xBFFFF, 0xDF9A0, 0xDF9A1, 0xDF9A2,
  0xDF9A3, 0xDF9A4, 0xDF9A5, 0xDF9A6, 0xDF9A7, 0xDF9A8,
  0xDF9A9, 0x37FFE, 0x6FCDE, 0x6FFFA, 0x0BFF7, 0x0B7FF,
  0x0DF9F, 0x05FF8, 0x0B7FE, 0x05FF9, 0x06FCE, 0x05BFE,
  0x037FE, 0x02DFE, 0x00DFA, 0x00DFE, 0x017FC, 0x00DBE,
  0x00B7E, 0x005FE, 0x0037D, 0x002DE, 0x0017E, 0x0016C,
  0x000DE, 0x000BE, 0x0006C, 0x0005A, 0x0003E, 0x00034,
  0x0002C, 0x0001F, 0x0000E, 0x0000E, 0x00006, 0x00002,
  0x00000, 0x00004, 0x0000A, 0x0000C, 0x0001E, 0x0001E,
  0x0002E, 0x00035, 0x0003F, 0x0005E, 0x0006E, 0x000DA,
  0x0016D, 0x0016E, 0x001B6, 0x002FE, 0x0036E, 0x0037C,
  0x005BE, 0x006DE, 0x006FE, 0x00DBF, 0x00DFB, 0x016FE,
  0x017FD, 0x01BFE, 0x01BF2, 0x02FFE, 0x06FCC, 0x05FFE,
  0x05FFA, 0x06FFE, 0x0BFF6, 0x0BFFE, 0x0DF9E, 0x00DF8,
  0x0DFFE, 0x37FFC, 0x6FFFB, 0x5FFF8, 0xDF9AA, 0xDF9AB,
  0xDF9AC, 0xDF9AD, 0xDF9AE, 0xDF9AF, 0xDF9B0, 0xDF9B1,
  0xDF9B2, 0xDF9B3, 0x6FFFE, 0xDF9B4, 0xDF9B5, 0xDF9B6,
  0xDF9B7, 0xDF9B8, 0xDF9B9, 0xDF9BA, 0xDF9BB, 0xDF9BE,
Lengths:
  20, 20, 20, 20, 20, 20,
  20, 20, 20, 20, 20, 20,
  20, 20, 20, 21, 21, 21,
  21, 21, 21, 21, 21, 21,
  21, 19, 20, 20, 16, 16,
  17, 15, 16, 15, 16, 15,
  15, 14, 13, 13, 13, 13,
  12, 11, 11, 10,  9,  9,
  9,  8,  8,  7,  7,  7,
  6,  5,  5,  4,  3,  3,
  2,  3,  4,  5,  5,  6,
  6,  7,  7,  7,  8,  9,
  9,  9, 10, 10, 11, 11,
  11, 12, 12, 13, 13, 13,
  13, 14, 14, 14, 16, 15,
  15, 16, 16, 16, 17, 13,
  17, 19, 20, 19, 21, 21,
  21, 21, 21, 21, 21, 21,
  21, 21, 20, 21, 21, 21,
  21, 21, 21, 21, 21, 21,


[[Category:Audio Codecs]]
[[Category:Audio Codecs]]
[[Category:Undiscovered Audio Codecs]]

Latest revision as of 23:42, 23 April 2014

  • Codec ID: 0x0500, 0x0501
  • Company: On2

On2's Audio for Video codec (AVC) is a perceptual audio codec by On2, packaged in AVI files along with their video codecs.

The codec seems to be MDCT-based with frame of 1024 samples.

Version 0x0500 coded only monaural sound with one chunk per audio frame, 0x0501 can be stereo and contain several chunks in a single frame (every chunk has 16-bit little-endian coded size before it).

Chunk format

 enhanced mode flag (should be always zero)
 coding mode (3 bits)
 if (coding mode == 3) // short windows
   window grouping flags (7 bits)
 M/S present flag
 if (M/S present)
   M/S flags for each independent band
 codebook description
 scales
 coefficients

Window mode

  • 0 - ordinary long window
  • 1 - long window with fading in delay
  • 2 - long window with special windowing and delay handling
  • 3 - eight short windows
  • 4-7 - long window with special windowing and delay handling

Codebook description

 base  = 0;
 nsect = 0;
 bps = long window ? 5 : 3;
 esc = (1 << bps) - 1;
 while (base < bands) {
   section[nsect].cb = get_bits(4);
   val = get_bits(bps);
   while (val == esc) {
     base += val;
     val   = get_bits(bps);
   }
   base += val;
   section[nsect].end = base;
   nsect++;
 }

Scale description

Scales are read for all independent bands with non-zero coding. First scale is explicitly coded as 7-bit value, the following scales are coded as a difference to the previous scale with static Huffman code.

Coefficients

Coefficients are coded with 14 different static Huffman codesets. Codeset 0 is not coded, codesets 1-8 encode quadruplets of coefficients, codesets 9-15 code pairs of coefficients. Additionally, for codeset 15 values -16 and 16 are escape values. In case those escape values happen, real values are read as exp-Golomb plus three additional bits and the sign should be the same as the sign of escape value.

Unscaling is performed as coeffs[i] = val * sqrt(val) * scale_tab[scale]

Tables

Long window band ends

    4,   8,  12,  16,  20,  24,  28,  32,
   36,  40,  48,  56,  64,  72,  80,  88,
   96, 108, 120, 132, 144, 156, 172, 188,
  204, 224, 244, 264, 288, 312, 340, 368,
  400, 432, 464, 496, 528, 560, 592, 624,
  656, 688, 720, 752, 784, 816, 848, 880,
 1024

Short window band ends

  4,  8, 12, 16,  20,  24, 32, 40,
 48, 56, 68, 80, 108, 128

Scale table

For 0-19:

 scale_tab[i] = ceil(exp(ln(10) / 10 * i) * 16) / 32

For 20-127:

 scale_tab[i] = ceil(exp(ln(10) / 10 * i) * 0.5)

Huffman tables

TODO

Scale differences table

Codes (-60..59):

 0x6FFFF, 0xBFFF2, 0xBFFF3, 0xBFFF4, 0xBFFF5, 0xBFFF6,
 0xBFFF7, 0xBFFF8, 0xBFFF9, 0xBFFFA, 0xBFFFB, 0xBFFFC,
 0xBFFFD, 0xBFFFE, 0xBFFFF, 0xDF9A0, 0xDF9A1, 0xDF9A2,
 0xDF9A3, 0xDF9A4, 0xDF9A5, 0xDF9A6, 0xDF9A7, 0xDF9A8,
 0xDF9A9, 0x37FFE, 0x6FCDE, 0x6FFFA, 0x0BFF7, 0x0B7FF,
 0x0DF9F, 0x05FF8, 0x0B7FE, 0x05FF9, 0x06FCE, 0x05BFE,
 0x037FE, 0x02DFE, 0x00DFA, 0x00DFE, 0x017FC, 0x00DBE,
 0x00B7E, 0x005FE, 0x0037D, 0x002DE, 0x0017E, 0x0016C,
 0x000DE, 0x000BE, 0x0006C, 0x0005A, 0x0003E, 0x00034,
 0x0002C, 0x0001F, 0x0000E, 0x0000E, 0x00006, 0x00002,
 0x00000, 0x00004, 0x0000A, 0x0000C, 0x0001E, 0x0001E,
 0x0002E, 0x00035, 0x0003F, 0x0005E, 0x0006E, 0x000DA,
 0x0016D, 0x0016E, 0x001B6, 0x002FE, 0x0036E, 0x0037C,
 0x005BE, 0x006DE, 0x006FE, 0x00DBF, 0x00DFB, 0x016FE,
 0x017FD, 0x01BFE, 0x01BF2, 0x02FFE, 0x06FCC, 0x05FFE,
 0x05FFA, 0x06FFE, 0x0BFF6, 0x0BFFE, 0x0DF9E, 0x00DF8,
 0x0DFFE, 0x37FFC, 0x6FFFB, 0x5FFF8, 0xDF9AA, 0xDF9AB,
 0xDF9AC, 0xDF9AD, 0xDF9AE, 0xDF9AF, 0xDF9B0, 0xDF9B1,
 0xDF9B2, 0xDF9B3, 0x6FFFE, 0xDF9B4, 0xDF9B5, 0xDF9B6,
 0xDF9B7, 0xDF9B8, 0xDF9B9, 0xDF9BA, 0xDF9BB, 0xDF9BE,

Lengths:

 20, 20, 20, 20, 20, 20,
 20, 20, 20, 20, 20, 20,
 20, 20, 20, 21, 21, 21,
 21, 21, 21, 21, 21, 21,
 21, 19, 20, 20, 16, 16,
 17, 15, 16, 15, 16, 15,
 15, 14, 13, 13, 13, 13,
 12, 11, 11, 10,  9,  9,
  9,  8,  8,  7,  7,  7,
  6,  5,  5,  4,  3,  3,
  2,  3,  4,  5,  5,  6,
  6,  7,  7,  7,  8,  9,
  9,  9, 10, 10, 11, 11,
 11, 12, 12, 13, 13, 13,
 13, 14, 14, 14, 16, 15,
 15, 16, 16, 16, 17, 13,
 17, 19, 20, 19, 21, 21,
 21, 21, 21, 21, 21, 21,
 21, 21, 20, 21, 21, 21,
 21, 21, 21, 21, 21, 21,