Terrarium Polyphonic Octaves Code & Demo

Hi there, Love this project and the code.

I'm currently trying to get it to compile, but having issues with the gcc10.3 that comes with the arm/daisy tools (using that in the path to toolchain). It does not support std::bit_cast used in the FastSqrt.h code, which only became available in gcc11. I'm guessing you got around this somehow - how did you do it? Set the toolchain path to a different gcc?
Essentially, yes. If you look in .github/workflows/build.yml, you can see the exact commands I use to build in CI. It looks like I'm currently using gcc 13.3. I'd expect anything newer to work as well.
 
I have it running! I ended up doing a nasty de-referenced pointer cast to get bit_cast functionality in gcc 10.3

Quick question: the link to the original paper seems to be gone. I'd like to look it up; do you have the author, paper name, any other identification for it?
 
For those interested in making it run with the standard Daisy toolchain, here's the code I modified in util/FastSqrt.h
C++:
static constexpr float fastInvSqrt(float x) noexcept
{
    static_assert(std::numeric_limits<float>::is_iec559);
    // TMay, June 2026:
    // std::bit_cast not implemented in daisy tool tree (gcc 10.3.1)
    // To make it work, I replaced these two lines:
    //
    //    float const y = std::bit_cast<float>(
    //            0x5F1FFFF9 - (std::bit_cast<std::uint32_t>(x) >> 1));
    // with these three lines:
    uint32_t i = * ( uint32_t * ) &x;   // What sort of utter madness is THIS?!??...
    i = 0x5F1FFFF9 - (i >> 1);          // gotta love magic numbers
    float const y = * (float * ) &i;    // Same colossal f*ckery as two lines above, but in reverse.

    return y * (0.703952253f * (2.38924456f - (x * y * y)));
}
 
Last edited:
Hi Steve,
I noticed that you've got a pair of filters on the output of the octave block (high shelf and low shelf). Just trying to understand - what are the purpose of these? I'm only interested in octave up, and I'm wondering if I could remove one or both of these.
 
Hi Steve,
I noticed that you've got a pair of filters on the output of the octave block (high shelf and low shelf). Just trying to understand - what are the purpose of these? I'm only interested in octave up, and I'm wondering if I could remove one or both of these.
You can drop those. They're just my attempt to reproduce the sound I wanted. They're not essential in any way and I debated whether to include them myself.
 
Back
Top