Search code examples
oggopus

Opus ID Header, what is that?


Looking at the documentation of OggOpus I can't figure out what this table means:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       'O'     |      'p'      |     'u'       |     's'       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|       'H'     |       'e'     |     'a'       |     'd'       |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  version = 1  | channel count |           pre-skip            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                original input sample rate in Hz               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    output gain Q7.8 in dB     |  channel map  |               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+               :
|                                                               |
:          optional channel mapping table...                    :
|                                                               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

How am I supposed to get a header out of this?


Solution

  • This is a type of graphical representation of a data format that is common in RFCs, for example in RFC791 section 3.1 the IPv4 header is described by the same kind of picture.

    The numbers across the top are 0 to 31, each numbering a single bit. Every row represents 32 bits.

    All of the boxes in your diagram are multiples of 8 bits wide, which makes it a nice byte-oriented format. The first box contains 'O' so the first byte of the header is 'O' (presumably in ASCII, so its hex value is 4F). The next byte is 'p' (hex 70) and so on through the first 8 bytes. After that, the next byte is a version byte. The version defined by this document is 1, so that byte will have value 1.

    After the version, the next byte is the channel count, then there is a value called "pre-skip" and it occupies 16 bits worth of horizontal space, so it's a 16-bit field. Continue reading left to right in each row, top to bottom through the rows, to get the rest of the fields. The final field, "optional channel mapping table" is drawn as a large area with ellipses to indicate that its size is not fixed.

    There isn't any information in the picture that you can't also get from the text below it.