Limit values produced by oscillators

Hi!

This is my first post at this forum.

Is there a way to limit the values produced by an oscillator in order to cut off the peaks of a sine wave.

For example, limit the high pass filter to values between 400 and 700 in this example…

d1 \$ s "808sd!16" # hpf (range 100 1000 \$ sine)

…and producing these type of values: 400 400 400 400 500 600 700 700 700 700

To be clear, I'm not referring to the range of the sine wave. I want to truncate the sine wave.

Off the top of my head, and completely untested, you should be able to do the following. It sounds like a fun exercise to wrap up in a nice function, where the clamping values are themselves patternable, so I might do that a little later today (I’m tied up atm) but for now try:

d1 \$ s "808sd!16" # (hpf \$ (max 400 . min 700) <\$> (range 100 1000 \$ sine))
1 Like

Here you go:

let
clamp :: Ord a => Pattern a -> Pattern a -> Pattern a -> Pattern a
clamp xpat ypat pat = (fmap clamp' xpat <*> ypat) `applyPatToPatRight` pat
where clamp' x y n = if x > y then min x (max y n) else min y (max x n)

I've taken the liberty of adopting Hedgehog's style of clamp function, so that xpat's and ypat's values can be above or below one another arbitrarily. Should help when patterning xpat and/or ypat with various things.

Here's your example pattern, but using this new function:

d1 \$ s "808sd!16" # (hpf \$ clamp 400 700 \$ range 100 1000 sine)

And here's an example of some silliness to demonstrate the Hedgehog style clamping. Note how the xpat and ypat values can be above or below another at various times:

d1 \$ s "808sd!16" # (hpf \$ clamp (slow 3 \$ range 400 700 sine) (slow 5 \$ range 400 700 sine) \$ range 100 1000 sine)
3 Likes

Thanks @mvdirty! That was what I was looking for!

I really like the last example. It is powerful method create interesting sounds

Thanks! It was a fun little bit of code to put together. I love when there are clean ways to make everything patternable in a helper like this. It expands the usage possibilities so much.

2 Likes