Okay, I’m running into a weird thing. Is it a bug? Or am I missing how to handle this?
I have a wav file that’s a funk guitar loop. I’m looping on it and randomly playing chunks using onset: pick. So far, so good. But when I try a pitch change, all of a sudden the clean attack turns into a soft swell.
What I think might be happening is that sonic pi is calculating where the transients are when the sample is un-pitch-shifted, then when it pitch shifts uses the old locations even though the actual location of the transients has shifted along with the pitch.
Is this a known bug? Or is there a way to compensate for this?
Here’s the code in question. I’m using a loop from looperman, located here: Free 110bpm Funk Guitar Electric Loops Samples Wav Download #353860
use_bpm 120
mysample = "D:\\Loops\\Afroplug - Soul and Jazz Guitar Loops\\looperman-l-6258600-0353860-spilled-coffee.wav"
64.times do
sample mysample ,onset: pick, pitch: 0, release: 0.5 if [true, true, true, false].choose
sleep 0.5
end
#this time with a pitch change
64.times do
sample mysample ,onset: pick, pitch: 2, release: 0.5 if [true, true, true, false].choose
sleep 0.5
end
Hi
when I pitch shift a sample slice I prefer to use the rate opt - perhaps for the reason you describe.
use_bpm 120
32.times do
sample :guit_em9, onset: pick, rate: 1, sustain: 0.25 if spread(3,4).choose
sleep 0.5
end
#this time with a pitch change
32.times do
sample :guit_em9, onset: pick, rate: 1.5, sustain: 0.25 if spread(3,4).choose
sleep 0.5
end
PD-Pi
It’s not a bug, it’s an effect of the pitch shifter. There are options for it, I don’t remember the exact names but you can find them in the help window. Setting the window size down should help.
As @brendanmac said, you probably want to use rate or rpitch, which takes semitones.
OK, thanks to you both. This clarifies things. Rpitch seems to do what I want (shifting by specified semitones), while rate is like an overall ration. So (if I understand) rpitch of 2 is up 2 semitones, while rate of 2 is double speed, aka up an octave?
Have I mentioned how great it is to have such a supportive community? Thsnks for all your patience as I clamber up the learning curve.

1 Like
Correct, rate of 2 is +1 octave; rpitch is more transparent/intuitive, but both will affect sample playback time as well as pitch.
5.times do |i|
tick
inc = i/12.0
sample :bass_hit_c, rate: 1+inc
sleep 1
end
5.times do |inc|
tick
sample :bass_voxy_hit_c, rpitch: 1+inc
sleep 1
end
PD-Pi