# Simple semitone array for the rate opt

**URL:** <https://in-thread.sonic-pi.net/t/simple-semitone-array-for-the-rate-opt/9634>\
**Category:** Creations & Ideas\
**Created:** [April 15, 2025, 12:23pm UTC](https://in-thread.sonic-pi.net/t/simple-semitone-array-for-the-rate-opt/9634 "2025-04-15T12:23:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [April 15, 2025, 12:23pm UTC](https://in-thread.sonic-pi.net/t/simple-semitone-array-for-the-rate-opt/9634/1 "2025-04-15T12:23:25Z")

</div>

Hi  
My student and I are exploring samples and re-pitching via rate:, so here is a simple sketch that fills an array with increments of the 12th root of 2, then applies those values to a sample’s playback rate - this is prolly already in the tutorial somewhere 😉

```ruby
a = []
12.times do
  y = tick #counter from 0 to 11
  x = 2**(y/12.0) #12th root of 2 = ~1.0594
  a.push(x) #fill array with semitone increments, starting at 1.0
end
puts a
sleep 1

12.times do
  sample :bass_thick_c, onset: 0, sustain: 0.4, rate: a.tick
  sleep 0.5
end

```

PD-Pi

---

<div class="post-metadata">

**Author:** ![brendanmac](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/brendanmac/32/2809_2.png) [@brendanmac](https://in-thread.sonic-pi.net/u/brendanmac)\
**Post date:** [April 15, 2025, 12:38pm UTC](https://in-thread.sonic-pi.net/t/simple-semitone-array-for-the-rate-opt/9634/2 "2025-04-15T12:38:48Z")

</div>

. . . and from there, you can choose different diatonic patterns - yes, you can do this with the scale function, but I like to teach students how to ‘roll your own’ first.

```ruby
a = []
13.times do
  y = tick #counter from 0 to 12
  x = 2**(y/12.0) 
  a.push(x) 
end
puts a
sleep 1
tick_reset

8.times do
  maj = [0,2,4,5,7,9,11,12].tick
  sample :bass_thick_c, onset: 0, sustain: 0.4, rate: a[maj]
  sleep 0.5
end

```

PD-Pi

---

<div class="post-metadata">

**Author:** ![HarryLeBlanc](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/harryleblanc/32/2813_2.png) [@HarryLeBlanc](https://in-thread.sonic-pi.net/u/HarryLeBlanc)\
**Post date:** [April 15, 2025, 6:36pm UTC](https://in-thread.sonic-pi.net/t/simple-semitone-array-for-the-rate-opt/9634/3 "2025-04-15T18:36:24Z")

</div>

Interesting. It’s an easy way to get just intonation, too. Could stick it in an array.
