hi everyone thanks for your help so far below is a small simple riff played with the square synth:
live_loop :example do
with_swing 0.6 do
riff = (ring :e , :r , :g , :f , :r , :e)
is it possible to play this riff with a sample instead of the square synth and please could you explain to me how to do this? thanks for all your help
There is no built-in command to directly say ‘play note X with sample Y’. However, there are ways to change the pitch or the rate that a sample plays at. (Using opts for the
sample command such as
It’s definitely possible to write a function that takes into account your sample and a desired note to play at, which then calculates how much to adjust the pitch of the sample to match the desired note; but this would also depend on knowing beforehand (or being able to figure out, even if only approximately) the basic ‘note’ of the un-modified sample.
There is a short discussion at the topic http://in-thread.sonic-pi.net/t/tune-samples-with-a-note-input/1703 which may be of interest, with a function that @robin.newman once demonstrated for playing specific notes with a sample. Does any of it make any sense? - there’s comments in the code, and I’m sure we can explain the details as well
hi that makes sense thanks could I say for example using pitch or repitch set notes for the sample to play at?
hi everyone thanks for your help
Yes, you can use
rpitch: when calling
sample in your own function so that you can pass the function a note, and it works out the right pitch for the sample to play at. (The other topic I linked above - Tune samples with a note input shows an example: Robin’s
:plAmbiChoir function there takes a note to play at, a note length, and a number representing the ratio between the note’s sustain and release values, for a basic sound envelope, and plays the sample at the correct pitch). I’m sure you could use a similar function with your own samples - you’d just need to work out the basic pitch of your un-modified sample, as Robin describes in his thread.
Feel free to have a go at adapting Robin’s example if you like - I’m happy to help you if you want.