amy icon indicating copy to clipboard operation
amy copied to clipboard

Redundant storage of deltas for partials

Open dpwe opened this issue 1 year ago • 1 comments

The partials oscillator stores each set of partial trajectories by a sequence of partial_breakpoint_t elements in partial_breakpoints[]. The last three elements of a partial_breakpoint_t are ms_delta, amp_delta, freq_delta, which are redundant with the ms_offset, amp and freq of the next breakpoint entry for that oscillator (specifically, ms_delta is the increment in the ms_offset, and amp_delta and freq_delta are multiplicative scales to transform the current amp and freq into the next ones).

We could save three fields for each breakpoint entry by, instead, scanning ahead to the next entry for the current oscillator, reading its ms_offset, amp, freq, and calculating the deltas on-the-fly. This would also simplify adding partials, since the partial-construction system would not have to calculate the deltas.

dpwe avatar Aug 11 '24 12:08 dpwe

Would it make sense to also compress the remaining fields to uint16_t fixed-point values too? It would still be easy to get back to the original floating point values at runtime, with a relatively minor loss of precision.

I mean, something like this:

  • frequency: 8.8 split, where MSB is semitones (same as midi note, but extended beyond 127), and LSB 256ths of a semitone.
  • amplitude: 0.16 no sign and fractional part only (since I presume it's always < 1.0 right?)
  • phase: 1.2.13 with sign, so with a range of -2.0000 to 1.9999 (and still allow for that -2.0 terminator thing)

AntoineDoinel69 avatar Sep 19 '24 15:09 AntoineDoinel69