Samples adjustment

Hello!

I’ve been struggling a bit with this issue. I downloaded a sample, and after trying the suggested approaches, I still haven’t achieved the result I want. What I’m aiming for is to perfectly loop a portion of the sample. I’ve read the following links, which gave me some ideas:

What I tried:

  • I tried to find a loopable part of the sample by adjusting the start and finish points, and experimenting with beat_stretch.
  • I manually tried to calculate the BPM.
  • I just plugged in numbers to see what would fit.

the following is a sketch of what I tried

live_loop :shaker, sync: :met do
  samba_shake = sample_paths samples_dir, "samba_shake"
  ##| sample_length = sample_duration(samba_shake)
  ##| bar_length = 60.0 / 128 * 4  # Length of one bar
  ##| rate = sample_length / bar_length
  sample samba_shake, start: 0.0986, finish: 0.3552, beat_stretch: 30
  ##| sample samba_shake,  start: 0.5, finish: 0.8, rate: 1.5
  sample_lengh = sample_duration(samba_shake, start: 0.0986, finish: 0.3552)
  ##| puts 0.3552 - 0.0986
  ##| sleep  sample_lengh
  puts sample_duration(samba_shake, start: 0.0986, finish: 0.3552, beat_stretch: 32)
  ##| sleep sample_duration(samba_shake, start: 0.0986, finish: 0.3552, beat_stretch: 30)
  sleep 8
end

The sample doesn’t sound quite right along the other instruments, it wasn’t in sync.

I found the acceptable interval using Audacity.

What I ended up doing was passing the sample through Audacity, chopping from 0.0986 to 0.3552, which sounded pretty acceptable, and changing the tempo from 120 BPM to 128 BPM. I got the result I wanted.

live_loop :shaker_3, sync: :met do
  stop
  samba_shake = sample_paths samples_dir, "samba_shake_128"
  sample samba_shake, beat_stretch: 5
  sleep 5
end

I don’t know if I’m doing something wrong, or if this process is too tedious for every external sample I use, or if there’s a better workflow someone could guide me through.

full current “song”

use_bpm 128

samples_dir = "~/Workbench/Sonic-pi/resources/guaracha"
load_samples samples_dir

live_loop :met do
  play 60
  sleep 1
end

live_loop :kick, sync: :met do
  stop
  sample :bd_ada
  sleep 1
end

##| #chuck
with_fx :compressor, threshold: 0.9 do
  live_loop :clap, sync: :met do
    stop
    sample :drum_snare_hard,  hpf: 90, pre_amp: 2
    sleep 1
  end
end


# Perc
drums = [0,0,0,1,0,0,2,0,0,0,0,1,0,0,2,0]
live_loop :perc, sync: :met do
  ##| stop
  drums.tick
  sample :tabla_ke1 if drums.look == 1
  sample :tabla_tun1, finish: 0.5 if drums.look == 2
  sleep 0.25
end

live_loop :shaker_3, sync: :met do
  ##| stop
  samba_shake = sample_paths samples_dir, "samba_shake_128"
  puts samba_shake
  sample samba_shake, beat_stretch: 5
  sleep 5
end

Any guidance or help would be greatly appreciated :pray:

In terms of getting the portion of the sample you want, I think the Audacity approach is the way to go. It is so much easier to have a visual reference of the section you want to loop instead of trying to do it with code. You can also customize the number of beats much easier that way (I mention this because in your example, the sleep value for the sample was 5 which doesn’t seem consistent with the drum loop before it which seems to be in 4 unless you are doing that for a specific reason)

Once you have that, you can use the use_sample_bpm function and set the num_beats: option to the number of beats the loop lasts for (Assuming you want the bpm to be in line with the looped sample, otherwise, you can use the beat_stretch: option)

Hope that helps

1 Like

thanks, it does help a lot!

also dj_dave answer me in her discord, that she does a lot of sample manipulation outside sonic pi, and bring them into the program.