# Using samples to play a chord sequence

**URL:** <https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397>\
**Category:** Support, Help & Resources\
**Created:** [September 19, 2020, 8:10pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397 "2020-09-19T20:10:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@tim](https://in-thread.sonic-pi.net/u/tim)\
**Post date:** [September 19, 2020, 8:10pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/1 "2020-09-19T20:10:29Z")

</div>

Hello , new to sonic pi , i was using an inbuilt synth to generate the following chord sequence

```
use_bpm 120

#use_synth_defaults amp: 0.7, cutoff: 60
#use_synth_defaults wave: 1, phase: 0.25, release: 1, cutoff: 66
#use_synth :tb303
#sample :bass_hit_c
use_synth :dpulse
8.times do
  play :D
  sleep 1
end
3.times do
  play :C
  sleep 1
end
3.times do
  play :B
  sleep 1
end
1.times do
  play :C
  sleep 1
end
8.times do
  play :D
  sleep 1
end
2.times do
  play :F
  sleep 1
end
2.times do
  play :C
  sleep 1
end
3.times do
  play :B
  sleep 1
end
1.times do
  play :C
  sleep 1
end

9.times do
  play :D
  sleep 1
end

3.times do
  play :C
  sleep 1
end

```

Instead of the synth , i wanted to use the sample` sample :bass_hit_c` to create a sound sequence in the above pattern. Is it not possible to manipulate `samples` just like synths ? ( I was trying to recreate the pattern of in motion soundtrack, as a context and the ` sample :bass_hit_c` was perfect for one layer. Any idea would be appreciated

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [September 19, 2020, 9:00pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/2 "2020-09-19T21:00:02Z")

</div>

Maybe you can use the pitch parameter of the sample instruction. +12 to get an octave higher.  
I haven’t tested it’s an idea maybe I am totally wrong 😆

---

<div class="post-metadata">

**Author:** ![nlb](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/nlb/32/997_2.png) [@nlb](https://in-thread.sonic-pi.net/u/nlb)\
**Post date:** [September 19, 2020, 9:04pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/3 "2020-09-19T21:04:41Z")

</div>

Check if there is a pitch parameter not sure at all… right now far from a sonicpi to see

---

<div class="post-metadata">

**Author:** ![Davids-Music-Lab](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/davids-music-lab/32/512_2.png) [@Davids-Music-Lab](https://in-thread.sonic-pi.net/u/Davids-Music-Lab)\
**Post date:** [September 20, 2020, 8:10am UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/4 "2020-09-20T08:10:38Z")

</div>

Pitch is a pitch-shifter effect, there is rpitch which changes the rate of the sample. Both work in semitones, I don’t know if you can give them note names.

> sample :sample, rpitch [0,7,12).look

---

<div class="post-metadata">

**Author:** ![tim](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@tim](https://in-thread.sonic-pi.net/u/tim)\
**Post date:** [September 20, 2020, 9:08am UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/5 "2020-09-20T09:08:46Z")

</div>

Could you explain it a bit in this context ? If i want to start with a D note and do the manipulations

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [September 20, 2020, 5:58pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/6 "2020-09-20T17:58:46Z")

</div>

This will play a d major scale using the tom\_lo\_lhard sample which naturally sounds as a g The rpitch: value is the difference between the note required and the natural pitch of the sample. Find the natural pitch by playing the sample and a known note with a synth and adjust that note until they are the same.

```ruby
define :ps do |n|
  sample :drum_tom_lo_hard,rpitch: n - note(:g2)
end

tune = scale(:d3,:major)

tune.each do |n|
  ps n
  sleep 0.25
end

```

---

<div class="post-metadata">

**Author:** ![tim](https://avatars.discourse-cdn.com/v4/letter/t/ce73a5/32.png) [@tim](https://in-thread.sonic-pi.net/u/tim)\
**Post date:** [September 20, 2020, 6:42pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/7 "2020-09-20T18:42:04Z")

</div>

Thanks , I am trying to understand it but i feel a bit lost (beginner level in prog). I am wondering how can i convert or map it to the below format.

```ruby
8.times do
  play :D
  sleep 1
end
3.times do
  play :C
  sleep 1
end

```

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [September 20, 2020, 6:54pm UTC](https://in-thread.sonic-pi.net/t/using-samples-to-play-a-chord-sequence/4397/8 "2020-09-20T18:54:37Z")

</div>

The note :C is equivalent to :c4 (the c in octave 4). This is quite high for a drum, but you could play it like this.

```ruby
8.times do
  sample :drum_tom_lo_hard,rpitch: :d4 - note(:g2)
  sleep 1
end
3.times do
  sample :drum_tom_lo_hard,rpitch: :c4- note(:g2)
  sleep 1
end

```

You may find it better down an octave, changing the :d4 and :c4 for :d3 and :c3

You can simplify the code by defining a function to play the sample by defining

```ruby
define :playsample do |n|
  sample :drum_tom_lo_hard,rpitch: n - note(:g2)
end

```

you can then use this in the form  
`playsample :c4`  
This will substitute the paramter n with :c4, work out the difference in pitch between it and the natural pitch of note(:g2)and then play the sample using this as a relative pitch value eg up 4 semitones or down 2 semitones.

```ruby
define :playsample do |n|
  sample :drum_tom_lo_hard,rpitch: n - note(:g2)
end

8.times do
  playsample :d4
  sleep 1
end
3.times do
 playsample :c4
  sleep 1
end

```
