====== Serialized Envelope Y Coordinates ====== The envelope Y coordinates are values between 0 and 15, with 0 -> 2-6, 6 -> 1 and 15 -> 29. The Y coordinates can be stored in different modes. A mode once chosen is used for all stored envelopes. Bands with 0 envelope points don't have any envelopes and thus no data stored. ==== Encoding Modes ==== === 0: Directly encoded === All Y coordinates are encoded directly as binary numbers (4 bits, obviously) === 1 (on master channel): Variable length encoding using differences between points === The first Y coordinate of each envelope is encoded using [[envelope y trees#envelope y tree]], the following coordinates using [[envelope y trees#delta y tree]], applied to the previous y value in this envelope. Difference application wraps around after 15. === 1 (on slave channel): Variable length encoding using difference to master channel === The Y values for the envelopes in the slave channel are stored as variable-length-encoded differences to the Y-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 assumed as 7. Difference application wraps around at 15. The slave channel should not have more envelopes than the master channel. === 2 (on master channel): Variable length encoding using difference between envelopes === The first envelope is stored as in mode 1. The later envelopes are stored as variable-length-encoded differences to the previous envelope. If an envelope has more points than the previous one, the missing Y coordinates of the previous one are assumed as 7. Difference application wraps around at 15. === 2 (on slave channel): Either VLC with difference between points or clone from master === For each envelope, a bit is stored indicating loading like in master/mode1 or cloning like in slave/mode3. === 3 (on master channel): Base/difference encoding === One base value (stored plain binary) is used for all coordinates in all bands. Every Y coordinate is obtained by adding a second number to the base value. This second number is also stored in plain binary, but with fewer bits (but the same bit count for all Y coordinates in one channel, it might even be 0 bits for constant 0). No wraparound happens, overflow makes the data invalid. === 3 (on slave channel): Clone master values === The Y values for the envelopes in the slave channel are copied from the Y-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 assumed as 7. The slave channel should not have more envelopes than the master channel. ===== Encoding ===== ==== Envelope Y Coordinates ==== * 2 bits encoding mode === Encoding mode 0: direct encoding === * For each point in each envelope: 4 bits === Encoding mode 1 on master channel: variable length encoding; delta between points === * For each envelope with at least one point * Code from [[envelope y trees#envelope y tree]] for the first Y value * For each point after the first one * Code from [[envelope y trees#delta y tree]] difference to previous Y value === Encoding mode 1 on slave channel: variable length encoding; delta to master === * For each point in each envelope: * Code from [[envelope y trees#delta-to-master y tree]] difference to corresponding master point === Encoding mode 2 on master channel: variable length encoding; delta between envelopes === * For each envelope with at least one point * Code from [[envelope y trees#envelope y tree]] for the first Y value * For each point after the first one * Code from [[envelope y trees#delta-to-prev-envelope y tree]] difference to corresponding point in previous envelope === Encoding mode 2 on slave channel: choose master/1 or slave/3 === * For each envelope with at least one point: 1 bit mode selection * If that bit is zero: //nothing//, cloning like in mode 3 on slave * If that bit is one: * Code from [[envelope y trees#envelope y tree]] for the first Y value * For each point after the first one * Code from [[envelope y trees#delta y tree]] difference to previous Y value === Encoding mode 3 on master channel: base/difference === * 2 bits: diffence bit count (call it //n//) * 4 bits: base level * for each point in each envelope * //n// bits: difference between desired value and base level