Table of Contents
Serialized Envelope X Coordinates
The envelope X coordinates are values between 0 and 31. They are in units of 4 samples in the subband time domain buffers, so they represent sample numbers between 0 and 124. As the points are stored in ascending X order, some encoding method exploit that the X coordinates are monotonically increasing.
Encoding Modes
0: Nearly directly encoded
The first value is a plain 5-bit number. For all later points, the encoding depends on the magnitude of the previous X coordinate value. If it was below 15, the current point is directly encoded as 5-bit number. Otherwise, the value is delta-encoded relative to the successor of the previous X coordinate value, with as few bits as possible for the delta value. That means for values between 15 and 22, there are 4 delta bits to be able to reach 31 (with 3 data bits, the maximum encodable number is 7, so from 22 the highest value reachable with 3 bits would be 22+1+7 = 30). For 23..26, 3 bits are used and so on up to 30, where the delta (only 0 is valid) is encoded using 0 bits.
1 (on master channel): Variable length encoding using differences between points
The first X value of each envelope is directly encoded. The following X values are delta-encoded using one of two huffman trees depending on whether there is an increasing or decreasing slope.
1 (on slave channel): Variable length encoding using difference to master channel
The X value for the first point is stored as difference to the X value of the first point in the master channel, assuming 0 if the master channel has no point; difference application wraps around after 31. This difference value is variable-length encoded. Each further X value that has an associated X value (with the same point number) in the master channel is encoded depending on whether it is an upwards or downwards step. For upwards steps, a bit indicates whether the X value should be cloned or it is stored like in mode 0, while for downwards step, the difference is stored to the master channel X value. The remaining template-less X values are encoded like in mode 1 on the master channel.
2 (on master channel): Variable length encoding using difference between envelopes
The envelope for band 0 is stored as in mode 0 (that means: if band 0 has no envelope, no envelope is stored that way!). The X coordinates of the later envelopes are stored as difference to the X coordinate of the corresponding point (with the same index) of the directly preceding envelope. Application of deltas wraps around. Different trees are used for increasing or decreasing slope of the envelope, the first point is defined to be handled like on a decreasing slope. In case that the directly preceeding envelope has no point with the same index, it is assumed as zero for the first point in the envelope or as the previously read X value of the current envelope for later points.
2 (on slave channel): Either VLC with difference between points or clone from master
For each envelope in the slave channel having not more points than the corresponding envelope in the master channel, a bit is stored indicating loading like in master/mode1 or cloning like in slave/mode3. If the slave envelope point count exceeds the master envelope point count, the envelope is loaded as in master/mode1 without a mode select bit.
3 (on master channel): Base/difference encoding
One base value (stored plain binary) is used for all coordinates in all bands. Every X coordinate is obtained by adding a second number to the sum of the base value and the current point number (0-based). This second number is also stored in plain binary, but with fewer bits (but the same bit count for all X coordinates in one channel). No wraparound happens, overflow makes the data invalid.
3 (on slave channel): Clone master values, fill plain
The X values for the envelopes in the slave channel are copied from the X values of the master channel. If an envelope in the slave channel has more points than the corresponding envelope in the master channel, the missing values are encoded near-directly as in master/mode0
Encoding
Envelope X Coordinates
- 2 bits encoding mode
Encoding mode 0: nearly direct encoding
- for each envelope with at least one point:
- 5 bits first X coordinate
- for each additional X coordinate:
- if previous X coordinate < 15:
- 5 bits for that X coordinate
- if previous X coordinate < 23:
- 4 bits: current X coordinate - previous X coordinate - 1
- if previous X coordinate < 27:
- 3 bits: current X coordinate - previous X coordinate - 1
- if previous X coordinate < 29:
- 2 bits: current X coordinate - previous X coordinate - 1
- if previous X coordinate == 29:
- 1 bits: current X coordinate - previous X coordinate - 1
- if previous X coordinate == 30:
- 0 bits, next X coordinate must be 31
Encoding mode 1 on master channel: variable length encoding; delta between points
- for each envelope with at least one point:
- 5 bits first X coordinate
- for each additional X coordinate:
- if the associated Y coordinate is lower than the previous Y coordinate
- one code from the delta x for decreasing y tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one code from the delta x for increasing y tree
Encoding mode 1 on slave channel: variable length encoding; difference to master
- for each envelope with at least one point:
- one code from delta x to master tree
- for each further point that has an associated master point
- if the associated Y coordinate is lower than the pevious Y coordinate
- one code from delta x to master tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one bit chosing
- if that bit is 0: just copy the associated X coordinate
- if that bit is 1: One X coordinate encoded as in mode 0
- for each remaining point (in excess of master points) (this is like mode1/master)
- if the associated Y coordinate is lower than the previous Y coordinate
- one code from the delta x for decreasing y tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one code from the delta x for increasing y tree
Encoding mode 2 on master channel: variable length encoding; delta between envelopes
- First envelope as in mode 0
- For each remaining envelope with at least one point
- one code from delta x to previous band for decreasing y tree
- for each further point that has an associated point in the previous band
- if the associated Y coordinate is lower than the pevious Y coordinate
- one code from delta x to previous band for decreasing y tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one code from delta x to previous band for increasing y tree
- for each remaining point (in excess of master points) (this is like mode1/master)
- if the associated Y coordinate is lower than the previous Y coordinate
- one code from the delta x for decreasing y tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one code from the delta x for increasing y tree
Encoding mode 2 on slave channel: choose master/1 or slave/3
- For each envelope with points:
- If it does not have more points than the corresponding master envelope:
- 1 bit. If set it indicates that this channel should not be cloned.
- Otherwise the envelope is not cloned.
- In cloning mode: nothing, cloning like in mode 3 on slave
- In non-cloning mode: envelope info as in master/1:
- 5 bits first X coordinate
- for each additional X coordinate:
- if the associated Y coordinate is lower than the previous Y coordinate
- one code from the delta x for decreasing y tree
- otherwise, i.e. if the associated Y coordinate is higher than the previous Y coordinate
- one code from the delta x for increasing y tree
Encoding mode 3 on master channel: base/difference
- 2 bits: diffence bit count - 1 (call it n-1)
- 5 bits: base X position
- for each point in each envelope
- n bits: difference between desired X coordinate and (base X coordinate + current point number in the envelope)