shorepine / amy

AMY - A high-performance fixed-point Music synthesizer librarY for microcontrollers
https://shorepine.github.io/amy/
MIT License
216 stars 14 forks source link

Redundant storage of deltas for partials #143

Open dpwe opened 3 months ago

dpwe commented 3 months ago

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.

AntoineDoinel69 commented 1 month ago

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: