libkate  0.4.1
Granule encoding

Ogg leaves the encoding of granules up to a particular codec, only mandating that granules be non decreasing with time.

The Kate bitstream format uses a linear mapping between time and granule, described here.

A Kate granule position is composed of two different parts:

  • a base granule, in the high bits
  • a granule offset, in the low bits
+----------------+----------------+
| base           | offset         |
+----------------+----------------+

The number of bits these parts occupy is variable, and each stream may choose how many bits to dedicate to each. The kate_info structure for a stream holds that information in the granule_shift field, so each part may be reconstructed from a granulepos.

The kate_info structure for a stream also holds a rational fraction representing the time span of granule units.

The granule rate is defined by the two fields:

kate_uint32_t gps_denominator
Definition: kate.h:287
kate_uint32_t gps_numerator
Definition: kate.h:286

The number of bits reserved for the offset is defined by the field:

unsigned char granule_shift
Definition: kate.h:283