Bit crusher

I’ve been playing with the “Nyquist Prompt”, but it seems generating a bit-crusher effect is more difficult than I thought. (I’m using Audacity 2.0.5 in LinuxMint)

I’ve been looking at two approaches, but both give me dead ends. Note that I want the effect to be “tunable” i.e: you can choose how many bits you want, not just 8-bit (which I know can be generated via exporting).

Approach #1 - Bitwise AND to obtain the required most significant bits using the logand function
CODE: (logand s “number”)
=> “number” has required number of most significant bits set, eg: #xFF000000 for 8-bit
=>returns “Nyquist did not return audio”

Approach #2 - Divide by a power of two, then multiply by a power of two
CODE: (mult (mult s (power 2 -24)) (power 2 24))
=> should bit crush down to 8-bit (32-24=8)
=> unfortunately just returns the same audio that was input. Attempts to round down before remultiplying (using truncate) have not worked so far either.

Bit-crushing is just some simple math, yet I’m stuck on how to make it work in Nyquist (and surprised a Nyquist plugin doesnt exist - at least as far as my searches have gone)

Help please? (Cheers!)

PS: Very new at this, so am probably making a really simple error. Please forgive.

Why not simply quantize?

(quantize s 256)

gives 8-bit.

Logand, truncate and so on won’t work with sounds–the former only with integer in fact.

Description of Quantize in the manual: