# Perlin Modulation

**URL:** <https://in-thread.sonic-pi.net/t/perlin-modulation/4627>\
**Category:** Creations & Ideas\
**Created:** [November 17, 2020, 12:33am UTC](https://in-thread.sonic-pi.net/t/perlin-modulation/4627 "2020-11-17T00:33:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enkerli](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/enkerli/32/54_2.png) [@enkerli](https://in-thread.sonic-pi.net/u/enkerli)\
**Post date:** [November 17, 2020, 12:33am UTC](https://in-thread.sonic-pi.net/t/perlin-modulation/4627/1 "2020-11-17T00:33:35Z")

</div>

Continuing the discussion from [Some Sonic Pi Jewels](https://in-thread.sonic-pi.net/t/some-sonic-pi-jewels/2253/3):

Started playing with Matt Tytel’s [Vital](http://vital.audio) (pre-release with patchpack through In the Mix on [YouTube](https://www.youtube.com/watch?v=UmSQZRmYOa8)) and what struck me the most was the use of [Perlin noise](https://www.youtube.com/watch?v=8ZEMLCnn8v0) as modulation. Sure, that’s pretty close to smoothing out a random function… and that’s a neat thing to do.

I started prototyping Perlin-style modulation in a few environments. Eventually, I’d like to make it work as some kind of AUv3 plugin (on iPadOS). For now, I’m exploring several options on the desktop: the Grid in Bitwig, Cycling ‘74 Max and, of course, [p5js](https://editor.p5js.org/Enkerli/sketches/xd7KcMYUq) using tips & tricks from Perlin’s NYU neighbour (and hyper enthusiastic Processing champion) [Daniel Shiffman](https://www.youtube.com/watch?v=8ZEMLCnn8v0).

Now it’s time for SPi.

In that aforementioned discussion, @minced_mind tweaked a script by @H_Tachibana -san which leveraged Perlin noise to create melodic lines. While that’s obviously very neat, I’m searching for something which would be usable directly as a modulation source, maybe a bit like `ramp`?  
Conceptually, I’m thinking of this as a smoother version of some kind of pseudo-random LFO. In fact, my Bitwig prototype is basically made with that. And it sounds quite cool.

So, any help in building a Perlin modulator would be appreciated.

Thanks, gang!

---

<div class="post-metadata">

**Author:** ![xavierriley](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/xavierriley/32/9_2.png) [@xavierriley](https://in-thread.sonic-pi.net/u/xavierriley)\
**Post date:** [November 18, 2020, 6:53pm UTC](https://in-thread.sonic-pi.net/t/perlin-modulation/4627/2 "2020-11-18T18:53:31Z")

</div>

I added this recently. I’ll dig it out…

---

<div class="post-metadata">

**Author:** ![xavierriley](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/xavierriley/32/9_2.png) [@xavierriley](https://in-thread.sonic-pi.net/u/xavierriley)\
**Post date:** [November 18, 2020, 7:13pm UTC](https://in-thread.sonic-pi.net/t/perlin-modulation/4627/3 "2020-11-18T19:13:40Z")

</div>

[https://github.com/sonic-pi-net/sonic-pi/pull/2350](https://github.com/sonic-pi-net/sonic-pi/pull/2350) All here I think. Enjoy! Let me know if you have questions

---

<div class="post-metadata">

**Author:** ![minced\_mind](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@minced\_mind](https://in-thread.sonic-pi.net/u/minced_mind)\
**Post date:** [November 18, 2020, 9:00pm UTC](https://in-thread.sonic-pi.net/t/perlin-modulation/4627/4 "2020-11-18T21:00:43Z")

</div>

Hi,

I think you can do a perlin noise like function as this:

```ruby
# Initialize
my_note = rrand_i(note(:C4), note(:B5))
my_old_note = my_note

steps = 4.0

live_loop :perlin_noise do
  random_next = rrand_i(note(:C4), note(:B5))
  my_step = (random_next - my_old_note)/steps

  i = 0

  for i in 1..steps do
      my_note = my_old_note + quantise(i * my_step, 1)
      synth :sine, note: my_note
      sleep 0.5
    end

  my_old_note = my_note
end

```

It runs smoothly in number of “steps” from the old note to a random new note. You can optimize it through running through a scale instead of a diatonic scale. The quantise makes sure that it’s always a tuned note.  
You could even make it more complex through randomizing the sleep value (one of 0.25, 0.5, 1.0).  
Hope, this gives you some ideas how to use this.

Cu.
