Repository navigation
genlib: fixes and operators from Max 9's gen~ export - #137
Merged
Merged
Conversation
Max 9's gen~ export (Copyright 2023 Cycling '74) is dual-licensed: Cycling '74 License for Max-Generated Code for Export, or GPLv3. OwlProgram is GPLv3. spline6_interp() was already taken from it; the following commits take more.
From Max 9: v - range*numWraps can round to exactly hi, e.g. wrap(-1e-8, 0, 1) returned 1. Keeps long (not Max 9's int64_t) for the wrap count: float to int64 is a library call (__aeabi_f2lz, __aeabi_l2f) on Cortex-M4/M7.
cubic_interp() is now the 4-point Lagrange cubic that Max 9 uses, so cubic interpolation matches Max. The previous formula is kept as fastcubic_interp(), which Max 9 deprecates for instability with feedback. Delay::read_fastcubic() and Delay::read_spline6() let exports with delay interp modes fastcubic and spline6 compile.
…ax 9 Exports from Max 9 that use them did not compile. genlib_fastertanh() is Max 9's rational approximation, which only holds for x >= 0 (Max 9 returns +22 for -4): it is mirrored for negative input and clamped to +-1; max error 0.0009 against tanh on [-8, 8].
Max 9's single-precision Noise: xoshiro128+ seeded with splitmix32, replacing the 32-bit linear congruential generator. Per sample it is 32-bit integer operations and one int-to-float conversion; splitmix runs only on reset. Seeds come from the tick count or the bits of a float seed, not Max 9's (uint64_t)(seed*1E6): float <-> 64-bit int conversions pulled 2.4 KB of soft-float library code into a patch. The random sequence changes.
wrap() range (including the case that rounded to hi), cubic_interp() exact for a cubic, fastcubic_interp(), Delay reads of a ramp (4-point reads are one sample shorter than linear, spline6 two, as in Max 9), fastertanh() odd, bounded and within 0.001 of tanh, fasteratan2(), fasterpow2/log2, and Noise range, mean, variance and seeding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings genlib (GenSource/genlib_ops.h) up to the gen~ export of Max 9 where it fixes bugs or adds operators that Max 9 exports use. Delay-read fixes follow in a separate PR on top of this one.
Changes
hi:v - range*numWrapscould round to exactlyhi, e.g.wrap(-1e-8, 0, 1)returned 1fastcubic_interp()(Max 9 deprecates it for instability with feedback; it is not exact even for a straight line between samples). AddsDelay::read_fastcubic()andDelay::read_spline6()fastertanh,fasteratan2,fasterlog2,fasterpow2; Max 9 exports using them did not compilespline6_interp()Where this differs from Max 9
wrap()/fold()keeplongfor the wrap count, not Max 9'sint64_t: float to 64-bit int is a library call (__aeabi_f2lz,__aeabi_l2f) on Cortex-M4/M7. Max 9's int64FLOAT_TO_UINT32infasterpow2is not taken for the same reasonfastertanh(): Max 9's rational approximation only holds for x >= 0 (it returns +22 for -4, and tends to 1.17 for large x); it is mirrored for negative input and clamped to +-1, within 0.0009 of tanh on [-8, 8]Noiseseeds from the tick count or the bits of a float seed, not Max 9's(uint64_t)(seed*1E6), whose float <-> uint64 conversions pulled 2.4 KB of soft-float library code into a patch (now +256 B on the Gen test patch)logf,expf, ...) is keptBehaviour changes for existing patches
cubicinterpolation sounds different (matches Max 9)noisesequence changesTests
GenOpsTest: wrap range including the rounding case, cubic_interp exact for a cubic, fastcubic_interp, Delay reads of a ramp (as in Max 9 the 4-point reads are one sample shorter than linear, spline6 two), fastertanh odd/bounded/accuracy, fasteratan2, fasterpow2/log2, Noise range, mean, variance and seeding.Verification
make checkpasses; Gen test patch builds without warnings on OWL2 and OWL3